first part !!!!
-------------------------------------------------------------
-- Database script - Originally Created by Guibs Feb, 2003 --
-- Latest Version - v1.3 written by Guibs 12th Apr 2003 --
-------------------------------------------------------------
---------------------
-- Version History --
---------------------
-- v1.3 Post/Req/News titles & contains can be now 'very long', by Guibs Apr-12, 2003
-- v1.3 Added !news ?new !new !delnew, by Guibs Apr-11, 2003
-- v1.3 Changed !help to !helpd, by Guibs Apr-12, 2003
-- v1.3 Script re-written, by Guibs Apr-11, 2003
-- v1.2 Major Bug fixed : the '?post NoId' and '?req NoId' commands, by Guibs Feb, 2003
-- v1.1 Added !req ?req ?reqs !delreq, by Guibs Feb, 2003
-- v1.0 First version, by Guibs Feb, 2003
------------------------------------
-- Sourcecode is below this point --
------------------------------------
-------------------
-- Main function --
-------------------
function Main()
Bot="![Database]?"
gr=strrep("-",100)
frmHub:RegBot(Bot)
end
------------------
-- Data Arrival --
------------------
function DataArrival(user, data)
returndata = 0
if(strsub(data, 1, 4) == "$To:") then
data=strsub(data,1,strlen(data)-1)
s,e,whoTo = strfind(data,"$To:%s+(%S+)")
s,e,To,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.*)")
if (whoTo == Bot) then
s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")
if (cmd=="!helpd")then
user:SendPM(Bot,"\r\n\?news\t\t\t- Show all the news\r\n?new
\t\t- Read a news, by the NewsId\r\n!new subject#article#\t- Write a news - send it to all users in pm\r\n!delnew \t\t- Delete a news, by the NewsId\r\n\?posts\t\t\t- Show all the posts\r\n?post \t\t- Read the post, by the PostId\r\n!post subject#article#\t- Write a new post - send it to all users in pm\r\n!delpost \t\t- Delete a post, by the PostId\r\n\?reqs\t\t\t- Show all the requests\r\n?req \t\t- Read the request, by the ReqId\r\n!req subject#article#\t- Write a new request - send it to all users in pm\r\n!delreq \t\t- Delete a request, by the ReqId\r\n!helpd\t\t\t- This help again\r\n")
elseif (cmd=="?posts") then
DoShowAllPosts(user)
elseif (cmd=="?post") then
ShowPost(user,data)
elseif (cmd=="!post") then
Post(user,data)
elseif (cmd=="!delpost") then
if user.bOperator then
DeletePost(user,data)
end
elseif (cmd=="?reqs") then
DoShowAllReqs(user)
elseif (cmd=="?req") then
ShowReq(user,data)
elseif (cmd=="!req") then
Req(user,data)
elseif (cmd=="!delreq") then
if user.bOperator then
DeleteReq(user,data)
end
elseif (cmd=="?news") then
DoShowAllNews(user)
elseif (cmd=="?new") then
ShowNew(user,data)
elseif (cmd=="!new") then
if user.bOperator then
New(user,data)
end
elseif (cmd=="!delnew") then
if user.bOperator then
DeleteNew(user,data)
end
end
end
end
end
-- New News --
function New(user,data)
arg = GetLongArgPM(data)
if arg ~= nil then
arg2 = GetLongArgRemnantsPM(user,data)
if arg2 ~= nil then
DoNew(user,arg,arg2)
else
user:SendPM(Bot,"Wrong synthax: !new subject#article#")
end
else
user:SendPM(Bot,"Wrong synthax: !new subject#article#")
end
end
function DoNew(user,arg,arg2)
GetnewId()
Date = GetTime()
entry = d..s..h..user.sName..newnb.."|"..arg.."|"..Date.."|"..user.sName.."|"..newnb
local temp={}
TextLoad("database/news/news.lst",temp)
tinsert(temp,entry)
TextSave("database/news/news.lst",temp)
local handle=openfile("database/news/"..d..s..h..user.sName..newnb..".txt","a")
write(handle,(arg2))
closefile(handle)
SendPmToAll("[News?]","\r\nFrom: "..user.sName.."\r\nDate: ["..Date.."]\r\nSubject: "..arg.."\r\nNew:\r\n"..arg2.."\r\n"..newnb)
user:SendPM(Bot,"News Written :o)")
end
-- Show New By NewId --
function ShowNew(user,data)
arg = GetSingleNumPM(data)
if arg ~= nil then
DoShowNew(arg)
if list ~= nil then
user:SendPM(Bot,list)
else
user:SendPM(Bot,"No output for news No: "..arg)
end
else
user:SendPM(Bot,"Wrong synthax: ?new ")
end
end
function DoShowNew(number)
newname,title,newdate,sender,newid=nil,nil,nil,nil,nil
list=""
new=""
local temp={}
r=0
TextLoad("database/news/news.lst",temp)
for x=1,getn(temp) do s,e,newname,title,newdate,sender,newid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
if (number==newid) then
r=r+1
break
end
end
if (r==0) then
list=nil
else
readfrom("database/news/"..newname..".txt")
while 1 do
local line = read()
if (line == nil) then
break
else
new = new..line.."\r\n"
end
end
readfrom()
list=list.."\r\nTitle: "..title.."\r\nBy: "..sender.."\r\nDate: "..newdate.."\r\nContains:\r\n\r\n"..new.."\r\nNewid: "..newid
end
return list
end
-- Show All The News --
function DoShowAllNews(user)
newname,title,newdate,sender,newid=nil,nil,nil,nil,nil
local temp={}
r=0
TextLoad("database/news/news.lst",temp)
list="\r\n\r\n\tSubject\t\t\tBy\t\t\Date\t\t\NewsId\r\n\t"..gr.."\r\n"
for x=1,getn(temp) do s,e,newname,title,newdate,sender,newid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
list=list.."\t"..title.."\t\t"..sender.."\t\t"..newdate.."\t\t"..newid.."\r\n"
r=r+1
end
if (r==0) then
list="No output."
else
list=list.."\t"..gr.."\r\n\tNews Record count: "..r.."\r\n"
end
user:SendPM(Bot,list)
end
-- Get NewId --
function GetnewId()
newname,title,newdate,sender,newid=nil,nil,nil,nil,nil
local temp={}
newnb=1
TextLoad("database/news/news.lst",temp)
for x=1,getn(temp) do s,e,newname,title,newdate,sender,newid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
if newid == nil then
else
newnb=newnb+1
end
end
return newnb
end
-- Delete A New by NewId --
function DeleteNew(user,data)
arg = GetSingleNumPM(data)
if arg ~= nil then
DoShowNew(arg)
if list ~= nil then
DoDeleteNew(arg)
user:SendPM(Bot,"News No "..arg.." deleted :o)")
else
user:SendPM(Bot,arg.." can't be find as NewsId")
end
else
user:SendPM(Bot,"Wrong synthax: !delnew ")
end
end
function DoDeleteNew(number)
newname,title,newdate,sender,newid=nil,nil,nil,nil,nil
local temp={}
newnb=1
TextLoad("database/news/news.lst",temp)
for x=1,getn(temp) do s,e,newname,title,newdate,sender,newid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
if (number==newid) then
break
end
end
remove("database/news/"..newname..".txt")
TextLoad("database/news/news.lst",temp)
for x=1,getn(temp) do s,e,newname,title,newdate,sender,newid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
if (number==newid) then
else
newlist=newname.."|"..title.."|"..newdate.."|"..sender.."|"..newnb
newnb=newnb+1
local temp={}
TextLoad("database/news/news.temp.lst",temp)
tinsert(temp,newlist)
TextSave("database/news/news.temp.lst",temp)
end
end
remove("database/news/news.lst")
newname,title,newdate,sender,newid=nil,nil,nil,nil,nil
local temp={}
TextLoad("database/news/news.temp.lst",temp)
for x=1,getn(temp) do s,e,newname,title,newdate,sender,newid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
newlist=newname.."|"..title.."|"..newdate.."|"..sender.."|"..newid
local temp={}
TextLoad("database/news/news.lst",temp)
tinsert(temp,newlist)
TextSave("database/news/news.lst",temp)
end
remove("database/news/news.temp.lst")
end
-- New Req --
function Req(user,data)
arg = GetLongArgPM(data)
if arg ~= nil then
arg2 = GetLongArgRemnantsPM(user,data)
if arg2 ~= nil then
user:SendPM(Bot,"arg: "..arg.."\r\narg2: "..arg2)
DoReq(user,arg,arg2)
else
user:SendPM(Bot,"Wrong synthax: !req subject#article#")
end
else
user:SendPM(Bot,"Wrong synthax: !req subject#article#")
end
end
function DoReq(user,arg,arg2)
GetreqId()
Date = GetTime()
entry = d..s..h..user.sName..reqnb.."|"..arg.."|"..Date.."|"..user.sName.."|"..reqnb
local temp={}
TextLoad("database/reqs/reqs.lst",temp)
tinsert(temp,entry)
TextSave("database/reqs/reqs.lst",temp)
local handle=openfile("database/reqs/"..d..s..h..user.sName..reqnb..".txt","a")
write(handle,(arg2))
closefile(handle)
SendPmToAll("[Req?]","\r\nFrom: "..user.sName.."\r\nDate: ["..Date.."]\r\nSubject: "..arg.."\r\nReq:\r\n"..arg2.."\r\n"..reqnb)
user:SendPM(Bot,"Req Written :o)")
end
-- Show Req By ReqId --
function ShowReq(user,data)
arg = GetSingleNumPM(data)
second part !!!
if arg ~= nil then
DoShowReq(arg)
if list ~= nil then
user:SendPM(Bot,list)
else
user:SendPM(Bot,"No output for req No: "..arg)
end
else
user:SendPM(Bot,"Wrong synthax: ?req
")
end
end
function DoShowReq(number)
reqname,title,reqdate,sender,reqid=nil,nil,nil,nil,nil
list=""
req=""
local temp={}
r=0
TextLoad("database/reqs/reqs.lst",temp)
for x=1,getn(temp) do s,e,reqname,title,reqdate,sender,reqid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
if (number==reqid) then
r=r+1
break
end
end
if (r==0) then
list=nil
else
readfrom("database/reqs/"..reqname..".txt")
while 1 do
local line = read()
if (line == nil) then
break
else
req = req..line.."\r\n"
end
end
readfrom()
list=list.."\r\nTitle: "..title.."\r\nBy: "..sender.."\r\nDate: "..reqdate.."\r\nContains:\r\n\r\n"..req.."\r\nReqid: "..reqid
end
return list
end
-- Show All The Reqs --
function DoShowAllReqs(user)
reqname,title,reqdate,sender,reqid=nil,nil,nil,nil,nil
local temp={}
r=0
TextLoad("database/reqs/reqs.lst",temp)
list="\r\n\r\n\tSubject\t\t\tBy\t\t\Date\t\t\ReqId\r\n\t"..gr.."\r\n"
for x=1,getn(temp) do s,e,reqname,title,reqdate,sender,reqid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
list=list.."\t"..title.."\t\t"..sender.."\t\t"..reqdate.."\t\t"..reqid.."\r\n"
r=r+1
end
if (r==0) then
list="No output."
else
list=list.."\t"..gr.."\r\n\tReqs Record count: "..r.."\r\n"
end
user:SendPM(Bot,list)
end
-- Get ReqId --
function GetreqId()
reqname,title,reqdate,sender,reqid=nil,nil,nil,nil,nil
local temp={}
reqnb=1
TextLoad("database/reqs/reqs.lst",temp)
for x=1,getn(temp) do s,e,reqname,title,reqdate,sender,reqid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
if reqid == nil then
else
reqnb=reqnb+1
end
end
return reqnb
end
-- Delete A Req by ReqId --
function DeleteReq(user,data)
arg = GetSingleNumPM(data)
if arg ~= nil then
DoShowReq(arg)
if list ~= nil then
DoDeleteReq(arg)
user:SendPM(Bot,"Req No "..arg.." deleted :o)")
else
user:SendPM(Bot,arg.." can't be find as ReqId")
end
else
user:SendPM(Bot,"Wrong synthax: !delreq ")
end
end
function DoDeleteReq(number)
reqname,title,reqdate,sender,reqid=nil,nil,nil,nil,nil
local temp={}
reqnb=1
TextLoad("database/reqs/reqs.lst",temp)
for x=1,getn(temp) do s,e,reqname,title,reqdate,sender,reqid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
if (number==reqid) then
break
end
end
remove("database/reqs/"..reqname..".txt")
TextLoad("database/reqs/reqs.lst",temp)
for x=1,getn(temp) do s,e,reqname,title,reqdate,sender,reqid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
if (number==reqid) then
else
newlist=reqname.."|"..title.."|"..reqdate.."|"..sender.."|"..reqnb
reqnb=reqnb+1
local temp={}
TextLoad("database/reqs/reqs.temp.lst",temp)
tinsert(temp,newlist)
TextSave("database/reqs/reqs.temp.lst",temp)
end
end
remove("database/reqs/reqs.lst")
reqname,title,reqdate,sender,reqid=nil,nil,nil,nil,nil
local temp={}
TextLoad("database/reqs/reqs.temp.lst",temp)
for x=1,getn(temp) do s,e,reqname,title,reqdate,sender,reqid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
newlist=reqname.."|"..title.."|"..reqdate.."|"..sender.."|"..reqid
local temp={}
TextLoad("database/reqs/reqs.lst",temp)
tinsert(temp,newlist)
TextSave("database/reqs/reqs.lst",temp)
end
remove("database/reqs/reqs.temp.lst")
end
-- New Post --
function Post(user,data)
arg = GetLongArgPM(data)
if arg ~= nil then
arg2 = GetLongArgRemnantsPM(user,data)
if arg2 ~= nil then
user:SendPM(Bot,"arg: "..arg.."\r\narg2: "..arg2)
DoPost(user,arg,arg2)
else
user:SendPM(Bot,"Wrong synthax: !post subject#article#")
end
else
user:SendPM(Bot,"Wrong synthax: !post subject#article#")
end
end
function DoPost(user,arg,arg2)
GetpostId()
Date = GetTime()
entry = d..s..h..user.sName..postnb.."|"..arg.."|"..Date.."|"..user.sName.."|"..postnb
local temp={}
TextLoad("database/posts/posts.lst",temp)
tinsert(temp,entry)
TextSave("database/posts/posts.lst",temp)
local handle=openfile("database/posts/"..d..s..h..user.sName..postnb..".txt","a")
write(handle,(arg2))
closefile(handle)
SendPmToAll("[Post?]","\r\nFrom: "..user.sName.."\r\nDate: ["..Date.."]\r\nSubject: "..arg.."\r\nPost:\r\n"..arg2.."\r\n"..postnb)
user:SendPM(Bot,"Post Written :o)")
end
-- Show Post By PostId --
function ShowPost(user,data)
arg = GetSingleNumPM(data)
if arg ~= nil then
DoShowPost(arg)
if list ~= nil then
user:SendPM(Bot,list)
else
user:SendPM(Bot,"No output for post No: "..arg)
end
else
user:SendPM(Bot,"Wrong synthax: ?post ")
end
end
function DoShowPost(number)
postname,title,postdate,sender,postid=nil,nil,nil,nil,nil
list=""
post=""
local temp={}
r=0
TextLoad("database/posts/posts.lst",temp)
for x=1,getn(temp) do s,e,postname,title,postdate,sender,postid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
if (number==postid) then
r=r+1
break
end
end
if (r==0) then
list=nil
else
readfrom("database/posts/"..postname..".txt")
while 1 do
local line = read()
if (line == nil) then
break
else
post = post..line.."\r\n"
end
end
readfrom()
list=list.."\r\nTitle: "..title.."\r\nBy: "..sender.."\r\nDate: "..postdate.."\r\nContains:\r\n\r\n"..post.."\r\nPostid: "..postid
end
return list
end
-- Show All The Posts --
function DoShowAllPosts(user)
postname,title,postdate,sender,postid=nil,nil,nil,nil,nil
local temp={}
r=0
TextLoad("database/posts/posts.lst",temp)
list="\r\n\r\n\tSubject\t\t\tBy\t\t\Date\t\t\PostId\r\n\t"..gr.."\r\n"
for x=1,getn(temp) do s,e,postname,title,postdate,sender,postid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
list=list.."\t"..title.."\t\t"..sender.."\t\t"..postdate.."\t\t"..postid.."\r\n"
r=r+1
end
if (r==0) then
list="No output."
else
list=list.."\t"..gr.."\r\n\tPosts Record count: "..r.."\r\n"
end
user:SendPM(Bot,list)
end
-- Get PostId --
function GetpostId()
postname,title,postdate,sender,postid=nil,nil,nil,nil,nil
local temp={}
postnb=1
TextLoad("database/posts/posts.lst",temp)
for x=1,getn(temp) do s,e,postname,title,postdate,sender,postid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
if postid == nil then
else
postnb=postnb+1
end
end
return postnb
end
-- Delete A Post by PostId --
function DeletePost(user,data)
arg = GetSingleNumPM(data)
if arg ~= nil then
DoShowPost(arg)
if list ~= nil then
DoDeletePost(arg)
user:SendPM(Bot,"Post No "..arg.." deleted :o)")
else
user:SendPM(Bot,arg.." can't be find as PostId")
end
else
user:SendPM(Bot,"Wrong synthax: !delpost ")
end
end
function DoDeletePost(number)
postname,title,postdate,sender,postid=nil,nil,nil,nil,nil
local temp={}
postnb=1
TextLoad("database/posts/posts.lst",temp)
for x=1,getn(temp) do s,e,postname,title,postdate,sender,postid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
if (number==postid) then
break
end
end
remove("database/posts/"..postname..".txt")
TextLoad("database/posts/posts.lst",temp)
for x=1,getn(temp) do s,e,postname,title,postdate,sender,postid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
if (number==postid) then
else
newlist=postname.."|"..title.."|"..postdate.."|"..sender.."|"..postnb
postnb=postnb+1
local temp={}
TextLoad("database/posts/posts.temp.lst",temp)
tinsert(temp,newlist)
TextSave("database/posts/posts.temp.lst",temp)
end
end
remove("database/posts/posts.lst")
postname,title,postdate,sender,postid=nil,nil,nil,nil,nil
local temp={}
TextLoad("database/posts/posts.temp.lst",temp)
for x=1,getn(temp) do s,e,postname,title,postdate,sender,postid=strfind(temp- ,"(.-)|(.-)|(.-)|(.-)|(%S+)")
newlist=postname.."|"..title.."|"..postdate.."|"..sender.."|"..postid
local temp={}
TextLoad("database/posts/posts.lst",temp)
tinsert(temp,newlist)
TextSave("database/posts/posts.lst",temp)
end
remove("database/posts/posts.temp.lst")
end
--------- Text Loaded ---------
function TextLoad(file,array,text) array[0]="" local x=0
readfrom(file)
repeat if (text) then text=text..array- .."\r\n" end x=x+1 array
- =read() until (array
- ==nil)
readfrom() return text
end
--------- Text Written ---------
function TextSave(file,array)
writeto(file)
for x=1,getn(array) do write(array writeto()
end
----------------------------------
function GetSingleNumPM(data)
s,e,cmd,arg = strfind(data,"$%b<>%s+(%S+)%s+(%d+)")
return arg
end
function GetArgPM(data)
s,e,cmd,arg = strfind(data,"$%b<>%s+(%S+)%s+(%S+)")
return arg
end
function GetLongArgPM(data)
s,e,cmd,arg = strfind(data,"$%b<>%s+(%S+)%s+(.*)#")
return arg
end
function GetLongArgRemnantsPM(user, data)
s,e,cmd,arg,arg2 = strfind(data,"$%b<>%s+(%S+)%s+(.*)#+(.*)#")
return arg2
end
--------- Get Time ---------
function GetTime()
s = date("%S")
h = date("%H")
m = date("%M")
d = date("%d")
mm = date("%m")
y = date("%y")
Date = d.."."..mm.."."..y.." Time: "..h..":"..m..":"..s
return Date
end
Hi all !
been trie to work this script for a wall no but I have not got this working
I have been add a txt file in every folder but no it will not work anyway ......
hope some any can help me with this problem .....
Hallo again !
I get this fr?n the database ....
Wrong synthax ???????
I would be very happy if some one can help me with this problem .......
?news - Show all the news
?new
- Read a news, by the NewsId
!new subject#article# - Write a news - send it to all users in pm
!delnew - Delete a news, by the NewsId
?posts - Show all the posts
?post - Read the post, by the PostId
!post subject#article# - Write a new post - send it to all users in pm
!delpost - Delete a post, by the PostId
?reqs - Show all the requests
?req - Read the request, by the ReqId
!req subject#article# - Write a new request - send it to all users in pm
!delreq - Delete a request, by the ReqId
!helpd - This help again
<[BBB]nisse> ?news
No output.
<[BBB]nisse> !post bla bla bla
Wrong synthax: !post subject#article#
<[BBB]nisse> ?post
Wrong synthax: ?post ?
my bet is that your database is still empty, so there is never something 2 be shown.
try adding something and then check a bit better how the commands work, as you mix it up a little in your example.
plop
alright I understand but the think I could add some thing new with out me add some think in to the text file so the user?s could do this of the own I tought this was possible in this script .......
never used this script myself but try this.
!new test#is this working#
after that type
?news
and it should show the test msg.
plop