From 049b7f5049199bcbe5927127ab4a16d572233cbf Mon Sep 17 00:00:00 2001 From: James Lu Date: Wed, 8 Jul 2015 18:23:32 -0700 Subject: [PATCH] pr/insp: add modeServer, modeClient commands Closes #32. --- protocols/inspircd.py | 31 +++++++++++++++++++++++++++++++ tests/test_proto_inspircd.py | 12 ++++++++++++ 2 files changed, 43 insertions(+) diff --git a/protocols/inspircd.py b/protocols/inspircd.py index 0da3713..6151b91 100644 --- a/protocols/inspircd.py +++ b/protocols/inspircd.py @@ -128,6 +128,37 @@ def nickClient(irc, numeric, newnick): _sendFromUser(irc, numeric, 'NICK %s %s' % (newnick, int(time.time()))) irc.users[numeric].nick = newnick +def _sendModes(irc, numeric, target, modes): + # -> :9PYAAAAAA FMODE #pylink 1433653951 +os 9PYAAAAAA + # -> :9PYAAAAAA MODE 9PYAAAAAA -i+w + joinedmodes = utils.joinModes(modes) + utils.applyModes(irc, target, modes) + if utils.isChannel(target): + ts = irc.channels[target.lower()].ts + _sendFromUser(irc, numeric, 'FMODE %s %s %s' % (target, ts, joinedmodes)) + else: + _sendFromUser(irc, numeric, 'MODE %s %s' % (target, joinedmodes)) + +def modeClient(irc, numeric, target, modes): + """ + + Sends modes from a PyLink PseudoClient. should be + a list of (mode, arg) tuples, in the format of utils.parseModes() output. + """ + if not utils.isInternalClient(irc, numeric): + raise LookupError('No such PyLink PseudoClient exists.') + _sendModes(irc, numeric, target, modes) + +def modeServer(irc, numeric, target, modes): + """ + + Sends modes from a PyLink PseudoServer. should be + a list of (mode, arg) tuples, in the format of utils.parseModes() output. + """ + if not utils.isInternalServer(irc, numeric): + raise LookupError('No such PyLink PseudoClient exists.') + _sendModes(irc, numeric, target, modes) + def connect(irc): irc.start_ts = ts = int(time.time()) irc.uidgen = {} diff --git a/tests/test_proto_inspircd.py b/tests/test_proto_inspircd.py index c9786d2..aa551de 100644 --- a/tests/test_proto_inspircd.py +++ b/tests/test_proto_inspircd.py @@ -87,6 +87,18 @@ class TestProtoInspIRCd(unittest.TestCase): self.proto.nickClient(self.irc, self.u, 'NotPyLink') self.assertEqual('NotPyLink', self.irc.users[self.u].nick) + def testModeClient(self): + testuser = self.proto.spawnClient(self.irc, 'testcakes') + self.irc.takeMsgs() + self.proto.modeClient(self.irc, self.u, testuser.uid, [('+i', None), ('+w', None)]) + self.assertEqual({('i', None), ('w', None)}, testuser.modes) + + self.proto.modeClient(self.irc, self.u, '#pylink', [('+s', None), ('+l', '30')]) + self.assertEqual({('s', None), ('l', '30')}, self.irc.channels['#pylink'].modes) + + cmds = self.irc.takeCommands(self.irc.takeMsgs()) + self.assertEqual(cmds, ['MODE', 'FMODE']) + def testSpawnServer(self): # Incorrect SID length self.assertRaises(Exception, self.proto.spawnServer, self.irc, 'subserver.pylink', '34Q0')