Пример #1
0
    async def multi_user_markov(self, ctx: Context, *users: discord.User):
        """Generate a markov chain based off a list of users messages.

        `users`: The list of users who's messages should be used to generate the markov chain.
        """
        users = set(users)  # type: ignore
        if len(users) < 2:
            raise commands.BadArgument(
                'You need to specify at least two users.')

        is_nsfw = ctx.channel.is_nsfw() if ctx.guild is not None else False
        coros = list()

        async with ctx.typing():
            async with ctx.db as conn:
                for user in users:
                    if user == ctx.author:
                        await Opt_In_Status.is_opted_in(ctx, connection=conn)
                    else:
                        await Opt_In_Status.is_public(ctx,
                                                      user,
                                                      connection=conn)

                    coros.append(
                        Message_Log.get_user_log(user,
                                                 is_nsfw,
                                                 connection=conn))

                query = (is_nsfw, 3) + tuple(user.id for user in users)
                model = await self.get_model(query, *coros, order=3)

            await self.send_markov(ctx, model, 3)
Пример #2
0
 def process_command(self, command):
     if command == "start":
         context = Context(repository)
         run_flow(Flow(input_language, context), self._handle, USER_ID)
     elif USER_ID in user_states and command in user_states[USER_ID][
             0].commands:
         _, flow = user_states.pop(USER_ID)
         continue_flow(flow, Results.make_command(command), self._handle,
                       USER_ID)
     else:
         print("unknown command: " + command)
Пример #3
0
    async def code_guild_markov(self, ctx: Context):
        """Generate a markov chain code block.
        """
        async with ctx.typing():
            async with ctx.db as conn:
                is_nsfw = ctx.channel.is_nsfw() if ctx.guild is not None else False
                query = ('cgm', is_nsfw, 2, ctx.guild.id)

                coro = Message_Log.get_guild_log(ctx.guild, is_nsfw, connection=conn)
                model = await self.get_model(query, coro, order=2)

            await self.send_markov(ctx, model, 2, callable=make_code)
Пример #4
0
    async def guild_markov(self, ctx: Context):
        """Generate a markov chain based off messages in the server.
        """
        async with ctx.typing():
            async with ctx.db as conn:
                is_nsfw = ctx.channel.is_nsfw() if ctx.guild is not None else False
                query = ('gm', is_nsfw, 3, ctx.guild.id)

                coro = Message_Log.get_guild_log(ctx.guild, is_nsfw, connection=conn)
                model = await self.get_model(query, coro, order=3)

            await self.send_markov(ctx, model, 3)
Пример #5
0
    async def seeded_guild_markov(self, ctx: Context, *, seed: str):
        """Generate a markov chain based off messages in the server which starts with a given seed.

        `seed`: The string to attempt to seed the markov chain with.
        """
        async with ctx.typing():
            async with ctx.db as conn:
                is_nsfw = ctx.channel.is_nsfw() if ctx.guild is not None else False
                query = ('sgm', is_nsfw, 3, ctx.guild.id)

                coro = Message_Log.get_guild_log(ctx.guild, is_nsfw, False, connection=conn)
                model = await self.get_model(query, coro, order=3)

            await self.send_markov(ctx, model, 3, seed=seed.lower())
Пример #6
0
    async def code_user_markov(self, ctx: Context, user: Optional[discord.User] = None):
        """Generate a markov chain code block.
        """
        user = user or ctx.author

        async with ctx.typing():
            async with ctx.db as conn:
                await Opt_In_Status.is_public(ctx, user, connection=conn)

                is_nsfw = ctx.channel.is_nsfw() if ctx.guild is not None else False
                query = ('cum', is_nsfw, 2, user.id)

                coro = Message_Log.get_user_log(user, is_nsfw, connection=conn)
                model = await self.get_model(query, coro, order=2)

            await self.send_markov(ctx, model, 2, callable=make_code)
Пример #7
0
    async def user_markov(self, ctx: Context, *, user: Optional[discord.User] = None):
        """Generate a markov chain based off a users messages.

        `user`: The user who's messages should be used to generate the markov chain, defaults to you.
        """
        user = user or ctx.author

        async with ctx.typing():
            async with ctx.db as conn:
                await Opt_In_Status.is_public(ctx, user, connection=conn)

                is_nsfw = ctx.channel.is_nsfw() if ctx.guild is not None else False
                query = ('um', is_nsfw, 2, user.id)

                coro = Message_Log.get_user_log(user, is_nsfw, connection=conn)
                model = await self.get_model(query, coro, order=2)

            await self.send_markov(ctx, model, 2)
Пример #8
0
    async def seeded_user_markov(self, ctx: Context, user: Optional[discord.User] = None, *, seed: str):
        """Generate a markov chain based off a users messages which starts with a given seed.

        `user`: The user who's messages should be used to generate the markov chain, defaults to you.
        `seed`: The string to attempt to seed the markov chain with.
        """
        user = user or ctx.author

        async with ctx.typing():
            async with ctx.db as conn:
                await Opt_In_Status.is_public(ctx, user, connection=conn)

                is_nsfw = ctx.channel.is_nsfw() if ctx.guild is not None else False
                query = ('sum', is_nsfw, 2, user.id)

                coro = Message_Log.get_user_log(user, is_nsfw, connection=conn)
                model = await self.get_model(query, coro, order=2)

            await self.send_markov(ctx, model, 2, seed=seed.lower())
Пример #9
0
    async def status_pie(self, ctx: Context, user: Optional[discord.User] = None, show_totals: bool = True):
        """Display a status pie.

        `user`: The user who's status log to look at, defaults to you.
        `show_totals`: Sets whether status percentages should be shown, defaults to True.
        """
        user = user or ctx.author

        async with ctx.typing():
            async with ctx.db as conn:
                await Opt_In_Status.is_public(ctx, user, connection=conn)
                data = await get_status_totals(user, conn, days=30)

                if not data:
                    raise commands.BadArgument(f'User "{user}" currently has no status log data, please try again later.')

            avatar_fp = BytesIO()
            await user.avatar_url_as(format='png', size=IMAGE_SIZE // 2).save(avatar_fp)

            draw_call = partial(draw_status_pie, data, avatar_fp, show_totals=show_totals)
            image = await self.bot.loop.run_in_executor(None, draw_call)

            await ctx.send(file=discord.File(image, f'{user.id}_status_{ctx.message.created_at}.png'))
Пример #10
0
from api import Channel, Results, Flow, Repository, run_flow
from bot import Context, TestRepository, input_language
from console_runner import handle

context = Context(TestRepository())
flow = Flow(input_language, context)
run_flow(flow, handle)
Пример #11
0
def reset(message):
    chat_id = message.chat.id
    context = Context(repository)
    flow = Flow(input_language, context).run()
    _continue_flow(flow, None)