Hi All
Big thanx to bastya_elvtars for his permison and help
heres a hub dateing script ive made for therapy-X thourght i share it with u all :) hope ya like
more to add if ppl like it
yours
shad
-- hubs Persoanl Ads script by shad_dow of Therapy-Net.co.uk
-- moded version of the script below with permsion
-- all commands type in main only .
-- PostMan Bot 0.1 by (the rock n' roll doctor)
-- offline message system
-- you can set the inbox size and the bot name
-- code ripped from law maker bot
-- comands can be PMed or typed in main, the bot responds to them according to the environment (sometimes at least :D)
-- the commands are case insensitive, the parameters aren't :)
-- 0.2: added function so ppl cannot post 2 offline users
------------- settings
Bot="Hub-Dateing" -- he he he
inboxsize=10 -- the maximum amount of messages users can have in their inbox
------------ end of settings
Paper = "ads.dat"
function Main()
if not readfrom("offline.ini") then message={} else dofile("offline.ini") end
frmHub:RegBot(Bot)
end
function loadlist(file) -- to see if the user was in the hub at all
table=nil
table={}
readfrom(file)
while 1 do
local line = read()
if line == nil then
readfrom()
break
end
table[line] = 1
end
readfrom()
if table then
return table
else
return {}
end
end
function savefile(table,file) -- save users names who were in the hub
writeto(file)
for a,b in table do
write(a.."\n")
end
writeto()
end
function postmsg(user,data,env)
local _,_,nick,msg=strfind(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if nick then
if not GetItemByName(nick) then
local washere=loadlist("washere.lst")
if not washere then washere={} end
if washere[nick] then
if not message[nick] then
message[nick]={[1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}}
user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
savemsg()
else
if checksize(nick)>=inboxsize then -- >= only for safety lol
user:SendData(parseenv(user,env,Bot).."Sorry, but "..nick.." has a full inbox. Try again later.")
else
message[nick][checksize(nick)+1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}
user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
savemsg()
end
end
else
user:SendData(parseenv(user,env,Bot).."User "..nick.." has never been in the hub.")
end
else
user:SendData(parseenv(user,env,Bot)..nick.." is online! PM would be simpler in this case...")
end
else
user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !postmsg ")
end
end
function readmsg (user,data,env)
if message[user.sName] then
local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
if args then
gsub(args,"(%d+)",function(nmbr)
nmbr=tonumber(nmbr)
if message[%user.sName][nmbr] then
local msg="\r\n\r\n\t\t\t\t\t\t\tMessage #"..nmbr.."\r\n=================================================================================================================================\r\n\r\nFrom: "..message[%user.sName][nmbr]["who"].."\r\nTime of sending: "..message[%user.sName][nmbr]["when"]..
"\r\nMessage: "..message[%user.sName][nmbr]["message"].."\r\n\r\n================================================================================================================================="
%user:SendPM(Bot,msg)
if message[%user.sName][nmbr]["read"]==0 then
message[%user.sName][nmbr]["read"]=1
savemsg()
end
else
%user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
end
end)
else
user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !showmsg . Multiple numbers can be added separated by spaces.")
end
else
user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
end
end
function numess(nick,a)
if message[nick][a]["read"]==0 then return "no"
else return "yes" end
end
function inbox (user,env)
local msg="\r\n\r\n\t\t\t\t\t\t\tHere is your inbox:\r\n================================================================================================================================="..
"\r\nMessage #\t\t\tSender\t\t\t\t\tTime of sending\t\t\t\t\tRead\r\n================================================================================================================================="
if message[user.sName] then
for a,b in message[user.sName] do
msg=msg.."\r\n"..a.."\t\t\t\t"..b["who"].."\t\t\t"..b["when"].."\t\t\t\t"..numess(user.sName,a).."\r\n================================================================================================================================="
end
user:SendPM(Bot,msg)
user:SendPM(Bot,"Type !readmsg too see an individual message. Multiple numbers can be added separated by spaces.")
if checksize(user.sName) >= inboxsize then
user:SendPM(Bot,"Alert: Your inbox is full!")
end
else
user:SendData(parseenv(user,env,Bot).."You have no messages.")
end
end
function checksize(nick)
local array={}
for a,b in message[nick] do
tinsert(array,a)
end
return getn(array)
end
function delmsg(user,data,env)
if message[user.sName] then
local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
if args then
gsub(args,"(%d+)",function (nmbr)
nmbr=tonumber(nmbr)
if message[%user.sName][nmbr] then
message[%user.sName][nmbr]=nil
%user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." has been successfully deleted!")
else
%user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
end
end)
if checksize(user.sName)==0 then
message[user.sName]=nil
savemsg()
else
local array={}
for a,b in message[user.sName] do
tinsert(array,b)
end
for i=1,getn(array) do
message[user.sName]=resort(array)
end
savemsg()
end
else
user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !delmsg . Multiple numbers can be added separated by spaces.")
end
else
user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
end
end
function resort(array)
local tbl={}
for i=1,getn(array) do
tbl[i]=array[i]
end
return tbl
end
-- nmbr, who, when, message
function parse(tbl)
local cnt=""
for a,b in tbl do
cnt=cnt.."\t\t\t\t\t\t\t\t\t["..a.."]=\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t[\"who\"]=\""..b["who"].."\",\n\t\t\t\t\t\t\t\t\t[\"when\"]=\""..b["when"]..
"\",\n\t\t\t\t\t\t\t\t\t[\"message\"]=\""..b["message"].."\",\n\t\t\t\t\t\t\t\t\t},\n"
end
return cnt
end
function savemsg()
writeto("offline.ini")
local what="message=\n{"
for a,b in message do
what=what.."\n\t\t\t[\""..a.."\"]={\n"..parse(b).."\t\t\t},"
end
what=what.."\n}"
write(what)
writeto()
end
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 NewUserConnected(user)
local washere=loadlist("washere.lst")
if not washere then washere={} end
if not washere[user.sName] then
washere[user.sName]=1
savefile(washere,"washere.lst")
end
if message[user.sName] then
local count={[user.sName]=0}
for a,b in message[user.sName] do
if b["read"]==0 then
count[user.sName]=count[user.sName]+1
end
end
if count[user.sName]>0 then
user:SendPM(Bot,"You have "..count[user.sName].." new messages. Type !inbox to see your inbox!")
end
end
end
function GetArgs1(data)
local _,_, arg1 = strfind(data,"%s+%S+%s+(.+)")
return arg1
end
function doreadad(user)
readfrom(Paper)
local message = ""
while 1 do
local line = read()
if line == nil then break
else
message = message..line.."\r\n"
end
end
user:SendPM(Bot,"\r\n"..message.."\r\n")
end
function dowritead(user,data)
arg1 = GetArgs1(data)
if arg1 ~= nil then
SendToAll(Bot,"A New Personal AD has been added , plz type !readad in main chat..!")
appendto(Paper)
write("******"..user.sName.."*** Personal Ad ******\r\n")
write("\r\n")
write("description: "..arg1.."\r\n")
write("\r\n")
write("********************************************\r\n")
write("**Type !postmsg in Main **\r\n")
write("**To answer To this Personal AD :) **\r\n")
write("********************************************\r\n")
write("\r\n")
write("\r\n")
writeto()
elseif arg1 == nil then
user:SendPM(Bot,"Cmd is !myad [description of ur self]..!")
end
end
function DataArrival(user,data)
if strsub(data,1,1)=="<" then
data=strsub(data,1,strlen(data)-1)
local _,_,cmd = strfind(data,"%b<>%s+(%S+)")
cmd=strlower(cmd)
return parsecmds(user,data,cmd,"MAIN")
end
end
function parsecmds(user,data,cmd,env)
local returndata=0
if cmd=="!postmsg" then
postmsg(user,data,env) returndata=1
elseif cmd=="!readmsg" then
readmsg (user,data,env) returndata=1
elseif cmd=="!inbox" then
inbox(user,env) returndata=1
elseif cmd=="!delmsg" then
delmsg(user,data, env) returndata=1
elseif cmd=="!readad" then
doreadad(user) returndata=1
elseif cmd=="!writead" then
dowritead(user,data) returndata=1
end return returndata
end
function UserDisconnected(user)
local washere=loadlist("washere.lst")
if not washere then washere={} end
if not washere[user.sName] then
washere[user.sName]=1
savefile(washere,"washere.lst")
end
end
function OnExit()
savemsg()
end
OpDisconnected=UserDisconnected
OpConnected=NewUserConnected