示例#1
0
    async def send_channel_start_text(self) -> None:
        msg = '\n \N{BULLET} To suggest a time, use `.suggest`. (See `.help suggest` for more info.) Give the time ' \
              'in your own local timezone (which you\'ve registered using `.timezone`).\n' \
              '\N{BULLET} Confirm a suggested time with `.confirm`. You may remove a confirmation with ' \
              '`.unconfirm`.\n' \
              '\N{BULLET} To reschedule a time both racers have confirmed, both racers must call `.unconfirm`.\n' \
              '\N{BULLET} You may alert CoNDOR staff at any time by calling `.staff`.\n'

        if self.match.racer_1.timezone is not None and self.match.racer_2.timezone is not None:
            utcnow = pytz.utc.localize(datetime.datetime.utcnow())
            r1off = utcnow.astimezone(self.match.racer_1.timezone).utcoffset()
            r2off = utcnow.astimezone(self.match.racer_2.timezone).utcoffset()

            if r1off > r2off:
                ahead_racer_name = self.match.racer_1.display_name
                behind_racer_name = self.match.racer_2.display_name
                diff_str = timestr.timedelta_to_str(r1off - r2off)
                # noinspection PyUnresolvedReferences
                msg += '\N{BULLET} {0} is currently {1} ahead of {2}.\n'.format(
                    ahead_racer_name, diff_str, behind_racer_name)
            elif r1off < r2off:
                ahead_racer_name = self.match.racer_2.display_name
                behind_racer_name = self.match.racer_1.display_name
                diff_str = timestr.timedelta_to_str(r2off - r1off)
                # noinspection PyUnresolvedReferences
                msg += '\N{BULLET} {0} is currently {1} ahead of {2}.\n'.format(
                    ahead_racer_name, diff_str, behind_racer_name)
            else:
                # noinspection PyUnresolvedReferences
                msg += '\N{BULLET} The two racers in this match currently have the same UTC offset.\n'

        else:
            if self.match.racer_1.timezone is None and self.match.racer_2.timezone is not None:
                # noinspection PyUnresolvedReferences
                msg += '\N{BULLET} {0} has not registered a timezone. Please call `.timezone`.\n'.format(
                    self.match.racer_1.display_name)
            elif self.match.racer_1.timezone is not None and self.match.racer_2.timezone is None:
                # noinspection PyUnresolvedReferences
                msg += '\N{BULLET} {0} has not registered a timezone. Please call `.timezone`.\n'.format(
                    self.match.racer_2.display_name)
            else:
                # noinspection PyUnresolvedReferences
                msg += '\N{BULLET} {0} and {1} have not registered a timezone. Please call `.timezone`.\n'.format(
                    self.match.racer_1.display_name,
                    self.match.racer_2.display_name)

        # noinspection PyUnresolvedReferences
        msg += '\N{BULLET} This match is a {0}.'.format(self.match.format_str)

        await self.channel.send(msg)
示例#2
0
async def get_nextrace_displaytext(match_list: list) -> str:
    utcnow = pytz.utc.localize(datetime.datetime.utcnow())
    if len(match_list) > 1:
        display_text = 'Upcoming matches: \n'
    else:
        display_text = 'Next match: \n'

    for match in match_list:
        # noinspection PyUnresolvedReferences
        display_text += '\N{BULLET} **{0}** - **{1}**'.format(
            match.racer_1.display_name, match.racer_2.display_name)
        if match.suggested_time is None:
            display_text += '\n'
            continue

        display_text += ': {0} \n'.format(
            timestr.timedelta_to_str(match.suggested_time - utcnow,
                                     punctuate=True))
        match_cawmentator = await match.get_cawmentator()
        if match_cawmentator is not None:
            display_text += '    Cawmentary: <http://www.twitch.tv/{0}> \n'.format(
                match_cawmentator.twitch_name)
        elif match.racer_1.twitch_name is not None and match.racer_2.twitch_name is not None:
            display_text += '    Kadgar: {} \n'.format(
                rtmputil.kadgar_link(match.racer_1.twitch_name,
                                     match.racer_2.twitch_name))
            # display_text += '    RTMP: {} \n'.format(
            #     rtmputil.rtmp_link(match.racer_1.rtmp_name, match.racer_2.rtmp_name)
            # )

    display_text += '\nFull schedule: <https://condor.host/schedule>'

    return display_text
示例#3
0
 def _format_as_timestr(td: datetime.timedelta) -> str:
     """Format the given timedelta into a string"""
     if td < datetime.timedelta(minutes=1):
         return 'under a minute'
     else:
         return timestr.timedelta_to_str(td)