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