From 6b79793336678c5acf7b164e8946c10d9b1b182e Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 24 Apr 2015 23:00:01 -0700 Subject: [PATCH] cleanup, add commands.py plugin (incomplete) --- plugins/commands.py | 16 ++++++++++++++++ plugins/hello.py | 2 +- proto.py | 9 +++------ 3 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 plugins/commands.py diff --git a/plugins/commands.py b/plugins/commands.py new file mode 100644 index 0000000..beec961 --- /dev/null +++ b/plugins/commands.py @@ -0,0 +1,16 @@ +# commands.py: base PyLink commands +import sys, os +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +import proto + +@proto.add_cmd +def tell(irc, source, args): + try: + target, text = args[0], ' '.join(args[1:]) + except IndexError: + proto._sendFromUser(irc, 'PRIVMSG %s :Error: not enough arguments' % source) + return + try: + proto._sendFromUser(irc, 'NOTICE %s :%s' % (irc.users[target].uid, text)) + except KeyError: + proto._sendFromUser(irc, 'PRIVMSG %s :unknown user %r' % (source, target)) diff --git a/plugins/hello.py b/plugins/hello.py index 982796f..1dec4e3 100644 --- a/plugins/hello.py +++ b/plugins/hello.py @@ -3,5 +3,5 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import proto @proto.add_cmd -def hello(irc, source, command, args): +def hello(irc, source, args): proto._sendFromUser(irc, 'PRIVMSG %s :hello!' % source) diff --git a/proto.py b/proto.py index 85312c2..0380bad 100644 --- a/proto.py +++ b/proto.py @@ -78,18 +78,16 @@ def handle_ping(irc, servernumeric, command, args): _sendFromServer(irc, 'PONG %s' % args[1]) def handle_privmsg(irc, source, command, args): - # _sendFromUser(irc, 'PRIVMSG %s :hello!' % numeric) - print(irc.users) prefix = irc.conf['bot']['prefix'] if args[0] == irc.pseudoclient.uid: - cmd_args = args[1].split(' ', 1) + cmd_args = args[1].split(' ') cmd = cmd_args[0] try: - cmd_args = cmd_args[1] + cmd_args = cmd_args[1:] except IndexError: cmd_args = [] try: - bot_commands[cmd](irc, source, command, args) + bot_commands[cmd](irc, source, cmd_args) except KeyError: _sendFromUser(irc, 'PRIVMSG %s :unknown command %r' % (source, cmd)) @@ -161,7 +159,6 @@ def handle_events(irc, data): numeric = args[0] command = args[1] args = args[2:] - print(args) except IndexError: return