Beispiel #1
0
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))
Beispiel #2
0
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")
Beispiel #3
0
def incorrect_increment(ctx, fossil, amount):
    logger.info(f"incrementing incorrect {fossil} by {amount}")
    database.zincrby("incorrect:global", amount, str(fossil))
    database.zincrby(f"incorrect.user:{ctx.author.id}", amount, str(fossil))
    if ctx.guild is not None:
        logger.info("no dm")
        database.zincrby(f"incorrect.server:{ctx.guild.id}", amount,
                         str(fossil))
    else:
        logger.info("dm context")
Beispiel #4
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)
Beispiel #5
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("-", " ")))