PtokaX forum

Archive => Archived 5.0 boards => Finished Scripts => Topic started by: bastya_elvtars on 28 February, 2005, 02:55:48

Title: Guestbook
Post by: bastya_elvtars on 28 February, 2005, 02:55:48
OK, i am faster than I thought... anyway, this is very test script, use at own risk. After optimization and debugging i will release a stable.

-- guestbook by bastya_elvtars (the rock n' roll doctor) ---> bastyaelvtars@gmail.com
--------------------------------
-- v2.0prebeta >>>>>>>> use with caution, bugs can occur
--------------------------------
--------------- THIS IS LUA5 VERSION NOW
-- thx Hawk and nErBoS for helping me out in my first lua5 script
-------------------------------------------------------------------------------------------------------------------------------------

-- no flush function, delete a dat file instead (gonna add if needed ^^)
-- multiple entries can be deleted by adding multiple nubers separated by spaces (meaning !delguestbook 1 43 555 756612346239)
-- but u can separate them with any non-number char if u like it better
-- commands can be added in PM or in main, bot responds according 2 them

--=========== IMPORTANT ================

-- DO make a folder called dats in the scripts folder!!! Otherwise it won't work!




---------------------- CONFIG PART


Bot="NoteBook"


-- i made only 3 of this add/show/delete shit.
-- if you need more, notify me
-- The help text can only be changed by experts,altho you might translate it - see a lua documentation
-- levels are always the following, determining who CAN use the command:
        -- 5:only superops
        -- 4 ops & above
        -- 3 vips & above
        -- 2 registered users & above
        -- 1 anyone
        -- 0 disabled
---=========== #1


-- What it is called?


gbname="guestbook" -- the name of this function (call it what you want)


-- name of the textfile that contains entries - if it does not exist, the script will create one.
gbfile="dats/guestbook.dat"


-- this shows the guestbook or wtf
levgbcmd1=1
gbcmd1="!showguestbook"
-- adds new entry to guestbook or wtf
levgbcmd2=1
gbcmd2="!addguestbook" -- deletes an entry by ID
levgbcmd3=5
gbcmd3="!delguestbook"





--========== #2


-- What it is called?


nname="news bulletin" -- the name of this function (call it what you want)


-- name of the textfile that contains entries - if it does not exist, the script will create one.
nfile="dats/news.dat"


-- this shows the news bulletin or wtf
levncmd1=1
ncmd1="!shownews"


-- adds new entry to news bulletin or wtf
levncmd2=1
ncmd2="!addnews"

-- deletes an entry by ID
levncmd3=5
ncmd3="!delnews"





--========== #3


-- What it is called?


rname="request board" -- the name of this function (call it what you want)


-- name of the textfile that contains entries - if it does not exist, the script will create one.
rfile="dats/requests.dat"


-- this shows the requests or wtf
levrcmd1=1
rcmd1="!showrequests"


-- adds new entry to requests or wtf
levrcmd2=1
rcmd2="!addrequest"

-- deletes an entry by ID
levrcmd3=5
rcmd3="!delrequest"



-------------------- END OF CONFIG


function parseenv(user,env,bot)
if env=="PM" then
return "$To: "..user.sName.." From: "..bot.." $<"..bot.."> "
elseif env=="MAIN" then
return "<"..bot.."> "
end
end


function ChatArrival(user,data)
local returndata=0
data=string.sub(data,1,string.len(data)-1)
local _,_,cmd = string.find(data,"%b<>%s+(%S+)")
if cmd then
returndata=parsecmds(user,data,string.lower(cmd),"MAIN")
end
end

function ToArrival(user,data)
local returndata=0
data=string.sub(data,1,string.len(data)-1)
-- is this meant for our bot?
local _,_,whoTo = string.find(data,"$To:%s+(%S+)")
if (whoTo == Bot) then
local _,_,cmd = string.find(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
returndata=parsecmds(user,data,string.lower(cmd),"PM")
end return returndata
end

function parsecmds(user,data,cmd,env)
local returndata=0
if cmd==gbcmd1 then
showshit(user,entries,gbname,gbfile,levgbcmd1,env) returndata=1 -- (user,container,wtf,file)
elseif cmd==gbcmd2 then
addshit(user,data,entries,gbfile,levgbcmd2,env) returndata=1 -- (user,data,container,file)
elseif cmd==gbcmd3 then
delshit(user,data,entries,gbfile,gbname,levgbcmd3,env) returndata=1 -- delshit(user,data,container,file,wtf)
-- news stuff
elseif cmd==ncmd1 then
showshit(user,entries,nname,nfile,levncmd1,env) returndata=1 -- (user,container,wtf,file)
elseif cmd==ncmd2 then
addshit(user,data,entries,nfile,levncmd2,env) returndata=1 -- (user,data,container,file)
elseif cmd==ncmd3 then
delshit(user,data,entries,nfile,nname,levncmd3,env) returndata=1 -- delshit(user,data,container,file,wtf)
-- requests stuff
elseif cmd==rcmd1 then
showshit(user,entries,rname,rfile,levrcmd1,env) returndata=1 -- (user,container,wtf,file)
elseif cmd==rcmd2 then
addshit(user,data,entries,rfile,levrcmd2,env) returndata=1 -- (user,data,container,file)
elseif cmd==rcmd3 then
delshit(user,data,entries,rfile,rname,levrcmd3,env) returndata=1 -- delshit(user,data,container,file,wtf)
end return returndata
end


function addshit(user,data,container,file,cmdlevel,env)
if cmdlevel~=0 then
if CheckUserLevel(user) >= cmdlevel then
local container=loadshit(file)
number=number+1
local _,_,entry=string.find(data,"%b<>%s+%S+%s+(.*)")
if entry then
container[number]=os.date("%c").."|"..user.sName.."|"..entry
saveshit(container,file)
user:SendData(parseenv(user,env,Bot).."Your entry has been successfully added.")
else
user:SendData(parseenv(user,env,Bot).."Please add an entry, too.")
end
container={}
else
user:SendData(parseenv(user,env,Bot).."You do not have sufficient rights to run that command! |")
end
else
user:SendData(parseenv(user,env,Bot).."That command is disabled.")
end
end


function loadshit(file)
local shit={}
number=0
local f,e = io.open(file,"r")
if f then
while 1 do
local line = f:read("*l")
if line ==  nil then
break
else
number = number +1
shit[number]=line
end
end
f:close(f)
end
return shit
end


function saveshit(container,file)
local handle = io.open(file,"w+")
for i=1,number do
if container[i] then
handle:write(container[i].."\n")
end
end
handle:flush()
        handle:close()
end

 function showshit(user,container,wtf,file,cmdlevel,env)
if cmdlevel~=0 then
if CheckUserLevel(user) >= cmdlevel then
local container=loadshit(file)
local msg="\r\nHere you go, the "..wtf..":\r\n\r\n"
if number>0 then
for i=1,number do
s,e,who,when,entry=string.find(container[i], "(.+)|(.+)|(.+)")
msg=msg..i..".\t"..who.." - "..when.." ---> "..entry.."\r\n"
end
else
msg=msg.."No entries in "..wtf.."."
end
user:SendPM(Bot,msg)
else
user:SendData(parseenv(user,env,Bot).."You do not have sufficient rights to run that command! |")
end
else
user:SendData(parseenv(user,env,Bot).."That command is disabled.")
end
end


function delshit(user,data,container,file,wtf,cmdlevel,env)
if cmdlevel~=0 then
if CheckUserLevel(user) >= cmdlevel then
local container=loadshit(file)
local _,_,args=string.find(data,"%b<>%s+%S+%s+(.+)")
if args then
string.gsub(args,"(%d+)",function (what)
what = tonumber(what)
if what then
if container[what] then
user:SendData(parseenv(user,env,Bot).."Entry #"..what.." is deleted from the "..wtf..".|")
container[what]=nil
saveshit(container,file)
else
user:SendData(parseenv(user,env,Bot).."Entry #"..what.." wasn't found in the "..wtf..".|")
end
else
user:SendData(parseenv(user,env,Bot).. "I need the ID number to delete an entry.|")
end
end)
else
user:SendData(parseenv(user,env,Bot).. "I need at least one ID number to work! ;).|")
end
else
user:SendData(parseenv(user,env,Bot).."You do not have sufficient rights to run that command! |")
end
else
user:SendData(parseenv(user,env,Bot).."That command is disabled.")
end
container=nil
end


function CheckUserLevel(user)
if user.iProfile==0 then
return 5
elseif user.iProfile==1 then
return 4
elseif user.iProfile==3 then
return 2
elseif user.iProfile==2 then
return 3
else
return 1
end
end


function Main()
frmHub:RegBot(Bot)
end
Title: stop cmd in main
Post by: Skynet on 01 March, 2005, 00:10:28
great script works fine is there any way of stopping the cmd going to main chat :>eg:

[TN]Skynet> !showrequests
Title:
Post by: TiMeTrAVelleR on 04 April, 2005, 17:04:53
What do i need to change  to get rit of commands showing in main

Greetzz TT
Title:
Post by: jiten on 04 April, 2005, 17:32:31
QuoteOriginally posted by T?M??r?V?ll?R
What do i need to change  to get rit of commands showing in main

Greetzz TT

Just add the red line to ChatArrival like this:

function ChatArrival(user,data)
local returndata=0
data=string.sub(data,1,string.len(data)-1)
local _,_,cmd = string.find(data,"%b<>%s+(%S+)")
if cmd then
returndata=parsecmds(user,data,string.lower(cmd),"MAIN")
[COLOR=red]return 1[/COLOR]
end
end


Cheers.
Title:
Post by: bastya_elvtars on 04 April, 2005, 18:01:10
Oooooooooooops, seems I have forgotten. Anyway, will release an updated version soon. Cheers!
Title:
Post by: TiMeTrAVelleR on 04 April, 2005, 18:05:21
Got this  now
Syntax ...tings\Roger.CP436745-A\Bureaublad\-=(TrAnCe)=- Hub\scripts\guestbook.lua:141: `=' expected near `end'

Greetzz   TT
Title:
Post by: bastya_elvtars on 04 April, 2005, 18:28:56
OMG this needs an urgent fix... l8r.
Title:
Post by: Syphrone-NL on 06 April, 2005, 19:07:32
I posted the script with the error in the wrong directory so heres my error again:

Syntax D:\ptokax\ptokax\scripts\guestbook.lua:243: attempt to concatenate global `entry' (a nil value)

I got this from 2 days ago and i didnt changed anything
Title:
Post by: bastya_elvtars on 07 April, 2005, 02:21:36
Sorry to say, but in the next 2 weeks I will not be able to do any scripting, I will be lucky if I can do my other tasks. Sorry guys.
Title: Creats its directory Alone
Post by: Skippy84 on 07 April, 2005, 02:27:12
-- guestbook by bastya_elvtars (the rock n' roll doctor) ---> [EMAIL]bastyaelvtars@gmail.com[/EMAIL]
--------------------------------
-- v2.1prebeta >>>>>>>> use with caution, bugs can occur
--------------------------------
--------------- THIS IS LUA5 VERSION NOW
-- thx Hawk and nErBoS for helping me out in my first lua5 script
-------------------------------------------------------------------------------------------------------------------------------------

-- no flush function, delete a dat file instead (gonna add if needed ^^)
-- multiple entries can be deleted by adding multiple nubers separated by spaces (meaning !delguestbook 1 43 555 756612346239)
-- but u can separate them with any non-number char if u like it better
-- commands can be added in PM or in main, bot responds according 2 them

-----------------------------------------------------------------------
-- little change by Skippy: script creates Directory Dats alone

---------------------- CONFIG PART


Bot="NoteBook"


-- i made only 3 of this add/show/delete shit.
-- if you need more, notify me
-- The help text can only be changed by experts,altho you might translate it - see a lua documentation
-- levels are always the following, determining who CAN use the command:
-- 5:only superops
-- 4 ops & above
-- 3 vips & above
-- 2 registered users & above
-- 1 anyone
-- 0 disabled
---=========== #1


-- What it is called?


gbname="guestbook" -- the name of this function (call it what you want)


-- name of the textfile that contains entries - if it does not exist, the script will create one.

path = "dats" -- set path to the  directory thats created
gbfile="dats/guestbook.dat"


levgbcmd1=1
gbcmd1="!showguestbook" -- this shows the guestbook or wtf
levgbcmd2=1
gbcmd2="!addguestbook" -- adds new entry to guestbook or wtf
levgbcmd3=5
gbcmd3="!delguestbook" -- deletes an entry by ID





--========== #2


-- What it is called?


nname="news bulletin" -- the name of this function (call it what you want)


-- name of the textfile that contains entries - if it does not exist, the script will create one.
nfile="dats/news.dat"


-- this shows the news bulletin or wtf
levncmd1=1
ncmd1="!shownews"


-- adds new entry to news bulletin or wtf
levncmd2=1
ncmd2="!addnews"

-- deletes an entry by ID
levncmd3=5
ncmd3="!delnews"





--========== #3


-- What it is called?


rname="request board" -- the name of this function (call it what you want)


-- name of the textfile that contains entries - if it does not exist, the script will create one.
rfile="dats/requests.dat"


-- this shows the requests or wtf
levrcmd1=1
rcmd1="!showrequests"


-- adds new entry to requests or wtf
levrcmd2=1
rcmd2="!addrequest"

-- deletes an entry by ID
levrcmd3=5
rcmd3="!delrequest"



-------------------- END OF CONFIG


os.execute("mkdir ".."\""..string.gsub(path, "/", "\\").."\"")




function parseenv(user,env,bot)
if env=="PM" then
return "$To: "..user.sName.." From: "..bot.." $<"..bot.."> "
elseif env=="MAIN" then
return "<"..bot.."> "
end
end


function ChatArrival(user,data)
local returndata=0
data=string.sub(data,1,string.len(data)-1)
local _,_,cmd = string.find(data,"%b<>%s+(%S+)")
if cmd then
returndata=parsecmds(user,data,string.lower(cmd),"MAIN")
end
end

function ToArrival(user,data)
local returndata=0
data=string.sub(data,1,string.len(data)-1)
-- is this meant for our bot?
local _,_,whoTo = string.find(data,"$To:%s+(%S+)")
if (whoTo == Bot) then
local _,_,cmd = string.find(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
returndata=parsecmds(user,data,string.lower(cmd),"PM")
end return returndata
end

function parsecmds(user,data,cmd,env)
local returndata=0
if cmd==gbcmd1 then
showshit(user,entries,gbname,gbfile,levgbcmd1,env) returndata=1 -- (user,container,wtf,file)
elseif cmd==gbcmd2 then
addshit(user,data,entries,gbfile,levgbcmd2,env) returndata=1 -- (user,data,container,file)
elseif cmd==gbcmd3 then
delshit(user,data,entries,gbfile,gbname,levgbcmd3,env) returndata=1 -- delshit(user,data,container,file,wtf)
-- news stuff
elseif cmd==ncmd1 then
showshit(user,entries,nname,nfile,levncmd1,env) returndata=1 -- (user,container,wtf,file)
elseif cmd==ncmd2 then
addshit(user,data,entries,nfile,levncmd2,env) returndata=1 -- (user,data,container,file)
elseif cmd==ncmd3 then
delshit(user,data,entries,nfile,nname,levncmd3,env) returndata=1 -- delshit(user,data,container,file,wtf)
-- requests stuff
elseif cmd==rcmd1 then
showshit(user,entries,rname,rfile,levrcmd1,env) returndata=1 -- (user,container,wtf,file)
elseif cmd==rcmd2 then
addshit(user,data,entries,rfile,levrcmd2,env) returndata=1 -- (user,data,container,file)
elseif cmd==rcmd3 then
delshit(user,data,entries,rfile,rname,levrcmd3,env) returndata=1 -- delshit(user,data,container,file,wtf)
end return returndata
end


function addshit(user,data,container,file,cmdlevel,env)
if cmdlevel~=0 then
if CheckUserLevel(user) >= cmdlevel then
local container=loadshit(file)
number=number+1
local _,_,entry=string.find(data,"%b<>%s+%S+%s+(.*)")
if entry then
container[number]=os.date("%c").."|"..user.sName.."|"..entry
saveshit(container,file)
user:SendData(parseenv(user,env,Bot).."Your entry has been successfully added.")
else
user:SendData(parseenv(user,env,Bot).."Please add an entry, too.")
end
container={}
else
user:SendData(parseenv(user,env,Bot).."You do not have sufficient rights to run that command! |")
end
else
user:SendData(parseenv(user,env,Bot).."That command is disabled.")
end
end


function loadshit(file)
local shit={}
number=0
local f,e = io.open(file,"r")
if f then
while 1 do
local line = f:read("*l")
if line == nil then
break
else
number = number +1
shit[number]=line
end
end
f:close(f)
end
return shit
end


function saveshit(container,file)
local handle = io.open(file,"w+")
for i=1,number do
if container[i] then
handle:write(container[i].."\n")
end
end
handle:flush()
handle:close()
end

function showshit(user,container,wtf,file,cmdlevel,env)
if cmdlevel~=0 then
if CheckUserLevel(user) >= cmdlevel then
local container=loadshit(file)
local msg="\r\nHere you go, the "..wtf..":\r\n\r\n"
if number>0 then
for i=1,number do
s,e,who,when,entry=string.find(container[i], "(.+)|(.+)|(.+)")
msg=msg..i..".\t"..who.." - "..when.." ---> "..entry.."\r\n"
end
else
msg=msg.."No entries in "..wtf.."."
end
user:SendPM(Bot,msg)
else
user:SendData(parseenv(user,env,Bot).."You do not have sufficient rights to run that command! |")
end
else
user:SendData(parseenv(user,env,Bot).."That command is disabled.")
end
end


function delshit(user,data,container,file,wtf,cmdlevel,env)
if cmdlevel~=0 then
if CheckUserLevel(user) >= cmdlevel then
local container=loadshit(file)
local _,_,args=string.find(data,"%b<>%s+%S+%s+(.+)")
if args then
string.gsub(args,"(%d+)",function (what)
what = tonumber(what)
if what then
if container[what] then
user:SendData(parseenv(user,env,Bot).."Entry #"..what.." is deleted from the "..wtf..".|")
container[what]=nil
saveshit(container,file)
else
user:SendData(parseenv(user,env,Bot).."Entry #"..what.." wasn't found in the "..wtf..".|")
end
else
user:SendData(parseenv(user,env,Bot).. "I need the ID number to delete an entry.|")
end
end)
else
user:SendData(parseenv(user,env,Bot).. "I need at least one ID number to work! ;).|")
end
else
user:SendData(parseenv(user,env,Bot).."You do not have sufficient rights to run that command! |")
end
else
user:SendData(parseenv(user,env,Bot).."That command is disabled.")
end
container=nil
end


function CheckUserLevel(user)
if user.iProfile==0 then
return 5
elseif user.iProfile==1 then
return 4
elseif user.iProfile==3 then
return 2
elseif user.iProfile==2 then
return 3
else
return 1
end
end


function Main()
frmHub:RegBot(Bot)
end


Title:
Post by: Skippy84 on 07 April, 2005, 02:34:39
@  Syphrone-NL   please can you post youre line 243
i hope i can help you





for german speaking people:
the german Version you find  today 15:00
at skippy.dyndns.ws\forum\index.php
Title:
Post by: Syphrone-NL on 08 April, 2005, 21:36:32
Oke i worked it out my script is now working
You cant post whole storys in it only 1 line that was my problem.

My second problem:
I can see !showguestbook and !addguestbook in mainchat. So i saw that you need to add a line in the script i did that but now my whole mainchat is blocked LOL  :D

NOT FUNNY

Can somebody help i dont want to block my whole mainchat only the !showguestbook and !addguestbook
Title:
Post by: jiten on 08 April, 2005, 22:04:49
QuoteOriginally posted by Syphrone-NL
Oke i worked it out my script is now working
You cant post whole storys in it only 1 line that was my problem.

My second problem:
I can see !showguestbook and !addguestbook in mainchat. So i saw that you need to add a line in the script i did that but now my whole mainchat is blocked LOL  :D

NOT FUNNY

Can somebody help i dont want to block my whole mainchat only the !showguestbook and !addguestbook

Howdy... Well, post your modded script so that we can help you.

Best regards,

jiten
Title:
Post by: bastya_elvtars on 08 April, 2005, 22:19:41
Inside

function ChatArrival(user,data)
replace

returndata=parsecmds(user,data,string.lower(cmd),"MAIN")
to

return parsecmds(user,data,string.lower(cmd),"MAIN")
.

:)
Title:
Post by: ???ZzC??? on 08 April, 2005, 23:23:34
Thanks bastya.

Nice script. And its running ok.

Greetz

Edit://

Still one command that shows in main.

!showguestbook

Eventhough there are some entries in guestbook it won't show.
Title:
Post by: ???ZzC??? on 11 April, 2005, 22:33:34
Script is working ok now.

Made mistake.

Thanks

 :D
Title:
Post by: Syphrone-NL on 14 April, 2005, 07:52:57
I got its working great this is what i changed:

function ChatArrival(user,data)
local returndata=0
data=string.sub(data,1,string.len(data)-1)
local _,_,cmd = string.find(data,"%b<>%s+(%S+)")
if cmd then
return parsecmds(user,data,string.lower(cmd),"MAIN")
end
end
Title:
Post by: remaster-it on 15 April, 2005, 23:23:13
Nice ..  works  well  .. thx

a small request  ..  

if a new message is posted / added  to News...  guestbook   or   request  files   ..  
can we have the option for notifying ops by sending a message to the ops room  
( including  which  dat file has been added 2 ) ..
Title:
Post by: remaster-it on 16 April, 2005, 09:28:25
If you have the moderator and netfounder  profiles in your hub  u need to change the following ..

function CheckUserLevel(user)
   if user.iProfile==0 then
      return 5
   elseif user.iProfile==1 then
      return 4
   elseif user.iProfile==3 then
      return 2
   elseif user.iProfile==2 then
      return 3
   else
      return 1
   end
end


---------------    to the following


function CheckUserLevel(user)
   if user.iProfile==0 then
      return 5
   elseif user.iProfile==1 then
      return 4
   elseif user.iProfile==3 then
      return 2
   elseif user.iProfile==2 then
      return 3
   elseif user.iProfile==4 then
      return 4
   elseif user.iProfile==5 then
      return 5
   else
      return 1
   end
end

I have also added the following to the zrightclicker.lua

NEWS AND GUEST BOOK

sMenu = "RC"
wMenu = "NEWS AND GUEST BOOK"


and  

customCMDs = function(user) --// You can put your custome commands here
   user:SendData("$UserCommand 1 3 "..wMenu.."\\REQUESTS\\ADD A REQUEST$<%[mynick]> !addrequest %[line:Type request]||")
   user:SendData("$UserCommand 1 3 "..wMenu.."\\REQUESTS\\READ REQUEST$<%[mynick]> !showrequests||")
   user:SendData("$UserCommand 1 3 "..wMenu.."\\REQUESTS\\DELETE A REQUEST ENTRY$<%[mynick]> !delrequest %[line:ENTER NUMBER TO DELETE]||")
   user:SendData("$UserCommand 1 3 "..wMenu.."\\NEWS\\ADD NEWS BULLETIN$<%[mynick]> !addnews %[line:Type NEWS MESSAGE]||")
   user:SendData("$UserCommand 1 3 "..wMenu.."\\NEWS\\READ NEWS$<%[mynick]> !shownews||")
   user:SendData("$UserCommand 1 3 "..wMenu.."\\NEWS\\DELETE A NEWS ENTRY$<%[mynick]> !delnews %[line:ENTER NUMBER TO DELETE]||")
   user:SendData("$UserCommand 1 3 "..wMenu.."\\GUEST BOOK\\ADD A MESSAGE TO THE GUEST BOOK$<%[mynick]> !addguestbook %[line:Type MESSAGE]||")
   user:SendData("$UserCommand 1 3 "..wMenu.."\\GUEST BOOK\\READ GUEST BOOK$<%[mynick]> !showguestbook||")
   user:SendData("$UserCommand 1 3 "..wMenu.."\\GUEST BOOK\\DELETE A GUEST BOOK ENTRY$<%[mynick]> !delguestbook %[line:ENTER NUMBER TO DELETE]||")