Offline msg
 

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

Offline msg

Started by plop, 15 May, 2004, 19:11:53

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

plop

stripped from a.i..
-- 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
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 <----<<

UwV?

*Net nu ik Phatty's mailscript al aan het testen ben ..

*translation:
 Grrr , just when i am putting Phatty's script through the test ..

;0)
Music = Love
                              &
                   plop rulez
                          (feed [en]danger[ed][ous] things so they will grow!!)  

plop

QuoteOriginally posted by UwV?
*Net nu ik Phatty's mailscript al aan het testen ben ..

*translation:
 Grrr , just when i am putting Phatty's script through the test ..

;0)
sorry, forgot about this thing a bit.
wanted 2 release it more then a week before i posted it.
i had the idea for something like this for a long time but seeing phatty's version convinced me 2 make it myself.
not that his version is bad, i just like 2 try and make things myself.

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 <----<<

SMF spam blocked by CleanTalk