Example #1
0
class SlackLogHandler(Handler):
    def __init__(self, api_key, channel, stack_trace=False, username='******', icon_url=None, icon_emoji=None):
        Handler.__init__(self)
        self.slack_chat = Chat(api_key)
        self.channel = channel
        self.stack_trace = stack_trace
        self.username = username
        self.icon_url = icon_url
        self.icon_emoji = icon_emoji if (icon_emoji or icon_url) else ':heavy_exclamation_mark:'

        if not self.channel.startswith('#'):
            self.channel = '#' + self.channel

    def emit(self, record):
        message = '{}'.format(record.getMessage())
        if self.stack_trace and record.exc_info:
            message += '\n'
            message += '\n'.join(traceback.format_exception(*record.exc_info))

        self.slack_chat.post_message(
            text=message,
            channel=self.channel,
            username=self.username,
            icon_url=self.icon_url,
            icon_emoji=self.icon_emoji
        )
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 '{0} encountered an error: {1}'.format(
            stf.PROJECT_INFO['name_full'],
            str(err)
        )

    # Return successful
    return
Example #3
0
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
Example #4
0
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
Example #5
0
    def __init__(self, api_key, channel, stack_trace=False, username='******', icon_url=None, icon_emoji=None):
        Handler.__init__(self)
        self.slack_chat = Chat(api_key)
        self.channel = channel
        self.stack_trace = stack_trace
        self.username = username
        self.icon_url = icon_url
        self.icon_emoji = icon_emoji if (icon_emoji or icon_url) else ':heavy_exclamation_mark:'

        if not self.channel.startswith('#'):
            self.channel = '#' + self.channel
Example #6
0
def send_flip(token, table, args):
    ''' Posts 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:
        # Report if we got any errors
        return err

    # Return successful
    return
Example #7
0
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 successful
    return