コード例 #1
0
ファイル: server_settings.py プロジェクト: Tron842/YaDc
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
ファイル: server_settings.py プロジェクト: Tron842/YaDc
 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
ファイル: server_settings.py プロジェクト: Tron842/YaDc
 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
ファイル: server_settings.py プロジェクト: Tron842/YaDc
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
ファイル: server_settings.py プロジェクト: Tron842/YaDc
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.')