@@ -17,7 +17,7 @@ class Data(object): | |||||
def parse_args(self): | def parse_args(self): | ||||
"""Parse command args from self.msg into self.command and self.args.""" | """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: | while "" in args: | ||||
args.remove("") | args.remove("") | ||||
@@ -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)) |
@@ -29,7 +29,7 @@ class Command(BaseCommand): | |||||
# Create a dummy message to test which commands pick up the user's | # Create a dummy message to test which commands pick up the user's | ||||
# input: | # input: | ||||
dummy = Data("PRIVMSG #fake-channel :Fake messsage!") | |||||
dummy = Data("PRIVMSG #fake-channel :Fake messsage!".split()) | |||||
dummy.command = command.lower() | dummy.command = command.lower() | ||||
dummy.is_command = True | dummy.is_command = True | ||||
@@ -91,13 +91,13 @@ def _process_message(line): | |||||
print "Restarting bot per owner request..." | print "Restarting bot per owner request..." | ||||
return | 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])) | msg = " ".join(("PONG", line[1])) | ||||
connection.send(msg) | connection.send(msg) | ||||
# On successful connection to the server: | # On successful connection to the server: | ||||
if line[1] == "376": | |||||
elif line[1] == "376": | |||||
# If we're supposed to auth to NickServ, do that: | # If we're supposed to auth to NickServ, do that: | ||||
try: | try: | ||||
username = config.irc["frontend"]["nickservUsername"] | username = config.irc["frontend"]["nickservUsername"] | ||||