async def ex_fpa(self, args, message): if len(args) == 1 and args[0] in ('on', 'off'): if not can_monitor(message): resp = 'Sorry %(reply_to)s, only race monitors can do that.' elif args[0] == 'on': if self.state['fpa']: resp = 'Fair play agreement is already activated.' else: self.state['fpa'] = True resp = ( 'Fair play agreement is now active. @entrants may ' 'use the !fpa command during the race to notify of a ' 'crash. Race monitors should enable notifications ' 'using the bell 🔔 icon below chat.') else: # args[0] == 'off' if not self.state['fpa']: resp = 'Fair play agreement is not active.' else: self.state['fpa'] = False resp = 'Fair play agreement is now deactivated.' elif self.state['fpa']: if self._race_in_progress(): resp = '@everyone FPA has been invoked by @%(reply_to)s.' else: resp = 'FPA cannot be invoked before the race starts.' else: resp = ( 'Fair play agreement is not active. Race monitors may enable ' 'FPA for this race with !fpa on') if resp: reply_to = message.get('user', {}).get('name', 'friend') await self.send_message(resp % {'reply_to': reply_to})
async def ex_spoilerlogurl(self, args, message): if ( self.state.get("spoiler_log_seed_rolled") and (can_monitor(message) or self.state.get("spoiler_log_available")) ): spoiler_log_url = self.state.get("spoiler_log_url") await self.send_message(f"Spoiler Log: {spoiler_log_url}")
async def roll_and_send(self, args, message, encrypt): """ Read an incoming !seed or !race command, and generate a new seed if valid. """ reply_to = message.get('user', {}).get('name') if self.state.get('locked') and not can_monitor(message): await self.send_message( 'Sorry %(reply_to)s, seed rolling is locked. Only race ' 'monitors may roll a seed for this race.' % {'reply_to': reply_to or 'friend'} ) return if self.state.get('seed_id') and not can_moderate(message): await self.send_message( 'Well excuuuuuse me princess, but I already rolled a seed. ' 'Don\'t get greedy!' ) return await self.roll( preset=args[0] if args else 'weekly', encrypt=encrypt, reply_to=reply_to, )
async def ex_filename(self, args, message): if self.state.get("seed_rolled") and (can_monitor(message) or self.state.get("file_name_available") and self.state.get("force_filename")): file_name = self.state.get("file_name") await self.send_message(f"File Name: {file_name}") elif not self.state.get("force_filename"): await self.send_message("I mean if you want one so bad, I hear Cubsrule is a decent one.") else: await self.send_message("File Name is not available yet!")
async def ex_bantingletuner(self, args, message): if self.state.get("tingle_tuner_banned"): await self.send_message("The Tingle Tuner is already banned in this race.") elif self.state.get("spoiler_log_seed_rolled") and not can_monitor(message): await self.send_message("The race has already started! The Tingle Tuner is allowed in this race.") else: self.state["tingle_tuner_banned"] = True await self.send_message("The Tingle Tuner is now banned in this race.")
async def ex_rollseed(self, args, message): if self.state.get("locked") and not can_monitor(message): await self.send_mesage("Seed rolling is locked. Only the creator of this room, a race monitor, or a moderator can roll a seed.") return if self.state.get("race_type") == RaceType.SPOILER: await self.send_message("Please use !startspoilerlograce to start this race.") elif self.state.get("race_type") == RaceType.STANDARD: await self.startstandardrace() else: await self.startcustomrace()
async def is_locked(self, message): """ Check if room is locked or seed already exists. Post in chat if that is the case. """ if self.seed_rolled: await self.send_message( 'I already rolled a seed! Use !cancel to clear the currently rolled game.' ) return True if self.state.get('locked') and not can_monitor(message): await self.send_message( 'Seed rolling is locked in this room. Only the creator of this room, a race monitor, or a moderator can roll.' ) return True return False
async def ex_startspoilerlograce(self, message): if self.state.get("locked") and not can_monitor(message): await self.send_message( "Seed rolling is locked. Only the creator of this room, a race monitor, or a moderator can roll a seed." ) return if self.state.get("race_type") == RaceType.SPOILER: await self.send_message("This is not a spoiler log race room!") await self.send_message("Please use !isspoilerlog to change it, or !rollseed.") return if self.state.get("spoiler_log_seed_rolled"): await self.send_message("Seed already rolled!") return self.loop.create_task(self.start_spoiler_log_race(self.state.get("permalink")))
async def ex_rollseed(self, args, message): print("rolling seed") if self.state.get("locked") and not can_monitor(message): await self.send_message( "Seed rolling is locked! Only the creator of this room, a race monitor, " "or a moderator can roll a seed.") if self.state.get("use_french"): await self.send_message( "Translate 'Seed rolling is locked! Only the creator of this room, a race " "monitor, or a moderator can roll a seed.'") return if self.state.get("permalink_available"): await self.send_message( "The seed is already rolled! Use !seed to view it.") if self.state.get("use_french"): await self.send_message( "Translate 'The seed is already rolled! Use !permalink to view it.' to French." ) return await self.send_message("Rolling seed.....") if self.state.get("version") == None: generated_seed = self.generator.generate_seed( self.state.get("permalink"), self.state.get("spoiler")) permalink = generated_seed.get("permalink") hash = generated_seed.get("hash") seed = generated_seed.get("seed") version = generated_seed.get("version") else: version = self.state.get("version") commit = version.split('_')[1] seed_name = "".join( random.choice(string.digits) for _ in range(18)) file_name = "".join( random.choice(string.digits) for _ in range(18)) permalink = f"{self.state.get('permalink')}#{seed_name}" current_hash = hashlib.md5() current_hash.update(str(seed_name).encode("ASCII")) current_hash.update(permalink.encode("ASCII")) current_hash.update(version.encode("ASCII")) with urllib.request.urlopen( f"http://raw.githubusercontent.com/ssrando/ssrando/{commit}/names.txt" ) as f: data = f.read().decode("utf-8") names = [s.strip() for s in data.split("\n")] hash_random = random.Random() hash_random.seed(current_hash.digest()) hash = " ".join(hash_random.choice(names) for _ in range(3)) seed = seed_name self.logger.info(permalink) self.state["permalink"] = permalink self.state["hash"] = hash self.state["seed"] = seed self.state["permalink_available"] = True await self.send_message( f"{version} Permalink: {permalink}, Hash: {hash}") if self.state.get("spoiler"): url = generated_seed.get("spoiler_log_url") self.state["spoiler_url"] = url await self.send_message(f"Spoiler Log URL available at {url}") await self.set_raceinfo( f" - {version} Seed: {seed}, Hash: {hash}, Permalink: {permalink}", False, False)
async def ex_permalink(self, args, message): if self.state.get("permalink") and (can_monitor(message) or self.state.get("permalink_available")): permalink = self.state.get("permalink") await self.send_message(f"Permalink: {permalink}") else: await self.send_message(f"Permalink is not available! Current Settings Example: {permalink}")