From 76246dea70338c8958a4d856fbc0a6ebeed1379a Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 5 Sep 2015 12:02:45 -0700 Subject: [PATCH] unreal: add NOTICE and PRIVMSG (inbound/outbound) --- protocols/unreal.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/protocols/unreal.py b/protocols/unreal.py index 47a2285..511b5a5 100644 --- a/protocols/unreal.py +++ b/protocols/unreal.py @@ -8,7 +8,7 @@ curdir = os.path.dirname(__file__) sys.path += [curdir, os.path.dirname(curdir)] import utils from log import log -from ts6_common import parseArgs, removeClient, _send +from ts6_common import parseArgs, removeClient, _send, messageClient, noticeClient from ts6_common import handle_quit, handle_part, handle_nick, handle_kill from classes import * @@ -17,6 +17,8 @@ proto_ver = 2351 hook_map = {} +### OUTGOING COMMAND FUNCTIONS + def spawnClient(irc, nick, ident='null', host='null', realhost=None, modes=set(), server=None, ip='0.0.0.0', realname=None, ts=None, opertype=None): server = server or irc.sid @@ -52,6 +54,8 @@ def pingServer(irc, source=None, target=None): if not (target is None or source is None): _send(irc, source, 'PING %s %s' % (irc.servers[source].name, irc.servers[target].name)) +### HANDLERS + def connect(irc): ts = irc.start_ts irc.caps = [] @@ -196,6 +200,13 @@ def _sidToServer(irc, sname): if v.name.lower() == nick: return k +def _convertNick(irc, target): + target = utils.nickToUid(irc, target) or target + if target not in irc.users: + log.warning("(%s) Possible desync? Got command target %s, who " + "isn't in our user list!") + return target + def handle_events(irc, data): # Unreal's protocol has three styles of commands, @servernumeric, :user, and plain commands. # e.g. NICK introduction looks like: @@ -229,3 +240,12 @@ def handle_events(irc, data): parsed_args = func(irc, numeric, command, args) if parsed_args is not None: return [numeric, command, parsed_args] + +def handle_privmsg(irc, source, command, args): + # Convert nicks to UIDs, where they exist. + target = _convertNick(irc, args[0]) + # We use lowercase channels internally, but uppercase UIDs. + if utils.isChannel(target): + target = utils.toLower(irc, target) + return {'target': target, 'text': args[1]} +handle_notice = handle_privmsg