async def _do_execute(self, cmd: Command): if LeagueMgr().league is None: await self.client.send_message( cmd.channel, 'Error: No league set.' ) return deadline_str = LeagueMgr().league.deadline if deadline_str is None: await self.client.send_message( cmd.channel, 'No deadline is set for the current league.' ) return try: deadline = dateparse.parse_datetime(deadline_str) except necrobot.exception.ParseException as e: await self.client.send_message(cmd.channel, str(e)) return await self.client.send_message( cmd.channel, 'The current league deadline is "{deadline_str}". As of now, this is ' '{deadline:%b %d (%A) at %I:%M %p} (UTC).' .format( deadline_str=deadline_str, deadline=deadline ) )
async def _do_execute(self, cmd): # Parse the inputs as a datetime try: suggested_time_utc = dateparse.parse_datetime(cmd.arg_string, pytz.utc) except necrobot.exception.ParseException as e: await cmd.channel.send( 'Failed to parse your input as a time ({0}).'.format(e)) return match = self.bot_channel.match # Suggest the time and confirm match.suggest_time(suggested_time_utc) # Output what we did for racer in match.racers: if racer.member is not None: if racer.timezone is not None: await cmd.channel.send( '{0}: This match is suggested to be scheduled for {1}. Please confirm with ' '`.confirm`.'.format( racer.member.mention, timestr.str_full_12h(racer.timezone.normalize(suggested_time_utc)) ) ) else: await cmd.channel.send( '{0}: A match time has been suggested; please confirm with `.confirm`. I also suggest ' 'you register a timezone (use `.timezone`), so I can convert to your local time.'.format( racer.member.mention ) ) await self.bot_channel.update()
async def _do_execute(self, cmd: Command): if LeagueMgr().league is None: await self.client.send_message( cmd.channel, 'Error: No league set.' ) return try: deadline = dateparse.parse_datetime(cmd.arg_string) except necrobot.exception.ParseException as e: await self.client.send_message(cmd.channel, str(e)) return LeagueMgr().league.deadline = cmd.arg_string LeagueMgr().league.commit() await self.client.send_message( cmd.channel, 'Set the current league\'s deadline to "{deadline_str}". As of now, this is ' '{deadline:%b %d (%A) at %I:%M %p (%Z)}.' .format( deadline_str=cmd.arg_string, deadline=deadline ) )
async def _do_execute(self, cmd: Command): if not CondorMgr().has_event: await cmd.channel.send('Error: No league set.') return try: deadline = dateparse.parse_datetime(cmd.arg_string) except necrobot.exception.ParseException as e: await cmd.channel.send(str(e)) return await CondorMgr().set_deadline(cmd.arg_string) await cmd.channel.send( 'Set the current league\'s deadline to "{deadline_str}". As of now, this is ' '{deadline:%b %d (%A) at %I:%M %p (%Z)}.'.format( deadline_str=cmd.arg_string, deadline=deadline))
async def _do_execute(self, cmd: Command): if not CondorMgr().has_event: await cmd.channel.send('Error: No league set.') return deadline_str = CondorMgr().deadline_str if deadline_str is None: await cmd.channel.send('No deadline is set for the current league.' ) return try: deadline = dateparse.parse_datetime(deadline_str) except necrobot.exception.ParseException as e: await cmd.channel.send(str(e)) return await cmd.channel.send( 'The current league deadline is "{deadline_str}". As of now, this is ' '{deadline:%b %d (%A) at %I:%M %p} (UTC).'.format( deadline_str=deadline_str, deadline=deadline))
async def find_match(input_str: str, tz: pytz.timezone = pytz.utc, finished_only: Optional[bool] = None) -> Match: """Find a match in the league database corresponding to the input args Parameters ---------- input_str: str A user-input string that we want to use to find a registered match. tz: pytz.timezone A timezone (used for interpreting dates in the input_str) finished_only: bool If not None, then: If True, only return finished matches; if False, only return unfinished matches Returns ------- Match The found match. Raises ------ NotFoundException If no match could be found. ParseException If the input string couldn't be parsed meaningfully. """ args = shlex.split(input_str) if len(args) < 2: raise necrobot.exception.ParseException( 'Need at least two arguments to find a match.') racer_1 = await userlib.get_user(any_name=args[0]) if racer_1 is None: raise necrobot.exception.NotFoundException( "Can't find any racer by the name `{0}`.".format(args[0])) args.pop(0) racer_2 = await userlib.get_user(any_name=args[0]) if racer_2 is None: raise necrobot.exception.NotFoundException( "Can't find any racer by the name `{0}`.".format(args[0])) args.pop(0) match_date = None match_date_str = '' for arg in args: match_date_str += arg + ' ' if match_date_str: match_date_str = match_date_str[:-1] match_date = dateparse.parse_datetime(match_date_str, tz) match_id = await matchdb.get_match_id(racer_1_id=racer_1.user_id, racer_2_id=racer_2.user_id, scheduled_time=match_date, finished_only=finished_only) if match_id is None: raise necrobot.exception.NotFoundException( "Can't find any match between `{0}` and `{1}`.".format( racer_1.display_name, racer_2.display_name)) return await matchutil.get_match_from_id(match_id)
async def _do_execute(self, cmd): match = self.bot_channel.match # Check for match already being confirmed if match.is_scheduled: await self.client.send_message( cmd.channel, 'The scheduled time for this match has already been confirmed by both racers. To reschedule, ' 'both racers should first call `.unconfirm`; you will then be able to `.suggest` a new time.') return # Get the command's author as a NecroUser object author_as_necrouser = await userlib.get_user(discord_id=cmd.author.id) if not author_as_necrouser: await self.client.send_message( cmd.channel, 'Error: {0} is not registered. Please register with `.stream` in the main channel. ' 'If the problem persists, contact CoNDOR Staff.'.format(cmd.author.mention)) return # Check that both racers in the match are registered if not match.racer_1 or not match.racer_2 \ or not match.racer_1.discord_id or not match.racer_2.discord_id: await self.client.send_message( cmd.channel, 'Error: At least one of the racers in this match is not registered, and needs to call ' '`.register` in the main channel. (To check if you are registered, you can call `.userinfo ' '<discord name>`. Use quotes around your discord name if it contains a space.)') return # Check that the command author is racing in the match if not match.racing_in_match(author_as_necrouser): await self.client.send_message( cmd.channel, 'Error: {0} does not appear to be one of the racers in this match. ' 'If this is in error, contact CoNDOR Staff.'.format(cmd.author.mention)) return # Get the racer's timezone if author_as_necrouser.timezone is None: await self.client.send_message( cmd.channel, '{0}: Please register a timezone with `.timezone`.'.format(cmd.author.mention)) return # Parse the inputs as a datetime try: suggested_time_utc = dateparse.parse_datetime(cmd.arg_string, author_as_necrouser.timezone) except necrobot.exception.ParseException as e: await self.client.send_message( cmd.channel, 'Failed to parse your input as a time ({0}).'.format(e)) return # Check if the scheduled time is in the past utcnow = pytz.utc.localize(datetime.datetime.utcnow()) time_until = suggested_time_utc - utcnow if not time_until.total_seconds() >= 0: await self.client.send_message( cmd.channel, '{0}: Error: The time you are suggesting for the match appears to be in the past.'.format( cmd.author.mention)) return # Check for deadlines on suggested times. league = LeagueMgr().league if league is not None: deadline_str = league.deadline if deadline_str is not None: deadline = dateparse.parse_datetime(deadline_str) if suggested_time_utc - deadline > datetime.timedelta(seconds=0): await self.client.send_message( cmd.channel, 'Matches must be scheduled before {deadline:%b %d (%A) at %I:%M %p} UTC' .format(deadline=deadline) ) return # Suggest the time and confirm match.suggest_time(suggested_time_utc) match.confirm_time(author_as_necrouser) # Output what we did for racer in match.racers: if racer.member is not None: if racer.timezone is not None: if racer == author_as_necrouser: await self.client.send_message( cmd.channel, '{0}: You\'ve suggested the match be scheduled for {1}. Waiting for the other ' 'racer to `.confirm`.'.format( racer.member.mention, timestr.str_full_12h(racer.timezone.normalize(suggested_time_utc)))) else: await self.client.send_message( cmd.channel, '{0}: This match is suggested to be scheduled for {1}. Please confirm with ' '`.confirm`.'.format( racer.member.mention, timestr.str_full_12h(racer.timezone.normalize(suggested_time_utc)))) else: await self.client.send_message( cmd.channel, '{0}: A match time has been suggested; please confirm with `.confirm`. I also suggest ' 'you register a timezone (use `.timezone`), so I can convert to your local time.'.format( racer.member.mention)) await self.bot_channel.update()
def deadline() -> Optional[datetime.datetime]: if LeagueMgr._the_league is not None: deadline_str = LeagueMgr._the_league.deadline if deadline_str is not None: return dateparse.parse_datetime(deadline_str) return None
def deadline(self) -> Optional[datetime.datetime]: if self._event.deadline_str is not None: return dateparse.parse_datetime(self._event.deadline_str) return None