Advertisement
ds84182

botframework.lua

Apr 9th, 2014
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. print("botframework.lua - So you can bot inside a bot")
  2. settings = {prefix=":"}
  3. bot = {}
  4. bot.stop = false
  5. bot.commands = {}
  6. function bot.addCommand(name,func) bot.commands[name] = func end
  7. function bot.removeCommand(name) bot.commands[name] = nil end
  8. bot.commands.say = function(args,msg,nick,chan,host) print(msg) end
  9. bot.commands.stop = function(args,msg,nick) if nick == irc.nick then print("Stopping botframework.lua") bot.stop = true end end
  10.  
  11. -- copypasta
  12. function split(str, pat)
  13.     local t = {}  -- NOTE: use {n = 0} in Lua-5.0
  14.     local fpat = "(.-)" .. pat
  15.     local last_end = 1
  16.     local s, e, cap = str:find (fpat, 1)
  17.     while s do
  18.         if s ~= 1 or cap ~= "" then
  19.      table.insert(t,cap)
  20.         end
  21.         last_end = e+1
  22.         s, e, cap = str:find(fpat, last_end)
  23.     end
  24.     if last_end <= #str then
  25.         cap = str:sub(last_end)
  26.         table.insert(t, cap)
  27.     end
  28.     return t
  29. end
  30.  
  31. while not bot.stop do
  32.     local msg, nick, chan, host = event.wait("msg")
  33.     if msg:sub(1,#settings.prefix) == settings.prefix then
  34.         msg = msg:sub(#settings.prefix+1)
  35.         local args = split(msg," ")
  36.         local cmd = table.remove(args,1)
  37.         msg = msg:sub(#cmd+2)
  38.         if bot.commands[cmd] then
  39.             bot.commands[cmd](args,msg,nick,chan,host)
  40.         end
  41.     end
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement