Added bold, underline and italic/inverted shortcodes to plugins/factoids.py
This commit is contained in:
parent
e10637c366
commit
a63e35d043
1 changed files with 23 additions and 1 deletions
|
@ -6,6 +6,16 @@ from util import hook
|
|||
import re
|
||||
|
||||
|
||||
# the dictionary has target_word : replacement_word pairs
|
||||
shortcodes = {
|
||||
'<b>': '\x02',
|
||||
'</b>': '\x02',
|
||||
'<u>': '\x1F',
|
||||
'</u>': '\x1F',
|
||||
'<i>': '\x16',
|
||||
'</i>': '\x16'}
|
||||
|
||||
|
||||
def db_init(db):
|
||||
db.execute("create table if not exists mem(word, data, nick,"
|
||||
" primary key(word))")
|
||||
|
@ -21,6 +31,17 @@ def get_memory(db, word):
|
|||
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):
|
||||
".r <word> [+]<data> -- maps word to data in the memory"
|
||||
|
@ -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)
|
||||
|
|
Reference in a new issue