Browse Source

adding CTCP command support; cleanup

tags/v0.1^2
Ben Kurtovic 12 years ago
parent
commit
0992d3c9d9
4 changed files with 50 additions and 5 deletions
  1. +1
    -1
      bot/classes/data.py
  2. +45
    -0
      bot/commands/ctcp.py
  3. +1
    -1
      bot/commands/help.py
  4. +3
    -3
      bot/frontend.py

+ 1
- 1
bot/classes/data.py View File

@@ -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("")


+ 45
- 0
bot/commands/ctcp.py View File

@@ -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))

+ 1
- 1
bot/commands/help.py View File

@@ -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



+ 3
- 3
bot/frontend.py View File

@@ -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"]


Loading…
Cancel
Save