Dynamic factoids (and normal ones) can now take input with inp
This commit is contained in:
parent
d15e4ff3cf
commit
7f98bf912c
1 changed files with 17 additions and 2 deletions
|
@ -129,8 +129,17 @@ def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None):
|
||||||
|
|
||||||
db_init(db)
|
db_init(db)
|
||||||
|
|
||||||
|
# split up the input
|
||||||
|
split = inp.group(1).strip().split(" ")
|
||||||
|
factoid_id = split[0]
|
||||||
|
|
||||||
|
if len(split) >= 1:
|
||||||
|
arguments = " ".join(split[1:])
|
||||||
|
else:
|
||||||
|
arguments = None
|
||||||
|
|
||||||
# attempt to get the factoid from the database
|
# attempt to get the factoid from the database
|
||||||
data = get_memory(db, inp.group(1).strip())
|
data = get_memory(db, factoid_id)
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
|
|
||||||
|
@ -139,6 +148,12 @@ def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None):
|
||||||
data = data.replace("$chan", input.chan)
|
data = data.replace("$chan", input.chan)
|
||||||
data = data.replace("$botnick", conn.nick)
|
data = data.replace("$botnick", conn.nick)
|
||||||
|
|
||||||
|
# if factoid had arguments, replace $inp with that
|
||||||
|
if arguments:
|
||||||
|
data = data.replace("$inp", arguments)
|
||||||
|
else
|
||||||
|
data = data.replace("$inp", "null")
|
||||||
|
|
||||||
# if <py>, execute python code
|
# if <py>, execute python code
|
||||||
if data.startswith("<py>"):
|
if data.startswith("<py>"):
|
||||||
data = data[4:].strip()
|
data = data[4:].strip()
|
||||||
|
@ -162,6 +177,6 @@ def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None):
|
||||||
me(result)
|
me(result)
|
||||||
else:
|
else:
|
||||||
if prefix_on:
|
if prefix_on:
|
||||||
say("\x02[%s]:\x02 %s" % (inp.group(1).strip(), result))
|
say("\x02[%s]:\x02 %s" % (factoid_id, result))
|
||||||
else:
|
else:
|
||||||
say(result)
|
say(result)
|
||||||
|
|
Reference in a new issue