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 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 ban(self, ctx, *, user: typing.Optional[typing.Union[discord.Member, str]] = None): logger.info("command: ban") if user is None: logger.info("no args") await ctx.send("Invalid User!") return logger.info(f"user-id: {user.id}") database.zadd("banned:global", {str(user.id): 0}) await ctx.send(f"Ok, {user.name} cannot use the bot anymore!")
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 skipgoat(self, ctx): logger.info("command: skipgoat") await channel_setup(ctx) await user_setup(ctx) database.zadd("streak:global", {str(ctx.author.id): 0}) currentBird = str(database.hget(f"channel:{str(ctx.channel.id)}", "goatsucker"))[2:-1] database.hset(f"channel:{str(ctx.channel.id)}", "goatsucker", "") database.hset(f"channel:{str(ctx.channel.id)}", "gsAnswered", "1") if currentBird != "": # check if there is bird birdPage = wikipedia.page(f"{currentBird} (bird)") await ctx.send(f"Ok, skipping {currentBird.lower()}\n{birdPage.url}") # sends wiki page else: await ctx.send("You need to ask for a bird first!")
async def fossil_setup(ctx, fossil): logger.info("checking fossil data") if database.zscore("incorrect:global", string.capwords(str(fossil))) is not None: logger.info("fossil global ok") else: database.zadd("incorrect:global", {string.capwords(str(fossil)): 0}) logger.info("fossil global added") if database.zscore(f"incorrect.user:{ctx.author.id}", string.capwords(str(fossil))) is not None: logger.info("fossil user ok") else: database.zadd(f"incorrect.user:{ctx.author.id}", {string.capwords(str(fossil)): 0}) logger.info("fossil user added") if ctx.guild is not None: logger.info("no dm") if database.zscore(f"incorrect.server:{ctx.guild.id}", string.capwords(str(fossil))) is not None: logger.info("fossil server ok") else: database.zadd(f"incorrect.server:{ctx.guild.id}", {string.capwords(str(fossil)): 0}) logger.info("fossil server added") else: logger.info("dm context")
async def user_setup(ctx): logger.info("checking user data") if database.zscore("users:global", str(ctx.author.id)) is not None: logger.info("user global ok") else: database.zadd("users:global", {str(ctx.author.id): 0}) logger.info("user global added") await ctx.send("Welcome <@" + str(ctx.author.id) + ">!") if ctx.guild is not None: logger.info("no dm") if database.zscore(f"users.server:{ctx.guild.id}", str(ctx.author.id)) is not None: server_score = database.zscore(f"users.server:{ctx.guild.id}", str(ctx.author.id)) global_score = database.zscore("users:global", str(ctx.author.id)) if server_score is global_score: logger.info("user server ok") else: database.zadd(f"users.server:{ctx.guild.id}", {str(ctx.author.id): global_score}) else: score = int(database.zscore("users:global", str(ctx.author.id))) database.zadd(f"users.server:{ctx.guild.id}", {str(ctx.author.id): score}) logger.info("user server added") else: logger.info("dm context")
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("-", " ")))
global_score = database.zscore("users:global", str(ctx.author.id)) if server_score is global_score: logger.info("user server ok") else: database.zadd(f"users.server:{ctx.guild.id}", {str(ctx.author.id): global_score}) else: score = int(database.zscore("users:global", str(ctx.author.id))) database.zadd(f"users.server:{ctx.guild.id}", {str(ctx.author.id): score}) logger.info("user server added") else: logger.info("dm context") #Add streak if (database.zscore("streak:global", str(UserID)) is not None) and (database.zscore("streak.max:global", str(UserID)) is not None): logger.info("user streak in already") else: database.zadd("streak:global", {str(UserID): 0}) database.zadd("streak.max:global",{str(UserID): 0}) print("added streak") # sets up new birds 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:
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)