[hearts2] Add smart quote support; add some missing imports; map links to users and channels
This commit is contained in:
parent
6e8e250737
commit
c1f264b714
1 changed files with 15 additions and 6 deletions
|
@ -1,7 +1,10 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Eryn Wells <eryn@erynwells.me>
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
import re
|
||||||
from service import slack
|
from service import slack
|
||||||
|
|
||||||
HEARTS_FILE = 'hearts.json'
|
HEARTS_FILE = 'hearts.json'
|
||||||
|
@ -61,7 +64,7 @@ def process_message(data):
|
||||||
if score_pair is not None:
|
if score_pair is not None:
|
||||||
name = score_pair[0]
|
name = score_pair[0]
|
||||||
score = score_pair[1]
|
score = score_pair[1]
|
||||||
LOGGER.info('Adding %s to %s', score, name)
|
LOG.info('Adding %s to %s', score, name)
|
||||||
if score != 0:
|
if score != 0:
|
||||||
score = update_item(name, score)
|
score = update_item(name, score)
|
||||||
outputs.append([data['channel'], '_{}_ now has a score of {}.'.format(name, score)])
|
outputs.append([data['channel'], '_{}_ now has a score of {}.'.format(name, score)])
|
||||||
|
@ -117,16 +120,22 @@ def t_NAME(t):
|
||||||
if name:
|
if name:
|
||||||
t.value = name
|
t.value = name
|
||||||
elif idee:
|
elif idee:
|
||||||
# TODO: Look up the user name.
|
users = [u for u in USERS if u['id'] == idee]
|
||||||
t.value = idee
|
try:
|
||||||
|
t.value = users[0]['name']
|
||||||
|
except IndexError:
|
||||||
|
t.value = idee
|
||||||
return t
|
return t
|
||||||
elif typ == '#':
|
elif typ == '#':
|
||||||
# It's a channel!
|
# It's a channel!
|
||||||
if name:
|
if name:
|
||||||
t.value = name
|
t.value = name
|
||||||
elif idee:
|
elif idee:
|
||||||
# TODO: Look up the channel name.
|
channels = [c for c in CHANNELS if c['id'] == idee]
|
||||||
t.value = idee
|
try:
|
||||||
|
t.value = channels[0]['name']
|
||||||
|
except IndexError:
|
||||||
|
t.value = idee
|
||||||
return t
|
return t
|
||||||
elif typ == '!':
|
elif typ == '!':
|
||||||
# It's a variable!
|
# It's a variable!
|
||||||
|
@ -136,7 +145,7 @@ def t_NAME(t):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def t_STR(t):
|
def t_STR(t):
|
||||||
r'"[^"]*"|' r"'[^']*'"
|
r'"[^"]*"|' r"'[^']*'|" r'“[^“”]*”|' r'‘[^‘’]*’'
|
||||||
LOG.debug('t_STR {}'.format(t.value))
|
LOG.debug('t_STR {}'.format(t.value))
|
||||||
t.value = t.value[1:-1]
|
t.value = t.value[1:-1]
|
||||||
return t
|
return t
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue