async def skipsong(self, ctx): logger.info("command: skipsong") await channel_setup(ctx) await user_setup(ctx) database.zadd("streak:global", {str(ctx.author.id): 0}) currentSongBird = str(database.hget(f"channel:{str(ctx.channel.id)}", "sBird"))[2:-1] database.hset(f"channel:{str(ctx.channel.id)}", "sBird", "") database.hset(f"channel:{str(ctx.channel.id)}", "sAnswered", "1") if currentSongBird != "": # check if there is bird birdPage = wikipedia.page(f"{currentSongBird} (bird)") await ctx.send(f"Ok, skipping {currentSongBird.lower()}") await ctx.send(birdPage.url if not database.exists(f"race.data:{str(ctx.channel.id)}") else f"<{birdPage.url}>") # sends wiki page if database.exists(f"race.data:{str(ctx.channel.id)}") and str( database.hget(f"race.data:{str(ctx.channel.id)}", "media"))[2:-1] == "song": limit = int(database.hget(f"race.data:{str(ctx.channel.id)}", "limit")) first = database.zrevrange(f"race.scores:{str(ctx.channel.id)}", 0, 0, True)[0] if int(first[1]) >= limit: logger.info("race ending") race = self.bot.get_cog("Race") await race.stop_race_(ctx) else: logger.info("auto sending next bird song") addon, bw = map(str, database.hmget(f"race.data:{str(ctx.channel.id)}", ["addon", "bw"])) birds = self.bot.get_cog("Birds") await birds.send_bird_(ctx, addon[2:-1], bw[2:-1]) else: await ctx.send("You need to ask for a bird first!")
async def check(self, ctx, *, guess): logger.info("command: check") await channel_setup(ctx) await user_setup(ctx) current_fossil = str( database.hget(f"channel:{str(ctx.channel.id)}", "fossil"))[2:-1] if current_fossil == "": await ctx.send("You must ask for a fossil first!") else: # if there is a fossil, it checks answer await fossil_setup(ctx, current_fossil) database.hset(f"channel:{str(ctx.channel.id)}", "fossil", "") database.hset(f"channel:{str(ctx.channel.id)}", "answered", "1") if spellcheck(guess.split(" ")[-1], current_fossil.split(" ")[-1]): logger.info("correct") if database.exists(f"session.data:{ctx.author.id}"): logger.info("session active") session_increment(ctx, "correct", 1) await ctx.send("Correct! Good job!") page = wikipedia.page(current_fossil) await ctx.send(page.url) score_increment(ctx, 1) if int(database.zscore("users:global", str(ctx.author.id))) in achievements: number = str( int(database.zscore("users:global", str(ctx.author.id)))) await ctx.send( f"Wow! You have answered {number} fossils correctly!") filename = 'achievements/' + number + ".PNG" with open(filename, 'rb') as img: await ctx.send( file=discord.File(img, filename="award.png")) else: logger.info("incorrect") if database.exists(f"session.data:{ctx.author.id}"): logger.info("session active") session_increment(ctx, "incorrect", 1) incorrect_increment(ctx, str(current_fossil), 1) await ctx.send("Sorry, the fossil was actually " + current_fossil.lower() + ".") page = wikipedia.page(current_fossil) await ctx.send(page.url) logger.info("current_fossil: " + str(current_fossil.lower().replace("-", " "))) logger.info("guess: " + str(guess.lower().replace("-", " ")))
async def bird_setup(ctx, bird): logger.info("checking bird data") if database.zscore("incorrect:global", string.capwords(str(bird))) is not None: logger.info("bird global ok") else: database.zadd("incorrect:global", {string.capwords(str(bird)): 0}) logger.info("bird global added") if database.zscore(f"incorrect.user:{ctx.author.id}", string.capwords(str(bird))) is not None: logger.info("bird user ok") else: database.zadd(f"incorrect.user:{ctx.author.id}", {string.capwords(str(bird)): 0}) logger.info("bird user added") if ctx.guild is not None: logger.info("no dm") if database.zscore(f"incorrect.server:{ctx.guild.id}", string.capwords(str(bird))) is not None: logger.info("bird server ok") else: database.zadd(f"incorrect.server:{ctx.guild.id}", {string.capwords(str(bird)): 0}) logger.info("bird server added") else: logger.info("dm context") if database.exists(f"session.data:{str(ctx.author.id)}"): logger.info("session in session") if database.zscore(f"session.incorrect:{ctx.author.id}", string.capwords(str(bird))) is not None: logger.info("bird session ok") else: database.zadd(f"session.incorrect:{ctx.author.id}", {string.capwords(str(bird)): 0}) logger.info("bird session added") else: logger.info("no session")
async def channel_setup(ctx): logger.info("checking channel setup") if database.exists(f"channel:{str(ctx.channel.id)}"): logger.info("channel data ok") else: database.hmset( f"channel:{str(ctx.channel.id)}", { "bird": "", "answered": 1, "sBird": "", "sAnswered": 1, "goatsucker": "", "gsAnswered": 1, "prevJ": 20, "prevB": "", "prevS": "", "prevK": 20 } ) # true = 1, false = 0, index 0 is last arg, prevJ is 20 to define as integer logger.info("channel data added") await ctx.send("Ok, setup! I'm all ready to use!") if database.zscore("score:global", str(ctx.channel.id)) is not None: logger.info("channel score ok") else: database.zadd("score:global", {str(ctx.channel.id): 0}) logger.info("channel score added")
async def goatsucker(self, ctx): logger.info("command: goatsucker") await channel_setup(ctx) await user_setup(ctx) answered = int( database.hget(f"channel:{str(ctx.channel.id)}", "gsAnswered")) # check to see if previous bird was answered if answered: # if yes, give a new bird if database.exists(f"session.data:{ctx.author.id}"): logger.info("session active") session_increment(ctx, "total", 1) database.hset(f"channel:{str(ctx.channel.id)}", "gsAnswered", "0") currentBird = random.choice(goatsuckers) database.hset(f"channel:{str(ctx.channel.id)}", "goatsucker", str(currentBird)) logger.info("currentBird: " + str(currentBird)) await send_bird(ctx, currentBird, on_error=error_skip_goat, message=GS_MESSAGE) else: # if no, give the same bird await send_bird(ctx, str( database.hget(f"channel:{str(ctx.channel.id)}", "goatsucker"))[2:-1], on_error=error_skip_goat, message=GS_MESSAGE)
async def stop(self, ctx): logger.info("command: stop race") await channel_setup(ctx) await user_setup(ctx) if database.exists(f"race.data:{str(ctx.channel.id)}"): await self.stop_race_(ctx) else: await ctx.send("**There is no race in session.** *You can start one with `b!race start`*")
async def view(self, ctx): logger.info("command: view race") await channel_setup(ctx) await user_setup(ctx) if database.exists(f"race.data:{str(ctx.channel.id)}"): await self._send_stats(ctx, f"**Race In Progress**") else: await ctx.send("**There is no race in session.** *You can start one with `b!race start`*")
async def view(self, ctx): logger.info("command: view session") await channel_setup(ctx) await user_setup(ctx) if database.exists(f"session.data:{str(ctx.author.id)}"): await self._send_stats(ctx) else: await ctx.send("**There is no session running.** *You can start one with `f!session start`*")
async def start(self, ctx, *, args_str: str = ""): logger.info("command: start session") await channel_setup(ctx) await user_setup(ctx) if database.exists(f"session.data:{str(ctx.author.id)}"): logger.info("already session") await ctx.send("**There is already a session running.** *Change settings/view stats with `b!session edit`*") return else: args = args_str.split(" ") logger.info(f"args: {args}") if "bw" in args: bw = "bw" else: bw = "" states_args = set(states.keys()).intersection({arg.upper() for arg in args}) if states_args: state = " ".join(states_args).strip() else: state = " ".join(check_state_role(ctx)) order_args = set(orders["orders"]).intersection({arg.lower() for arg in args}) if order_args: order = " ".join(order_args).strip() else: order = "" female = "female" in args or "f" in args juvenile = "juvenile" in args or "j" in args if female and juvenile: await ctx.send("**Juvenile females are not yet supported.**\n*Please try again*") return elif female: addon = "female" elif juvenile: addon = "juvenile" else: addon = "" logger.info(f"adding bw: {bw}; addon: {addon}; state: {state}") database.hmset( f"session.data:{str(ctx.author.id)}", { "start": round(time.time()), "stop": 0, "correct": 0, "incorrect": 0, "total": 0, "bw": bw, "state": state, "addon": addon, "order": order } ) await ctx.send(f"**Session started with options:**\n{await self._get_options(ctx)}")
def score_increment(ctx, amount): logger.info(f"incrementing score by {amount}") database.zincrby("score:global", amount, str(ctx.channel.id)) database.zincrby("users:global", amount, str(ctx.author.id)) if ctx.guild is not None: logger.info("no dm") database.zincrby(f"users.server:{ctx.guild.id}", amount, str(ctx.author.id)) else: logger.info("dm context") if database.exists(f"race.data:{str(ctx.channel.id)}"): logger.info("race in session") database.zincrby(f"race.scores:{str(ctx.channel.id)}", amount, str(ctx.author.id))
async def stop(self, ctx): logger.info("command: stop session") await channel_setup(ctx) await user_setup(ctx) if database.exists(f"session.data:{str(ctx.author.id)}"): database.hset(f"session.data:{str(ctx.author.id)}", "stop", round(time.time())) await self._send_stats(ctx) database.delete(f"session.data:{str(ctx.author.id)}") else: await ctx.send("**There is no session running.** *You can start one with `f!session start`*")
def incorrect_increment(ctx, bird, amount): logger.info(f"incrementing incorrect {bird} by {amount}") database.zincrby("incorrect:global", amount, str(bird)) database.zincrby(f"incorrect.user:{ctx.author.id}", amount, str(bird)) if ctx.guild is not None: logger.info("no dm") database.zincrby(f"incorrect.server:{ctx.guild.id}", amount, str(bird)) else: logger.info("dm context") if database.exists(f"session.data:{str(ctx.author.id)}"): logger.info("session in session") database.zincrby(f"session.incorrect:{ctx.author.id}", amount, str(bird)) else: logger.info("no session")
async def send_song_(self, ctx): songAnswered = int( database.hget(f"channel:{str(ctx.channel.id)}", "sAnswered")) # check to see if previous bird was answered if songAnswered: # if yes, give a new bird roles = check_state_role(ctx) if database.exists(f"session.data:{ctx.author.id}"): logger.info("session active") session_increment(ctx, "total", 1) roles = str( database.hget(f"session.data:{ctx.author.id}", "state"))[2:-1].split(" ") if roles[0] == "": roles = [] if len(roles) is 0: logger.info("no session lists") roles = check_state_role(ctx) logger.info(f"roles: {roles}") if roles: birds = list( itertools.chain.from_iterable(states[state]["songBirds"] for state in roles)) else: birds = songBirds logger.info(f"number of birds: {len(birds)}") currentSongBird = random.choice(birds) prevS = str( database.hget(f"channel:{str(ctx.channel.id)}", "prevS"))[2:-1] while currentSongBird == prevS: currentSongBird = random.choice(birds) database.hset(f"channel:{str(ctx.channel.id)}", "prevS", str(currentSongBird)) database.hset(f"channel:{str(ctx.channel.id)}", "sBird", str(currentSongBird)) logger.info("currentSongBird: " + str(currentSongBird)) await send_birdsong(ctx, currentSongBird, on_error=error_skip_song, message=SONG_MESSAGE) database.hset(f"channel:{str(ctx.channel.id)}", "sAnswered", "0") else: await send_birdsong( ctx, str(database.hget(f"channel:{str(ctx.channel.id)}", "sBird"))[2:-1], on_error=error_skip_song, message=SONG_MESSAGE)
async def start(self, ctx): logger.info("command: start session") await channel_setup(ctx) await user_setup(ctx) if database.exists(f"session.data:{str(ctx.author.id)}"): logger.info("already session") await ctx.send("**There is already a session running.** *View stats with `f!session`*") return else: database.hmset( f"session.data:{str(ctx.author.id)}", { "start": round(time.time()), "stop": 0, "correct": 0, "incorrect": 0, "total": 0 } ) await ctx.send("**Session started. Your stats are now being tracked**")
async def fossil(self, ctx): logger.info("command: fossil") await channel_setup(ctx) await user_setup(ctx) logger.info("fossil: " + str( database.hget(f"channel:{str(ctx.channel.id)}", "fossil"))[2:-1]) answered = int( database.hget(f"channel:{str(ctx.channel.id)}", "answered")) logger.info(f"answered: {answered}") # check to see if previous fossil was answered if answered: # if yes, give a new fossil if database.exists(f"session.data:{ctx.author.id}"): logger.info("session active") session_increment(ctx, "total", 1) logger.info(f"number of fossils: {len(fossils_list)}") current_fossil = random.choice(fossils_list) prevB = str( database.hget(f"channel:{str(ctx.channel.id)}", "prevB"))[2:-1] while current_fossil == prevB: current_fossil = random.choice(fossils_list) database.hset(f"channel:{str(ctx.channel.id)}", "prevB", str(current_fossil)) database.hset(f"channel:{str(ctx.channel.id)}", "fossil", str(current_fossil)) logger.info("current fossil: " + str(current_fossil)) await send_fossil(ctx, current_fossil, on_error=error_skip, message=FOSSIL_MESSAGE) database.hset(f"channel:{str(ctx.channel.id)}", "answered", "0") else: # if no, give the same fossil await send_fossil( ctx, str(database.hget(f"channel:{str(ctx.channel.id)}", "fossil"))[2:-1], on_error=error_skip, message=FOSSIL_MESSAGE)
async def on_command_error(ctx, error): logger.exception(error) # don't handle errors with local handlers if hasattr(ctx.command, 'on_error'): return if isinstance(error, commands.CommandOnCooldown): # send cooldown await ctx.send("**Cooldown.** Try again after " + str(round(error.retry_after)) + " s.", delete_after=5.0) elif isinstance(error, commands.CommandNotFound): await ctx.send("Sorry, the command was not found.") elif isinstance(error, commands.MissingRequiredArgument): await ctx.send("This command requires an argument!") elif isinstance(error, commands.BadArgument): logger.error("bad argument") await ctx.send("The argument passed was invalid. Please try again.") elif isinstance(error, commands.ArgumentParsingError): logger.error("quote error") await ctx.send("An invalid character was detected. Please try again.") elif isinstance(error, commands.TooManyArguments): logger.error("too many args") await ctx.send("Too many arguments were provided. Please try again.") elif isinstance(error, commands.BotMissingPermissions): logger.error("missing permissions error") await ctx.send( f"""**The bot does not have enough permissions to fully function.** **Permissions Missing:** `{', '.join(map(str, error.missing_perms))}` *Please try again once the correct permissions are set.*""" ) elif isinstance(error, commands.NoPrivateMessage): await ctx.send("**This command is unavaliable in DMs!**") elif isinstance(error, commands.CommandInvokeError): if isinstance(error.original, redis.exceptions.ResponseError): if database.exists(f"channel:{str(ctx.channel.id)}"): await ctx.send( """**An unexpected ResponseError has occurred.** *Please log this message in #support in the support server below, or try again.* **Error:** """ + str(error) ) await ctx.send("https://discord.gg/husFeGG") else: await channel_setup(ctx) await ctx.send("Please run that command again.") elif isinstance(error.original, wikipedia.exceptions.DisambiguationError): await ctx.send("Wikipedia page not found. (Disambiguation Error)") elif isinstance(error.original, wikipedia.exceptions.PageError): await ctx.send("Wikipedia page not found. (Page Error)") elif isinstance(error.original, wikipedia.exceptions.WikipediaException): await ctx.send("Wikipedia page unavaliable. Try again later.") elif isinstance(error.original, aiohttp.ClientOSError): if error.original.errno != errno.ECONNRESET: await ctx.send( """**An unexpected ClientOSError has occurred.** *Please log this message in #support in the support server below, or try again.* **Error:** """ + str(error) ) await ctx.send("https://discord.gg/husFeGG") else: await ctx.send("**An error has occured with discord. :(**\n*Please try again.*") else: logger.exception(error) await ctx.send( """**An uncaught command error has occurred.** *Please log this message in #support in the support server below, or try again.* **Error:** """ + str(error) ) await ctx.send("https://discord.gg/husFeGG") raise error else: logger.error("uncaught non-command") await ctx.send( """**An uncaught non-command error has occurred.** *Please log this message in #support in the support server below, or try again.* **Error:** """ + str(error) ) await ctx.send("https://discord.gg/husFeGG") raise error
async def check(self, ctx, *, arg): logger.info("command: check") await channel_setup(ctx) await user_setup(ctx) currentBird = str( database.hget(f"channel:{str(ctx.channel.id)}", "bird"))[2:-1] if currentBird == "": # no bird await ctx.send("You must ask for a bird first!") else: # if there is a bird, it checks answer logger.info("currentBird: " + str(currentBird.lower().replace("-", " "))) logger.info("args: " + str(arg.lower().replace("-", " "))) await bird_setup(ctx, currentBird) sciBird = await get_sciname(currentBird) if spellcheck(arg, currentBird) is True or spellcheck( arg, sciBird) is True: logger.info("correct") database.zincrby("streak:global", 1, str(ctx.author.id)) database.hset(f"channel:{str(ctx.channel.id)}", "bird", "") database.hset(f"channel:{str(ctx.channel.id)}", "answered", "1") if database.exists(f"session.data:{ctx.author.id}"): logger.info("session active") session_increment(ctx, "correct", 1) # check if streak is greater than max, if so, increases max if database.zscore("streak:global", str( ctx.author.id)) > database.zscore( "streak.max:global", str(ctx.author.id)): database.zadd( "streak.max:global", { str(ctx.author.id): database.zscore("streak:global", str( ctx.author.id)) }) await ctx.send("Correct! Good job!" if not database.exists( f"race.data:{str(ctx.channel.id)}" ) else f"**{str(ctx.author.mention)}**, you are correct!") page = wikipedia.page(f"{currentBird} (bird)") await ctx.send(page.url if not database.exists( f"race.data:{str(ctx.channel.id)}") else f"<{page.url}>") score_increment(ctx, 1) if int(database.zscore("users:global", str(ctx.author.id))) in achievement: number = str( int(database.zscore("users:global", str(ctx.author.id)))) await ctx.send( f"Wow! You have answered {number} birds correctly!") filename = 'achievements/' + number + ".PNG" with open(filename, 'rb') as img: await ctx.send( file=discord.File(img, filename="award.png")) if database.exists(f"race.data:{str(ctx.channel.id)}") and str( database.hget(f"race.data:{str(ctx.channel.id)}", "media"))[2:-1] == "image": limit = int( database.hget(f"race.data:{str(ctx.channel.id)}", "limit")) first = database.zrevrange( f"race.scores:{str(ctx.channel.id)}", 0, 0, True)[0] if int(first[1]) >= limit: logger.info("race ending") race = self.bot.get_cog("Race") await race.stop_race_(ctx) else: logger.info("auto sending next bird image") addon, bw = map( str, database.hmget(f"race.data:{str(ctx.channel.id)}", ["addon", "bw"])) birds = self.bot.get_cog("Birds") await birds.send_bird_(ctx, addon[2:-1], bw[2:-1]) else: logger.info("incorrect") database.zadd("streak:global", {str(ctx.author.id): 0}) if database.exists(f"session.data:{str(ctx.author.id)}"): logger.info("session active") session_increment(ctx, "incorrect", 1) incorrect_increment(ctx, str(currentBird), 1) if database.exists(f"race.data:{str(ctx.channel.id)}"): await ctx.send("Sorry, that wasn't the right answer.") else: database.hset(f"channel:{str(ctx.channel.id)}", "bird", "") database.hset(f"channel:{str(ctx.channel.id)}", "answered", "1") await ctx.send("Sorry, the bird was actually " + currentBird.lower() + ".") page = wikipedia.page(f"{currentBird} (bird)") await ctx.send(page.url)
async def checkgoat(self, ctx, *, arg): logger.info("command: checkgoat") await channel_setup(ctx) await user_setup(ctx) currentBird = str( database.hget(f"channel:{str(ctx.channel.id)}", "goatsucker"))[2:-1] if currentBird == "": # no bird await ctx.send("You must ask for a bird first!") else: # if there is a bird, it checks answer await bird_setup(ctx, currentBird) index = goatsuckers.index(currentBird) sciBird = sciGoat[index] database.hset(f"channel:{str(ctx.channel.id)}", "gsAnswered", "1") database.hset(f"channel:{str(ctx.channel.id)}", "goatsucker", "") if spellcheck(arg, currentBird) is True or spellcheck( arg, sciBird) is True: logger.info("correct") database.zincrby("streak:global", 1, str(ctx.author.id)) if database.zscore("streak:global", str( ctx.author.id)) > database.zscore( "streak.max:global", str(ctx.author.id)): database.zadd( "streak.max:global", { str(ctx.author.id): database.zscore("streak:global", str( ctx.author.id)) }) if database.exists(f"session.data:{ctx.author.id}"): logger.info("session active") session_increment(ctx, "correct", 1) await ctx.send("Correct! Good job!") page = wikipedia.page(f"{currentBird} (bird)") await ctx.send(page.url) score_increment(ctx, 1) if int(database.zscore("users:global", str(ctx.author.id))) in achievement: number = str( int(database.zscore("users:global", str(ctx.author.id)))) await ctx.send( f"Wow! You have answered {number} birds correctly!") filename = 'achievements/' + number + ".PNG" with open(filename, 'rb') as img: await ctx.send( file=discord.File(img, filename="award.png")) else: logger.info("incorrect") database.zadd("streak:global", {str(ctx.author.id): 0}) if database.exists(f"session.data:{ctx.author.id}"): logger.info("session active") session_increment(ctx, "incorrect", 1) incorrect_increment(ctx, str(currentBird), 1) await ctx.send("Sorry, the bird was actually " + currentBird.lower() + ".") page = wikipedia.page(f"{currentBird} (bird)") await ctx.send(page.url) logger.info("currentBird: " + str(currentBird.lower().replace("-", " "))) logger.info("args: " + str(arg.lower().replace("-", " ")))
async def send_bird_(self, ctx, add_on: str = "", bw: bool = False, order: str = ""): if add_on == "": message = BIRD_MESSAGE.format(option="n image") else: message = BIRD_MESSAGE.format(option=f" {add_on}") if order: order = order.split(" ") logger.info( "bird: " + str(database.hget(f"channel:{str(ctx.channel.id)}", "bird"))[2:-1]) answered = int( database.hget(f"channel:{str(ctx.channel.id)}", "answered")) logger.info(f"answered: {answered}") # check to see if previous bird was answered if answered: # if yes, give a new bird roles = check_state_role(ctx) if database.exists(f"session.data:{ctx.author.id}"): logger.info("session active") session_increment(ctx, "total", 1) roles = str( database.hget(f"session.data:{ctx.author.id}", "state"))[2:-1].split(" ") if roles[0] == "": roles = [] if not roles: logger.info("no session lists") roles = check_state_role(ctx) logger.info(f"addon: {add_on}; bw: {bw}; roles: {roles}") if order: birds_in_order = set( itertools.chain.from_iterable(orders[o] for o in order)) if roles: birds_in_state = set( itertools.chain.from_iterable(states[state]["birdList"] for state in roles)) birds = list(birds_in_order.intersection(birds_in_state)) else: birds = list(birds_in_order.intersection(set(birdList))) else: if roles: birds = list( set( itertools.chain.from_iterable( states[state]["birdList"] for state in roles))) else: birds = birdList if len(birds) is 0: logger.info("no birds for order/state") await ctx.send( f"**Sorry, no birds could be found for the order/state combo.**\n*Please try again*" ) return logger.info(f"number of birds: {len(birds)}") currentBird = random.choice(birds) prevB = str( database.hget(f"channel:{str(ctx.channel.id)}", "prevB"))[2:-1] while currentBird == prevB: currentBird = random.choice(birds) database.hset(f"channel:{str(ctx.channel.id)}", "prevB", str(currentBird)) database.hset(f"channel:{str(ctx.channel.id)}", "bird", str(currentBird)) logger.info("currentBird: " + str(currentBird)) await send_bird(ctx, currentBird, on_error=error_skip, message=message, addOn=add_on, bw=bw) database.hset(f"channel:{str(ctx.channel.id)}", "answered", "0") else: # if no, give the same bird await send_bird(ctx, str( database.hget(f"channel:{str(ctx.channel.id)}", "bird"))[2:-1], on_error=error_skip, message=message, addOn=add_on, bw=bw)
async def bird(self, ctx, *, args_str: str = ""): logger.info("command: bird") await channel_setup(ctx) await user_setup(ctx) args = args_str.split(" ") logger.info(f"args: {args}") if "bw" in args: bw = True else: bw = False order_args = set(orders["orders"]).intersection( {arg.lower() for arg in args}) if order_args: order = " ".join(order_args).strip() else: order = "" female = "female" in args or "f" in args juvenile = "juvenile" in args or "j" in args if female and juvenile: await ctx.send( "**Juvenile females are not yet supported.**\n*Please try again*" ) return elif female: add_on = "female" elif juvenile: add_on = "juvenile" else: add_on = "" if database.exists(f"session.data:{ctx.author.id}"): logger.info("session parameters") if order_args: toggle_order = list(order_args) current_orders = str( database.hget(f"session.data:{str(ctx.author.id)}", "order"))[2:-1].split(" ") add_orders = [] logger.info(f"toggle orders: {toggle_order}") logger.info(f"current orders: {current_orders}") for o in set(toggle_order).symmetric_difference( set(current_orders)): add_orders.append(o) logger.info(f"adding orders: {add_orders}") order = " ".join(add_orders).strip() else: order = str( database.hget(f"session.data:{str(ctx.author.id)}", "order"))[2:-1] session_add_on = str( database.hget(f"session.data:{ctx.author.id}", "addon"))[2:-1] if add_on == "": add_on = session_add_on elif add_on == session_add_on: add_on = "" else: await ctx.send( "**Juvenile females are not yet supported.**\n*Overriding session options...*" ) if str(database.hget(f"session.data:{ctx.author.id}", "bw"))[2:-1]: bw = not bw logger.info(f"args: bw: {bw}; addon: {add_on}; order: {order}") if int(database.hget(f"channel:{str(ctx.channel.id)}", "answered")): await ctx.send( f"**Recongnized arguments:** *Black & White*: `{str(bw)}`, " + f"*Female/Juvenile*: `{'None' if add_on == '' else add_on}`, " + f"*Orders*: `{'None' if order == '' else order}`") else: await ctx.send( f"**Recongnized arguments:** *Black & White*: `{str(bw)}`") await self.send_bird_(ctx, add_on, bw, order)
async def edit(self, ctx, *, args_str: str = ""): logger.info("command: view session") await channel_setup(ctx) await user_setup(ctx) if database.exists(f"session.data:{str(ctx.author.id)}"): args = args_str.split(" ") logger.info(f"args: {args}") if "bw" in args: if len(database.hget(f"session.data:{str(ctx.author.id)}", "bw")) is 0: logger.info("adding bw") database.hset(f"session.data:{str(ctx.author.id)}", "bw", "bw") else: logger.info("removing bw") database.hset(f"session.data:{str(ctx.author.id)}", "bw", "") states_args = set(states.keys()).intersection({arg.upper() for arg in args}) if states_args: toggle_states = list(states_args) current_states = str(database.hget(f"session.data:{str(ctx.author.id)}", "state"))[2:-1].split(" ") add_states = [] logger.info(f"toggle states: {toggle_states}") logger.info(f"current states: {current_states}") for state in set(toggle_states).symmetric_difference(set(current_states)): add_states.append(state) logger.info(f"adding states: {add_states}") database.hset(f"session.data:{str(ctx.author.id)}", "state", " ".join(add_states).strip()) order_args = set(orders["orders"]).intersection({arg.lower() for arg in args}) if order_args: toggle_order = list(order_args) current_orders = str(database.hget(f"session.data:{str(ctx.author.id)}", "order"))[2:-1].split(" ") add_orders = [] logger.info(f"toggle orders: {toggle_order}") logger.info(f"current orders: {current_orders}") for o in set(toggle_order).symmetric_difference(set(current_orders)): add_orders.append(o) logger.info(f"adding orders: {add_orders}") database.hset(f"session.data:{str(ctx.author.id)}", "order", " ".join(add_orders).strip()) female = "female" in args or "f" in args juvenile = "juvenile" in args or "j" in args if female and juvenile: await ctx.send("**Juvenile females are not yet supported.**\n*Please try again*") return elif female: addon = "female" if len(database.hget(f"session.data:{str(ctx.author.id)}", "addon")) is 0: logger.info("adding female") database.hset(f"session.data:{str(ctx.author.id)}", "addon", addon) else: logger.info("removing female") database.hset(f"session.data:{str(ctx.author.id)}", "addon", "") elif juvenile: addon = "juvenile" if len(database.hget(f"session.data:{str(ctx.author.id)}", "addon")) is 0: logger.info("adding juvenile") database.hset(f"session.data:{str(ctx.author.id)}", "addon", addon) else: logger.info("removing juvenile") database.hset(f"session.data:{str(ctx.author.id)}", "addon", "") await self._send_stats(ctx, f"**Session started previously.**\n") else: await ctx.send("**There is no session running.** *You can start one with `b!session start`*")
async def start(self, ctx, *, args_str: str = ""): logger.info("command: start race") await channel_setup(ctx) await user_setup(ctx) if ctx.guild is None: logger.info("dm context") await ctx.send("**Sorry, racing is not avaliable in DMs.**") return if not str(ctx.channel.name).startswith("racing"): logger.info("not race channel") await ctx.send("**Sorry, racing is not availiable in this channel.**\n" + "*Set the channel name to start with `racing` to enable it.*") return if database.exists(f"race.data:{str(ctx.channel.id)}"): logger.info("already race") await ctx.send("**There is already a race in session.** *Change settings/view stats with `b!race view`*") return else: args = args_str.split(" ") logger.info(f"args: {args}") if "bw" in args: bw = "bw" else: bw = "" states_args = set(states.keys()).intersection( {arg.upper() for arg in args}) if states_args: state = " ".join(states_args).strip() else: state = " ".join(check_state_role(ctx)) female = "female" in args or "f" in args juvenile = "juvenile" in args or "j" in args if female and juvenile: await ctx.send("**Juvenile females are not yet supported.**\n*Please try again*") return elif female: addon = "female" elif juvenile: addon = "juvenile" else: addon = "" song = "song" in args or "s" in args image = "image" in args or "i" in args or "picture" in args or "p" in args if song and image: await ctx.send("**Songs and images are not yet supported.**\n*Please try again*") return elif song: media = "song" elif image: media = "image" else: media = "image" ints = [] for n in args: try: ints.append(int(n)) except ValueError: continue if len(ints) is not 0: limit = int(ints[0]) else: limit = 10 if limit > 1000000: await ctx.send("**Sorry, the maximum amount to win is 1 million.**") limit = 1000000 logger.info( f"adding bw: {bw}; addon: {addon}; state: {state}; media: {media}; limit: {limit}") database.hmset( f"race.data:{str(ctx.channel.id)}", { "start": round(time.time()), "stop": 0, "limit": limit, "bw": bw, "state": state, "addon": addon, "media": media } ) database.zadd(f"race.scores:{str(ctx.channel.id)}", { str(ctx.author.id): 0}) await ctx.send(f"**Race started with options:**\n{await self._get_options(ctx)}") if str(database.hget(f"race.data:{str(ctx.channel.id)}", "media"))[2:-1] == "image": logger.info("auto sending next bird image") addon, bw = map(str, database.hmget( f"race.data:{str(ctx.channel.id)}", ["addon", "bw"])) birds = self.bot.get_cog("Birds") await birds.send_bird_(ctx, addon[2:-1], bw[2:-1]) if str(database.hget(f"race.data:{str(ctx.channel.id)}", "media"))[2:-1] == "song": logger.info("auto sending next bird song") birds = self.bot.get_cog("Birds") await birds.send_song_(ctx)