mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-19 23:20:57 +01:00
Add standard substitution function
This commit is contained in:
parent
bef71df2ee
commit
70be390875
@ -43,6 +43,8 @@ import sets
|
|||||||
import string
|
import string
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import operator
|
import operator
|
||||||
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
def isUserHostmask(s):
|
def isUserHostmask(s):
|
||||||
"""Returns whether or not the string s is a valid User hostmask."""
|
"""Returns whether or not the string s is a valid User hostmask."""
|
||||||
@ -367,6 +369,24 @@ class IrcSet(sets.Set):
|
|||||||
|
|
||||||
has_key = __contains__
|
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__':
|
if __name__ == '__main__':
|
||||||
import sys, doctest
|
import sys, doctest
|
||||||
|
Loading…
x
Reference in New Issue
Block a user