-- changed chatarrival removed useless code
--- v 4a --
-- removed myinfo arrival (not needed)
-- Debugged ToArrival
--- --- --- Awayer v 4 --- ---
--lua 5 version
--By jiten and Dessamator
-- enabled it for normal users (not recommended)
--- --- --- --- --- --- ---
--- Awayer v3 --- idea by QuitckThinker
--- by Herodes
--- This bot has been writen offline and based on no other script
--- Although the initial idea for the AwayBot is from tezlo's RetroBot...
--- This diplays a prefix for those operators and above that are away
--- It also places the Away message in the users description ...
--- --- --- This script works only for Operators (as intended) --- --- ---
--- !away --- is optional
--- !back
--- !awaylist
--- feel free to develop this further ...
--- --- v 2 --- ---
--- currently has a problem with the following path ..
--- 1) !away
--- 2) user reconnnects
--- 3) !back
--- this produces a lot of shity names in the list ... dunno y ...:(
--- --- v 3 --- ---
--- fixed v2 problem but has abother one ...
--- following path ..
--- 1) !away
--- 2) or !back
--- 3) user disconnects ...
--- 4) user receives nickname reserved message (???)
--- --- all other scenarios I have tested and work fine ...
--- --- --- --- --- --- ---
tAways = {}
awpref = "[AWAY]"
defmsg = "I'm away. I might answer later if you're lucky."
allowuser = false --(allows use of awayer for normal regged users,true/false )--> true not recommended might cause myinfo spam
function Main()
Bot = frmHub:GetHubBotName()
SetTimer(1000)
StartTimer()
end
function OnExit()
for nick, msg in tAways do
SendToAll("$Quit "..awpref..nick)
if GetItemByName(nick).bOperator then
SendToAll("$OpList "..nick)
end
if GetItemByName(nick) then
SendToAll(GetItemByName(nick).sMyInfoString)
end
end
end
function NewUserConnected(user)
for nick, msg in tAways do
if GetItemByName(nick).bOperator then
user:SendData("$OpList "..awpref..nick)
end
if not GetItemByName(nick).bOperator then
user:SendData(user.sMyInfoString)
end
end
end
OpConnected =NewUserConnected
function OnTimer()
for nick, msg in tAways do
if GetItemByName(nick) then
SendToAll("$Quit "..nick)
SendToAll("$Quit "..nick)
end
end
end
function ToArrival(user, data)
local s,e,whoTo,from = string.find(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s%$")
local _,__,msg = string.find(data, "%b<>%s+(%S+)")
if string.find(whoTo, awpref) then
SendPmToNick((string.sub(whoTo, string.len(awpref)+1, string.len(whoTo))),from, msg)
end
if tAways[whoTo] then
if tAways[whoTo]["reason"] then
SendPmToNick(from,awpref..whoTo, tAways[whoTo]["reason"].." ")
end
end
for nick,message in tAways do
if string.find(from, nick) then
SendPmToNick(whoTo,awpref..from, msg)
return 1
end
end
end
function ChatArrival(user, data)
local s,e,cmd,arg,strAway = string.find(data, "%b<>%s+(%S+)s*(.*)|")
tCmds = {
["!away"] = function(user,data)
if arg == nil or arg == "" then arg = defmsg end
if not tAways[user.sName] then
tAways[user.sName] = arg
SendToAll("Awayer", user.sName.." is away because : "..arg )
strAway = string.gsub(user.sMyInfoString,user.sName,awpref..user.sName)
SendToAll(strAway)
if user.bOperator then
SendToAll("$OpList "..awpref..user.sName)
end
SendToAll("$Quit "..user.sName)
else
user:SendData("Awayer", "You are away already ... ")
SendToAll("$Quit "..awpref..user.sName)
end
end,
["!back"] = function(user,data)
if tAways[user.sName] then
SendToAll("$Quit "..awpref..user.sName)
SendToAll("Awayer", user.sName.." is back .. :)")
SendToAll(user.sMyInfoString)
if user.bOperator then
SendToAll("$OpList "..user.sName)
end
tAways[user.sName] = nil
else
user:SendData("Awayer", "You were not away... :)")
end
end,
["!awaylist"] =
function(user,data)
local list,cnt = "These users are set to away\r\n",0
for nick, msg in tAways do
cnt = cnt + 1
list = list.."\t"..cnt..". "..nick.."\tAway Msg :"..msg.."\r\n"
end
user:SendData(list)
end,
}
if tCmds[cmd] then
if user.bOperator or (user.bRegistered and allowuser) then
return tCmds[cmd](user,data),1
else
user:SendData(Bot,"Thou art not worthy of thee mighty AWAYER!")
return 1
end
end
if tAways[user.sName] then
SendToAll("$Quit "..awpref..user.sName)
user:SendData("Awayer", "You spoke in main chat so you are not away anymore.")
SendToAll(user.sMyInfoString)
if user.bOperator then
SendToAll("$OpList "..user.sName)
end
tAways[user.sName] = nil
end
end
thx dessamator.
If this fix really only one return1, can you tell me, where exactly i have to put in? So i could use my changed version again:)
Greets
QuoteOriginally posted by Krysalis
thx dessamator.
If this fix really only one return1, can you tell me, where exactly i have to put in? So i could use my changed version again:)
Greets
function OnTimer()
for nick, msg in tAways do
if GetItemByName(nick) then
SendToAll("$Quit "..nick)
SendToAll("$Quit "..nick)
end
end
end
function ToArrival(user, data)
local s,e,whoTo,from = string.find(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s%$")
local _,__,msg = string.find(data, "%b<>%s+(%S+)")
if string.find(whoTo, awpref) then
SendPmToNick((string.sub(whoTo, string.len(awpref)+1, string.len(whoTo))),from, msg)
end
if tAways[whoTo] then
if tAways[whoTo]["reason"] then
SendPmToNick(from,awpref..whoTo, tAways[whoTo]["reason"].." ")
end
end
for nick,message in tAways do
if string.find(from, nick) then
SendPmToNick(whoTo,awpref..from, msg)
return 1
end
end
end
well i changed quite a few things but either way, u only need to replace those 2 functions , and remove this :
function MyINFOArrival(user, data)
if (tAways[user.sName]) then
SendToAll("$Quit "..user.sName)
if user.bOperator then
SendToAll("$OpList "..awpref..user.sName)
end
return 1
end
end
thank you:)
ur welcome
Here is one, I wrote it almost a year ago, now updated.
--[[
Awaybot 1.0 by bastya_elvtars
From LawMaker.
Sends away message.
No tag and other things like this.
You can see others' away messages w/o PMing them if you want.
Enjoy.
]]
-- // CONFIG
------------
-- The bot's data (will show in userlist):
Bot={
name="AwayBot",
desc="Away bot.",
email="awaybot@bastya-editor.click",
}
--[[
----------------------------------------------------------------------------------------
NO levels. If anyone is allowed to use it, I do not consider it a security risk myself.
Commands must be added without prefix, bot will detect them with prefix.
Syntax:
{"command","help text"},
----------------------------------------------------------------------------------------
]]
cmd={
-- Go away
afk={"afk"," Go away and leave a message (that's optional.)"},
-- Come back
back={"back","Come back if away."},
-- Shows whether you are away
mystatus={"mystatus","Shows whether you are away."},
-- Shows a specific user's or all users' away messages
showaways={"showaways"," Shows away messages of a user, with no option it shows all users'."},
-- guess :-]
awayhelp={"awayhelp","Guess! :-]"},
}
-------------------
-- // END OF CONFIG
afk={}
function away(user,data,env)
if not afk[user.sName] then
local _,_,why=string.find(data,"%b<>%s+%S+%s+(.+)")
if not why then
SendTxt(user,env,Bot.name,"You have been set to away.")
SendToAll(Bot.name,"User "..user.sName.." went away.")
afk[user.sName]=os.date("%A, %c")
saveaway()
else
SendTxt(user,env,Bot.name,"You have been set to away. Reason: "..why)
SendToAll(Bot.name,"User "..user.sName.." went away, because: \""..why.."\".")
afk[user.sName]=why.."|"..os.date("%A, %c")
saveaway()
end
else
SendToAll(Bot.name,"User "..user.sName.." has come back now.")
local _,_,why=string.find(data,"%b<>%s+%S+%s+(.+)")
if not why then
SendTxt(user,env,Bot.name,"You have been set to away.")
SendToAll(Bot.name,"User "..user.sName.." went away.")
afk[user.sName]=os.date("%A, %c")
saveaway()
else
SendTxt(user,env,Bot.name,"You have been set to away. Reason: "..why)
SendToAll(Bot.name,"User "..user.sName.." went away, because: \""..why.."\".")
afk[user.sName]=why.."|"..os.date("%A, %c")
saveaway()
end
end
end
function returned(user,data,env)
if afk[user.sName] then
SendTxt(user,env,Bot.name,"You are no longer away and have been set back to normal.")
SendToAll(Bot.name,"User "..user.sName.." has came back now.")
afk[user.sName]=nil
saveaway()
else
SendTxt(user,env,Bot.name,"You weren't away, baby.")
end
end
function awaymsg(user,whoTo)
if not string.find(afk[whoTo],"%|") then
user:SendPM(whoTo,"I went away on "..afk[whoTo]..".")
else
local _,_,why,dat=string.find(afk[whoTo],"(.+)%|(.+)")
user:SendPM(whoTo,"I went away on "..dat..", because: "..why..".")
end
end
function myawaystatus(user,env)
if afk[user.sName] then
if not string.find(afk[user.sName],"%|") then
SendTxt(user,env,Bot.name,"You went away on "..afk[user.sName]..".")
else
local _,_,why,dat=string.find(afk[user.sName],"(.+)%|(.+)")
SendTxt(user,env,Bot.name,"You went away on "..dat..", because: "..why..".")
end
else
SendTxt(user,env,Bot.name,"You are not away.")
end
end
function showawaymsgs(user,data,env)
awayarray={}
local _,_,nick=string.find(data,"%b<>%s+%S+%s+(%S+)")
if nick then
if afk[nick] then
if not string.find(afk[nick],"%|") then
user:SendPM(Bot.name,nick.." went away at "..afk[nick].." and left no message.")
else
local _,_,why,dat=string.find(afk[nick],"(.+)|(.+)")
user:SendPM(Bot.name,nick.." went away at "..dat.." and left this away message: "..why)
end
else
user:SendPM(Bot.name,nick.." is not away or offline.")
end
else
local msg="\r\n\r\n\t\t\t\t\t\tALL USERS' AWAY MESSAGES\r\n=================================================================================================================================\r\n\r\n"
for a,b in afk do
table.insert(awayarray,a)
table.sort(awayarray)
end
if table.getn(awayarray)==0 then
msg=msg.."Nobody is away.\r\n\r\n"
else
for a=1,table.getn(awayarray) do
if not string.find(afk[awayarray[a]],"%|") then
msg=msg..awayarray[a].." went away at "..afk[awayarray[a]].." and left no message.\r\n\r\n"
else
local _,_,why,dat=string.find(afk[awayarray[a]],"(.+)|(.+)")
msg=msg..awayarray[a].." went away at "..dat.." and left this away message: "..why.."\r\n\r\n"
end
end
end
msg=msg.."================================================================================================================================="
user:SendPM(Bot.name,msg)
end; awayarray=nil; collectgarbage(); io.flush()
end
function saveaway()
local f=io.open("away.dat","w+")
for a,b in afk do
f:write(a.."|"..b.."\n")
end
f:close()
end
function loadaway()
local f=io.open("away.dat","r")
if f then
for line in f:lines() do
local _,_,nick,msg=string.find(line,"(%S+)|(.+|.+)")
afk[nick]=msg
end
f:close()
end
end
function help(user)
local msg=""
for a,b in cmd do
msg=msg.."\r\n"..b[1].." - "..b[2]
end
user:SendPM(Bot.name,msg)
end
function ParseCmd(user,data,c,env)
local tmptbl= {
[cmd.afk[1]]={away,{user,data,env}},
[cmd.back[1]]={returned,{user,data,env}},
[cmd.mystatus[1]]={myawaystatus,{user,data,env}},
[cmd.showaways[1]]={showawaymsgs,{user,data,env}},
[cmd.awayhelp[1]]={help,{user,data,env}},
}
if tmptbl[c] then
tmptbl[c][1](unpack(tmptbl[c][2]))
return 1
end
end
function Main()
loadaway()
frmHub:RegBot(Bot.name,1,Bot.desc,Bot.email)
end
function SendTxt(user,env,bot,text)
if env=="PM" then
user:SendPM(bot,text)
else
user:SendData(bot,text)
end
end
function ToArrival(user,data)
data=string.sub(data,1,string.len(data)-1)
local _,_,whoTo = string.find(data,"$To:%s+(%S+)")
if (whoTo == Bot) then
local _,_,c = string.find(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+[%!%+%#](%S+)")
if c then
return ParseCmd(user,data,string.lower(c),"PM")
end
elseif afk[whoTo] then
awaymsg(user,whoTo)
end
end
function ChatArrival(user,data)
data=string.sub(data,1,string.len(data)-1)
local _,_,c = string.find(data,"%b<>%s+[%!%+%#](%S+)")
if c then
return ParseCmd(user,data,string.lower(c),"MAIN")
end
end
function OnExit()
saveaway()
end
hmm, nice one, good thing u didnt add tag and stuff, hehe, its annoying at times, and can cause myinfo spam, if used improperly .
QuoteOriginally posted by Dessamator
hmm, nice one, good thing u didnt add tag and stuff, hehe, its annoying at times, and can cause myinfo spam, if used improperly .
These bots are totally useless, since if one does not answer, he is probably away. :P
However, despite my bot's having no tag, you can display away messages' (thus away users') list. :)
Well, ur right in saying away scripts are useless but the awayer by herodes has a nice feature, the prefix, so u dont even need to send the person a pvt, ull know right ahead just by looking at the nick
QuoteOriginally posted by Dessamator
Well, ur right in saying away scripts are useless but the awayer by herodes has a nice feature, the prefix, so u dont even need to send the person a pvt, ull know right ahead just by looking at the nick
In theory the best idea would be to parse the myinfo, as you can retrieve from it ("$ $[^$+]([^$])$") the magic char that can show if user is away. However, I am unsure that every client supports this. PPK? :)
hmm, yah the original script included that, i think or something like it
Hi
dont work the command !awaylist
Syntax ...gs\Oz\Desktop\0.3.3.21.nt.dbg\scripts\Awayer v 4.lua:295: attempt to concatenate
can u correct this?
tnx :)
more error :(
0.3.3.21.nt.dbg\scripts\Awayer v 4.lua:121: attempt to index a nil value
plzzzzz helpp
this is the one i use i changed afew things but it works all the same
--- v 4a --
-- removed myinfo arrival (not needed)
-- Debugged ToArrival
--- --- --- Awayer v 4 --- ---
--lua 5 version
--By jiten and Dessamator
-- enabled it for normal users (not recommended)
--- --- --- --- --- --- ---
--- Awayer v3 --- idea by QuitckThinker
--- by Herodes
--- This bot has been writen offline and based on no other script
--- Although the initial idea for the AwayBot is from tezlo's RetroBot...
--- This diplays a prefix for those operators and above that are away
--- It also places the Away message in the users description ...
--- --- --- This script works only for Operators (as intended) --- --- ---
--- !away
--- is optional
--- !back
--- !awaylist
--- feel free to develop this further ...
--- --- v 2 --- ---
--- currently has a problem with the following path ..
--- 1) !away
--- 2) user reconnnects
--- 3) !back
--- this produces a lot of shity names in the list ... dunno y ...:(
--- --- v 3 --- ---
--- fixed v2 problem but has abother one ...
--- following path ..
--- 1) !away
--- 2) or !back
--- 3) user disconnects ...
--- 4) user receives nickname reserved message (???)
--- --- all other scenarios I have tested and work fine ...
--- --- --- --- --- --- ---
tAways = {}
awpref = "[AWAY]"
defmsg = "I'm away. I might answer later if you're lucky."
allowuser = true --(allows use of awayer for normal regged users,true/false )--> true not recommended might cause myinfo spam
function Main()
Bot = frmHub:GetHubBotName()
SetTimer(1000)
StartTimer()
end
function OnExit()
for nick, msg in tAways do
SendToAll("$Quit "..awpref..nick)
if GetItemByName(nick).bOperator then
SendToAll("$OpList "..nick)
end
if GetItemByName(nick) then
SendToAll(GetItemByName(nick).sMyInfoString)
end
end
end
function NewUserConnected(user)
for nick, msg in tAways do
if GetItemByName(nick).bOperator then
user:SendData("$OpList "..awpref..nick)
end
if not GetItemByName(nick).bOperator then
user:SendData(user.sMyInfoString)
end
end
end
OpConnected =NewUserConnected
function OnTimer()
for nick, msg in tAways do
if GetItemByName(nick) then
SendToAll("$Quit "..nick)
SendToAll("$Quit "..nick)
end
end
end
function ToArrival(user, data)
local s,e,whoTo,from = string.find(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s%$")
local _,__,msg = string.find(data, "%b<>%s+(%S+)")
if string.find(whoTo, awpref) then
SendPmToNick((string.sub(whoTo, string.len(awpref)+1, string.len(whoTo))),from, msg)
end
if tAways[whoTo] then
if tAways[whoTo]["reason"] then
SendPmToNick(from,awpref..whoTo, tAways[whoTo]["reason"].." ")
end
end
for nick,message in tAways do
if string.find(from, nick) then
SendPmToNick(whoTo,awpref..from, msg)
return 1
end
end
end
function ChatArrival(user, data)
data =string.sub(data, 1, string.len(data)-1)
local s,e,cmd = string.find(data, "%b<>%s+(%S+)")
tCmds = { ["!gone"] = function(user,data)
local s,e,arg = string.find(data, "%b<>%s+"..cmd.."%s(.*)")
if arg == nil or arg == "" then arg = defmsg end
if not tAways[user.sName] then
local s,e,name,desc,tag, con,email,share = string.find(user.sMyInfoString, "$MyINFO $ALL (%S+)%s+(.*)<([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")
tAways[user.sName] = {}
if desc == nil then desc = "" end
tAways[user.sName]["d"] = desc
tAways[user.sName]["t"] = "<"..tag
tAways[user.sName]["c"] = con
if email == nil then email = "" end
tAways[user.sName]["e"] = email
tAways[user.sName]["s"] = share
tAways[user.sName]["reason"] = arg
user:SendData("Awayer", "You are now set to away ..")
SendToAll("$MyINFO $ALL "..awpref..user.sName.." AwayMsg: "..arg..tAways[user.sName]["t"].."$ $"..tAways[user.sName]["c"].." $"..tAways[user.sName]["e"].."$"..tAways[user.sName]["s"].."$")
if user.bOperator then
SendToAll("$OpList "..awpref..user.sName)
end
SendToAll("$Quit "..user.sName)
else
user:SendData("Awayer", "You are away already ... ")
SendToAll("$Quit "..awpref..user.sName)
end
end,
["!here"] = function(user,data)
if tAways[user.sName] then
SendToAll("$Quit "..awpref..user.sName)
SendToAll("Awayer", user.sName.." is back .. :)")
SendToAll(user.sMyInfoString)
if user.bOperator then
SendToAll("$OpList "..user.sName)
end
tAways[user.sName] = nil
else
user:SendData("Awayer", "You were not away... :)")
end
end,
["!gonelist"] = function(user,data)
local list = "These users are set to away\r\n"
local cnt = 0
for nick, msg in tAways do
cnt = cnt + 1
list = list.."\t"..cnt..". "..nick.."\tAway Msg :"..msg.."\r\n"
end
user:SendData(list)
end, }
if tCmds[cmd] then
if user.bOperator or (user.bRegistered and allowuser) then
return tCmds[cmd](user,data),1
else
user:SendData(Bot,"Thou art not worthy of thee mighty AWAYER!")
return 1
end
end
if tAways[user.sName] then
SendToAll("$Quit "..awpref..user.sName)
user:SendData("Awayer", "You spoke in main chat so you are not away anymore.")
SendToAll(user.sMyInfoString)
if user.bOperator then
SendToAll("$OpList "..user.sName)
end
tAways[user.sName] = nil
end
end
now i have this error
[08:10] Syntax ...gs\Oz\Desktop\0.3.3.21.nt.dbg\scripts\Awayer v 4.lua:113: attempt to concatenate local `tag' (a nil value)
and the command !gonelist dont work :(
I want to know if this script sucks too much bandwith... ???
Quote from: Markitos on 08 April, 2006, 13:15:20
I want to know if this script sucks too much bandwith... ???
It will depend on how many users use its features.
Just as an example, if you use the "away" command with this bot (as it's a regularly used command) a lot of bandwidth will be consumed.
If you look at the code, the MyINFO will be updated every second for each user in that table.
Actually, it Only removes the "normal " nicks that reappear in the userlist, and it checks for this every 1 second, but are listed as away in the table, so that there arent 2 nicks from the same person, 1 away and 1 normal . I recommend that its only used for ops, as herodes originally made it for.