Dawgie

Bot code

Dec 7th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. from Libraries import biblib
  2.  
  3. server = input("What Server do you want me to connect to? ")
  4. channel = input("What channel do you want to join on " + server + "? ")
  5.  
  6. bot = biblib.bot()
  7. bot.initconnection((server, 6667), "Nyghtbot")
  8.  
  9. def connected():
  10. bot.Join(channel)
  11.  
  12. commands = {}
  13. commandtag = "!"
  14.  
  15. def set_tag(tag):
  16. global commandtag
  17. commandtag = tag
  18.  
  19. def look_for_command(source, user, message):
  20. tokens = message.split(" ")
  21. if len(tokens) < 1:
  22. return
  23. command = tokens[0]
  24. if command.startswith(commandtag):
  25. command = command.lstrip(commandtag)
  26. if command in commands:
  27. commands[command](source, user, message)
  28.  
  29. def privmsg(user, message):
  30. look_for_command(user, user, message)
  31.  
  32. def register_command(command, callback):
  33. commands[command] = callback
  34.  
  35. def command_eval(source, user, message):
  36. message = " ".join(message.split(" ")[1:])
  37. try:
  38. bot.Msg(source, "{}: {}".format(user, eval(message)))
  39. except Exception as e:
  40. bot.Msg(source, "{}: error: {}".format(user, e))
  41.  
  42. def command_help(source, user, message):
  43. bot.Msg(source, "Available commands: {}".format(", ".join(commands.keys())))
  44.  
  45.  
  46.  
  47.  
  48. bot.ircevents.Connected += connected
  49. bot.ircevents.ChanMsg += look_for_command
  50. bot.ircevents.PrivMsg += privmsg
  51.  
  52.  
  53. register_command("eval", command_eval)
  54. register_command("help", command_help)
Advertisement
Add Comment
Please, Sign In to add comment