mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-09 02:54:13 +01:00
Converted to use commands.
This commit is contained in:
parent
2ff2dadd81
commit
349155191a
@ -44,9 +44,9 @@ from cStringIO import StringIO
|
|||||||
|
|
||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
|
from supybot.commands import wrap
|
||||||
import supybot.ircmsgs as ircmsgs
|
import supybot.ircmsgs as ircmsgs
|
||||||
import supybot.ircutils as ircutils
|
import supybot.ircutils as ircutils
|
||||||
import supybot.privmsgs as privmsgs
|
|
||||||
import supybot.registry as registry
|
import supybot.registry as registry
|
||||||
import supybot.callbacks as callbacks
|
import supybot.callbacks as callbacks
|
||||||
|
|
||||||
@ -98,16 +98,14 @@ class Filter(callbacks.Privmsg):
|
|||||||
'scramble', 'morse', 'reverse', 'colorize', 'squish',
|
'scramble', 'morse', 'reverse', 'colorize', 'squish',
|
||||||
'supa1337', 'colorstrip', 'aol', 'rainbow', 'spellit',
|
'supa1337', 'colorstrip', 'aol', 'rainbow', 'spellit',
|
||||||
'hebrew']
|
'hebrew']
|
||||||
def outfilter(self, irc, msg, args, channel):
|
def outfilter(self, irc, msg, args, channel, command):
|
||||||
"""[<channel>] [<command>]
|
"""[<channel>] [<command>]
|
||||||
|
|
||||||
Sets the outFilter of this plugin to be <command>. If no command is
|
Sets the outFilter of this plugin to be <command>. If no command is
|
||||||
given, unsets the outFilter. <channel> is only necessary if the
|
given, unsets the outFilter. <channel> is only necessary if the
|
||||||
message isn't sent in the channel itself.
|
message isn't sent in the channel itself.
|
||||||
"""
|
"""
|
||||||
command = privmsgs.getArgs(args, required=0, optional=1)
|
|
||||||
if command:
|
if command:
|
||||||
command = callbacks.canonicalName(command)
|
|
||||||
if command in self._filterCommands:
|
if command in self._filterCommands:
|
||||||
method = getattr(self, command)
|
method = getattr(self, command)
|
||||||
self.outFilters.setdefault(channel, []).append(method)
|
self.outFilters.setdefault(channel, []).append(method)
|
||||||
@ -117,35 +115,36 @@ class Filter(callbacks.Privmsg):
|
|||||||
else:
|
else:
|
||||||
self.outFilters[channel] = []
|
self.outFilters[channel] = []
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
outfilter = privmsgs.checkChannelCapability(outfilter, 'op')
|
outfilter = wrap(outfilter,
|
||||||
|
[('checkChannelCapability', 'op'), '?commandName'])
|
||||||
|
|
||||||
def hebrew(self, irc, msg, args):
|
def hebrew(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Removes all the vowels from <text>. (If you're curious why this is
|
Removes all the vowels from <text>. (If you're curious why this is
|
||||||
named 'hebrew' it's because I (jemfinch) thought of it in Hebrew class,
|
named 'hebrew' it's because I (jemfinch) thought of it in Hebrew class,
|
||||||
and printed Hebrew often elides the vowels.)
|
and printed Hebrew often elides the vowels.)
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
text = filter(lambda c: c not in 'aeiou', text)
|
text = filter(lambda c: c not in 'aeiou', text)
|
||||||
irc.reply(text)
|
irc.reply(text)
|
||||||
|
hebrew = wrap(hebrew, ['text'])
|
||||||
|
|
||||||
def squish(self, irc, msg, args):
|
def squish(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Removes all the spaces from <text>.
|
Removes all the spaces from <text>.
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
text = ''.join(text.split())
|
text = ''.join(text.split())
|
||||||
irc.reply(text)
|
irc.reply(text)
|
||||||
|
squish = wrap(squish, ['text'])
|
||||||
|
|
||||||
def binary(self, irc, msg, args):
|
def binary(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Returns the binary representation of <text>.
|
Returns the binary representation of <text>.
|
||||||
"""
|
"""
|
||||||
L = []
|
L = []
|
||||||
for c in privmsgs.getArgs(args):
|
for c in text:
|
||||||
LL = []
|
LL = []
|
||||||
i = ord(c)
|
i = ord(c)
|
||||||
counter = 8
|
counter = 8
|
||||||
@ -162,44 +161,44 @@ class Filter(callbacks.Privmsg):
|
|||||||
LL.reverse()
|
LL.reverse()
|
||||||
L.extend(LL)
|
L.extend(LL)
|
||||||
irc.reply(''.join(L))
|
irc.reply(''.join(L))
|
||||||
|
binary = wrap(binary, ['text'])
|
||||||
|
|
||||||
def hexlify(self, irc, msg, args):
|
def hexlify(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Returns a hexstring from the given string; a hexstring is a string
|
Returns a hexstring from the given string; a hexstring is a string
|
||||||
composed of the hexadecimal value of each character in the string
|
composed of the hexadecimal value of each character in the string
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
irc.reply(text.encode('hex_codec'))
|
irc.reply(text.encode('hex_codec'))
|
||||||
|
hexlify = wrap(hexlify, ['text'])
|
||||||
|
|
||||||
def unhexlify(self, irc, msg, args):
|
def unhexlify(self, irc, msg, args, text):
|
||||||
"""<hexstring>
|
"""<hexstring>
|
||||||
|
|
||||||
Returns the string corresponding to <hexstring>. Obviously,
|
Returns the string corresponding to <hexstring>. Obviously,
|
||||||
<hexstring> must be a string of hexadecimal digits.
|
<hexstring> must be a string of hexadecimal digits.
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
try:
|
try:
|
||||||
irc.reply(text.decode('hex_codec'))
|
irc.reply(text.decode('hex_codec'))
|
||||||
except TypeError:
|
except TypeError:
|
||||||
irc.error('Invalid input.')
|
irc.error('Invalid input.')
|
||||||
|
unhexlify = wrap(unhexlify, ['text'])
|
||||||
|
|
||||||
def rot13(self, irc, msg, args):
|
def rot13(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Rotates <text> 13 characters to the right in the alphabet. Rot13 is
|
Rotates <text> 13 characters to the right in the alphabet. Rot13 is
|
||||||
commonly used for text that simply needs to be hidden from inadvertent
|
commonly used for text that simply needs to be hidden from inadvertent
|
||||||
reading by roaming eyes, since it's easily reversible.
|
reading by roaming eyes, since it's easily reversible.
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
irc.reply(text.encode('rot13'))
|
irc.reply(text.encode('rot13'))
|
||||||
|
rot13 = wrap(rot13, ['text'])
|
||||||
|
|
||||||
def lithp(self, irc, msg, args):
|
def lithp(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Returns the lisping version of <text>
|
Returns the lisping version of <text>
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
text = text.replace('sh', 'th')
|
text = text.replace('sh', 'th')
|
||||||
text = text.replace('SH', 'TH')
|
text = text.replace('SH', 'TH')
|
||||||
text = text.replace('Sh', 'Th')
|
text = text.replace('Sh', 'Th')
|
||||||
@ -216,6 +215,7 @@ class Filter(callbacks.Privmsg):
|
|||||||
text = text.replace('tion', 'thion')
|
text = text.replace('tion', 'thion')
|
||||||
text = text.replace('TION', 'THION')
|
text = text.replace('TION', 'THION')
|
||||||
irc.reply(text)
|
irc.reply(text)
|
||||||
|
lithp = wrap(lithp, ['text'])
|
||||||
|
|
||||||
_leettrans = string.maketrans('oOaAeElBTiIts', '004433187!1+5')
|
_leettrans = string.maketrans('oOaAeElBTiIts', '004433187!1+5')
|
||||||
_leetres = [(re.compile(r'\b(?:(?:[yY][o0O][oO0uU])|u)\b'), 'j00'),
|
_leetres = [(re.compile(r'\b(?:(?:[yY][o0O][oO0uU])|u)\b'), 'j00'),
|
||||||
@ -224,16 +224,16 @@ class Filter(callbacks.Privmsg):
|
|||||||
(re.compile(r'[aA][tT]'), '@'),
|
(re.compile(r'[aA][tT]'), '@'),
|
||||||
(re.compile(r'[sS]\b'), 'z'),
|
(re.compile(r'[sS]\b'), 'z'),
|
||||||
(re.compile(r'x'), '><'),]
|
(re.compile(r'x'), '><'),]
|
||||||
def leet(self, irc, msg, args):
|
def leet(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Returns the l33tspeak version of <text>
|
Returns the l33tspeak version of <text>
|
||||||
"""
|
"""
|
||||||
s = privmsgs.getArgs(args)
|
|
||||||
for (r, sub) in self._leetres:
|
for (r, sub) in self._leetres:
|
||||||
s = re.sub(r, sub, s)
|
text = re.sub(r, sub, text)
|
||||||
s = s.translate(self._leettrans)
|
text = text.translate(self._leettrans)
|
||||||
irc.reply(s)
|
irc.reply(text)
|
||||||
|
leet = wrap(leet, ['text'])
|
||||||
|
|
||||||
_supaleetreplacers = [('xX', '><'), ('kK', '|<'), ('rR', '|2'),
|
_supaleetreplacers = [('xX', '><'), ('kK', '|<'), ('rR', '|2'),
|
||||||
('hH', '|-|'), ('L', '|_'), ('uU', '|_|'),
|
('hH', '|-|'), ('L', '|_'), ('uU', '|_|'),
|
||||||
@ -243,22 +243,22 @@ class Filter(callbacks.Privmsg):
|
|||||||
('D', '|)'), ('B', '|3'), ('I', ']['), ('Vv', '\\/'),
|
('D', '|)'), ('B', '|3'), ('I', ']['), ('Vv', '\\/'),
|
||||||
('wW', '\\/\\/'), ('d', 'c|'), ('b', '|>'),
|
('wW', '\\/\\/'), ('d', 'c|'), ('b', '|>'),
|
||||||
('c', '<'), ('h', '|n'),]
|
('c', '<'), ('h', '|n'),]
|
||||||
def supa1337(self, irc, msg, args):
|
def supa1337(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Replies with an especially k-rad translation of <text>.
|
Replies with an especially k-rad translation of <text>.
|
||||||
"""
|
"""
|
||||||
s = privmsgs.getArgs(args)
|
|
||||||
for (r, sub) in self._leetres:
|
for (r, sub) in self._leetres:
|
||||||
s = re.sub(r, sub, s)
|
text = re.sub(r, sub, text)
|
||||||
for (letters, replacement) in self._supaleetreplacers:
|
for (letters, replacement) in self._supaleetreplacers:
|
||||||
for letter in letters:
|
for letter in letters:
|
||||||
s = s.replace(letter, replacement)
|
text = text.replace(letter, replacement)
|
||||||
irc.reply(s)
|
irc.reply(text)
|
||||||
|
supa1337 = wrap(supa1337, ['text'])
|
||||||
|
|
||||||
_scrambleRe = re.compile(r'(?:\b|(?![a-zA-Z]))([a-zA-Z])([a-zA-Z]*)'
|
_scrambleRe = re.compile(r'(?:\b|(?![a-zA-Z]))([a-zA-Z])([a-zA-Z]*)'
|
||||||
r'([a-zA-Z])(?:\b|(?![a-zA-Z]))')
|
r'([a-zA-Z])(?:\b|(?![a-zA-Z]))')
|
||||||
def scramble(self, irc, msg, args):
|
def scramble(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Replies with a string where each word is scrambled; i.e., each internal
|
Replies with a string where each word is scrambled; i.e., each internal
|
||||||
@ -268,9 +268,9 @@ class Filter(callbacks.Privmsg):
|
|||||||
L = list(m.group(2))
|
L = list(m.group(2))
|
||||||
random.shuffle(L)
|
random.shuffle(L)
|
||||||
return '%s%s%s' % (m.group(1), ''.join(L), m.group(3))
|
return '%s%s%s' % (m.group(1), ''.join(L), m.group(3))
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
s = self._scrambleRe.sub(_subber, text)
|
s = self._scrambleRe.sub(_subber, text)
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
|
scramble = wrap(scramble, ['text'])
|
||||||
|
|
||||||
_code = {
|
_code = {
|
||||||
"A" : ".-",
|
"A" : ".-",
|
||||||
@ -322,12 +322,11 @@ class Filter(callbacks.Privmsg):
|
|||||||
}
|
}
|
||||||
_revcode = dict([(y, x) for (x, y) in _code.items()])
|
_revcode = dict([(y, x) for (x, y) in _code.items()])
|
||||||
_unmorsere = re.compile('([.-]+)')
|
_unmorsere = re.compile('([.-]+)')
|
||||||
def unmorse(self, irc, msg, args):
|
def unmorse(self, irc, msg, args, text):
|
||||||
"""<Morse code text>
|
"""<Morse code text>
|
||||||
|
|
||||||
Does the reverse of the morse command.
|
Does the reverse of the morse command.
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
text = text.replace('_', '-')
|
text = text.replace('_', '-')
|
||||||
def morseToLetter(m):
|
def morseToLetter(m):
|
||||||
s = m.group(1)
|
s = m.group(1)
|
||||||
@ -337,13 +336,13 @@ class Filter(callbacks.Privmsg):
|
|||||||
text = text.replace(' ', '')
|
text = text.replace(' ', '')
|
||||||
text = text.replace('\x00', ' ')
|
text = text.replace('\x00', ' ')
|
||||||
irc.reply(text)
|
irc.reply(text)
|
||||||
|
unmorse = wrap(unmorse, ['text'])
|
||||||
|
|
||||||
def morse(self, irc, msg, args):
|
def morse(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Gives the Morse code equivalent of a given string.
|
Gives the Morse code equivalent of a given string.
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
L = []
|
L = []
|
||||||
for c in text.upper():
|
for c in text.upper():
|
||||||
if c in self._code:
|
if c in self._code:
|
||||||
@ -351,14 +350,15 @@ class Filter(callbacks.Privmsg):
|
|||||||
else:
|
else:
|
||||||
L.append(c)
|
L.append(c)
|
||||||
irc.reply(' '.join(L))
|
irc.reply(' '.join(L))
|
||||||
|
morse = wrap(morse, ['text'])
|
||||||
|
|
||||||
def reverse(self, irc, msg, args):
|
def reverse(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Reverses <text>.
|
Reverses <text>.
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
irc.reply(text[::-1])
|
irc.reply(text[::-1])
|
||||||
|
reverse = wrap(reverse, ['text'])
|
||||||
|
|
||||||
def _color(self, c, fg=None):
|
def _color(self, c, fg=None):
|
||||||
if c == ' ':
|
if c == ' ':
|
||||||
@ -367,39 +367,38 @@ class Filter(callbacks.Privmsg):
|
|||||||
fg = str(random.randint(2, 15)).zfill(2)
|
fg = str(random.randint(2, 15)).zfill(2)
|
||||||
return '\x03%s%s' % (fg, c)
|
return '\x03%s%s' % (fg, c)
|
||||||
|
|
||||||
def colorize(self, irc, msg, args):
|
def colorize(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Returns <text> with each character randomly colorized.
|
Returns <text> with each character randomly colorized.
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
L = [self._color(c) for c in text]
|
L = [self._color(c) for c in text]
|
||||||
irc.reply('%s%s' % (''.join(L), '\x03'))
|
irc.reply('%s%s' % (''.join(L), '\x03'))
|
||||||
|
colorize = wrap(colorize, ['text'])
|
||||||
|
|
||||||
def rainbow(self, irc, msg, args):
|
def rainbow(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Returns <text> colorized like a rainbow.
|
Returns <text> colorized like a rainbow.
|
||||||
"""
|
"""
|
||||||
colors = itertools.cycle([4, 7, 8, 3, 2, 12, 6])
|
colors = itertools.cycle([4, 7, 8, 3, 2, 12, 6])
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
L = [self._color(c, fg=colors.next()) for c in text]
|
L = [self._color(c, fg=colors.next()) for c in text]
|
||||||
irc.reply(''.join(L) + '\x03')
|
irc.reply(''.join(L) + '\x03')
|
||||||
|
rainbow = wrap(rainbow, ['text'])
|
||||||
|
|
||||||
def stripcolor(self, irc, msg, args):
|
def stripcolor(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Returns <text> stripped of all color codes.
|
Returns <text> stripped of all color codes.
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
irc.reply(ircutils.stripColor(text))
|
irc.reply(ircutils.stripColor(text))
|
||||||
|
stripcolor = wrap(stripcolor, ['text'])
|
||||||
|
|
||||||
def aol(self, irc, msg, args):
|
def aol(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Returns <text> as if an AOLuser had said it.
|
Returns <text> as if an AOLuser had said it.
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
text = text.replace(' you ', ' u ')
|
text = text.replace(' you ', ' u ')
|
||||||
text = text.replace(' are ', ' r ')
|
text = text.replace(' are ', ' r ')
|
||||||
text = text.replace(' love ', ' <3 ')
|
text = text.replace(' love ', ' <3 ')
|
||||||
@ -419,8 +418,9 @@ class Filter(callbacks.Privmsg):
|
|||||||
smiley = random.choice(['<3', ':)', ':-)', ':D', ':-D'])
|
smiley = random.choice(['<3', ':)', ':-)', ':D', ':-D'])
|
||||||
text += smiley*3
|
text += smiley*3
|
||||||
irc.reply(text)
|
irc.reply(text)
|
||||||
|
aol = wrap(aol, ['text'])
|
||||||
|
|
||||||
def jeffk(self, irc, msg, args):
|
def jeffk(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Returns <text> as if JeffK had said it himself.
|
Returns <text> as if JeffK had said it himself.
|
||||||
@ -468,11 +468,11 @@ class Filter(callbacks.Privmsg):
|
|||||||
'!!~', '~~~!'])
|
'!!~', '~~~!'])
|
||||||
if random.random() < 0.5:
|
if random.random() < 0.5:
|
||||||
exclaim += random.choice(['!', '~', '!~', '~!!~~',
|
exclaim += random.choice(['!', '~', '!~', '~!!~~',
|
||||||
|
|
||||||
'!!~', '~~~!'])
|
'!!~', '~~~!'])
|
||||||
laugh = ''.join([' ', laugh1, laugh2, insult, exclaim])
|
laugh = ''.join([' ', laugh1, laugh2, insult, exclaim])
|
||||||
text += laugh
|
text += laugh
|
||||||
return text
|
return text
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
if random.random() < .03:
|
if random.random() < .03:
|
||||||
irc.reply(randomlyLaugh('NO YUO', probability=1))
|
irc.reply(randomlyLaugh('NO YUO', probability=1))
|
||||||
return
|
return
|
||||||
@ -513,6 +513,7 @@ class Filter(callbacks.Privmsg):
|
|||||||
if random.random() < .4:
|
if random.random() < .4:
|
||||||
text = text.upper()
|
text = text.upper()
|
||||||
irc.reply(text)
|
irc.reply(text)
|
||||||
|
jeffk = wrap(jeffk, ['text'])
|
||||||
|
|
||||||
# Keeping these separate so people can just replace the alphabets for
|
# Keeping these separate so people can just replace the alphabets for
|
||||||
# whatever their language of choice
|
# whatever their language of choice
|
||||||
@ -563,12 +564,11 @@ class Filter(callbacks.Privmsg):
|
|||||||
'0': 'zero', '1': 'one', '2': 'two', '3': 'three', '4': 'four',
|
'0': 'zero', '1': 'one', '2': 'two', '3': 'three', '4': 'four',
|
||||||
'5': 'five', '6': 'six', '7': 'seven', '8': 'eight', '9': 'nine'
|
'5': 'five', '6': 'six', '7': 'seven', '8': 'eight', '9': 'nine'
|
||||||
}
|
}
|
||||||
def spellit(self, irc, msg, args):
|
def spellit(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Returns <text>, phonetically spelled out.
|
Returns <text>, phonetically spelled out.
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
d = {}
|
d = {}
|
||||||
if self.registryValue('spellit.replaceLetters'):
|
if self.registryValue('spellit.replaceLetters'):
|
||||||
d.update(self._spellLetters)
|
d.update(self._spellLetters)
|
||||||
@ -591,6 +591,7 @@ class Filter(callbacks.Privmsg):
|
|||||||
pass
|
pass
|
||||||
write(c)
|
write(c)
|
||||||
irc.reply(out.getvalue())
|
irc.reply(out.getvalue())
|
||||||
|
spellit = wrap(spellit, ['text'])
|
||||||
|
|
||||||
|
|
||||||
Class = Filter
|
Class = Filter
|
||||||
|
Loading…
Reference in New Issue
Block a user