mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 06:49:24 +01:00
New implementation of standardSubstitute.
This commit is contained in:
parent
288c6785a8
commit
8a9ca0bb06
@ -373,43 +373,46 @@ class PeriodicFileDownloader(object):
|
|||||||
world.threadsSpawned += 1
|
world.threadsSpawned += 1
|
||||||
|
|
||||||
|
|
||||||
_randomnickRe = re.compile(r'\$rand(?:om)?nick', re.I)
|
def standardSubstitute(irc, msg, text, env=None):
|
||||||
_randomdateRe = re.compile(r'\$rand(?:om)?date', re.I)
|
|
||||||
_randomintRe = re.compile(r'\$rand(?:omint)?', re.I)
|
|
||||||
_channelRe = re.compile(r'\$channel', re.I)
|
|
||||||
_whoRe = re.compile(r'\$(?:who|nick)', re.I)
|
|
||||||
_botnickRe = re.compile(r'\$botnick', re.I)
|
|
||||||
_todayRe = re.compile(r'\$(?:today|date)', re.I)
|
|
||||||
_nowRe = re.compile(r'\$(?:now|time)', re.I)
|
|
||||||
_userRe = re.compile(r'\$user', re.I)
|
|
||||||
_hostRe = re.compile(r'\$host', re.I)
|
|
||||||
def standardSubstitute(irc, msg, text):
|
|
||||||
"""Do the standard set of substitutions on text, and return it"""
|
"""Do the standard set of substitutions on text, and return it"""
|
||||||
if ircutils.isChannel(msg.args[0]):
|
if ircutils.isChannel(msg.args[0]):
|
||||||
channel = msg.args[0]
|
channel = msg.args[0]
|
||||||
else:
|
else:
|
||||||
channel = 'somewhere'
|
channel = 'somewhere'
|
||||||
def randInt(m):
|
def randInt():
|
||||||
return str(random.randint(-1000, 1000))
|
return str(random.randint(-1000, 1000))
|
||||||
def randDate(m):
|
def randDate():
|
||||||
t = pow(2,30)*random.random()+time.time()/4.0
|
t = pow(2,30)*random.random()+time.time()/4.0
|
||||||
return time.ctime(t)
|
return time.ctime(t)
|
||||||
def randNick(m):
|
def randNick():
|
||||||
if channel != 'somewhere':
|
if channel != 'somewhere':
|
||||||
return random.choice(list(irc.state.channels[channel].users))
|
return random.choice(list(irc.state.channels[channel].users))
|
||||||
else:
|
else:
|
||||||
return 'someone'
|
return 'someone'
|
||||||
text = _channelRe.sub(channel, text)
|
ctime = time.ctime()
|
||||||
text = _randomnickRe.sub(randNick, text)
|
localtime = time.localtime()
|
||||||
text = _randomdateRe.sub(randDate, text)
|
vars = ircutils.IrcDict({
|
||||||
text = _randomintRe.sub(randInt, text)
|
'who': msg.nick,
|
||||||
text = _whoRe.sub(msg.nick, text)
|
'nick': msg.nick,
|
||||||
text = _botnickRe.sub(irc.nick, text)
|
'user': msg.user,
|
||||||
text = _todayRe.sub(time.ctime(), text)
|
'host': msg.host,
|
||||||
text = _nowRe.sub(time.ctime(), text)
|
'channel': channel,
|
||||||
text = _userRe.sub(msg.user, text)
|
'botnick': irc.nick,
|
||||||
text = _hostRe.sub(msg.host, text)
|
'now': ctime, 'ctime': ctime,
|
||||||
return text
|
'randnick': randNick, 'randomnick': randNick,
|
||||||
|
'randdate': randDate, 'randomdate': randDate,
|
||||||
|
'rand': randInt, 'randint': randInt, 'randomint': randInt,
|
||||||
|
'year': localtime[0],
|
||||||
|
'month': localtime[1],
|
||||||
|
'date': localtime[2],
|
||||||
|
'h': localtime[3], 'hr': localtime[3], 'hour': localtime[3],
|
||||||
|
'm': localtime[4], 'min': localtime[4], 'minute': localtime[4],
|
||||||
|
's': localtime[5], 'sec': localtime[5], 'second': localtime[5],
|
||||||
|
'tz': time.tzname[time.daylight],
|
||||||
|
})
|
||||||
|
if env is not None:
|
||||||
|
vars.update(env)
|
||||||
|
return utils.perlVariableSubstitute(vars, text)
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
Loading…
Reference in New Issue
Block a user