Пример #1
0
 async def timer(self):
     if self.bot.ws is not None:
         dt_now = DateUtil.get_dt_now(self.bot.tz_str)
         if self.bot.race_time is not None:
             race_begin = self.bot.race_time
             race_end = self.bot.race_time + timedelta(hours=1)
             if dt_now > race_end:
                 await update_race_time(self.bot, None)
             else:
                 str = 'Summer Race'
                 if race_begin <= dt_now <= race_end:
                     str += ' ends '
                     str += DateUtil.fmt_time_short((race_end - dt_now) / timedelta(milliseconds=1))
                 else:
                     str += ' '
                     str += DateUtil.fmt_time_short((race_begin - dt_now) / timedelta(milliseconds=1))
                 str += ' (TalonRO)'
                 game = discord.Game(name=str)
                 await CoroutineUtil.run(self.bot.change_presence(activity=game))
                 return
         evt = get_next_evt(self.bot, timezone(self.bot.tz_str))
         str = ('WoE ' if evt['type'] == 'woe' else '') + evt['name']
         if evt['dt_begin'] <= dt_now <= evt['dt_end']:
             str += ' ends '
             str += DateUtil.fmt_time_short((evt['dt_end'] - dt_now) / timedelta(milliseconds=1))
         else:
             str += ' '
             str += DateUtil.fmt_time_short((evt['dt_begin'] - dt_now) / timedelta(milliseconds=1))
         str += ' (TalonRO)'
         game = discord.Game(name=str)
         await CoroutineUtil.run(self.bot.change_presence(activity=game))
Пример #2
0
 async def timer(self):
     if self.bot.ws is not None:
         dt_now = DateUtil.get_dt_now(self.bot.tz_str)
         evt = get_next_evt(self.bot, timezone(self.bot.tz_str))
         str = ('WoE ' if evt['type'] == 'woe' else '') + evt['name']
         if evt['dt_begin'] <= dt_now <= evt['dt_end']:
             str += ' ends '
             str += DateUtil.fmt_time_short((evt['dt_end'] - dt_now) / timedelta(milliseconds=1))
         else:
             str += ' '
             str += DateUtil.fmt_time_short((evt['dt_begin'] - dt_now) / timedelta(milliseconds=1))
         str += ' (TalonRO)'
         game = discord.Game(name=str)
         await CoroutineUtil.run(self.bot.change_presence(activity=game))
Пример #3
0
async def update_channel_message(bot, channel_state):
    mobile = bot.guild_state_map.get(channel_state['id_guild'])['mobile']
    type = channel_state['type']
    embed = discord.Embed()
    embed.colour = discord.Colour.gold()
    embed.title = (':crown: ' if type == TrackType.MVP else
                   ':pick: ') + entry_desc(type) + 'S'
    names = []
    maps = []
    remaining_times = []
    id_mob_first_entry = None
    cmp = 'r2' if type == TrackType.MVP else 'r1'
    for entry_state in channel_state['entry_state_list']:
        if entry_state[cmp] > -bot.config['table_entry_expiration_mins']:
            remaining_time = fmt_r1_r2(int(entry_state['r1']))
            if type == TrackType.MVP:
                if id_mob_first_entry is None:
                    id_mob_first_entry = entry_state['entry']['id_mob']
                remaining_time += ' to ' + fmt_r1_r2(int(entry_state['r2']))
            remaining_time += ' mins'
            if mobile:
                name = entry_state['entry']['name']
                if type == TrackType.MVP:
                    name += ' (' + entry_state['entry']['map'] + ')'
                name += ' | ' + remaining_time
                names.append(name)
            else:
                names.append(entry_state['entry']['name'])
                if type == TrackType.MVP:
                    maps.append(entry_state['entry']['map'])
                remaining_times.append(remaining_time)
    if len(names) == 0:
        embed.add_field(name=':x:',
                        value='No ' + entry_desc(type) + ' has been tracked.',
                        inline=False)
    else:
        max_length = 20
        if len(names) > max_length + 1:
            diff = len(names) - max_length
            for i in range(0, diff):
                names.pop()
                if type == TrackType.MVP:
                    maps.pop()
                remaining_times.pop()
            names.append('and ' + str(diff) + ' more...')
        if type == TrackType.MVP:
            embed.set_thumbnail(url="https://file5s.ratemyserver.net/mobs/" +
                                str(id_mob_first_entry) + ".gif")
        if mobile:
            embed.add_field(name='Name', value=fmt_column(names), inline=False)
        else:
            embed.add_field(name='Name', value=fmt_column(names), inline=True)
            if type == TrackType.MVP:
                embed.add_field(name='Map',
                                value=fmt_column(maps),
                                inline=True)
            embed.add_field(name='Remaining Time',
                            value=fmt_column(remaining_times),
                            inline=True)
    if len(channel_state['entry_log_list']) > 0:
        result = ''
        for entry_log in channel_state['entry_log_list']:
            if result != '':
                result += '\n'
            milliseconds = (entry_log['entry_time'] -
                            datetime.now()) / timedelta(milliseconds=1)
            result += '**[' + DateUtil.fmt_time_short(milliseconds) + ']**'
            result += ' ' + entry_log['entry']['name']
            if type == TrackType.MVP:
                result += ' (' + entry_log['entry']['map'] + ')'
            result += ' by <@' + str(entry_log['id_user']) + '>'
        embed.add_field(name='Track Log', value=result, inline=False)
    guild = next((x for x in bot.guilds if x.id == channel_state['id_guild']),
                 None)
    if guild is None:
        return
    channel = next(
        (x for x in guild.channels if x.id == channel_state['id_channel']),
        None)
    if validate_channel(bot, channel) is not None:
        return
    message = None
    if channel_state['id_message'] is not None:
        message = await CoroutineUtil.run_with_retries(
            channel.fetch_message(channel_state['id_message']))
    if message is None:
        message = await CoroutineUtil.run(channel.send(embed=embed))
        if message is not None:
            channel_state['id_message'] = message.id
    else:
        await CoroutineUtil.run(message.edit(embed=embed, content=''))
        await CoroutineUtil.run(message.clear_reactions())