<commit_before>from discord.ext import commands

from pony import orm


class Facts:
    Fact = None

    def __init__(self, bot: commands.Bot):
        super().__init__()
        class Fact(bot.db.Entity):
            id = orm.PrimaryKey(int, auto=True)
            text = orm.Required(str)
            author = orm.Required(str)
        self.Fact = Fact

    @commands.group(name="fact")
    async def root(self, ctx: commands.Context):
        if ctx.invoked_subcommand is None:
            if ctx.subcommand_passed is None:
                with orm.db_session:
                    f = self.Fact.select_random(1)
                    if len(f) == 0:
                        await ctx.send(content="We don't have any velvet facts :(")
                    else:
                        await ctx.send(content="'{}' ~{}".format(f[0].text, f[0].author))

    @root.command()
    async def add(self, ctx: commands.Context, *args):
        f = await commands.clean_content().convert(ctx, " ".join(args))
        with orm.db_session:
            self.Fact(text=f, author=str(ctx.author.mention))
        await ctx.send(content="Adding fact to database.")<commit_msg>Never double output same fact<commit_after>from discord.ext import commands

from pony import orm


class Facts:
    Fact = None

    def __init__(self, bot: commands.Bot):
        super().__init__()
        class Fact(bot.db.Entity):
            id = orm.PrimaryKey(int, auto=True)
            text = orm.Required(str)
            author = orm.Required(str)
        self.Fact = Fact
        self.last_fact = 0

    @commands.group(name="fact")
    async def root(self, ctx: commands.Context):
        if ctx.invoked_subcommand is None:
            if ctx.subcommand_passed is None:
                with orm.db_session:
                    f = self.Fact.select_random(1)
                    if len(f) == 0:
                        await ctx.send(content="We don't have any velvet facts :(")
                    else:
                        while f[0].id == self.last_fact:
                            f = self.Fact.select_random(1)
                        self.last_fact = f[0].id
                        await ctx.send(content="'{}' ~{}".format(f[0].text, f[0].author))

    @root.command()
    async def add(self, ctx: commands.Context, *args):
        f = await commands.clean_content().convert(ctx, " ".join(args))
        with orm.db_session:
            self.Fact(text=f, author=str(ctx.author.mention))
        await ctx.send(content="Adding fact to database.")
{'fraction_non_alphanumeric': 0.12134387351778655, 'fraction_numerical': 0.0047430830039525695, 'mean_word_length': 1.8342665173572228, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6559467', 'n_tokens_mistral': 772, 'n_tokens_neox': 730, 'n_words': 174}