Author Topic: PostMan by bastya_elvtars (the rock n' roll doctor)  (Read 11526 times)

0 Members and 1 Guest are viewing this topic.

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 744
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #25 on: 06 September, 2004, 22:12:46 »
mcopy the error corrected version
paste into notepad
and save it as offline.lua for example
into ptokax scripts folder
and restart scripts
Everything could have been anything else and it would have just as much meaning.

PtokaX forum

(No subject)
« Reply #25 on: 06 September, 2004, 22:12:46 »

Offline REBEL

  • Forum Ace
  • *****
  • Posts: 99
  • Karma: +1/-0
(No subject)
« Reply #26 on: 06 September, 2004, 22:17:05 »
arhhh now i got ya :)

ive been saving as ponyexpress
ok try again
dont move a inch
watch this space lol

Offline REBEL

  • Forum Ace
  • *****
  • Posts: 99
  • Karma: +1/-0
(No subject)
« Reply #27 on: 06 September, 2004, 22:23:13 »
nope sorry got this error and no bot on hub

Syntax Error: function arguments expected;
  last token read: `=' at line 12 in file `C:\Program Files\PtokaX-CJ\scripts\offline.lua'

i am useing the one you corrected

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 744
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #28 on: 06 September, 2004, 22:43:49 »
-- PostMan Bot 0.1 by bastya_elvtars (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="PostMan" -- he he he

inboxsize=10 -- the maximum amount of messages users can have in their inbox

------------ end of settings

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=array
   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 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")
   elseif strsub(data, 1, 4) == "$To:" then
      data=strsub(data,1,strlen(data)-1)
      local _,_,whoTo = strfind(data,"$To:%s+(%S+)")
      if (whoTo == Bot) then
         local _,_,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
         cmd=strlower(cmd)
         return parsecmds(user,data,cmd,"PM")
      end
   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
   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
Everything could have been anything else and it would have just as much meaning.

Herodes

  • Guest
(No subject)
« Reply #29 on: 06 September, 2004, 22:49:43 »
Quote
Originally posted by REBEL
ahha me wait, me let you sort out
if at sometime it works on version im useing without syntex error would be pleased to know :)
Thanks guys
Its works .. just read our dialog through ....

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 744
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #30 on: 06 September, 2004, 23:18:32 »
it might work, cause rebel is in silence lol
Everything could have been anything else and it would have just as much meaning.

Offline REBEL

  • Forum Ace
  • *****
  • Posts: 99
  • Karma: +1/-0
(No subject)
« Reply #31 on: 06 September, 2004, 23:24:50 »
haha just when you thought it was quiet ....Wrong lol

no seriously guys it didnt work
got another one of these for ya

Syntax Error: expected;
  last token read: `&' at line 88 in file `C:\Program Files\PtokaX-CJ\scripts\Offline.lua'


joking apart ....i hope my input is helping you
as i have enjoyed trying this out

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 744
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #32 on: 06 September, 2004, 23:27:24 »
yep if i dont send it as monospaced
wait heres a link

http://www.plop.nl/ptokaxbots/bastya_elvtars/offlinepost.lua

get it from here, and thx plop for hosting my scripts, will be reversed someday :PPPP
Everything could have been anything else and it would have just as much meaning.

Offline REBEL

  • Forum Ace
  • *****
  • Posts: 99
  • Karma: +1/-0
(No subject)
« Reply #33 on: 06 September, 2004, 23:33:28 »
ahha but will it work ....i hope so

this has been really a education lol

Offline REBEL

  • Forum Ace
  • *****
  • Posts: 99
  • Karma: +1/-0
(No subject)
« Reply #34 on: 06 September, 2004, 23:56:03 »
Well ....what can i say now .

I LIKE IT ....WORKS GREAT

Really nice work bastya_elvtars

i guess i'll have to find something else to play with now lol

give ya self a gold star lol
hope more try it
a very pleased REBEL

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 744
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #35 on: 06 September, 2004, 23:58:50 »
Quote
Originally posted by REBEL
Well ....what can i say now .

I LIKE IT ....WORKS GREAT

Really nice work bastya_elvtars

i guess i'll have to find something else to play with now lol

give ya self a gold star lol
hope more try it
a very pleased REBEL

well i am happy that at least one guy likes my first released script. This gives me the power to continue ^^.

----------------------------------------------------

try lawmaker please, need suggestions, my ideas are in it
Everything could have been anything else and it would have just as much meaning.

Herodes

  • Guest
(No subject)
« Reply #36 on: 07 September, 2004, 01:24:07 »
Oleee Finally ;)

Offline [PT]CableGuy

  • Forum Ace
  • *****
  • Posts: 98
  • Karma: +1/-0
(No subject)
« Reply #37 on: 07 September, 2004, 02:10:37 »
Quote
Originally posted by bastya_elvtars
...This gives me the power to continue...
Please , do continue !!!
I love this script also !!! Excelent job over here. :]

Offline kEwL

  • Member
  • ***
  • Posts: 27
  • Karma: +1/-0
(No subject)
« Reply #38 on: 14 July, 2005, 14:41:07 »
i get this error pls help me
[18:10] Syntax C:\ptokax\scripts\offline.lua:87: unexpected symbol near `%'

Offline Dessamator

  • Scripter
  • Emperor
  • ******
  • Posts: 1 262
  • Karma: +13/-9
(No subject)
« Reply #39 on: 14 July, 2005, 16:27:23 »
this script was written for lua4, it wont work on lua 5, and i think it has already been converted, somewhere !
Ignorance is Bliss.

Offline ?Tr??T_????

  • Triple Ace
  • **
  • Posts: 213
  • Karma: +0/-1
lua 5
« Reply #40 on: 08 August, 2005, 11:50:01 »
can someone give me this script in lua 5? :D

Offline HillyBilly

  • Scripter
  • Member
  • ******
  • Posts: 47
  • Karma: +4/-0
(No subject)
« Reply #41 on: 08 August, 2005, 12:51:51 »
Quote
Originally posted by ?Tr??T_????
can someone give me this script in lua 5? :D

Look at this thread Postman lua5

Cheers HB

Offline ?Tr??T_????

  • Triple Ace
  • **
  • Posts: 213
  • Karma: +0/-1
thnx
« Reply #42 on: 08 August, 2005, 13:41:30 »
oh yeah thats what i was lookin for hnk u one more time :P  :P  :)

PtokaX forum

thnx
« Reply #42 on: 08 August, 2005, 13:41:30 »