mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-02 17:29:22 +01:00
Move ircutils.standardsubttext to plugins.standardSubstitute, make it do case insensitive replacement
This commit is contained in:
parent
06ce1bcb94
commit
b0fd3f547c
@ -369,25 +369,6 @@ class IrcSet(sets.Set):
|
||||
|
||||
has_key = __contains__
|
||||
|
||||
def standardsubsttext(irc, msg, text):
|
||||
"""Do the standard set of substitutions on text, and return it"""
|
||||
nochannel = False
|
||||
try:
|
||||
channel = privmsgs.getChannel(msg, None)
|
||||
except:
|
||||
nochannel = True
|
||||
if nochannel:
|
||||
text = text.replace("$randomnick", 'anyone')
|
||||
else:
|
||||
text = text.replace("$randomnick",
|
||||
random.choice(irc.state.channels[channel].users._data.keys()))
|
||||
t = pow(2,30)*random.random()+time.time()/4.0
|
||||
text = text.replace("$randomdate", time.ctime(t))
|
||||
text = text.replace("$who", msg.nick)
|
||||
text = text.replace("$botnick", irc.nick)
|
||||
text = text.replace("$today", time.ctime())
|
||||
return text
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys, doctest
|
||||
doctest.testmod(sys.modules['__main__'])
|
||||
|
@ -49,6 +49,8 @@ import ircdb
|
||||
import ircutils
|
||||
import privmsgs
|
||||
import callbacks
|
||||
import re
|
||||
import random
|
||||
|
||||
__all__ = ['ChannelDBHandler', 'PeriodicFileDownloader', 'ToggleDictionary']
|
||||
|
||||
@ -307,4 +309,27 @@ class Toggleable(object):
|
||||
irc.error(msg, '%r isn\'t a valid name to toggle. '
|
||||
'Valid names are %s' % (name, self._toggleNames()))
|
||||
|
||||
randomnickre = re.compile ("\$randomnick", re.I)
|
||||
randomdatere = re.compile ("\$randomdate", re.I)
|
||||
whore = re.compile ("\$who", re.I)
|
||||
botnickre = re.compile("\$botnick", re.I)
|
||||
todayre = re.compile("\$today", re.I)
|
||||
def standardSubstitute(irc, msg, text):
|
||||
"""Do the standard set of substitutions on text, and return it"""
|
||||
nochannel = False
|
||||
try:
|
||||
channel = privmsgs.getChannel(msg, None)
|
||||
except:
|
||||
nochannel = True
|
||||
if nochannel:
|
||||
text = randomnickre.sub('anyone', text)
|
||||
else:
|
||||
text = randomnickre.sub(random.choice(irc.state.channels[channel].users._data.keys()),
|
||||
text)
|
||||
t = pow(2,30)*random.random()+time.time()/4.0
|
||||
text = randomdatere.sub(time.ctime(t), text)
|
||||
text = whore.sub(msg.nick, text)
|
||||
text = botnickre.sub(irc.nick, text)
|
||||
text = todayre.sub(time.ctime(), text)
|
||||
return text
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
Loading…
Reference in New Issue
Block a user