예제 #1
0
async def get_autodaily_settings_without_post(autodaily_settings: List[AutoDailySettings]) -> List[AutoDailySettings]:
    if autodaily_settings is None:
        autodaily_settings = GUILD_SETTINGS.autodaily_settings

    result = [autodaily_settings for autodaily_settings in GUILD_SETTINGS.autodaily_settings if autodaily_settings.no_post_yet]
    utils.dbg_prnt(f'[get_autodaily_settings_without_post] retrieved auto-daily settings for {len(result)} guilds, without a post yet.')
    return result
예제 #2
0
async def __post_raw_file(ctx: Context, retriever: entity.EntityRetriever, entity_name: str, mode: str, retrieved_at: datetime) -> None:
    retrieved_at = retrieved_at or utils.get_utc_now()
    entity_name = entity_name.replace(' ', '_')
    file_name_prefix = f'{entity_name}_designs'
    raw_data = await retriever.get_raw_data()
    raw_data_dict = utils.convert.raw_xml_to_dict(raw_data, fix_attributes=True, preserve_lists=True)
    if mode == 'xml':
        file_path = create_raw_file(raw_data, mode, file_name_prefix, retrieved_at)
    elif mode == 'json':
        data = json.dumps(raw_data_dict)
        file_path = create_raw_file(data, mode, file_name_prefix, retrieved_at)
    else:
        start = time.perf_counter()
        flattened_data = __flatten_raw_dict_for_excel(raw_data_dict)
        time1 = time.perf_counter() - start
        utils.dbg_prnt(f'Flattening the {entity_name} data took {time1:.2f} seconds.')

        start = time.perf_counter()
        file_path = excel.create_xl_from_raw_data_dict(flattened_data, file_name_prefix, retrieved_at)
        time2 = time.perf_counter() - start
        utils.dbg_prnt(f'Creating the excel sheet took {time2:.2f} seconds ({time1+time2:.2f} seconds in total).')
    file_paths = []
    if file_path:
        file_paths.append(file_path)
    await utils.discord.post_output_with_files(ctx, [], file_paths)
    if file_path:
        os.remove(file_path)
예제 #3
0
 def channel(self) -> TextChannel:
     if self.__channel is None:
         try:
             self.__channel = self.__bot.get_channel(self.channel_id)
         except Exception as error:
             self.__channel = None
             print(f'Could not get channel for id {self.channel_id}: {error}')
         if self.__channel is None and self.channel_id is not None:
             utils.dbg_prnt(f'Could not get channel for id {self.channel_id}')
     return self.__channel
예제 #4
0
 def guild(self) -> Guild:
     if not self.__guild:
         try:
             self.__guild = self.bot.get_guild(self.id)
         except Exception as error:
             self.__guild = None
             print(f'Could not get guild for id {self.id}: {error}')
         if self.__guild is None and self.id is not None:
             utils.dbg_prnt(f'Could not get guild for id {self.id}')
     return self.__guild
예제 #5
0
async def get_autodaily_settings(utc_now: datetime = None, bot: Bot = None, guild_id: int = None, can_post: bool = None, no_post_yet: bool = False) -> List[AutoDailySettings]:
    if guild_id:
        if not bot:
            raise ValueError('You need to provide the bot, when specifying the guild_id.')
        autodaily_settings = await get_autodaily_settings_for_guild(bot, guild_id)
        return [autodaily_settings]

    result = [autodaily_settings for autodaily_settings in GUILD_SETTINGS.autodaily_settings if autodaily_settings.channel_id]
    utils.dbg_prnt(f'[get_autodaily_settings] retrieved auto-daily settings for {len(result)} guilds')
    if no_post_yet:
        return await get_autodaily_settings_without_post(result)

    if utc_now:
        result = [autodaily_settings for autodaily_settings in result if not autodaily_settings.latest_message_created_at or autodaily_settings.latest_message_created_at.date != utc_now.date]
    return result
예제 #6
0
async def init(bot: Bot) -> None:
    await __fix_prefixes()
    await GUILD_SETTINGS.init(bot)
    utils.dbg_prnt(f'Loaded {len(GUILD_SETTINGS.keys())} guild settings with {len(GUILD_SETTINGS.autodaily_settings)} autodaily settings.')