Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def replace_params(text,params,nick,channel):
- openbrackets = 0
- innertext = ""
- result = ""
- for i in range(0,len(text)):
- if text[i] == "[":
- if openbrackets>0:
- innertext += "["
- openbrackets += 1
- elif text[i] == "]" and openbrackets>0:
- openbrackets -= 1
- if openbrackets == 0:
- innertext = replace_params(innertext,params,nick,channel)
- p = innertext.split("|",1)
- m = re.match("(\d+)(\+?)$",p[0])
- if m:
- q = params[int(m.group(1)):param_end(int(m.group(1)),m.group(2))]
- if q:
- result += " ".join(q)
- elif len(p)==2:
- result += p[1]
- elif innertext=="USER":
- result += nick.title()
- elif innertext=="CHANNEL":
- result += channel.title()
- elif innertext=="CHATTER":
- result += random_chatter(channel)
- elif innertext=="MOD":
- result += random_chatter(channel,cats=["moderators","staff","admins"])
- elif innertext.startswith("NOW"):
- n = re.match("NOW\((.*)\)$")
- if n:
- result += datetime.datetime.now().strftime(n.group(1))
- else:
- result += "[%s]"%(innertext,)
- elif innertext=="PUN":
- urlres = urllib2.urlopen(baseurl+"/api/pun")
- urlresdec = urlres.read().decode("utf-8")
- jsonres = json.loads(urlresdec)
- result += replace_params(jsonres["text"],params,nick,channel)
- else:
- result += "[%s]"%(innertext,)
- innertext = ""
- else:
- innertext += "]"
- elif openbrackets>0:
- innertext += text[i]
- else:
- result += text[i]
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement