Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Libraries import biblib
- server = input("What Server do you want me to connect to? ")
- channel = input("What channel do you want to join on " + server + "? ")
- bot = biblib.bot()
- bot.initconnection((server, 6667), "Nyghtbot")
- def connected():
- bot.Join(channel)
- commands = {}
- commandtag = "!"
- def set_tag(tag):
- global commandtag
- commandtag = tag
- def look_for_command(source, user, message):
- tokens = message.split(" ")
- if len(tokens) < 1:
- return
- command = tokens[0]
- if command.startswith(commandtag):
- command = command.lstrip(commandtag)
- if command in commands:
- commands[command](source, user, message)
- def privmsg(user, message):
- look_for_command(user, user, message)
- def register_command(command, callback):
- commands[command] = callback
- def command_eval(source, user, message):
- message = " ".join(message.split(" ")[1:])
- try:
- bot.Msg(source, "{}: {}".format(user, eval(message)))
- except Exception as e:
- bot.Msg(source, "{}: error: {}".format(user, e))
- def command_help(source, user, message):
- bot.Msg(source, "Available commands: {}".format(", ".join(commands.keys())))
- bot.ircevents.Connected += connected
- bot.ircevents.ChanMsg += look_for_command
- bot.ircevents.PrivMsg += privmsg
- register_command("eval", command_eval)
- register_command("help", command_help)
Advertisement
Add Comment
Please, Sign In to add comment