Ejemplo n.º 1
0
 async def penalty(self, ctx, *, arg=None):
     dice = diceroller.DiceRolls(arg if arg else self.settings.dice_default,
                                 repeat=2,
                                 keep=1)
     embed = self.__roll_with_format__(
         ctx=ctx, rolls=dice, additional_comment=" - with penalty.")
     await ctx.send(embed=embed)
Ejemplo n.º 2
0
 async def test(self, ctx, *, arg=None):
     dice = diceroller.DiceRolls(arg if arg else self.settings.dice_default,
                                 repeat=1,
                                 keep=0)
     dice.override_sumtotal(int(arg))
     embed = self.__roll_with_format__(
         ctx=ctx, rolls=dice, additional_comment=" - testing only.")
     embed = self.__successlevel_image__(embed, dice.getroll())
     await ctx.send(embed=embed)
Ejemplo n.º 3
0
    async def improve(self, ctx, *, arg=None):
        description = ""
        stats = arg.split(" ")
        roll = self.settings.dice_improve
        for stat in stats:
            if mathtools.RepresentsInt(stat):
                dice = diceroller.DiceRolls(stat)  # roll against the stat
                if dice.getroll().get_sumtotal() >= int(
                        stat):  # if the total roll is greater than the stat
                    stat_improve_roll = diceroller.DiceRolls(roll)
                    stat_improvement = stat_improve_roll.getroll(
                    ).get_sumtotal() + int(stat)
                    description += f"\nStat with {int(stat)} is now {stat_improvement} (1D100={dice.getroll().get_sumtotal()}, {roll}={stat_improve_roll.getroll().get_sumtotal()})"
                else:
                    description += f"\nStat with {int(stat)} is not improving (1D100={dice.getroll().get_sumtotal()})"

        if description == "":
            description = "No stats improved. Sorry!"

        embed = discord.Embed(colour=discord.Colour(0x24ed60),
                              description=description)
        embed.set_author(name=ctx.author.display_name,
                         icon_url=ctx.author.default_avatar_url)
        await ctx.send(embed=embed)
Ejemplo n.º 4
0
    async def rollcommand(self, ctx, *, arg=None):

        # rolls the dice and stores the result as a list. if no argument, roll the default
        dice = diceroller.DiceRolls(arg if arg else self.settings.dice_default)
        embed = self.__roll_with_format__(ctx=ctx, rolls=dice)

        # ADD TO DB: putting all results in the database.  It skips when there's nothing, including failures and syntax errors!
        for roll in dice.getrolls():

            # if ^test is present in the comment, the roll will not be store in the db (for testing purposes)
            if dice.getroll().get_comment(
            ) is not None and "^test" in dice.getroll().get_comment():
                print("Roll NOT added to Database!")
            elif self.settings.database_enabled:
                self.db.add_roll(str(ctx.author), ctx.author.display_name, arg,
                                 roll.get_equation(), roll.get_sumtotal(),
                                 roll.get_stat(), roll.get_success(),
                                 roll.get_comment(), str(ctx.guild),
                                 str(ctx.channel))
                print("{} {} {} {} {} {} {} {} {} {}".format(
                    ctx.guild, ctx.channel, ctx.author,
                    ctx.author.display_name, arg, roll.get_equation(),
                    roll.get_sumtotal(), roll.get_stat(), roll.get_success(),
                    roll.get_comment()))

        # embed a GIF or image for these special situations
        embed = self.__successlevel_image__(embed, dice.getroll())

        # read the results if announce is on and the bot is in a channel
        self.__announce_roll__(ctx, dice)

        # dramatic pause for fumbles and criticals
        await asyncio.sleep(4) if dice.getroll().get_success(
        ) == "fumble" or dice.getroll().get_success() == "critical" else None

        author_avatar_url = ctx.author.avatar_url or ctx.author.default_avatar_url
        embed.set_author(name=ctx.author.display_name,
                         icon_url=author_avatar_url)
        await ctx.send(embed=embed)
            else:
                output.append("**{}:** {} {}".format(roll.get_nick(),
                                                     roll.get_sumtotal(),
                                                     comment))

        return output


if __name__ == '__main__':

    db = Database('dicebot.db')
    db.initialize_db()

    #db = Database('postgres')

    result = diceroller.DiceRolls("45")
    print(result)

    date_in = datetime(2020, 10, 6, 23, 55, 59)
    date_out = datetime(2021, 10, 9, 23, 55, 59)
    rolls = db.get_as_rolls(date_in,
                            date_out,
                            3,
                            requested_guild="Not Art",
                            requested_user="******")
    # strings = db.get_entries_as_string(date_in, date_out, 3, requested_guild="Not Art", requested_user="******")

    # for string in strings:
    #     print (string)
    # for roll in rolls:
    #     print (roll.get_timestamp_pretty() + ": " + roll.get_user() + " // " + roll.get_argument() + " // " + roll.get_guild())