3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-01-23 18:54:05 +01:00

pr/insp: add modeServer, modeClient commands

Closes #32.
This commit is contained in:
James Lu 2015-07-08 18:23:32 -07:00
parent cbfabb2ba1
commit 049b7f5049
2 changed files with 43 additions and 0 deletions

View File

@ -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):
"""<irc object> <client numeric> <list of modes>
Sends modes from a PyLink PseudoClient. <list of modes> 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):
"""<irc object> <server SID> <list of modes>
Sends modes from a PyLink PseudoServer. <list of modes> 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 = {}

View File

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