コード例 #1
0
async def sync_background():
    await discord.bot.wait_until_ready()
    while not discord.bot.is_closed:
        job_start = analytics.getEventTime()
        logger.info(
            "Starting background task sync_background() - Interval {0}".format(
                config.cfg['chat']['crypto']['background_update_interval']))
        update = UpdateCoins()
        await update.update()
        result = await update.count()
        if update.oldtickers != update.newtickers:
            await discord.bot.send_message(
                discord.objectFactory(config.cfg['chat']['crypto']['channel']),
                result)

        journal.update_journal_job(
            module=__name__,
            job="sync_background",
            start=job_start,
            result="{0} change".format(update.oldtickers - update.newtickers))
        logger.info(
            "Sleeping background task sync_background() - Interval {0}".format(
                config.cfg['chat']['crypto']['background_update_interval']))
        await asyncio.sleep(
            config.cfg['chat']['crypto']['background_update_interval'])
コード例 #2
0
ファイル: subscriber.py プロジェクト: zoulos/Bernard
async def database_background():
    await discord.bot.wait_until_ready()
    if discord.bot_jobs_ready == False:
        logger.info(
            'database_background is ready to run, but has a timed hodl of {} seconds until first go.'
            .format(config.cfg['subscriber']['database_background']
                    ['start_delay']))
        await asyncio.sleep(
            config.cfg['subscriber']['database_background']['start_delay'])

    while not discord.bot.is_closed:
        job_start = analytics.getEventTime()
        logger.info(
            "Starting background task database_background() - Interval {0}".
            format(
                config.cfg['subscriber']['database_background']['interval']))

        #get the server server object
        server = discord.bot.get_server(config.cfg['discord']['server'])

        for member in list(server.members):
            update_user = subscriber_update(member)
            await update_user.purge_expired()

        journal.update_journal_job(module=__name__,
                                   job="database_background",
                                   start=job_start,
                                   result=None)
        logger.info(
            "Sleeping background task database_background() - Interval {0}".
            format(
                config.cfg['subscriber']['database_background']['interval']))
        await asyncio.sleep(
            config.cfg['subscriber']['database_background']['interval'])
コード例 #3
0
ファイル: housekeeping.py プロジェクト: zoulos/Bernard
async def purge_inactive_users():
    await discord.bot.wait_until_ready()
    while not discord.bot.is_closed:
        job_start = analytics.getEventTime()
        logger.info(
            "Starting background task purge_inactive_users() - Interval {0}".
            format(config.cfg['housekeeping']['purge_inactive_users']
                   ['interval']))

        est = await discord.bot.estimate_pruned_members(
            server=discord.objectFactory(config.cfg['discord']['server']),
            days=config.cfg['housekeeping']['purge_inactive_users']
            ['inactive_days'])
        if est > 0:
            #send the cleanup
            pruned = await discord.bot.prune_members(
                server=discord.objectFactory(config.cfg['discord']['server']),
                days=config.cfg['housekeeping']['purge_inactive_users']
                ['inactive_days'])

            #notify via mod room and console log whos getting purged
            logger.warn(
                "Purging {0} inactive users via purge_inactive_users() background job"
                .format(pruned))
            await discord.bot.send_message(
                discord.mod_channel(),
                "{0} **Pruned Inactive Users:** {1} users removed for inactivity of {2} days"
                .format(
                    common.bernardUTCTimeNow(), pruned,
                    config.cfg['housekeeping']['purge_inactive_users']
                    ['inactive_days']))

        logger.info(
            "Sleeping background task purge_inactive_users() - Interval {0}".
            format(config.cfg['housekeeping']['purge_inactive_users']
                   ['interval']))
        journal.update_journal_job(module=__name__,
                                   job="purge_inactive_users",
                                   start=job_start,
                                   result=est)
        await asyncio.sleep(
            config.cfg['housekeeping']['purge_inactive_users']['interval'])