Пример #1
0
    async def clean_bot(self, ctx):
        '''
        Delete the last 10000 bot messages from the current channel. 
        To confirm the deletion, react to the bot messages with thumbs up (👍) or thumbs down (👎) emoji.
        '''
        bot, message, channel, author = utils.parse_context(ctx)

        # Confirmation
        if not await bot.ask_confirmation(
                channel,
                '**Are you sure you want to delete all bot messages from this channel ?**',
                canceled_text='Deletion aborted.',
                accepted_text='Deleting messages ...'):
            logger.debug(
                '{} abort the deletion of all bot messages from channel {}.'.
                format(author, channel))
            return

        messages = []

        async for log in bot.logs_from(channel, limit=1000):
            if str(log.author) == bot.name:
                messages.append(log)

        length = len(messages)
        logger.info(
            '{} deleting the {} last bot messages from channel {}.'.format(
                author, length, channel))
        await bot.delete_messages(messages)
Пример #2
0
    async def get_votes(self, ctx):
        '''
        Get the list of all posted votes of month from 'ark-servers.net'.
        This command provide voter name, steamid and the date of the vote.
        '''

        bot, message, channel, author = utils.parse_context(ctx)

        tmp = await bot.send_message(channel, 'Retriving votes ...')

        try:
            r = requests.get(self.all_votes_url, headers=self.headers)
            top_votes = r.json()
        except Exception as e:
            logger.exception('Unable to connect to Ark-servers.net!')
            await bot.edit_message(tmp,
                                   'Unable to connect to Ark-servers.net!')
            return

        result = "__**All votes :**__\n"

        for vote in top_votes['votes']:
            result = '{}{}: {}  {}\n'.format(result, vote['date'],
                                             vote['nickname'], vote['steamid'])

        logger.debug('Get all votes from Ark-servers.net: \n{}'.format(result))
        await bot.edit_message(tmp, result)
Пример #3
0
    async def top_votes(self, ctx):
        '''
        Get the list of the top voters of the month from 'ark-servers.net'.
        '''

        bot, message, channel, author = utils.parse_context(ctx)

        tmp = await bot.send_message(channel, 'Retriving voters ...')

        try:
            r = requests.get(self.top_votes_url, headers=self.headers)
            top_votes = r.json()

        except Exception as e:
            logger.exception('Unable to connect to Ark-servers.net!')
            await bot.edit_message(tmp,
                                   'Unable to connect to Ark-servers.net!')
            return

        result = ''
        count = 0
        for vote in top_votes['voters']:
            result = '{}{}  {}\n'.format(result, vote['nickname'],
                                         vote['votes'])
            count += 1

        result = "__**Top voters of the month {} :**__\n```{}\n```".format(
            count, result)

        logger.debug(
            'Get top voters from Ark-servers.net: \n{}'.format(result))
        await bot.edit_message(tmp, result)
Пример #4
0
    async def delete_last(self, ctx):
        '''
        Delete the last message of the bot from the current channel.
        '''
        bot, message, channel, author = utils.parse_context(ctx)

        logger.info(
            '{} deleting the last bot messages from channel {}.'.format(
                author, channel))
        await bot.delete_last_messages(channel, bot.name)
Пример #5
0
    async def count_bot(self, ctx):
        """
        Count the number of messages posted by the bot on the current channel.
        
        """
        bot, message, channel, author = utils.parse_context(ctx)
        counter = 0

        tmp = await bot.send_message(channel, 'Calculating messages...')

        async for log in bot.logs_from(channel, limit=1000):
            if str(log.author) == bot.name:
                counter += 1

        response = 'Bot {} have posted {} messages on this channel.'.format(
            author, counter)
        logger.debug(response)
        await bot.edit_message(tmp, response)
Пример #6
0
    async def test(self, ctx):
        """
        Test command. Count the number of messages posted by the user on the current channel.
        
        """
        bot, channel, messages, author = parse_context(ctx)
        messages
        counter = 0

        tmp = await bot.send_message(channel, 'Calculating messages...')

        async for log in bot.logs_from(channel, limit=10000):
            if log.author == author:
                counter += 1

        messages = '{}, You have posted {} messages on this channel.'.format(
            author, counter)
        logger.debug(messages)
        await bot.edit_message(tmp, messages)