Use config settings for cowsay and reactions
This commit is contained in:
parent
afe1b0e35e
commit
1a71dd8a1e
2 changed files with 14 additions and 7 deletions
|
@ -8,16 +8,24 @@ import subprocess
|
||||||
|
|
||||||
LOGGER = logging.getLogger('cowsay')
|
LOGGER = logging.getLogger('cowsay')
|
||||||
|
|
||||||
COWSAY_PATH = '/usr/games/cowsay'
|
|
||||||
MESSAGE_RE = re.compile(r'(!cowsay)(.*)')
|
MESSAGE_RE = re.compile(r'(!cowsay)(.*)')
|
||||||
|
|
||||||
|
#
|
||||||
|
# rtmbot interface
|
||||||
|
#
|
||||||
|
|
||||||
|
config = None
|
||||||
outputs = []
|
outputs = []
|
||||||
|
|
||||||
def process_message(data):
|
def process_message(data):
|
||||||
|
if 'path' not in config:
|
||||||
|
LOGGER.error('Please define config.path pointing to the cowsay binary.')
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
text = data['text']
|
text = data['text']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
LOGGER.error('Missing "text" key in data.')
|
LOGGER.debug('Missing "text" key in data.')
|
||||||
return
|
return
|
||||||
|
|
||||||
# find the message
|
# find the message
|
||||||
|
@ -33,7 +41,7 @@ def process_message(data):
|
||||||
|
|
||||||
# cowsay it up
|
# cowsay it up
|
||||||
try:
|
try:
|
||||||
out = subprocess.check_output([COWSAY_PATH, msg]).decode()
|
out = subprocess.check_output([config['path'], msg]).decode()
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
LOGGER.error('Error running cowsay. (%d)', e.returncode)
|
LOGGER.error('Error running cowsay. (%d)', e.returncode)
|
||||||
return
|
return
|
||||||
|
|
|
@ -19,9 +19,8 @@ config = None
|
||||||
outputs = []
|
outputs = []
|
||||||
|
|
||||||
def process_message(data):
|
def process_message(data):
|
||||||
LOGGER.debug(config)
|
if 'root' not in config:
|
||||||
if 'reactions_root' not in config:
|
LOGGER.error('Please define the root URL where reactions live in config.root')
|
||||||
LOGGER.error('Please define the root URL where reactions live in config.reactions_root')
|
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -39,7 +38,7 @@ def process_message(data):
|
||||||
LOGGER.info('Reaction command but no reaction.')
|
LOGGER.info('Reaction command but no reaction.')
|
||||||
|
|
||||||
for ext in EXTENSIONS:
|
for ext in EXTENSIONS:
|
||||||
url = '{}/{}{}'.format(config['reactions_root'], reaction, ext)
|
url = '{}/{}{}'.format(config['root'], reaction, ext)
|
||||||
LOGGER.debug('Checking url: %s', url)
|
LOGGER.debug('Checking url: %s', url)
|
||||||
r = requests.head(url)
|
r = requests.head(url)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue