Advertising
Paste Description for Someone
Jabber bot
- Someone
- Wednesday, November 29th, 2006 at 3:46:41pm MST
- BotName = "John";
- BotJID = "mattj@jabber.org";
- BotPass = "********";
- activejids = {};
- function onMessage(msg)
- command, param = msg.body:match("^!(%a*)%s*(.*)");
- if (string.find(msg.body:upper(), BotName:upper())) ~= nil and GetResource(msg.fromFull) ~= BotName or msg.type == "chat" or string.find(msg.body:upper(),"HI ALL") then
- print("Refreshed active status of "..msg.fromFull.."\n");
- activejids[msg.fromFull] = os.time();
- end
- --print(msg.fromFull.." wrote: "..msg.body.."\n");
- if command == "time" then
- return Reply(msg, "The time (in the UK) is "..os.date());
- elseif command == "Jabber" then
- return Reply(msg, "http://getjabber.no-ip.info/");
- elseif command == "slap" then
- if (string.match(param:upper(),".*%s*M[%p%s]*A[%p%s]*T[%p%s]*T[%p%s]*.*")) == nil then
- return Reply(msg, "/me slaps "..param.." for "..GetResource(msg.fromFull));
- end
- return Reply(msg, "No way I'm touching him!");
- elseif command == "ping" then
- return Reply(msg, "pong");
- elseif command == "xep" then
- return Reply(msg, GetXEPInfo(param));
- elseif command == "join" and GetResource(msg.fromFull) == "MattJ" then
- JoinMUC(param);
- elseif command == "reload" then
- dofile("bot.lua");
- Reply(msg, "Reloaded ok");
- elseif command == "run" then
- return Reply(msg, "/me runs");
- end
- if os.difftime(os.time(),activejids[msg.fromFull]) < 120 then
- Sleep(math.random(3, 6));
- activejids[msg.fromFull] = os.time();
- return MatchPattern(msg);
- else
- print(msg.fromFull.." is not an active JID\n");
- return nil;
- end
- end
- function Reply(msg, text)
- reply = {};
- reply.body=text;
- if msg.type == MSG_GROUPCHAT then
- print("Replying to conference\n");
- reply.to = msg.fromBare; -- Reply to conference, not the participant
- reply.type = "groupchat";
- else
- print("Replying to individual\n");
- reply.to = msg.fromFull;
- reply.type = "chat"; -- Standard message
- end
- return reply;
- end
- function GetResource(jid)
- return jid:match("^.*/(.*)$");
- end
- function GetXEPInfo(xep)
- xep_num = tostring(tonumber(xep));
- xep_num = string.rep("0", 4-xep_num:len())..xep_num;
- if xep_num == "0000" or tonumber(xep_num) == nil or tonumber(xep_num) > 200 then
- return "Sorry, the XEP number is invalid. Try again..."; end
- i = 0;
- for line in io.lines("xeps2.txt") do
- i = i +1;
- if i == tonumber(xep_num) then
- XEP, Title, Type, Status, Date = string.match(line, "^(%d*)%s*,%s*(.*)%s*,%s*(.*)%s*,%s*(.*)%s*,%s*(.*)");
- if XEP == nil then return "Unable to grab XEP info"; end
- return "XEP-"..XEP.."\nName: "..Title.."\nType: "..Type.."\nStatus: "..Status.."\nDate: "..Date.."\nLink: http://xmpp.org/extensions/xep-"..xep_num..".html";
- end
- end
- return "Unable to find the XEP you specified, sorry."
- end
- function onConnect()
- print("JoinMUC is a "..type(JoinMUC));
- print("Attempting to join...\n");
- JoinMUC("test@conference.jabber.org/"..BotName);
- end
- function MatchPattern(msg)
- print("Fallen to pattern matcher...\n");
- msgin = msg.body:match("^"..BotName.."[:,]*%s*(.*)%s*$") or msg.body; -- Strip prefixed nick, if any
- print("Looking for matches for '"..msgin.."'\n");
- for line in io.lines("ai.txt") do
- --print("Testing: "..line.."\n");
- patterns, actions = line:match("^(.*])({.*)$");
- if patterns == nil then print(line.." is an invalid line, it seems\n"); end
- --print("Patterns: "..patterns.."\n");
- for pattern in patterns:gmatch("%b[]") do
- if (msgin:lower():match(pattern:sub(2,-2):lower())) then
- print("Match for '"..msgin.."' and '"..pattern:sub(2,-2).."'\n");
- return Reply(msg, ChooseAction(actions));
- else
- -- print(msgin.." does not match "..pattern:sub(2,-2).."\n");
- end
- end
- --print("No match on line: "..line.."\n");
- end
- print("No match in file\n");
- AddToBotLog(msg);
- end
- function ChooseAction(actionlist)
- actions = {};
- for action in actionlist:gmatch("%b{}") do
- table.insert(actions, action);
- end
- return string.sub(actions[math.random(1,#actions)],2,-2);
- end
- function AddToBotLog(m)
- log = io.open("log.txt","a+");
- log:write("From: "..m.fromFull.." Body: "..m.body.."\n");
- log:close();
- end
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.