fixes
This commit is contained in:
parent
3cab25f123
commit
51bcddd44a
|
@ -1,4 +1,5 @@
|
||||||
from util import hook
|
from util import hook
|
||||||
|
from util.text import multiword_replace
|
||||||
import random
|
import random
|
||||||
|
|
||||||
color_codes = {
|
color_codes = {
|
||||||
|
@ -8,10 +9,8 @@ color_codes = {
|
||||||
}
|
}
|
||||||
|
|
||||||
with open("plugins/data/8ball_responses.txt") as f:
|
with open("plugins/data/8ball_responses.txt") as f:
|
||||||
for code in color_codes:
|
responses = [multiword_replace(line.strip(), color_codes) for line in
|
||||||
f = f.replace(code, color_codes[code])
|
f.readlines()if not line.startswith("//")]
|
||||||
responses = [line.strip() for line in f.readlines()
|
|
||||||
if not line.startswith("//")]
|
|
||||||
|
|
||||||
|
|
||||||
@hook.command('8ball')
|
@hook.command('8ball')
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# Written by Scaevolus 2010
|
# Written by Scaevolus 2010
|
||||||
from util import hook, http
|
from util import hook, http
|
||||||
|
from util.text import multiword_replace
|
||||||
import string
|
import string
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -47,18 +48,6 @@ def get_memory(db, word):
|
||||||
return None
|
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", adminonly=True)
|
@hook.command("r", adminonly=True)
|
||||||
@hook.command(adminonly=True)
|
@hook.command(adminonly=True)
|
||||||
def remember(inp, nick='', db=None, say=None, input=None, notice=None):
|
def remember(inp, nick='', db=None, say=None, input=None, notice=None):
|
||||||
|
@ -164,7 +153,7 @@ def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None):
|
||||||
else:
|
else:
|
||||||
result = data
|
result = data
|
||||||
|
|
||||||
result = multiwordReplace(result, shortcodes)
|
result = multiword_replace(result, shortcodes)
|
||||||
|
|
||||||
if result.startswith("<act>"):
|
if result.startswith("<act>"):
|
||||||
result = result[5:].strip()
|
result = result[5:].strip()
|
||||||
|
|
|
@ -14,6 +14,18 @@ def capitalize_first(line):
|
||||||
return ' '.join([s[0].upper() + s[1:] for s in line.split(' ')])
|
return ' '.join([s[0].upper() + s[1:] for s in line.split(' ')])
|
||||||
|
|
||||||
|
|
||||||
|
def multiword_replace(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)
|
||||||
|
|
||||||
|
|
||||||
# from <http://stackoverflow.com/questions/250357/smart-truncate-in-python>
|
# from <http://stackoverflow.com/questions/250357/smart-truncate-in-python>
|
||||||
def truncate_words(content, length=100, suffix='...'):
|
def truncate_words(content, length=100, suffix='...'):
|
||||||
"Truncates a string after a certain number of chars."
|
"Truncates a string after a certain number of chars."
|
||||||
|
|
Reference in a new issue