diff --git a/bot/classes/data.py b/bot/classes/data.py index 7445097..7638878 100644 --- a/bot/classes/data.py +++ b/bot/classes/data.py @@ -17,7 +17,7 @@ class Data(object): def parse_args(self): """Parse command args from self.msg into self.command and self.args.""" - args = self.msg.strip().split(" ") + args = self.msg.strip().split() while "" in args: args.remove("") diff --git a/bot/commands/ctcp.py b/bot/commands/ctcp.py new file mode 100644 index 0000000..cc98441 --- /dev/null +++ b/bot/commands/ctcp.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +import platform +import time + +from classes import BaseCommand + +class Command(BaseCommand): + """Not an actual command, this module is used to respond to the CTCP + commands PING, TIME, and VERSION.""" + name = "ctcp" + hooks = ["msg_private"] + + def check(self, data): + if data.is_command and data.command == "ctcp": + return True + + commands = ["PING", "TIME", "VERSION"] + msg = data.line[3] + if msg[:2] == ":\x01" and msg[2:].rstrip("\x01") in commands: + return True + return False + + def process(self, data): + if data.is_command: + return + + target = data.nick + command = data.line[3][1:].strip("\x01") + + if command == "PING": + msg = " ".join(data.line[4:]) + if msg: + self.connection.notice(target, "\x01PING {0}\x01".format(msg)) + else: + self.connection.notice(target, "\x01PING\x01") + + elif command == "TIME": + ts = time.strftime("%a, %d %b %Y %H:%M:%S %Z", time.localtime()) + self.connection.notice(target, "\x01TIME {0}\x01".format(ts)) + + elif command == "VERSION": + vers = "EarwigBot - 0.1-dev - Python/{0} https://github.com/earwig/earwigbot" + vers = vers.format(platform.python_version()) + self.connection.notice(target, "\x01VERSION {0}\x01".format(vers)) diff --git a/bot/commands/help.py b/bot/commands/help.py index 10bad4f..5bb9e3d 100644 --- a/bot/commands/help.py +++ b/bot/commands/help.py @@ -29,7 +29,7 @@ class Command(BaseCommand): # Create a dummy message to test which commands pick up the user's # input: - dummy = Data("PRIVMSG #fake-channel :Fake messsage!") + dummy = Data("PRIVMSG #fake-channel :Fake messsage!".split()) dummy.command = command.lower() dummy.is_command = True diff --git a/bot/frontend.py b/bot/frontend.py index 8566f44..2679174 100644 --- a/bot/frontend.py +++ b/bot/frontend.py @@ -91,13 +91,13 @@ def _process_message(line): print "Restarting bot per owner request..." return - # If we are pinged, pong back to the server: - if line[0] == "PING": + # If we are pinged, pong back: + elif line[0] == "PING": msg = " ".join(("PONG", line[1])) connection.send(msg) # On successful connection to the server: - if line[1] == "376": + elif line[1] == "376": # If we're supposed to auth to NickServ, do that: try: username = config.irc["frontend"]["nickservUsername"]