mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-05-02 00:11:06 -05:00
Updates to SupyMisc
- SupyMisc: rename config variable repeat.max -> maxLen - Add more tests for SupyMisc - Move 'colors' command from Randomness to SupyMisc
This commit is contained in:
parent
f96f3c2527
commit
3fa5773183
@ -205,18 +205,6 @@ class Randomness(callbacks.Plugin):
|
||||
irc.reply(self._attack(user), action=True)
|
||||
attack = wrap(attack, ['text'])
|
||||
|
||||
def colors(self, irc, msg, args):
|
||||
"""takes no arguments.
|
||||
|
||||
Replies with a display of IRC colour codes."""
|
||||
s = ("\x03,00 \x0F\x0300 00\x0F \x03,01 \x0F\x0301 01\x0F \x03,02 \x0F\x0302 02\x0F \x03,03 "
|
||||
"\x0F\x0303 03\x0F \x03,04 \x0F\x0304 04\x0F \x03,05 \x0F\x0305 05\x0F \x03,06 \x0F\x0306"
|
||||
" 06\x0F \x03,07 \x0F\x0307 07\x0F \x03,08 \x0F\x0308 08\x0F \x03,09 \x0F\x0309 09\x0F "
|
||||
"\x03,10 \x0F\x0310 10\x0F \x03,11 \x0F\x0311 11\x0F \x03,12 \x0F\x0312 12\x0F \x03,13 "
|
||||
"\x0F\x0313 13\x0F \x03,14 \x0F\x0314 14\x0F \x03,15 \x0F\x0315 15\x0F")
|
||||
irc.reply(s)
|
||||
colors = wrap(colors)
|
||||
|
||||
Class = Randomness
|
||||
|
||||
|
||||
|
@ -48,13 +48,10 @@ def configure(advanced):
|
||||
|
||||
|
||||
SupyMisc = conf.registerPlugin('SupyMisc')
|
||||
# This is where your configuration variables (if any) should go. For example:
|
||||
# conf.registerGlobalValue(SupyMisc, 'someConfigVariableName',
|
||||
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
|
||||
|
||||
conf.registerGroup(SupyMisc, 'repeat')
|
||||
conf.registerGlobalValue(SupyMisc.repeat, 'max',
|
||||
registry.PositiveInteger(100, _("""The maximum value <num> someone can use with the repeat command.""")))
|
||||
conf.registerGlobalValue(SupyMisc, 'maxLen',
|
||||
registry.PositiveInteger(100, _("""The maximum value/lengths someone
|
||||
can use with the repeat and mreplace commands.""")))
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
@ -28,6 +28,10 @@
|
||||
|
||||
###
|
||||
import random
|
||||
try:
|
||||
from itertools import izip
|
||||
except ImportError:
|
||||
izip = zip
|
||||
|
||||
import supybot.conf as conf
|
||||
import supybot.utils as utils
|
||||
@ -68,7 +72,7 @@ class SupyMisc(callbacks.Plugin):
|
||||
Returns <text> repeated <num> times. <num> must be a positive integer.
|
||||
To keep leading and trailing spaces, it is recommended to quote the <text>
|
||||
argument " like this ". """
|
||||
maxN = self.registryValue("repeat.max")
|
||||
maxN = self.registryValue("maxLen")
|
||||
if num <= maxN:
|
||||
irc.reply(text * num)
|
||||
else:
|
||||
@ -97,13 +101,30 @@ class SupyMisc(callbacks.Plugin):
|
||||
Replaces all instances of <bad substringX> with <good substringX> in <text> (from left to right).
|
||||
Essentially an alternative for Supybot's format.translate, but with support for substrings
|
||||
of different lengths."""
|
||||
if len(good) != len(bad):
|
||||
maxLen = self.registryValue("maxLen")
|
||||
lbad, lgood = len(good), len(bad)
|
||||
if lbad > maxLen or lgood > maxLen:
|
||||
irc.error("Too many substrings given. Current maximum: {}" \
|
||||
.format(maxN), Raise=True)
|
||||
if lbad != lgood:
|
||||
irc.error("<bad substrings> must be the same length as <good substrings>", Raise=True)
|
||||
for pair in itertools.izip(bad, good):
|
||||
for pair in izip(bad, good):
|
||||
text = text.replace(pair[0], pair[1])
|
||||
irc.reply(text)
|
||||
mreplace = wrap(mreplace, [commalist('something'), commalist('something'), 'text'])
|
||||
|
||||
def colors(self, irc, msg, args):
|
||||
"""takes no arguments.
|
||||
|
||||
Replies with a display of IRC colour codes."""
|
||||
s = ("\x03,00 \x0F\x0300 00\x0F \x03,01 \x0F\x0301 01\x0F \x03,02 \x0F\x0302 02\x0F \x03,03 "
|
||||
"\x0F\x0303 03\x0F \x03,04 \x0F\x0304 04\x0F \x03,05 \x0F\x0305 05\x0F \x03,06 \x0F\x0306"
|
||||
" 06\x0F \x03,07 \x0F\x0307 07\x0F \x03,08 \x0F\x0308 08\x0F \x03,09 \x0F\x0309 09\x0F "
|
||||
"\x03,10 \x0F\x0310 10\x0F \x03,11 \x0F\x0311 11\x0F \x03,12 \x0F\x0312 12\x0F \x03,13 "
|
||||
"\x0F\x0313 13\x0F \x03,14 \x0F\x0314 14\x0F \x03,15 \x0F\x0315 15\x0F")
|
||||
irc.reply(s)
|
||||
colors = wrap(colors)
|
||||
|
||||
def tld(self, irc, msg, args, text):
|
||||
"""<tld>
|
||||
|
||||
|
@ -34,6 +34,10 @@ from supybot.test import *
|
||||
class SupyMiscTestCase(PluginTestCase):
|
||||
plugins = ('SupyMisc',)
|
||||
|
||||
def setUp(self):
|
||||
PluginTestCase.setUp(self)
|
||||
self.prefix = 'foo!bar@baz.not'
|
||||
|
||||
def testTld(self):
|
||||
self.assertNotError('tld .com')
|
||||
|
||||
@ -47,4 +51,17 @@ class SupyMiscTestCase(PluginTestCase):
|
||||
from codecs import unicode_escape_decode as u
|
||||
self.assertNotError('tld '+u('\u7f51\u7edc')[0])
|
||||
|
||||
def testColorwheel(self):
|
||||
self.assertRegexp('colors', '.*\x03.*')
|
||||
|
||||
def testHostFetchers(self):
|
||||
self.assertResponse('me', 'foo')
|
||||
self.assertResponse('getident', 'bar')
|
||||
self.assertResponse('gethost', 'baz.not')
|
||||
self.assertResponse('botnick', self.nick)
|
||||
|
||||
def testmreplace(self):
|
||||
self.assertResponse('mreplace hi,there hello,ok hmm, hi there everyone',
|
||||
'hmm, hello ok everyone')
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
Loading…
x
Reference in New Issue
Block a user