def send_roll(team, roll, args): """Post the roll to Slack.""" # Set up chat object chat = Chat(team.bot_token) try: # Attempt to post message chat.post_message(args['channel_id'], roll, username='******', icon_emoji=':game_die:') except Error as err: report_event(str(err), { 'team': team.__dict__, 'roll': roll, 'args': args }) # Check specifically for channel errors if str(err) == 'channel_not_found': err_msg = "{0} is not authorized to post in this channel.".format( 'The {0} bot'.format(PROJECT_INFO['name_full'])) err_msg += ' Please invite it to join this channel and try again.' return err_msg # Report any other errors return '{0} encountered an error: {1}'.format( PROJECT_INFO['name_full'], str(err)) # Return no errors return None
def send_flip(token, table, args): """Post the flip as the authenticated user in Slack.""" # Set up chat object chat = Chat(token) try: # Attempt to post message chat.post_message(args['channel_id'], table, username=args['user_id'], as_user=True) except Error as err: stf.report_event(str(err), { 'token': token, 'table': table, 'args': args }) # Report if we got any errors return '{app} encountered an error: {error}'.format( app=stf.PROJECT_INFO['name_full'], error=str(err)) # Return without errors return None