diff --git a/plugins/factoids.py b/plugins/factoids.py
index 740f810..71c9a84 100644
--- a/plugins/factoids.py
+++ b/plugins/factoids.py
@@ -6,6 +6,16 @@ from util import hook
import re
+# the dictionary has target_word : replacement_word pairs
+shortcodes = {
+'': '\x02',
+'': '\x02',
+'': '\x1F',
+'': '\x1F',
+'': '\x16',
+'': '\x16'}
+
+
def db_init(db):
db.execute("create table if not exists mem(word, data, nick,"
" primary key(word))")
@@ -20,6 +30,17 @@ def get_memory(db, word):
else:
return None
+
+def multiwordReplace(text, wordDic):
+ """
+ take a text and replace words that match a key in a dictionary with
+ the associated value, return the changed text
+ """
+ rc = re.compile('|'.join(map(re.escape, wordDic)))
+ def translate(match):
+ return wordDic[match.group(0)]
+ return rc.sub(translate, text)
+
@hook.command("r")
def remember(inp, nick='', db=None, say=None, input=None, notice=None):
@@ -92,4 +113,5 @@ def question(inp, say=None, db=None):
data = get_memory(db, inp.group(1).strip())
if data:
- say(data)
+ out = multiwordReplace(data, shortcodes)
+ say(out)