async def skip(self, ctx): logger.info("command: skip") currentBird = database.hget(f"channel:{ctx.channel.id}", "bird").decode("utf-8") database.hset(f"channel:{ctx.channel.id}", "bird", "") database.hset(f"channel:{ctx.channel.id}", "answered", "1") if currentBird != "": # check if there is bird url = get_wiki_url(ctx, currentBird) await ctx.send(f"Ok, skipping {currentBird.lower()}") await ctx.send(url) # sends wiki page streak_increment(ctx, None) # reset streak if database.exists(f"race.data:{ctx.channel.id}"): if Filter.from_int( int( database.hget(f"race.data:{ctx.channel.id}", "filter"))).vc: await voice_functions.stop(ctx, silent=True) media = database.hget(f"race.data:{ctx.channel.id}", "media").decode("utf-8") limit = int( database.hget(f"race.data:{ctx.channel.id}", "limit")) first = database.zrevrange(f"race.scores:{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(f"auto sending next bird {media}") filter_int, taxon, state = database.hmget( f"race.data:{ctx.channel.id}", ["filter", "taxon", "state"]) birds = self.bot.get_cog("Birds") await birds.send_bird_( ctx, media, Filter.from_int(int(filter_int)), taxon.decode("utf-8"), state.decode("utf-8"), ) else: await ctx.send("You need to ask for a bird first!")
async def skipgoat(self, ctx): logger.info("command: skipgoat") await channel_setup(ctx) await user_setup(ctx) currentBird = str( database.hget(f"channel:{ctx.channel.id}", "goatsucker"))[2:-1] database.hset(f"channel:{ctx.channel.id}", "goatsucker", "") database.hset(f"channel:{ctx.channel.id}", "gsAnswered", "1") if currentBird != "": # check if there is bird url = get_wiki_url(currentBird) await ctx.send(f"Ok, skipping {currentBird.lower()}") await ctx.send(url) # sends wiki page database.zadd("streak:global", {str(ctx.author.id): 0}) else: await ctx.send("You need to ask for a bird first!")
def skip_bird(): logger.info("endpoint: skip bird") session_id = get_session_id() user_id = int(database.hget(f"web.session:{session_id}", "user_id")) currentBird = database.hget(f"web.session:{session_id}", "bird").decode("utf-8") if currentBird != "": # check if there is bird database.hset(f"web.session:{session_id}", "bird", "") database.hset(f"web.session:{session_id}", "answered", "1") if user_id != 0: streak_increment(user_id, None) # reset streak scibird = asyncio.run(get_sciname(currentBird)) url = get_wiki_url(currentBird) # sends wiki page else: logger.info("bird is blank") flask.abort(406, "Bird is blank") return {"answer": currentBird, "sciname": scibird, "wiki": url}
async def skip(self, ctx): logger.info("command: skip") await channel_setup(ctx) await user_setup(ctx) currentBird = str(database.hget(f"channel:{ctx.channel.id}", "bird"))[2:-1] database.hset(f"channel:{ctx.channel.id}", "bird", "") database.hset(f"channel:{ctx.channel.id}", "answered", "1") if currentBird != "": # check if there is bird url = get_wiki_url(currentBird) await ctx.send(f"Ok, skipping {currentBird.lower()}") await ctx.send( url if not database.exists(f"race.data:{ctx.channel.id}") else f"<{url}>") # sends wiki page database.zadd("streak:global", {str(ctx.author.id): 0}) # end streak if database.exists( f"race.data:{ctx.channel.id}") and database.hget( f"race.data:{ctx.channel.id}", "media").decode("utf-8") == "image": limit = int( database.hget(f"race.data:{ctx.channel.id}", "limit")) first = database.zrevrange(f"race.scores:{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, taxon = database.hmget( f"race.data:{ctx.channel.id}", ["addon", "bw", "taxon"]) birds = self.bot.get_cog("Birds") await birds.send_bird_(ctx, addon.decode("utf-8"), bw.decode("utf-8"), taxon.decode("utf-8")) else: await ctx.send("You need to ask for a bird first!")
async def skip_bird(request: Request): logger.info("endpoint: skip bird") session_id = get_session_id(request) user_id = int(database.hget(f"web.session:{session_id}", "user_id")) database.zincrby(f"daily.web:{date()}", 1, "skip") currentBird = database.hget(f"web.session:{session_id}", "bird").decode("utf-8") if currentBird != "": # check if there is bird database.hset(f"web.session:{session_id}", "bird", "") database.hset(f"web.session:{session_id}", "answered", "1") if user_id != 0: streak_increment(user_id, None) # reset streak scibird = await get_sciname(currentBird) url = get_wiki_url(currentBird) # sends wiki page else: logger.info("bird is blank") raise HTTPException(status_code=404, detail="Bird is blank") return {"answer": currentBird, "sciname": scibird, "wiki": url}
async def check(self, ctx, *, arg): logger.info("command: check") await channel_setup(ctx) await user_setup(ctx) currentBird = database.hget(f"channel:{ctx.channel.id}", "bird").decode("utf-8") 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) or spellcheck(arg, sciBird): logger.info("correct") database.hset(f"channel:{ctx.channel.id}", "bird", "") database.hset(f"channel:{ctx.channel.id}", "answered", "1") if database.exists(f"session.data:{ctx.author.id}"): logger.info("session active") session_increment(ctx, "correct", 1) database.zincrby("streak:global", 1, str(ctx.author.id)) # 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:{ctx.channel.id}") else f"**{ctx.author.mention}**, you are correct!") url = get_wiki_url(currentBird) await ctx.send(url if not database.exists( f"race.data:{ctx.channel.id}") else f"<{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 = f"bot/media/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:{ctx.channel.id}") and str( database.hget(f"race.data:{ctx.channel.id}", "media"))[2:-1] == "image": limit = int( database.hget(f"race.data:{ctx.channel.id}", "limit")) first = database.zrevrange(f"race.scores:{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, taxon = database.hmget( f"race.data:{ctx.channel.id}", ["addon", "bw", "taxon"]) birds = self.bot.get_cog("Birds") await birds.send_bird_(ctx, addon.decode("utf-8"), bw.decode("utf-8"), taxon.decode("utf-8")) 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) if database.exists(f"race.data:{ctx.channel.id}"): await ctx.send("Sorry, that wasn't the right answer.") else: database.hset(f"channel:{ctx.channel.id}", "bird", "") database.hset(f"channel:{ctx.channel.id}", "answered", "1") await ctx.send("Sorry, the bird was actually " + currentBird.lower() + ".") url = get_wiki_url(currentBird) await ctx.send(url)
async def checkgoat(self, ctx, *, arg): logger.info("command: checkgoat") await channel_setup(ctx) await user_setup(ctx) currentBird = database.hget(f"channel:{ctx.channel.id}", "goatsucker").decode("utf-8") 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:{ctx.channel.id}", "gsAnswered", "1") database.hset(f"channel:{ctx.channel.id}", "goatsucker", "") if spellcheck(arg, currentBird) or spellcheck(arg, sciBird): logger.info("correct") if database.exists(f"session.data:{ctx.author.id}"): logger.info("session active") session_increment(ctx, "correct", 1) # increment streak and update max 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)) }) await ctx.send("Correct! Good job!") url = get_wiki_url(currentBird) await ctx.send(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 = f"bot/media/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() + ".") url = get_wiki_url(currentBird) await ctx.send(url) logger.info("currentBird: " + str(currentBird.lower().replace("-", " "))) logger.info("args: " + str(arg.lower().replace("-", " ")))
async def check(self, ctx, *, arg): logger.info("command: check") currentBird = database.hget(f"channel:{ctx.channel.id}", "bird").decode("utf-8") if currentBird == "": # no bird await ctx.send("You must ask for a bird first!") return # if there is a bird, it checks answer sciBird = (await get_sciname(currentBird)).lower().replace("-", " ") arg = arg.lower().replace("-", " ") currentBird = currentBird.lower().replace("-", " ") alpha_code = alpha_codes.get(string.capwords(currentBird)) logger.info("currentBird: " + currentBird) logger.info("arg: " + arg) bird_setup(ctx, currentBird) race_in_session = bool(database.exists(f"race.data:{ctx.channel.id}")) if race_in_session: logger.info("race in session") if database.hget(f"race.data:{ctx.channel.id}", "strict"): logger.info("strict spelling") correct = arg in (currentBird, sciBird) else: logger.info("spelling leniency") correct = spellcheck(arg, currentBird) or spellcheck( arg, sciBird) if not correct and database.hget(f"race.data:{ctx.channel.id}", "alpha"): logger.info("checking alpha codes") correct = arg.upper() == alpha_code else: logger.info("no race") if database.hget(f"session.data:{ctx.author.id}", "strict"): logger.info("strict spelling") correct = arg in (currentBird, sciBird) else: logger.info("spelling leniency") correct = (spellcheck(arg, currentBird) or spellcheck(arg, sciBird) or arg.upper() == alpha_code) if correct: logger.info("correct") database.hset(f"channel:{ctx.channel.id}", "bird", "") database.hset(f"channel:{ctx.channel.id}", "answered", "1") session_increment(ctx, "correct", 1) streak_increment(ctx, 1) database.zincrby(f"correct.user:{ctx.author.id}", 1, string.capwords(str(currentBird))) if (race_in_session and Filter.from_int( int(database.hget(f"race.data:{ctx.channel.id}", "filter"))).vc): await voice_functions.stop(ctx, silent=True) await ctx.send( f"Correct! Good job! The bird was **{currentBird}**." if not race_in_session else f"**{ctx.author.mention}**, you are correct! The bird was **{currentBird}**." ) url = get_wiki_url(ctx, currentBird) await ctx.send(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 = f"bot/media/achievements/{number}.PNG" with open(filename, "rb") as img: await ctx.send(file=discord.File(img, filename="award.png") ) if race_in_session: media = database.hget(f"race.data:{ctx.channel.id}", "media").decode("utf-8") limit = int( database.hget(f"race.data:{ctx.channel.id}", "limit")) first = database.zrevrange(f"race.scores:{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(f"auto sending next bird {media}") filter_int, taxon, state = database.hmget( f"race.data:{ctx.channel.id}", ["filter", "taxon", "state"]) birds = self.bot.get_cog("Birds") await birds.send_bird_( ctx, media, Filter.from_int(int(filter_int)), taxon.decode("utf-8"), state.decode("utf-8"), ) else: logger.info("incorrect") streak_increment(ctx, None) # reset streak session_increment(ctx, "incorrect", 1) incorrect_increment(ctx, str(currentBird), 1) if race_in_session: await ctx.send("Sorry, that wasn't the right answer.") else: database.hset(f"channel:{ctx.channel.id}", "bird", "") database.hset(f"channel:{ctx.channel.id}", "answered", "1") await ctx.send("Sorry, the bird was actually **" + currentBird + "**.") url = get_wiki_url(ctx, currentBird) await ctx.send(url)
async def check_bird(request: Request, guess: str): logger.info("endpoint: check bird") session_id = get_session_id(request) user_id = int(database.hget(f"web.session:{session_id}", "user_id")) currentBird = database.hget(f"web.session:{session_id}", "bird").decode("utf-8") if currentBird == "": # no bird logger.info("bird is blank") raise HTTPException(status_code=404, detail="Bird is blank") if guess == "": logger.info("empty guess") raise HTTPException(status_code=422, detail="empty guess") # if there is a bird, it checks answer sciBird = (await get_sciname(currentBird)).lower().replace("-", " ") guess = guess.lower().replace("-", " ") currentBird = currentBird.lower().replace("-", " ") alpha_code = alpha_codes.get(string.capwords(currentBird), "") logger.info("currentBird: " + currentBird) logger.info("args: " + guess) database.zincrby(f"daily.web:{date()}", 1, "check") if user_id != 0: bird_setup(user_id, currentBird) accepted_answers = [currentBird, sciBird] if currentBird == "screech owl": accepted_answers += screech_owls accepted_answers += sci_screech_owls if (better_spellcheck(guess, accepted_answers, birdListMaster + sciListMaster) or guess.upper() == alpha_code): logger.info("correct") database.hset(f"web.session:{session_id}", "bird", "") database.hset(f"web.session:{session_id}", "answered", "1") tempScore = int(database.hget(f"web.session:{session_id}", "tempScore")) if user_id != 0: database.zincrby(f"daily.webscore:{date()}", 1, user_id) score_increment(user_id, 1) streak_increment(user_id, 1) # elif tempScore >= 10: # logger.info("trial maxed") # raise HTTPException(status_code=403, detail="Sign in to continue") else: database.hset(f"web.session:{session_id}", "tempScore", str(tempScore + 1)) url = get_wiki_url(currentBird) return { "guess": guess, "answer": currentBird, "sciname": sciBird, "status": "correct", "wiki": url, } logger.info("incorrect") database.hset(f"web.session:{session_id}", "bird", "") database.hset(f"web.session:{session_id}", "answered", "1") database.zincrby("incorrect:global", 1, currentBird) if user_id != 0: incorrect_increment(user_id, currentBird, 1) streak_increment(user_id, None) # reset streak url = get_wiki_url(currentBird) return { "guess": guess, "answer": currentBird, "sciname": sciBird, "status": "incorrect", "wiki": url, }
def check_bird(): logger.info("endpoint: check bird") bird_guess = flask.request.args.get("guess", "", str) session_id = get_session_id() user_id = int(database.hget(f"web.session:{session_id}", "user_id")) currentBird = database.hget(f"web.session:{session_id}", "bird").decode("utf-8") if currentBird == "": # no bird logger.info("bird is blank") flask.abort(406, "Bird is blank") elif bird_guess == "": logger.info("empty guess") flask.abort(406, "Empty guess") # if there is a bird, it checks answer logger.info("currentBird: " + str(currentBird.lower().replace("-", " "))) logger.info("args: " + str(bird_guess.lower().replace("-", " "))) sciBird = asyncio.run(get_sciname(currentBird)) if spellcheck(bird_guess, currentBird) or spellcheck(bird_guess, sciBird): logger.info("correct") database.hset(f"web.session:{session_id}", "bird", "") database.hset(f"web.session:{session_id}", "answered", "1") tempScore = int(database.hget(f"web.session:{session_id}", "tempScore")) if user_id != 0: bird_setup(user_id, currentBird) score_increment(user_id, 1) session_increment(user_id, "correct", 1) streak_increment(user_id, 1) elif tempScore >= 10: logger.info("trial maxed") flask.abort(403, "Sign in to continue") else: database.hset(f"web.session:{session_id}", "tempScore", str(tempScore + 1)) url = get_wiki_url(currentBird) return { "guess": bird_guess, "answer": currentBird, "sciname": sciBird, "status": "correct", "wiki": url, } logger.info("incorrect") database.hset(f"web.session:{session_id}", "bird", "") database.hset(f"web.session:{session_id}", "answered", "1") database.zincrby("incorrect:global", 1, currentBird) if user_id != 0: bird_setup(user_id, currentBird) incorrect_increment(user_id, currentBird, 1) session_increment(user_id, "incorrect", 1) streak_increment(user_id, None) # reset streak url = get_wiki_url(currentBird) return { "guess": bird_guess, "answer": currentBird, "sciname": sciBird, "status": "incorrect", "wiki": url, }
async def drone_attack(ctx): logger.info(f"holiday check: invoked command: {str(ctx.command)}") if str(ctx.command) in ("help", "covid", "botinfo", "invite", "list", "meme", "taxon", "wikipedia", "remove", "set", "give_role", "remove_role", "test", "error", "ban", "unban", "send_as_bot"): logger.info("Passthrough Command") return True elif str(ctx.command) in ("bird", "song", "goatsucker"): images = os.listdir("bot/media/images/drone") path = f"bot/media/images/drone/{images[random.randint(0,len(images)-1)]}" BASE_MESSAGE = ( "*Here you go!* \n**Use `b!{new_cmd}` again to get a new {media} of the same bird, " + "or `b!{skip_cmd}` to get a new bird. Use `b!{check_cmd} guess` to check your answer. " + "Use `b!{hint_cmd}` for a hint.**") if str(ctx.command) == "bird": await ctx.send( BASE_MESSAGE.format(media="image", new_cmd="bird", skip_cmd="skip", check_cmd="check", hint_cmd="hint") + "\n*This is an image.*") elif str(ctx.command) == "goatsucker": await ctx.send( BASE_MESSAGE.format(media="image", new_cmd="gs", skip_cmd="skipgoat", check_cmd="checkgoat", hint_cmd="hintgoat")) elif str(ctx.command) == "bird": await ctx.send( BASE_MESSAGE.format(media="song", new_cmd="song", skip_cmd="skipsong", check_cmd="checksong", hint_cmd="hintsong")) file_obj = discord.File(path, filename=f"bird.{path.split('.')[-1]}") await ctx.send(file=file_obj) elif str(ctx.command) in ("check", "checkgoat", "checksong"): args = ctx.message.content.split(" ")[1:] matches = difflib.get_close_matches(" ".join(args), birdListMaster + sciBirdListMaster, n=1) if "drone" in args: await ctx.send( "SHHHHHH! Birds are **NOT** government drones! You'll blow our cover, and we'll need to get rid of you." ) elif matches: await ctx.send("Correct! Good job!") url = get_wiki_url(matches[0]) await ctx.send(url) else: await ctx.send( "Sorry, the bird was actually **definitely a real bird.**") await ctx.send( ("https://en.wikipedia.org/wiki/Bird" if random.randint(0, 1) == 0 else "https://youtu.be/Fg_JcKSHUtQ")) elif str(ctx.command) in ("skip", "skipgoat", "skipsong"): await ctx.send("Ok, skipping **definitely a real bird.**") await ctx.send(("https://en.wikipedia.org/wiki/Bird" if random.randint( 0, 1) == 0 else "https://youtu.be/Fg_JcKSHUtQ")) elif str(ctx.command) in ("hint", "hintgoat", "hintsong"): await ctx.send( "This is definitely a real bird, **NOT** a government drone.") elif str(ctx.command) in ("info"): await ctx.send( "Birds are real. Don't believe what others may say. **BIRDS ARE VERY REAL!**" ) elif str(ctx.command) in ("race", "session"): await ctx.send( "Races and sessions have been disabled today. We apologize for any inconvenience." ) elif str(ctx.command) in ("leaderboard", "missed", "score", "streak", "userscore"): embed = discord.Embed(type="rich", colour=discord.Color.blurple(), title=f"**{str(ctx.command).title()}**") embed.set_author(name="Bird ID - An Ornithology Bot") embed.add_field( name=f"**{str(ctx.command).title()}**", value= "User scores and data have been cleared. We apologize for the inconvenience.", inline=False) await ctx.send(embed=embed) raise GenericError(code=666)
def check_bird(): logger.info("endpoint: check bird") bird_guess = request.args.get("guess", "", str) session_id = get_session_id() user_id = int(database.hget(f"web.session:{session_id}", "user_id")) currentBird = database.hget(f"web.session:{session_id}", "bird").decode("utf-8") if currentBird == "": # no bird logger.info("bird is blank") abort(406, "Bird is blank") elif bird_guess == "": logger.info("empty guess") abort(406, "Empty guess") else: # if there is a bird, it checks answer logger.info("currentBird: " + str(currentBird.lower().replace("-", " "))) logger.info("args: " + str(bird_guess.lower().replace("-", " "))) bird_setup(user_id, currentBird) sciBird = asyncio.run(get_sciname(currentBird)) if spellcheck(bird_guess, currentBird) or spellcheck( bird_guess, sciBird): logger.info("correct") database.hset(f"web.session:{session_id}", "bird", "") database.hset(f"web.session:{session_id}", "answered", "1") tempScore = int( database.hget(f"web.session:{session_id}", "tempScore")) if user_id != 0: database.zincrby("users:global", 1, str(user_id)) database.zincrby("streak:global", 1, str(user_id)) # check if streak is greater than max, if so, increases max if database.zscore("streak:global", str(user_id)) > database.zscore( "streak.max:global", str(user_id)): database.zadd( "streak.max:global", { str(user_id): database.zscore("streak:global", str(user_id)) }) elif tempScore >= 10: logger.info("trial maxed") abort(403, "Sign in to continue") else: database.hset(f"web.session:{session_id}", "tempScore", str(tempScore + 1)) url = get_wiki_url(currentBird) return { "guess": bird_guess, "answer": currentBird, "sciname": sciBird, "status": "correct", "wiki": url } else: logger.info("incorrect") database.hset(f"web.session:{session_id}", "bird", "") database.hset(f"web.session:{session_id}", "answered", "1") database.zincrby("incorrect:global", 1, currentBird) if user_id != 0: database.zadd("streak:global", {str(user_id): 0}) database.zincrby(f"incorrect.user:{user_id}", 1, currentBird) url = get_wiki_url(currentBird) return { "guess": bird_guess, "answer": currentBird, "sciname": sciBird, "status": "incorrect", "wiki": url }