예제 #1
0
    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)
예제 #2
0
    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("-", " ")))
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
    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("-", " ")))
예제 #7
0
    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)