ofllinemsg in main
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

ofllinemsg in main

Started by OneHero, 12 August, 2004, 08:46:15

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

OneHero

hi there! i use this script from plop

-- offline message bot
-- stripped from artificial isanety
-- by plop

-- 

Bot = "offline_msg"
maxMsg = 10
Folder = "msg"

------------------------------------ what to do on startup
function Main()
   if readfrom(Folder.."/offlineMSG.lua") then
      dofile(Folder.."/offlineMSG.lua")
      readfrom()
   else
      tMSG = {}
   end
   frmHub:RegBot(Bot)
end

------------------------------------ return the amout of msg's a user has (read and unread)
function getMsgAmount(name)
   local C,R = 0,0
   if tMSG[name] then
      for a,b in tMSG[name] do
         if tMSG[name][a] then
            if tMSG[name][a]["read"]== 0 then
               R = R +1
            end
         end
         C=C+1
      end
   end
   return C,R
end

------------------------------------ post a msg
function Post(user,data)
   local s,e,to,msg = strfind(data,"%$%b<>%s+%S+%s*(%S*)%s*(.*)")
   if to == "" then
      return ("Lesson 1: post a msg to atleast a person!")
   elseif msg == "" then
      return ("How about telling @ least something?")
   else
      if tMSG[to] == nil then
         tMSG[to] = {}
         num = 1
      else
         num = getMsgAmount(to) + 1
      end
      local Total,Unread = getMsgAmount(to)
      if Total >= maxMsg then
         local toU = GetItemByName(to)
         if toU then
            toU:SendPM(Bot, user.sName.." tryed to mail you something but your mailbox is full! Pls delete 1 or more messeges!|")
         end
         return ("The mailbox from "..to.." is full! Try posting again later!")
      end
      msg = gsub(msg, "|","\r\n")
      tMSG[to][num] = {}
      tMSG[to][num]["who"]=user.sName
      tMSG[to][num]["msg"]=msg
      tMSG[to][num]["time"]=date()
      tMSG[to][num]["read"]=0
      SaveMsg()
      local toU = GetItemByName(to)
      if toU then
         toU:SendPM(Bot, "There is a messege waiting for you! type !readmsg "..num..".|")
         return ("msg posted to: "..toU.sName )
      else
         return ("msg posted to: "..to )
      end
   end
end

------------------------------------ reading msg's
function Read(user, data)
   if tMSG[user.sName] == nil then
      return ("You have no messages!")
   else 
      local s,e,num = strfind(data,"%$%b<>%s+%S+%s*(%S*)")
      num = tonumber(num)
      if num == nil then
         local Total,Unread = getMsgAmount(user.sName)
         return ("you have "..Total.." messages! ".. Unread.." new")
      elseif tMSG[user.sName][num] then
         if tMSG[user.sName][num]["read"]== 0 then
            tMSG[user.sName][num]["read"]=1
         end
         return ("\r\n\r\n   "..tMSG[user.sName][num]["who"].." posted on "..tMSG[user.sName][num]["time"]..
         "\r\n-----------------------------------------------------------------------\r\n"..format("%8s", tMSG[user.sName][num]["msg"])..
         "\r\n-----------------------------------------------------------------------\r\n")
      else
         return ("unknown msg number "..num) 
      end
   end
end

------------------------------------ bye bye msg
function Delete(user,data)
   local s,e,num = strfind(data,"%$%b<>%s+%S+%s*(%S*)")
   num = tonumber(num)
   if num then
      if tMSG[user.sName][num] then
         tMSG[user.sName][num] = nil
         Renumber(user.sName, num)
         SaveMsg()
         return ("messege number "..num.." deleted!")
      else
         return "unknow ID"
      end
   else
      return "Not a number!"
   end
end

------------------------------------ re-index after deleting
function Renumber(name, num)
   for i=(num+1), maxMsg do
      if tMSG[name][i] then
         tMSG[name][(i-1)] = tMSG[name][i]
         tMSG[name][i] = nil
      else
         break
      end
   end
end

------------------------------------ saving the table
function SaveMsg()
   writeto(Folder.."/offlineMSG.lua")
   write("\n--data file for the offline msg system\n\ntMSG={")
   local t = ""
   for a,b in tMSG do
      write(t.."\n   ["..format("%q", a).."]=")
      if t == "" then t = "," end
      if type(b) == "string" then
         write(format("%q", b))
      elseif type(b) == "number" then 
         write(b)
      elseif type(b) == "table" then
         t2 = ""
         t3 = ""
         write("{")
         for c,d in b do
            if type(c) =="number" then
               write(t2.."\n      ["..c.."]=")
               if t2 == "" then t2 = "," end
               if type(d) == "string" then
                  write(format("%q", d))
               elseif type(d) == "number" then
                  write(d)
               elseif type(d) == "table" then
                  write("{")
                  t4 = ""
                  for e,f in d do
                     if type(f) == "number" then
                        write(t4.."\n         ["..format("%q", e).."]="..f )
                     else
                        write(t4.."\n         ["..format("%q", e).."]="..format("%q", f) )
                     end
                     if t4 == "" then t4 = "," end
                  end
                  write("\n         }")
               else
                  SendToAll(Bot, "what the hell are you trying 2 save plop, thats no number/table or string!|")
               end
            elseif type(c) == "string" then
               write(t3.."\n      ["..format("%q", c).."]=")
               if t3 == "" then t3 = "," end
               if type(d) == "string" then
                  write(format("%q", d))
               elseif type(d) == "number" then
                  write(d)
               elseif type(d) == "table" then
                  write("{")
                  t5 = ""
                  for e,f in d do
                     write(t5.."\n         ["..e.."]="..f )
                     if t5 == "" then t5 = "," end
                  end
                  write("\n      }")
               else
                  SendToAll(Bot, "what the hell are you trying 2 save plop, thats no number/table or string!|")
               end
            else
               SendToAll(Bot, "what the hell are you trying 2 save plop, thats no number or string!|")
            end
         end
         write("\n   }")
      else
         SendToAll(Bot, "what the hell are you trying 2 save plop|")
      end
   end
   write("\n}\n\n--ploppyrights reserved")
   writeto()
   return "Done"
end

------------------------------------ show if a user has msg's or not
function EnterMsg(user)
   local Total,Unread = getMsgAmount(user.sName)
   local line = ""
   if Total >= maxMsg then
      if Unread ~= 0 then
         line = line.." ".. Unread.." new message(s)."
      else
         line = "Your mailbox is full! Pls delete 1 or more message(s)!"..line
      end
   elseif Unread ~= 0 then
      line = line.."You have ".. Unread.." new message(s)."
   end
   if line ~= "" then
      return line
   end
end

------------------------------------ standard stuff
function DataArrival(user, data)
   if(strsub(data, 1, 4) == "$To:") then
      local s,e,whoTo = strfind(data,"$To:%s+(%S+)")
      if whoTo == Bot then 
         data=strsub(data,1,strlen(data)-1) 
         local s,e,cmd = strfind(data,"%$%b<>%s+(%S+)")
         if cmd == "!postmsg" then
            user:SendPM(Bot, Post(user,data).."|")
            return 1
         elseif cmd == "!readmsg" then
            user:SendPM(Bot, Read(user, data).."|")
            return 1
         elseif cmd == "!delmsg" then
            user:SendPM(Bot, Delete(user, data).."|")
            return 1
         end
      end
   end
end

------------------------------------ hey a new user entered, maby he has msg's
function NewUserConnected(user)
   local tmp = EnterMsg(user)
   if tmp then
      user:SendPM(Bot, tmp.."|")
   end
end

------------------------------------ shouldn't forget the poor OP's
function OpConnected(user)
   local tmp = EnterMsg(user)
   if tmp then
      user:SendPM(Bot, tmp.."|")
   end
end

--ploppyrights reserved

but i want to write the cmd in main, and not to the bot, what can i do then?

plop

try version 1.1.
-------------------------------------
-- offline message bot
-- stripped from artificial isanety
-- by plop
-------------------------------------
---- version 1.1
-- accepts main and pm commands.
-------------------------------------

-- 

Bot = "offline_msg"
maxMsg = 10
Folder = "msg"

------------------------------------ what to do on startup
function Main()
   if readfrom(Folder.."/offlineMSG.lua") then
      dofile(Folder.."/offlineMSG.lua")
      readfrom()
   else
      tMSG = {}
   end
   frmHub:RegBot(Bot)
end

------------------------------------ return the amout of msg's a user has (read and unread)
function getMsgAmount(name)
   local C,R = 0,0
   if tMSG[name] then
      for a,b in tMSG[name] do
         if tMSG[name][a] then
            if tMSG[name][a]["read"]== 0 then
               R = R +1
            end
         end
         C=C+1
      end
   end
   return C,R
end

------------------------------------ post a msg
function Post(user,data)
   local s,e,to,msg = strfind(data,"%b<>%s+%S+%s*(%S*)%s*(.*)")
   if to == "" then
      return ("Lesson 1: post a msg to atleast a person!")
   elseif msg == "" then
      return ("How about telling @ least something?")
   else
      if tMSG[to] == nil then
         tMSG[to] = {}
         num = 1
      else
         num = getMsgAmount(to) + 1
      end
      local Total,Unread = getMsgAmount(to)
      if Total >= maxMsg then
         local toU = GetItemByName(to)
         if toU then
            toU:SendPM(Bot, user.sName.." tryed to mail you something but your mailbox is full! Pls delete 1 or more messeges!|")
         end
         return ("The mailbox from "..to.." is full! Try posting again later!")
      end
      msg = gsub(msg, "|","\r\n")
      tMSG[to][num] = {}
      tMSG[to][num]["who"]=user.sName
      tMSG[to][num]["msg"]=msg
      tMSG[to][num]["time"]=date()
      tMSG[to][num]["read"]=0
      SaveMsg()
      local toU = GetItemByName(to)
      if toU then
         toU:SendPM(Bot, "There is a messege waiting for you! type !readmsg "..num..".|")
         return ("msg posted to: "..toU.sName )
      else
         return ("msg posted to: "..to )
      end
   end
end

------------------------------------ reading msg's
function Read(user, data)
   if tMSG[user.sName] == nil then
      return ("You have no messages!")
   else 
      local s,e,num = strfind(data,"%b<>%s+%S+%s*(%S*)")
      if num == "" then
         
      num = tonumber(num)
      if num == nil then
         local Total,Unread = getMsgAmount(user.sName)
         return ("you have "..Total.." messages! ".. Unread.." new")
      elseif tMSG[user.sName][num] then
         if tMSG[user.sName][num]["read"]== 0 then
            tMSG[user.sName][num]["read"]=1
         end
         return ("\r\n\r\n   "..tMSG[user.sName][num]["who"].." posted on "..tMSG[user.sName][num]["time"]..
         "\r\n-----------------------------------------------------------------------\r\n"..format("%8s", tMSG[user.sName][num]["msg"])..
         "\r\n-----------------------------------------------------------------------\r\n")
      else
         return ("unknown msg number "..num) 
      end
   end
end

------------------------------------ bye bye msg
function Delete(user,data)
   local s,e,num = strfind(data,"%b<>%s+%S+%s*(%S*)")
   num = tonumber(num)
   if num then
      if tMSG[user.sName][num] then
         tMSG[user.sName][num] = nil
         Renumber(user.sName, num)
         SaveMsg()
         return ("messege number "..num.." deleted!")
      else
         return "unknow ID"
      end
   else
      return "Not a number!"
   end
end

------------------------------------ re-index after deleting
function Renumber(name, num)
   for i=(num+1), maxMsg do
      if tMSG[name][i] then
         tMSG[name][(i-1)] = tMSG[name][i]
         tMSG[name][i] = nil
      else
         break
      end
   end
end

------------------------------------ saving the table
function SaveMsg()
   writeto(Folder.."/offlineMSG.lua")
   write("\n--data file for the offline msg system\n\ntMSG={")
   local t = ""
   for a,b in tMSG do
      write(t.."\n   ["..format("%q", a).."]=")
      if t == "" then t = "," end
      if type(b) == "string" then
         write(format("%q", b))
      elseif type(b) == "number" then 
         write(b)
      elseif type(b) == "table" then
         t2 = ""
         t3 = ""
         write("{")
         for c,d in b do
            if type(c) =="number" then
               write(t2.."\n      ["..c.."]=")
               if t2 == "" then t2 = "," end
               if type(d) == "string" then
                  write(format("%q", d))
               elseif type(d) == "number" then
                  write(d)
               elseif type(d) == "table" then
                  write("{")
                  t4 = ""
                  for e,f in d do
                     if type(f) == "number" then
                        write(t4.."\n         ["..format("%q", e).."]="..f )
                     else
                        write(t4.."\n         ["..format("%q", e).."]="..format("%q", f) )
                     end
                     if t4 == "" then t4 = "," end
                  end
                  write("\n         }")
               else
                  SendToAll(Bot, "what the hell are you trying 2 save plop, thats no number/table or string!|")
               end
            elseif type(c) == "string" then
               write(t3.."\n      ["..format("%q", c).."]=")
               if t3 == "" then t3 = "," end
               if type(d) == "string" then
                  write(format("%q", d))
               elseif type(d) == "number" then
                  write(d)
               elseif type(d) == "table" then
                  write("{")
                  t5 = ""
                  for e,f in d do
                     write(t5.."\n         ["..e.."]="..f )
                     if t5 == "" then t5 = "," end
                  end
                  write("\n      }")
               else
                  SendToAll(Bot, "what the hell are you trying 2 save plop, thats no number/table or string!|")
               end
            else
               SendToAll(Bot, "what the hell are you trying 2 save plop, thats no number or string!|")
            end
         end
         write("\n   }")
      else
         SendToAll(Bot, "what the hell are you trying 2 save plop|")
      end
   end
   write("\n}\n\n--ploppyrights reserved")
   writeto()
   return "Done"
end

------------------------------------ show if a user has msg's or not
function EnterMsg(user)
   local Total,Unread = getMsgAmount(user.sName)
   local line = ""
   if Total >= maxMsg then
      if Unread ~= 0 then
         line = line.." ".. Unread.." new message(s)."
      else
         line = "Your mailbox is full! Pls delete 1 or more message(s)!"..line
      end
   elseif Unread ~= 0 then
      line = line.."You have ".. Unread.." new message(s)."
   end
   if line ~= "" then
      return line
   end
end

------------------------------------ commands table
tCommands = {
   ["!postmsg"] = function(user,data) Post(user, data) end,
   ["!readmsg"] = function(user,data) Read(user, data) end,
   ["!delmsg"] =  function(user,data) Delete(user, data) end,
}

------------------------------------ standard stuff
function DataArrival(user, data)
   if (strsub(data, 1, 4) == "$To:") then
      local s,e,whoTo = strfind(data,"$To:%s+(%S+)")
      if whoTo == Bot then 
         data=strsub(data,1,strlen(data)-1) 
         local s,e,cmd = strfind(data,"%$%b<>%s+(%S+)")
         if cmd and tCommands[cmd] then
            local s,e,data = strfind(data, "%$(%b<>.*)")
            user:SendPM(Bot, tCommands[cmd](user, data).."|")
            return 1
         end
      end
   elseif ( strsub(data, 1, 1) == "<" ) then
      data=strsub(data,1,strlen(data)-1) 
      local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      if cmd and tCommands[cmd] then
         user:SendData(Bot, tCommands[cmd](user, data).."|")
         return 1
      end
   end
end

------------------------------------ hey a new user entered, maby he has msg's
function NewUserConnected(user)
   local tmp = EnterMsg(user)
   if tmp then
      user:SendPM(Bot, tmp.."|")
   end
end

------------------------------------ shouldn't forget the poor OP's
function OpConnected(user)
   local tmp = EnterMsg(user)
   if tmp then
      user:SendPM(Bot, tmp.."|")
   end
end

--ploppyrights reserved
plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

OneHero

cant get it to work...

OneHero


BottledHate

Quotecant get it to work...
errors usually help.....


Quotehello!
remarks like this usually get u nowhere, and no help.


-BH
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

OneHero

i dont get any errors, it just wont work in main

nErBoS

Hi,

Answering to your question in the other topic, the message will popup when the user connects to the HUB.

Best regards, nErBoS
--## nErBoS Spot ##--

OneHero

first question is related to the script offlinemsg to plop (like seen over)

i cant get this to work in main?

the other question is to the robocop 8.0 script that contains a !offline command. i've tested it and it shows when i logg on, but i only get the first word, how to get to see the hole msg, or how to delete it so it wont pop up every time i logg on?

nErBoS

Hi,

Does it work in PM the plop script ???

About the robocop error you should post it in his topic that is in Later Scripts section. The error should be a little bug in with the wildcards.

Best regards, nErBoS
--## nErBoS Spot ##--

BoJlk

#9
I get an error ProtaX v0.3.2.6 TD4

Syntax Error: `end' expected (to close `function' at line 83);
  last token read: `' at line 272 in file `...\PtokaX-0.326.TestDrive4\scripts\offline_msg v1.1.lua'


And what are the commands to control this script
I didn't found the in the script text  ?(

BottledHate

try copy and paste again.. you missed an 'end' somewhere. ;)


-BH
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

Optimus

QuoteAbout the robocop error you should post it in his topic that is in Later Scripts section. The error should be a little bug in with the wildcards.
Yups you where right it wasn't working correct. It's fixed now....

;) Opti

BoJlk

plop

Which are the command to use the Offline_msg?
!offline to post a message?

And a Suggestion to all Scripters!

Please Publish the common commands to use the script

or !help command build in the script.

bastya_elvtars

What about this?

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

Usage:

!postmsg             Posts a message to an offline user, who has already been here.
!readmsg                Displays the message with the given number. Multiple numbers can be added, separated by spaces.
!inbox                  Shows your inbox.
!delmsg                Deletes the message with the given number. Multiple numbers can be added, separated by spaces
Everything could have been anything else and it would have just as much meaning.

OneHero

nice one, but is there some way that the "you got 1 new msg" can pop up in new window? and is there some way that the one who sent the msg can be notifyed when the othe one gets it?

bastya_elvtars

msg will only be sent to users that are really offline. And i thought there was a popup PM when notifies.

NB: you can't post to online users.
Everything could have been anything else and it would have just as much meaning.

SMF spam blocked by CleanTalk