PostMan 0.6
 

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

PostMan 0.6

Started by Skippy84, 30 September, 2005, 19:21:46

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Skippy84

i added a rightklick menu to the script it was a wish from a user of my hub :D

the german version is aviable at this link

German version PostMan 0.6



-- PostMan Bot 0.3 by bastya_elvtars (the rock n' roll doctor)
-- offline message system
-- 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 online users


------- 0.3:
-- converted to lua5
-- washere is now global, no more CPU spikes



------- 0.4:
-- touched by Herodes (optimisation tsunami)
-- added : more details on the bot
-- added : message privacy ;)
-- changed : better way to parseenv ;)
-- changed : better way to display messages and inbox
-- changed : better way to parsecmds ( thx bastya_elvtars ;)


------- 0.5:
-- touched by Skippy84
-- fix error: make offline.dat thx goto Herodes for the idea to fix the problem
-- fix error: false command !showmsg
-- added: commands can edit at the Settings section
-- added: shown commands linked to the editable commands (so ther change on the fly)



------- 0.51:
-- bastya_elvtars put his hands back on this
-- script now creates an empty offline.dat if does not exist... you guys keep ignoring new Lua5 features :P
-- thx guys for the features you added, they are really eye-candy



------- 0.6:
-- touched again by Skippy84
-- added: a little rightclick menu





--------------------------------SETTINGS----------------------------------------



Bot = {
       name = "PostMan" , -- bot's name
       email = "postman@mail.me", -- bot's email
       desc = "Post messages to other users here..", -- bot's desc
      }



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

cmdpost = "postmsg" -- Shows the Hub Stats
cmdread = "readmsg" -- Shows the Hub Stats
cmdibox = "inbox" -- Shows the Hub Stats
cmddbox = "delmsg" -- Shows the Hub Stats

----------------------END OF SETTINGS-------------------------------------------






-------------------------------------- Utility Functions


function cls()
   collectgarbage()
   io.flush()
end




function Main()
  local function load()
  local t = {}; local f = io.open("washere.lst", "r")
  if f then for l in f:lines() do t[l] = 1; end; f:close(); end
    return t;
  end
    washere = load()
    message = {}
	if loadfile("offline.dat") then
		dofile("offline.dat")
	else
		io.output("offline.dat")
		io.write("")
		io.output()
	end
    frmHub:RegBot(Bot.name, 1, Bot.desc, Bot.email )
    Bot = Bot.name
end




-------------------------------------- Command Functions


--- post msg

function postmsg( user, data, how )
  local _,_,nick,msg = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
  if nick then
    if not GetItemByName(nick) then
       if washere[nick] then
         local function checksize(n) local cnt = 0; for a,b in message[n] do cnt = cnt + 1; end return cnt; end
          if not message[nick] then message[nick] = {}; end
             if (checksize(nick) < inboxsize) then
                table.insert( message[nick], { ["message"] = msg, ["who"] = user.sName, ["when"] = os.date("%Y. %m. %d. %X"), ["read"] = 0, } )
                SendBack( user, "Successfully sent the message!", Bot, how )
                savemsg()
             else
                SendBack( user, "Sorry, but "..nick.." has a full inbox. Try again later.", Bot, how )
             end
          else
             SendBack( user, "User "..nick.." has never been in the hub.", Bot, how )
          end
       else
          SendBack( user, nick.." is online! PM would be simpler in this case...", Bot, how )
       end
    else
       SendBack( user, "Bad syntax! Usage: !"..cmdpost.."  ", Bot, how )
    end
  cls(); return 1;
end


--- del msg

function delmsg( user, data, how )
  if message[user.sName] then
    local _,_,args = string.find(data,"%b<>%s+%S+%s+(.+)")
    if args then
      local function checksize(n) local cnt = 0; for a,b in message[n] do cnt = cnt + 1; end return cnt; end
      local function resort(t) local r ={}; for i,v in t do table.insert(r, v); end; return r; end
      for num in string.gfind( args, "%s-(%d+)%s-" ) do
      if num then
        num = tonumber(num);
          if message[user.sName][num] then
            message[user.sName][num] = nil
            SendBack( user, "Message #"..num.." has been successfully deleted!", Bot, how )
          else
            SendBack( user, "Message #"..num.." does not exist!", Bot, how )
          end
      end
    end
    message[user.sName] = resort(message[user.sName]);
    if checksize(user.sName) == 0 then message[user.sName] = nil; end
      savemsg()
    else
      SendBack( user, "Bad syntax! Usage: !"..cmddbox.." . Multiple numbers can be added separated by spaces.", Bot, how )
    end
  else
    SendBack( user, "Your inbox is empty.", Bot, how )
  end
    cls(); return 1;
end



----------------------------------------------------------------------------------
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------- show inbox


function inbox( user, how )
  local sep, msg = string.rep( "=", 75 ), "\r\n\r\n\t\t\t\t\t\t\tHere is your inbox:\r\n"
  msg = msg..sep.."\r\n Msg#\tSender\tTime of sending\t\tRead\r\n"..sep
  if message[user.sName] then
    local function numess ( r ) if r == 0 then return "no"; end return "yes"; end
    local function checksize ( n ) local cnt = 0; for a,b in message[n] do cnt = cnt + 1; end return cnt; end
    local function dcode ( s ) if (string.sub(s,1,3) == "-n#") then s=string.sub(s,4,-1); local res = ""; for num in string.gfind( s, "#?(%d+)") do res = res..string.char(tonumber(num));end;return res;end;return s;end
    for num, t in message[user.sName] do
    msg=msg.."\r\n "..num.."\t"..dcode(t.who).."\t"..t.when.."\t"..numess(t.read).."\r\n"..sep
  end
    SendBack( user, msg, Bot, true )
    SendBack( user, "Type !"..cmdread.."  too see an individual message. Multiple numbers can be added separated by spaces.", Bot, true )
  if checksize(user.sName) >= inboxsize then SendBack( user, "Alert: Your inbox is full!", Bot, true ); end
  else
    SendBack( user, "You have no messages.", Bot, how )
  end
  cls(); return 1;
end



--- read msg(s)

function readmsg( user, data, how )
  if message[user.sName] then
    local _,_,args=string.find(data,"%b<>%s+%S+%s+(.+)")
    if args then
      local function dcode(s) if (string.sub(s,1,3) == "-n#") then s = string.sub(s,4,-1);local res = ""; for num in string.gfind( s, "#?(%d+)") do res = res..string.char(tonumber(num));end;return res;end;return s;
    end
    for num in string.gfind( args, "%s-(%d+)%s-" ) do
      if num then num = tonumber(num) end
      if num and message[user.sName][num] then
        local t = message[user.sName][num]
        local msg, sep,set = "\r\n\r\n\t\t\t\t\t\t\tMessage #"..num.."\r\n", string.rep( "=", 100 ), string.rep("- ", 85)
        msg = msg..sep.."\r\n\r\nFrom: "..dcode(t.who).."\tTime: "..t.when.."\t\tMessage follows\r\n"..set.."[Message start]\r\n"..dcode(t.message).."\r\n"..set.."[Message end]\r\n"..sep
        SendBack( user, msg, Bot, true )
        if t.read == 0 then t.read = 1; savemsg(); end
      else
         SendBack( user, "Message #"..num.." does not exist!", Bot, how )
      end
   end
  else
    SendBack( user, "Bad syntax! Usage: !"..cmdread.." . Multiple numbers can be added separated by spaces.", Bot, how )
  end
  else
    SendBack( user, "Your inbox is empty.", Bot, how )
  end
  cls(); return 1;
end




--- save msg


function savemsg()
  local function parse(tbl)
  local str, tab ="", string.rep( "\t", 9)
  local function fquot(s) return string.format( "%q", s) end
  local function ncode( s ) if (s ~= "") and (string.sub(s,1,3) ~= "-n#") then local t = {}; for i = 1, string.len(s) do t[i] = string.byte(string.sub(s,i,i)); end; return "-n#"..table.concat(t, "#"); end; return s; end
  for a, t in tbl do
    str = str.."\t\t{ ["..fquot("read").."] = "..t.read..", ["..fquot("who").."] = "..fquot(ncode(t.who))..", ["..fquot("when").."] = "..fquot(t.when)..",\n\t\t["..fquot("message").."] = "..fquot(ncode(t.message)).." },\n"
  end
  return str
  end
  local f = io.open ( "offline.dat", "w+" )
  local s = "message = {"
  for name, t in message do
   s = s.."\n\t["..string.format( "%q", string.gsub( name, "\"", "\"")).."] = {\n"..parse(t).."\t},"
  end;
   f:write(s.."\n}")
   f:close()
   end






function SendBack( user, msg, who, pm )
   if pm then user:SendPM ( who, msg ); else user:SendData( who, msg ); end
end






function NewUserConnected(user)
	if user.bUserCommand then
		user:SendData("$UserCommand 1 3 :PostMan:\\INBOX$<%[mynick]> !inbox||")
		user:SendData("$UserCommand 1 3 :PostMan:\\post a Message$<%[mynick]> !postmsg %[line:Enter  and :]||")
		user:SendData("$UserCommand 1 3 :PostMan:\\read a Message$<%[mynick]> !readmsg %[line:Enter Nr of Post you would read:]||")
		user:SendData("$UserCommand 1 3 :PostMan:\\Delete a Message$<%[mynick]> !delmsg %[line:Enter Nr of Post you would delete:]||")
		user:SendData(":PostMan:", "New Right-Click for Postman is Available..")
	end
	
	
  if not washere[user.sName] then washere[user.sName] = 1 end
  if message[user.sName] then
  local cnt=0
  for a,b in message[user.sName] do if (b.read == 0) then cnt = cnt+1; end end
  if (cnt > 0) then SendBack( user, "You have "..cnt.." new messages. Type !"..cmdibox.." to see your inbox!", Bot, true ); end
  end
end






function ChatArrival(user,data)
  local data = string.sub( data, 1, -2 )
  local _,_,cmd = string.find(data,"%b<>%s+[!+.#?](%S+)")
  if cmd then return parsecmds( user, data, string.lower(cmd) ); end
end






function ToArrival(user,data)
  if (string.sub( data, 1, string.len(Bot)+5) == "$To: "..Bot) then
   local data = string.sub( data, 1, -2 )
   local _,_,cmd = string.find(data,"%$%b<>%s+[!+.#?](%S+)")
   if cmd then return parsecmds( user, data, string.lower(cmd), true ) end
    return 1
  end
end






function parsecmds( user, data, cmd, how )
  local t = {
    [cmdpost] = { postmsg, { user, data, how } },
    [cmdread] = { readmsg, { user, data, how } },
    [cmdibox] = { inbox, { user, how } },
    [cmddbox] = { delmsg, { user, data, how } },
    }
  if t[cmd] then
    return t[cmd][1]( unpack(t[cmd][2]) )
  end
end





function UserDisconnected(user)
  if not washere[user.sName] then washere[user.sName] = 1; end
end




function OnExit()
  savemsg()
  local f = io.open( "washere.lst", "w+")
  for a,b in washere do f:write(a.."\n"); end
  f:close()
end



OpDisconnected=UserDisconnected
OpConnected=NewUserConnected

Marco52

nice script  :] , can you put(add) option, allow admin send mass message to all users ? if it's possiblle of course :) thx anyway

kunal

try this

By jiten
sBot = "Mass-Message";
sPrefix = "!";

CmdOpt = {
	["massmaster"] = {
		[0] = 1,
		[1] = 1,
		[2] = 0,
		[3] = 0,
		[-1] = 0,
	},
	["massop"] = {
		[0] = 1,
		[1] = 1,
		[2] = 0,
		[3] = 0,
		[-1] = 0,
	},
	["massvip"] = {
		[0] = 1,
		[1] = 1,
		[2] = 1,
		[3] = 0,
		[-1] = 0,
	},
	["massreg"] = {
		[0] = 1,
		[1] = 1,
		[2] = 1,
		[3] = 0,
		[-1] = 0,
	}, 
	["massall"] = {
		[0] = 1,
		[1] = 1,
		[2] = 0,
		[3] = 0,
		[-1] = 0,
	}
};

function Main()
	frmHub:RegBot(sBot);
end

function ChatArrival(user,data)
	data=string.sub(data,1,-2);
	local s,e,cmd = string.find(data,"^%b<>%s+(%S+)");
	local Prefix = string.sub(cmd,1,1);
	if (Prefix == sPrefix) then
		cmd = string.lower(string.sub(cmd,2,string.len(cmd)));
		if (Commands[cmd]) then
			return (Commands[cmd](user,data))
		end
	end
end

Commands = {
	["massmaster"] = 
	function(user,data)
		if (Denial("massmaster",user) == 1) then return 1 end
		local s,e,Msg = string.find(data,"^%b<>%s+%S+%s+(.*)");
		return MassMessage(1,Msg,nil,user);
	end,

	["massop"] = 
	function(user,data)
		if (Denial("massop",user) == 1) then return 1 end
		local s,e,Msg = string.find(data,"^%b<>%s+%S+%s+(.*)");
		return MassMessage(1,Msg,nil,user);
	end,

	["massvip"] = 
	function(user,data)
		if (Denial("massvip",user) == 1) then return 1 end
		local s,e,Msg = string.find(data,"^%b<>%s+%S+%s+(.*)");
		return MassMessage(2,Msg,nil,user);
	end,

	["massreg"] = 
	function(user,data)
		if (Denial("massreg",user) == 1) then return 1 end
		local s,e,Msg = string.find(data,"^%b<>%s+%S+%s+(.*)");
		return MassMessage(3,Msg,nil,user);
	end,

	["massall"] = 
	function(user,data)
		if (Denial("massall",user) == 1) then return 1 end
		local s,e,Msg = string.find(data,"^%b<>%s+%S+%s+(.*)");
		return MassMessage(-1,Msg,1,user);
	end
};

function MassMessage(ProfileIdx, Msg, bToAll, user)
	local MassSend = function(user,Msg,Profile)
		local msg = "\r\n\r\n\t"..string.rep("-",100).."\r\n"
		msg = msg.."\t-- Sender: "..user.sName.."\r\n\r\n"
		msg = msg.."\t-- To: "..Profile.."\r\n"
		msg = msg.."\t-- Message: "..Msg.."\r\n"
		msg = msg.."\t"..string.rep("-",100)
		return msg
	end
	if (bToAll) then
		SendPmToAll(sBot,MassSend(user,Msg,"All"));
		user:SendData(sBot,"Your message has been sent!");
		return 1;
	end
	for i,v in frmHub:GetOnlineUsers() do
		if (v.iProfile == ProfileIdx) then
			v:SendPM(sBot,MassSend(user,Msg,GetProfileName(ProfileIdx)));
			SendPmToOps(sBot,"Report of Mass Message:"..MassSend(user,Msg,GetProfileName(ProfileIdx)))
		end
	end
	user:SendData(sBot,"Your message has been sent!");
	return 1;
end

function Denial(Table, user)
	if (CmdOpt[Table][user.iProfile] ~= 1) then
		user:SendData(sBot,"You are not allowed to use this command!");
		return 1;
	end
end

6Marilyn6Manson6

#3
Or this:

sBot = "Mass-Message";
sPrefix = "!";

CmdOpt = {
	["massmaster"] = {
		[0] = 1,
		[1] = 1,
		[2] = 0,
		[3] = 0,
		[-1] = 0,
	},
	["massop"] = {
		[0] = 1,
		[1] = 1,
		[2] = 0,
		[3] = 0,
		[-1] = 0,
	},
	["massvip"] = {
		[0] = 1,
		[1] = 1,
		[2] = 1,
		[3] = 0,
		[-1] = 0,
	},
	["massreg"] = {
		[0] = 1,
		[1] = 1,
		[2] = 1,
		[3] = 0,
		[-1] = 0,
	}, 
	["massall"] = {
		[0] = 1,
		[1] = 1,
		[2] = 0,
		[3] = 0,
		[-1] = 0,
	},
	["massunreg"] = {
		[0] = 1,
		[1] = 1,
		[2] = 0,
		[3] = 0,
		[-1] = 0,
	}
};

function Main()
	frmHub:RegBot(sBot);
end

function ChatArrival(user,data)
	data=string.sub(data,1,-2);
	local s,e,cmd = string.find(data,"^%b<>%s+(%S+)");
	local Prefix = string.sub(cmd,1,1);
	if (Prefix == sPrefix) then
		cmd = string.lower(string.sub(cmd,2,string.len(cmd)));
		if (Commands[cmd]) then
			return (Commands[cmd](user,data))
		end
	end
end

Commands = {
	["massmaster"] = 
	function(user,data)
		if (Denial("massmaster",user) == 1) then return 1 end
		local s,e,Msg = string.find(data,"^%b<>%s+%S+%s+(.*)");
		return MassMessage(1,Msg,nil,user);
	end,

	["massop"] = 
	function(user,data)
		if (Denial("massop",user) == 1) then return 1 end
		local s,e,Msg = string.find(data,"^%b<>%s+%S+%s+(.*)");
		return MassMessage(1,Msg,nil,user);
	end,

	["massvip"] = 
	function(user,data)
		if (Denial("massvip",user) == 1) then return 1 end
		local s,e,Msg = string.find(data,"^%b<>%s+%S+%s+(.*)");
		return MassMessage(2,Msg,nil,user);
	end,

	["massreg"] = 
	function(user,data)
		if (Denial("massreg",user) == 1) then return 1 end
		local s,e,Msg = string.find(data,"^%b<>%s+%S+%s+(.*)");
		return MassMessage(3,Msg,nil,user);
	end,

	["massall"] = 
	function(user,data)
		if (Denial("massall",user) == 1) then return 1 end
		local s,e,Msg = string.find(data,"^%b<>%s+%S+%s+(.*)");
		return MassMessage(-1,Msg,1,user);
	end,
	["massunreg"] = 
	function(user,data)
		if (Denial("massunreg",user) == 1) then return 1 end
		local s,e,Msg = string.find(data,"^%b<>%s+%S+%s+(.*)");
		return MassMessage(-1,Msg,nil,user);
	end,
};

function MassMessage(ProfileIdx, Msg, bToAll, user)
	local MassSend = function(user,Msg,Profile)
		local msg = "\r\n\r\n\t"..string.rep("-",100).."\r\n"
		msg = msg.."\t-- Sender: "..user.sName.."\r\n\r\n"
		local Profile = Profile or "Unreg"
		msg = msg.."\t-- To: "..Profile.."\r\n"
		msg = msg.."\t-- Message: "..Msg.."\r\n"
		msg = msg.."\t"..string.rep("-",100)
		return msg
	end
	if (bToAll) then
		SendPmToAll(sBot,MassSend(user,Msg,"All"));
		user:SendData(sBot,"Your message has been sent!");
		return 1;
	end
	for i,v in frmHub:GetOnlineUsers() do
		if (v.iProfile == ProfileIdx) then
			v:SendPM(sBot,MassSend(user,Msg,GetProfileName(ProfileIdx)));
			SendPmToOps(sBot,"Report of Mass Message:"..MassSend(user,Msg,GetProfileName(ProfileIdx)))
		end
	end
	user:SendData(sBot,"Your message has been sent!");
	return 1;
end

function Denial(Table, user)
	if (CmdOpt[Table][user.iProfile] ~= 1) then
		user:SendData(sBot,"You are not allowed to use this command!");
		return 1;
	end
end

:D . C ya

Markitos

6Marilyn6Manson6 disable smilies in ur post

6Marilyn6Manson6

Now is ok... sorry for first :D

SMF spam blocked by CleanTalk