Kilvoctu / aiyabot

A neat Discord bot for AUTOMATIC1111's Web UI
GNU General Public License v2.0
305 stars 79 forks source link

Implement spoiler functionality #245

Closed FoxxMD closed 4 months ago

FoxxMD commented 4 months ago

I wasn't originally planning to do this but a user in my server forced my hand after generating some truly heinous images. :smiling_face_with_tear:

Closes #168


In /settings it shows formatted role name when present

image

Can use remove_spoiler_role boolean in settings to entirely remove role in which case it displays spoiler_role - None

image

The spoiler option in /settings is a default for the channel that can be overridden using the spoiler option in the /draw command

image

Finally, the entire channel can be forced to use spoilers if the spoiler_role is set to @everyone

image

sebaxakerhtc commented 4 months ago

It's a really nice PR! Copied it to my repo, thank you!

@FoxxMD There's a PR about Live preview Can you help with Live preview too?

Because if it will be merged - we will need to anyhow hide it.

I try but something wrong here

        with contextlib.ExitStack() as stack:
            buffer = stack.enter_context(io.BytesIO())
            image.save(buffer, 'PNG')
            buffer.seek(0)
            file = discord.File(fp=buffer, filename=f'{queue_object.seed}.png')

How to add your part right way?

            if queue_object.spoiler:
                filename=f'SPOILER_{queue_object.seed}.png'

I tried this way

        with contextlib.ExitStack() as stack:
            buffer = stack.enter_context(io.BytesIO())
            image.save(buffer, 'PNG')
            buffer.seek(0)
            filename=f'{queue_object.seed}.png'
            if queue_object.spoiler:
                filename=f'SPOILER_{queue_object.seed}.png'
            file = discord.File(fp=buffer, filename)

But it gives me SyntaxError: positional argument follows keyword argument

Upd. Solved this way:

        with contextlib.ExitStack() as stack:
            buffer = stack.enter_context(io.BytesIO())
            image.save(buffer, 'PNG')
            buffer.seek(0)
            filename=f'{queue_object.seed}.png'
            if queue_object.spoiler:
                filename=f'SPOILER_{queue_object.seed}.png'
            fp=buffer
            file = discord.File(fp, filename)

Working like a charm!

Kilvoctu commented 4 months ago

Heya, looks nice. Thanks for the PR 👍