mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 19:52:54 +01:00
* added mircColor() function to ircutils as well as mircColors dict
* added test cases for this function * implemented nick coloring for Relay
This commit is contained in:
parent
ebc3533275
commit
0e16b70f8b
@ -213,7 +213,7 @@ class Relay(callbacks.Privmsg):
|
||||
if abbreviation != self.abbreviations[realIrc]:
|
||||
Channel = otherIrc.state.channels[channel]
|
||||
usersS = ', '.join([s for s in Channel.users if s.strip()!=''])
|
||||
users.append('\x02%s\x02: %s' % (abbreviation, usersS))
|
||||
users.append('%s: %s' % (ircutils.bold(abbreviation), usersS))
|
||||
irc.reply(msg, '; '.join(users))
|
||||
|
||||
def relaywhois(self, irc, msg, args):
|
||||
@ -260,11 +260,17 @@ class Relay(callbacks.Privmsg):
|
||||
replyIrc.reply(replyMsg, s)
|
||||
|
||||
def _formatPrivmsg(self, nick, abbreviation, msg):
|
||||
# colorize nicks
|
||||
color_index = (hash(nick) % 14) + 2
|
||||
color = ircutils._colors.keys()[color_index]
|
||||
if ircmsgs.isAction(msg):
|
||||
return '* \x02%s\x02@%s %s' % \
|
||||
(nick, abbreviation, ircmsgs.unAction(msg))
|
||||
return '* %s@%s %s' % \
|
||||
(ircutils.mircColor(nick, color), abbreviation,
|
||||
ircmsgs.unAction(msg))
|
||||
else:
|
||||
return '<\x02%s\x02@%s> %s' % (nick, abbreviation, msg.args[1])
|
||||
return '<%s@%s> %s' % \
|
||||
(ircutils.mircColor(nick, color), abbreviation,
|
||||
msg.args[1])
|
||||
|
||||
def doPrivmsg(self, irc, msg):
|
||||
callbacks.Privmsg.doPrivmsg(self, irc, msg)
|
||||
|
@ -197,6 +197,35 @@ def bold(s):
|
||||
"""Returns the string s, bolded."""
|
||||
return "\x02%s\x02" % s
|
||||
|
||||
mircColors = {None: '',
|
||||
'white': '0',
|
||||
'black': '1',
|
||||
'blue': '2',
|
||||
'green': '3',
|
||||
'red': '4',
|
||||
'brown': '5',
|
||||
'purple': '6',
|
||||
'orange': '7',
|
||||
'yellow': '8',
|
||||
'light green': '9',
|
||||
'teal': '10',
|
||||
'light blue': '11',
|
||||
'dark blue': '12',
|
||||
'pink': '13',
|
||||
'dark grey': '14',
|
||||
'light grey': '15'}
|
||||
|
||||
def mircColor(s, fg=None, bg=None):
|
||||
"""Returns the string s, with the appropriate mIRC color codes applied."""
|
||||
if fg is None and bg is None:
|
||||
return s
|
||||
else:
|
||||
if bg is None:
|
||||
return "\x03%s%s\x03" % (mircColors[fg], s)
|
||||
else:
|
||||
return "\x03%s,%s%s\x03" % (mircColors[fg], mircColors[bg], s)
|
||||
|
||||
|
||||
def isValidArgument(s):
|
||||
"""Returns if s is strictly a valid argument for an IRC message."""
|
||||
return '\r' not in s and '\n' not in s and '\x00' not in s
|
||||
|
@ -70,6 +70,23 @@ class FunctionsTestCase(unittest.TestCase):
|
||||
s = ircutils.bold('foo')
|
||||
self.assertEqual(s[0], '\x02')
|
||||
self.assertEqual(s[-1], '\x02')
|
||||
|
||||
def testMircColor(self):
|
||||
# No colors provided should return the same string
|
||||
s = 'foo'
|
||||
self.assertEqual(s, ircutils.mircColor(s))
|
||||
# Test positional args
|
||||
self.assertEqual('\x030foo\x03',
|
||||
ircutils.mircColor(s, 'white'))
|
||||
self.assertEqual('\x031,2foo\x03',
|
||||
ircutils.mircColor(s, 'black', 'blue'))
|
||||
self.assertEqual('\x03,3foo\x03',
|
||||
ircutils.mircColor(s, None, 'green'))
|
||||
# Test keyword args
|
||||
self.assertEqual('\x034foo\x03', ircutils.mircColor(s, fg='red'))
|
||||
self.assertEqual('\x03,5foo\x03', ircutils.mircColor(s, bg='brown'))
|
||||
self.assertEqual('\x036,7foo\x03',
|
||||
ircutils.mircColor(s, bg='orange', fg='purple'))
|
||||
|
||||
def testSafeArgument(self):
|
||||
s = 'I have been running for 9 seconds'
|
||||
|
Loading…
Reference in New Issue
Block a user