PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: damo on 20 May, 2005, 00:26:35

Title: seen bot
Post by: damo on 20 May, 2005, 00:26:35
can anyone help me finish converting this seen bot please.
can it be changed to send answers in pm please. heres the script

BotName = "LeonBot"

SeenTrigger = "!seen"



minLen = 2

maxLen = 20

seenArray={}



function Main()

frmHub:RegBot(BotName)

end



function NewUserConnected(curUser)

local boolDisc = 0

if string.len(curUser.sName) < minLen then

curUser:SendPM(BotName, "Your nick is to short, a minimum of "..minLen.." chars is required!")

curUser:SendPM(BotName, "Disconnecting...")

curUser:Disconnect()

boolDisc = 1

elseif string.len(curUser.sName) > maxLen then

curUser:SendPM(BotName, "Your nick is to long, a maximum of "..maxLen.." chars is required!")

curUser:SendPM(BotName, "Disconnecting...")

curUser:Disconnect()

boolDisc = 1

elseif ( string.find (curUser.sName, " ", 1, 1) ) then

curUser:SendPM(BotName, "Spaces not allowed in nicknames!")

curUser:SendPM(BotName, "Disconnecting...")

curUser:Disconnect()

boolDisc = 1

end

if (boolDisc == 0) then

seenArray[curUser.sName]=os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")

end

end



function OpConnected(curUser)

seenArray[curUser.sName]=os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")

end



function OpDisconnected(curUser)

seenArray[curUser.sName]=os.date(curUser.sName.." disconnected at %d/%m/%Y %T and has not been seen since.")

end



function UserDisconnected(curUser)

seenArray[curUser.sName]=os.date(curUser.sName.." disconnected at %d/%m/%Y %T and has not been seen since.")

end



function DataArrival(curUser, data)

seenArray[curUser.sName]=os.date(curUser.sName.." was last seen at %d/%m/%Y %T writing things.")

if( string.sub(data, 1, 1) == "<" ) then

data=string.sub(data,1,string.len(data)-1)

_,_,cmd,arg = string.find( data, "%b<>%s+(%S+)%s+(%S+)" )

if (cmd == SeenTrigger) then

if (arg == curUser.sName) then

SendToAll(BotName, "You should not do #seen's for yourself ;)" )

elseif (seenArray[arg] ~= nil) then

SendToAll(BotName, "User: "..seenArray[arg] )

else

SendToAll(BotName, "I have not seen "..arg.."!" )

end

end

end

end
Title:
Post by: Dessamator on 20 May, 2005, 20:24:24
[COLOR=red]function DataArrival(curUser, data) [/COLOR]  
seenArray[curUser.sName]=os.date(curUser.sName.." was last seen at %d/%m/%Y %T writing things.")
[COLOR=blue]if( string.sub(data, 1, 1) == "<" ) then[/COLOR]
data=string.sub(data,1,string.len(data)-1)
_,_,cmd,arg = string.find( data, "%b<>%s+(%S+)%s+(%+)" )
if (cmd == SeenTrigger) then
if (arg == curUser.sName) then
[COLOR=red]SendToAll(BotName, "You should not do #seen's for yourself ;)" )  [/COLOR]  
elseif (seenArray[arg] ~= nil) then
[COLOR=red]SendToAll(BotName, "User: "..seenArray[arg] )   [/COLOR]  
else
[COLOR=red]SendToAll(BotName, "I have not seen "..arg.."!" ) [/COLOR]  
[COLOR=blue]end [/COLOR]  
end
end

end


yap sure, change the lines in red as follows:
Change from DataArrival to ChatArrival
Change from SendToAll to curUser:SendPM
and delete the lines in blue

Good luck !
Title: RE Seen
Post by: damo on 21 May, 2005, 14:08:27
changed and deleted lines but for some reason still dont wonna work. no errors comeing up to any thoughts
Title:
Post by: 6Marilyn6Manson6 on 21 May, 2005, 14:16:06
try this [ not tested ]:

BotName = "LeonBot"
SeenTrigger = "!seen"

minLen = 2
maxLen = 20
seenArray={}

function Main()
frmHub:RegBot(BotName)
end

function NewUserConnected(curUser)
local boolDisc = 0
if string.len(curUser.sName) < minLen then
curUser:SendPM(BotName, "Your nick is to short, a minimum of "..minLen.." chars is required!")
curUser:SendPM(BotName, "Disconnecting...")
curUser:Disconnect()
boolDisc = 1
elseif string.len(curUser.sName) > maxLen then
curUser:SendPM(BotName, "Your nick is to long, a maximum of "..maxLen.." chars is required!")
curUser:SendPM(BotName, "Disconnecting...")
curUser:Disconnect()
boolDisc = 1
elseif ( string.find (curUser.sName, " ", 1, 1) ) then
curUser:SendPM(BotName, "Spaces not allowed in nicknames!")
curUser:SendPM(BotName, "Disconnecting...")
curUser:Disconnect()
boolDisc = 1
end
if (boolDisc == 0) then
seenArray[curUser.sName]=os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")
end
end

function OpConnected(curUser)
seenArray[curUser.sName]=os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")
end

function OpDisconnected(curUser)
seenArray[curUser.sName]=os.date(curUser.sName.." disconnected at %d/%m/%Y %T and has not been seen since.")
end

function UserDisconnected(curUser)
seenArray[curUser.sName]=os.date(curUser.sName.." disconnected at %d/%m/%Y %T and has not been seen since.")
end

function ChatArrival(curUser, data)
seenArray[curUser.sName]=os.date(curUser.sName.." was last seen at %d/%m/%Y %T writing things.")
data=string.sub(data,1,string.len(data)-1)
_,_,cmd,arg = string.find( data, "%b<>%s+(%S+)%s+(%S+)" )
if (cmd == SeenTrigger) then
if (arg == curUser.sName) then
curUser:SendPM(BotName, "You should not do #seen's for yourself ;)" )
elseif (seenArray[arg] ~= nil) then
curUser:SendPM(BotName, "User: "..seenArray[arg] )
else
curUser:SendPM(BotName, "I have not seen "..arg.."!" )
end
end
end

c ya
Title: re seen
Post by: damo on 21 May, 2005, 16:13:12
thx for the help this script works but can i stop it from posting the command and who you are seeing in main
as i have users with nicks like [DH]damo then sends the pm like its suposed to but also sends the command and user name to main
Title:
Post by: Ubikk on 25 May, 2005, 07:31:46
Nice script. But can you guys also ad something like this?

howToSend = 2,       -- 1:Sends to all / 2:Sends to user / 3:PM to the user / 4:PM to the user and regs a bot.

:)

Thanks in advance :D
Title:
Post by: Madman on 25 May, 2005, 17:07:34
-- Creator Leon
-- Started lua 5 conversion, damo
-- Fully converted to lua 5 by 6Marilyn6Manson6
---- Modded By Madman
-- Added save to file
-- Added HowToSend, request by Ubikk
-- Hidden the command, request by damo

BotName = "LeonBot"
SeenTrigger = "!seen"

minLen = 2
maxLen = 20
HowToSend = 3 -- 1: Send to all, 2: Send to user, 3: PM to the user

require("seen.dat")

function Main()
if HowToSend == 3 then
frmHub:RegBot(BotName)
end
end

function NewUserConnected(curUser)
local boolDisc = 0
if string.len(curUser.sName) < minLen then
curUser:SendPM(BotName, "Your nick is to short, a minimum of "..minLen.." chars is required!")
curUser:SendPM(BotName, "Disconnecting...")
curUser:Disconnect()
boolDisc = 1
elseif string.len(curUser.sName) > maxLen then
curUser:SendPM(BotName, "Your nick is to long, a maximum of "..maxLen.." chars is required!")
curUser:SendPM(BotName, "Disconnecting...")
curUser:Disconnect()
boolDisc = 1
elseif ( string.find (curUser.sName, " ", 1, 1) ) then
curUser:SendPM(BotName, "Spaces not allowed in nicknames!")
curUser:SendPM(BotName, "Disconnecting...")
curUser:Disconnect()
boolDisc = 1
end
if (boolDisc == 0) then
if seenArray[curUser.sName] == nil then
seenArray[curUser.sName] = {}
seenArray[curUser.sName] = os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")
SaveToFile("Seen.dat", seenArray, "seenArray")
else
seenArray[curUser.sName] = os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")
SaveToFile("Seen.dat", seenArray, "seenArray")
end
end
end

function OpConnected(curUser)
if seenArray[curUser.sName] == nil then
seenArray[curUser.sName] = {}
seenArray[curUser.sName] = os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")
SaveToFile("Seen.dat", seenArray, "seenArray")
else
seenArray[curUser.sName] = os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")
SaveToFile("Seen.dat", seenArray, "seenArray")
end
end

function OpDisconnected(curUser)
if seenArray[curUser.sName] == nil then
seenArray[curUser.sName] = {}
seenArray[curUser.sName] = os.date(curUser.sName.." disconnected at %d/%m/%Y %T and has not been seen since.")
SaveToFile("Seen.dat", seenArray, "seenArray")
else
seenArray[curUser.sName] = os.date(curUser.sName.." disconnected at %d/%m/%Y %T and has not been seen since.")
SaveToFile("Seen.dat", seenArray, "seenArray")
end
end

UserDisconnected = OpDisconnected

function ChatArrival(curUser, data)
if seenArray[curUser.sName] == nil then
seenArray[curUser.sName] = {}
seenArray[curUser.sName] = os.date(curUser.sName.." was last seen at %d/%m/%Y %T writing things.")
SaveToFile("Seen.dat", seenArray, "seenArray")
else
seenArray[curUser.sName] = os.date(curUser.sName.." was last seen at %d/%m/%Y %T writing things.")
SaveToFile("Seen.dat", seenArray, "seenArray")
end
data=string.sub(data,1,string.len(data)-1)
_,_,cmd,arg = string.find( data, "%b<>%s+(%S+)%s+(%S+)" )
if (cmd == SeenTrigger) then
if (arg == curUser.sName) then
if HowToSend == 1 then
SendToAll(BotName, "You should not do #seen's for yourself " ..curUser.sName.. " ;)" )
elseif HowToSend == 2 then
curUser:SendData(BotName, "You should not do #seen's for yourself " ..curUser.sName.. " ;)" )
elseif HowToSend == 3 then
curUser:SendPM(BotName, "You should not do #seen's for yourself " ..curUser.sName.. " ;)" )
end
elseif (seenArray[arg] ~= nil) then
if HowToSend == 1 then
SendToAll(BotName, "User: "..seenArray[arg] )
elseif HowToSend == 2 then
curUser:SendData(BotName, "User: "..seenArray[arg] )
elseif HowToSend == 3 then
curUser:SendPM(BotName, "User: "..seenArray[arg] )
end
else
if HowToSend == 1 then
SendToAll(BotName, "I have not seen "..arg.."!" )
elseif HowToSend == 2 then
curUser:SendData(BotName, "I have not seen "..arg.."!" )
elseif HowToSend == 3 then
curUser:SendPM(BotName, "I have not seen "..arg.."!" )
end
end
return 1
end
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.." = {\n"
for key, value in tTable do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end

function LoadFromFile(file)
local handle = io.open(file,"r")
if (handle ~= nil) then
loadstring(handle:read("*all"))
handle:flush()
handle:close()
end
end

The bot must be regged to send pm.. so I skipped nr 4 =)

Important
Since it save to file, witch allows it to remeber after script restart, you must create a file called seen.dat with the the following text in it
seenArray = {
}
if you dont, it will give errors like
attempt to index global `seenArray' (a nil value)

*Edit*

Fixed an typo... ;)
HowToSend 2 Was not working....
Title: Re seen
Post by: damo on 25 May, 2005, 21:54:39
very nice changes you made however i have a small problem with an error that i get when you look for yourself all others work fine heres the error seen.lua:96: attempt to call field `sName' (a string value)
Title:
Post by: [UK]Madman on 25 May, 2005, 22:52:28
Just missing .. after curUser.sName in the followong line:

SendToAll(BotName, "You should not do #seen's for yourself " ..curUser.sName " ;)" )

Should read:

SendToAll(BotName, "You should not do #seen's for yourself " ..curUser.sName.."  ;)" )
Title:
Post by: Madman on 25 May, 2005, 23:00:58
Thanks [UK]Madman
Missed that... =)
Script has been edited
Title: Re seen
Post by: damo on 26 May, 2005, 00:44:00
Thx for all the help with this script is very nice and the save feature is a nice bonus
Title:
Post by: Madman on 26 May, 2005, 01:04:24
QuoteOriginally posted by damo
Thx for all the help with this script is very nice and the save feature is a nice bonus

Np at all =)
Title:
Post by: Ubikk on 26 May, 2005, 14:43:21
Is it possible to make the script to work for Ip's too?
E.g: !seen 192.168.240.31
Title:
Post by: Madman on 26 May, 2005, 21:24:55
For the version i posted
Fixed an typo... ;)
HowToSend 2 Was not working....

QuoteOriginally posted by Ubikk
Is it possible to make the script to work for Ip's too?
E.g: !seen 192.168.240.31

Yup it can...

-- Creator Leon
-- Started lua 5 conversion, damo
-- Fully converted to lua 5 by 6Marilyn6Manson6
---- Modded By Madman
-- Added save to file
-- Added HowToSend, request by Ubikk
-- Hidden the command, request by damo
-- Added OnError Msg
-- Rewrote the ChatArrival
-- Added postibilite so seen ips, Request by Ubikk

BotName = "LeonBot"

minLen = 2
maxLen = 20
HowToSend = 2 -- 1: Send to all, 2: Send to user, 3: PM to the user

require("seen.dat")

function Main()
if HowToSend == 3 then
frmHub:RegBot(BotName)
end
end

function NewUserConnected(curUser)
local boolDisc = 0
if string.len(curUser.sName) < minLen then
curUser:SendPM(BotName, "Your nick is to short, a minimum of "..minLen.." chars is required!")
curUser:SendPM(BotName, "Disconnecting...")
curUser:Disconnect()
boolDisc = 1
elseif string.len(curUser.sName) > maxLen then
curUser:SendPM(BotName, "Your nick is to long, a maximum of "..maxLen.." chars is required!")
curUser:SendPM(BotName, "Disconnecting...")
curUser:Disconnect()
boolDisc = 1
elseif ( string.find (curUser.sName, " ", 1, 1) ) then
curUser:SendPM(BotName, "Spaces not allowed in nicknames!")
curUser:SendPM(BotName, "Disconnecting...")
curUser:Disconnect()
boolDisc = 1
end
if (boolDisc == 0) then
if seenArray == nil then
seenArray = {}
seenArray[curUser.sName] = {}
seenArray[curUser.sIP] = {}
seenArray[curUser.sName] = os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." connected at %d/%m/%Y %T and is still here.")
SaveToFile("Seen.dat", seenArray, "seenArray")
SendToAll("Weee")
else
seenArray[curUser.sName] = os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." connected at %d/%m/%Y %T and is still here.")
SaveToFile("Seen.dat", seenArray, "seenArray")
end
end
end

function OpConnected(curUser)
if seenArray == nil then
seenArray = {}
seenArray[curUser.sName] = {}
seenArray[curUser.sIP] = {}
seenArray[curUser.sName] = os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." connected at %d/%m/%Y %T and is still here.")
SaveToFile("Seen.dat", seenArray, "seenArray")
else
seenArray[curUser.sName] = os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." connected at %d/%m/%Y %T and is still here.")
SaveToFile("Seen.dat", seenArray, "seenArray")
end
end

function OpDisconnected(curUser)
if seenArray == nil then
seenArray = {}
seenArray[curUser.sName] = {}
seenArray[curUser.sIP] = {}
seenArray[curUser.sName] = os.date(curUser.sName.." disconnected at %d/%m/%Y %T and has not been seen since.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." disconnected at %d/%m/%Y %T and has not been seen since.")
SaveToFile("Seen.dat", seenArray, "seenArray")
else
seenArray[curUser.sName] = os.date(curUser.sName.." disconnected at %d/%m/%Y %T and has not been seen since.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." disconnected at %d/%m/%Y %T and has not been seen since.")
SaveToFile("Seen.dat", seenArray, "seenArray")
end
end

UserDisconnected = OpDisconnected

function OnError(ErrorMsg)
SendToOps(ErrorMsg)
end

function ChatArrival(curUser, data)
if seenArray == nil then
seenArray = {}
seenArray[curUser.sName] = {}
seenArray[curUser.sIP] = {}
seenArray[curUser.sName] = os.date(curUser.sName.." was last seen at %d/%m/%Y %T writing things.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." was last seen at %d/%m/%Y %T writing things.")
SaveToFile("Seen.dat", seenArray, "seenArray")
else
seenArray[curUser.sName] = os.date(curUser.sName.." was last seen at %d/%m/%Y %T writing things.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." was last seen at %d/%m/%Y %T writing things.")
SaveToFile("Seen.dat", seenArray, "seenArray")
end
local data = string.sub(data, 1, -2)
local s,e,cmd = string.find(data, "%b<>%s+[%!%+%?%#](%S+)")
if cmd then
local tCmds = {
["seen"] = function(curUser, data)
local s,e,arg = string.find(data, "%b<>%s+%S+%s+(%S+)")
if not arg then
if HowToSend == 1 then
SendToAll(BotName, "Syntax is: !" ..cmd.. " ")
elseif HowToSend == 2 then
curUser:SendData(BotName, "Syntax is: !" ..cmd.. " ")
elseif HowToSend == 3 then
curUser:SendPM(BotName, "Syntax is: !" ..cmd.. " ")
end
return 1
end
if (arg == curUser.sName) or (arg == curUser.sIP) then
if HowToSend == 1 then
SendToAll(BotName, "You should not do seen's for yourself " ..curUser.sName.. " ;)" )
elseif HowToSend == 2 then
curUser:SendData(BotName, "You should not do seen's for yourself " ..curUser.sName.. " ;)" )
elseif HowToSend == 3 then
curUser:SendPM(BotName, "You should not do seen's for yourself " ..curUser.sName.. " ;)" )
end
return 1
end
if seenArray[arg] == nil then
if HowToSend == 1 then
SendToAll(BotName, "I have not seen "..arg.."!" )
elseif HowToSend == 2 then
curUser:SendData(BotName, "I have not seen "..arg.."!" )
elseif HowToSend == 3 then
curUser:SendPM(BotName, "I have not seen "..arg.."!" )
end
return 1
end
if HowToSend == 1 then
SendToAll(BotName, "User: "..seenArray[arg] )
elseif HowToSend == 2 then
curUser:SendData(BotName, "User: "..seenArray[arg] )
elseif HowToSend == 3 then
curUser:SendPM(BotName, "User: "..seenArray[arg] )
end
return 1
end,
}
if tCmds[cmd] then
return tCmds[cmd](curUser, data)
end
end
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.." = {\n"
for key, value in tTable do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end

function LoadFromFile(file)
local handle = io.open(file,"r")
if (handle ~= nil) then
loadstring(handle:read("*all"))
handle:flush()
handle:close()
end
end
Title: Re seen
Post by: damo on 26 May, 2005, 21:52:44
very nice updates glad i asked for help now :D
Title:
Post by: Ubikk on 03 June, 2005, 20:27:13
Are you sure HowToSend 2 works now?  ?(
Title:
Post by: Ubikk on 03 June, 2005, 20:34:06
Oh.. and by the way, the script is causing all the users a little bit of lag... even to me :( I have a lag of 1-2 seconds on my own hub !! :)
Title:
Post by: Madman on 04 June, 2005, 02:27:22
QuoteOriginally posted by Ubikk
Are you sure HowToSend 2 works now?  ?(

lol.. sorry... fixed it in Version 1... but forgot to change it in Version 2 ;p

QuoteOriginally posted by Ubikk
Oh.. and by the way, the script is causing all the users a little bit of lag... even to me :( I have a lag of 1-2 seconds on my own hub !! :)

hmm... no idea why...

Maybe somebody got an idea :/
Title:
Post by: jiten on 04 June, 2005, 09:26:29
QuoteOriginally posted by Ubikk
Oh.. and by the way, the script is causing all the users a little bit of lag... even to me :( I have a lag of 1-2 seconds on my own hub !! :)
Did the lag disappear when you unloaded (if) this script?

Cheers
Title:
Post by: plop on 05 June, 2005, 00:43:42
this script saves the data files on every chat msg.
poor harddrive, specialy if there is a av checking the data files.
now you found the cause, next find a way 2 solve it.

plop
Title:
Post by: Madman on 05 June, 2005, 02:48:44
QuoteOriginally posted by plop
this script saves the data files on every chat msg.
poor harddrive, specialy if there is a av checking the data files.
now you found the cause, next find a way 2 solve it.

plop

True.. didn't think of that... Thanks plop


My soultion is... make a switch for loging chat
and also a switch that is only triggerd if someone wrote something in main...
if both triger is 1 then save the new data...
on timer... the time can be setted on how many minues you want...  =)

-- Creator Leon
-- Started lua 5 conversion, damo
-- Fully converted to lua 5 by 6Marilyn6Manson6
---- Modded By Madman
-- Added save to file
-- Added HowToSend, request by Ubikk
-- Hidden the command, request by damo
-- Added OnError Msg
-- Rewrote the ChatArrival
-- Added postibilite so seen ips, Request by Ubikk
-- Added switch to seen on chatarrival
-- Added saveing ontimer, only updates chat
-- Added SomeoneChated, only set to 1 if somebody wrote something in main
---- if SomeoneChated is set to one, update file ontimer

BotName = "LeonBot"
SeenChat = 1 -- Save chat 1 = yes, nil = no
minLen = 2
maxLen = 20
HowToSend = 2 -- 1: Send to all, 2: Send to user, 3: PM to the user
ChatTime = 5 -- How many minutes beetween saves

require("Seen.dat")

function Main()
if HowToSend == 3 then
frmHub:RegBot(BotName)
end
SetTimer(1000*60*ChatTime)
StartTimer()
end

function OnTimer()
if SeenChat then
if SomeoneChated == 1 then
SaveToFile("Seen.dat", seenArray, "seenArray")
SomeoneChated = 0
end
end
end

function NewUserConnected(curUser)
local boolDisc = 0
if string.len(curUser.sName) < minLen then
curUser:SendPM(BotName, "Your nick is to short, a minimum of "..minLen.." chars is required!")
curUser:SendPM(BotName, "Disconnecting...")
curUser:Disconnect()
boolDisc = 1
elseif string.len(curUser.sName) > maxLen then
curUser:SendPM(BotName, "Your nick is to long, a maximum of "..maxLen.." chars is required!")
curUser:SendPM(BotName, "Disconnecting...")
curUser:Disconnect()
boolDisc = 1
elseif ( string.find (curUser.sName, " ", 1, 1) ) then
curUser:SendPM(BotName, "Spaces not allowed in nicknames!")
curUser:SendPM(BotName, "Disconnecting...")
curUser:Disconnect()
boolDisc = 1
end
if (boolDisc == 0) then
if seenArray == nil then
seenArray = {}
seenArray[curUser.sName] = {}
seenArray[curUser.sIP] = {}
seenArray[curUser.sName] = os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." connected at %d/%m/%Y %T and is still here.")
SaveToFile("Seen.dat", seenArray, "seenArray")
SendToAll("Weee")
else
seenArray[curUser.sName] = os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." connected at %d/%m/%Y %T and is still here.")
SaveToFile("Seen.dat", seenArray, "seenArray")
end
end
end

function OpConnected(curUser)
if seenArray == nil then
seenArray = {}
seenArray[curUser.sName] = {}
seenArray[curUser.sIP] = {}
seenArray[curUser.sName] = os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." connected at %d/%m/%Y %T and is still here.")
SaveToFile("Seen.dat", seenArray, "seenArray")
else
seenArray[curUser.sName] = os.date(curUser.sName.." connected at %d/%m/%Y %T and is still here.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." connected at %d/%m/%Y %T and is still here.")
SaveToFile("Seen.dat", seenArray, "seenArray")
end
end

function OpDisconnected(curUser)
if seenArray == nil then
seenArray = {}
seenArray[curUser.sName] = {}
seenArray[curUser.sIP] = {}
seenArray[curUser.sName] = os.date(curUser.sName.." disconnected at %d/%m/%Y %T and has not been seen since.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." disconnected at %d/%m/%Y %T and has not been seen since.")
SaveToFile("Seen.dat", seenArray, "seenArray")
else
seenArray[curUser.sName] = os.date(curUser.sName.." disconnected at %d/%m/%Y %T and has not been seen since.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." disconnected at %d/%m/%Y %T and has not been seen since.")
SaveToFile("Seen.dat", seenArray, "seenArray")
end
end

UserDisconnected = OpDisconnected

function OnError(ErrorMsg)
SendToOps(ErrorMsg)
end

function ChatArrival(curUser, data)
if SeenChat then
if seenArray == nil then
seenArray = {}
seenArray[curUser.sName] = {}
seenArray[curUser.sIP] = {}
seenArray[curUser.sName] = os.date(curUser.sName.." was last seen at %d/%m/%Y %T writing things.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." was last seen at %d/%m/%Y %T writing things.")
SomeoneChated = 1
else
seenArray[curUser.sName] = os.date(curUser.sName.." was last seen at %d/%m/%Y %T writing things.")
seenArray[curUser.sIP] = os.date(curUser.sIP.." was last seen at %d/%m/%Y %T writing things.")
SomeoneChated = 1
end
end
local data = string.sub(data, 1, -2)
local s,e,cmd = string.find(data, "%b<>%s+[%!%+%?%#](%S+)")
if cmd then
local tCmds = {
["seen"] = function(curUser, data)
local s,e,arg = string.find(data, "%b<>%s+%S+%s+(%S+)")
if not arg then
if HowToSend == 1 then
SendToAll(BotName, "Syntax is: !" ..cmd.. " ")
elseif HowToSend == 2 then
curUser:SendData(BotName, "Syntax is: !" ..cmd.. " ")
elseif HowToSend == 3 then
curUser:SendPM(BotName, "Syntax is: !" ..cmd.. " ")
end
return 1
end
arg = string.lower(arg)
if (arg == curUser.sName) or (arg == curUser.sIP) then
if HowToSend == 1 then
SendToAll(BotName, "You should not do seen's for yourself " ..curUser.sName.. " ;)" )
elseif HowToSend == 2 then
curUser:SendData(BotName, "You should not do seen's for yourself " ..curUser.sName.. " ;)" )
elseif HowToSend == 3 then
curUser:SendPM(BotName, "You should not do seen's for yourself " ..curUser.sName.. " ;)" )
end
return 1
end
if seenArray[arg] == nil then
if HowToSend == 1 then
SendToAll(BotName, "I have not seen "..arg.."!" )
elseif HowToSend == 2 then
curUser:SendData(BotName, "I have not seen "..arg.."!" )
elseif HowToSend == 3 then
curUser:SendPM(BotName, "I have not seen "..arg.."!" )
end
return 1
end
if HowToSend == 1 then
SendToAll(BotName, "User: "..seenArray[arg] )
elseif HowToSend == 2 then
curUser:SendData(BotName, "User: "..seenArray[arg] )
elseif HowToSend == 3 then
curUser:SendPM(BotName, "User: "..seenArray[arg] )
end
return 1
end,
}
if tCmds[cmd] then
return tCmds[cmd](curUser, data)
end
end
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.." = {\n"
for key, value in tTable do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end

function LoadFromFile(filename)
local f = io.open( filename, "r")
if f then
local r = f:read( "*a" )
f:flush()
f:close()
local func, err = loadstring(r)
if func then x,err = pcall(func) end
end
end

Important
Since it save to file, witch allows it to remeber after script restart, you must create a file called seen.dat with the the following text in it
seenArray = {
}
Title:
Post by: 6Marilyn6Manson6 on 05 June, 2005, 03:46:56
Nice madman very nice ^^
Title:
Post by: Dessamator on 05 June, 2005, 12:03:57
-- Creator Unknown

BotName = "LeonBot"


that should give u a hint of who created it, "leon bot"

and here (http://www.plop.nl/ptokaxbots/Leon/seenbot.lua) is the proof :)
Title:
Post by: Madman on 05 June, 2005, 13:02:15
QuoteOriginally posted by Dessamator
-- Creator Unknown

BotName = "LeonBot"


that should give u a hint of who created it, "leon bot"

and here (http://www.plop.nl/ptokaxbots/Leon/seenbot.lua) is the proof :)

thanks...
Scripts been edited =)
Title:
Post by: Dessamator on 05 June, 2005, 13:18:13
ur welcome :)
Title:
Post by: Ubikk on 05 June, 2005, 20:27:51
Thank you so much for your help guyz :)
One last request for this script, is it possible to make it work for like this (i dont know how to express this in english):
example:

If the nickname is Ubikk
I want the script to work for ubikk and for uBikk too...  i dont want it to depend on the capital of a nickname or on the littles.
!seen Ubikk = !seen ubikk = !seen uBiKK = !seen UbiKK  etc...
 :D

Too bad i dont know english that well. I hope you guyz understood what i ment to say :P if not, i will try to explain harder   :D
Title:
Post by: Dessamator on 05 June, 2005, 21:15:47
QuoteOriginally posted by Ubikk
Thank you so much for your help guyz :)
One last request for this script, is it possible to make it work for like this (i dont know how to express this in english):
example:

If the nickname is Ubikk
I want the script to work for ubikk and for uBikk too...  i dont want it to depend on the capital of a nickname or on the littles.
!seen Ubikk = !seen ubikk = !seen uBiKK = !seen UbiKK  etc...
 :D

Too bad i dont know english that well. I hope you guyz understood what i ment to say :P if not, i will try to explain harder   :D

what u mean is remove the case "sensetivity" just add/edit this :

local s,e,arg = string.find(data, "%b<>%s+%S+%s+(%S+)")
arg = string.lower(arg)
Title:
Post by: Ubikk on 06 June, 2005, 18:25:36
So, where should i add that? :)
All that i could find in my code similar to that was:

local s,e,cmd = string.find(data, "%b<>%s+[%!%+%?%#](%S+)")
Title:
Post by: jiten on 06 June, 2005, 19:10:47
Something like this (check the red line):
local tCmds = {
["seen"] = function(curUser, data)
local s,e,arg = string.find(data, "%b<>%s+%S+%s+(%S+)")
if not arg then
if HowToSend == 1 then
SendToAll(BotName, "Syntax is: !" ..cmd.. " ")
elseif HowToSend == 2 then
curUser:SendData(BotName, "Syntax is: !" ..cmd.. " ")
elseif HowToSend == 3 then
curUser:SendPM(BotName, "Syntax is: !" ..cmd.. " ")
end
return 1
end
[COLOR=red]arg = string.lower(arg)[/COLOR]
Best regards,

jiten
Title: guys
Post by: GodLike on 20 July, 2005, 18:51:54
can you make ubikk`s idea  ?( ? its a good idea !!!!  :D
 
If the nickname is GodLike
I want the script to work for GodLike and for godlike too... i dont want it to depend on the capital of a nickname or on the littles.
!seen GodLike = !seen GODLIKE = !seen godlike = !seen GODlike etc...

i hope can you make  :]
Title:
Post by: Madman on 20 July, 2005, 20:18:53
Check jitens post....
He tell u all about how to do it.. but i'll edit the script..
Title:
Post by: Ubikk on 03 August, 2005, 11:09:25
Unfortunately I keep this script disabled.... it still uses 90% of my CPU when I activate it...  :rolleyes:
Title:
Post by: kvisko on 03 August, 2005, 15:06:27
This script crashes my hub, only solution is restart, and renaming the script file so it does not load again on startup...I'm running Verli 0.9.8c RC2...anyone else with this problem?
Title:
Post by: Ubikk on 03 August, 2005, 15:47:37
It consumes way too much cpu and ram ... maybe a more experienced user can help us :)
Title:
Post by: Dessamator on 03 August, 2005, 18:06:06
hmm, it really shouldnt consume that much memory, only in a hub with a lot of traffic !
Title:
Post by: Madman on 03 August, 2005, 18:33:46
QuoteOriginally posted by kvisko
This script crashes my hub, only solution is restart, and renaming the script file so it does not load again on startup...I'm running Verli 0.9.8c RC2...anyone else with this problem?
Verli? this ia a PtokaX script...