Beispiel #1
0
async def create_autodaily_settings(bot: discord.ext.commands.Bot,
                                    guild_id: int) -> AutoDailySettings:
    if guild_id is None or bot is None:
        raise Exception(
            'No parameters given. You need to specify both parameters \'bot\' and \'guild_id\'.'
        )

    autodaily_settings = await _prepare_create_autodaily_settings(guild_id)
    _, channel_id, can_post, latest_message_id, delete_on_change, notify_id, notify_type, latest_message_create_date, latest_message_modify_date = autodaily_settings[
        0]
    try:
        channel = bot.get_channel(channel_id)
    except Exception as error:
        channel = None
    try:
        guild = bot.get_guild(guild_id)
    except Exception as error:
        guild = None

    notify = None
    if notify_id and notify_type and guild:
        if notify_type == AutoDailyNotifyType.USER:
            notify = guild.get_member(notify_id)
        elif notify_type == AutoDailyNotifyType.ROLE:
            notify = guild.get_role(notify_id)

    return AutoDailySettings(guild, channel, can_post, latest_message_id,
                             delete_on_change, notify,
                             latest_message_create_date,
                             latest_message_modify_date)
Beispiel #2
0
def setup(bot: discord.ext.commands.Bot):
    global client
    client = bot
    vac = Vac()
    bot.add_cog(vac)

    channel = bot.get_channel(int(config.default_channel))

    async def job():
        await vac.check_vac_status_and_send_results(channel, False)

    schedule.every().day.at("12:00").do(job)
Beispiel #3
0
async def wednesday(config: CONF0, bot: discord.ext.commands.Bot):
    while True:
        today, today_img = config.DailyDict[dt.datetime.today.weekday()]
        if today:
            for chan in config.DailyChan:
                async with bot.get_channel(chan).typing():
                    await bot.get_channel(chan).send(file=discord.File(today_img))
        hours = 60 * 60
        async def bg():
            while True:
                await asyncio.sleep(12 * hours)
        task = asyncio.create_task(bg())
        try:
            await asyncio.sleep(arg)
        finally:
            task.cancel()
Beispiel #4
0
def _schedule_event(bot: discord.ext.commands.Bot):
    task_info_list = execute_statement(
        create_select_query("configure__schedule")).all(as_dict=True)
    for task_info in task_info_list:
        local_guild: discord.Guild = bot.get_guild(task_info.get("guild_id"))
        re_schedule_task(
            bot,
            _get_task(task_info.get("task")),
            task_info.get("weekday"),
            task_info.get("at_time"),
            task_info.get("tag"),
            message=task_info.get("message"),
            channel=bot.get_channel(int(task_info.get("channel_id"))),
            number=task_info.get("number"),
            guild=local_guild,
            category=None if local_guild is None else discord.utils.get(
                local_guild.categories, id=int(task_info.get("category_id"))))
Beispiel #5
0
 def getLogChannel(self, bot: discord.ext.commands.Bot):
     return bot.get_channel(
         self.server_settings["log_channel"]
     ) if self.server_settings["log_channel"] else None