Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Craiyon API Image generator PR #156

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
41 changes: 41 additions & 0 deletions bot/commands/fun/gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import base64
import time
from io import BytesIO

from craiyon import Craiyon

from bot.base import Command
from bot.commands.utility.__blocked_prompts import blocked
from bot.config import Config, Embed


class cmd(Command):
"""A discord command instance."""

#
name = "gen"
usage = "gen <*prompt>"
description = "Uses the Craiyon AI API to generate an image with a given prompt"

async def execute(self, arguments, message) -> None:
prompt = arguments[0]
for word in prompt.split():
if word.lower() in blocked:
await message.channel.send(
"I'm not generating that you meanie >:( It's NSFW! Try something else!"
)
return

loadingE = Embed(
title=f"Image '{prompt}' currently generating, please wait a moment!"
)
loadingM = await message.channel.send(embed=loadingE)

generator = Craiyon()
result = generator.generate(prompt)
images = result.images
embed = Embed(title="Here is the generated image")
embed.set_image(url=images[0])

await loadingM.delete()
await message.channel.send(embed=embed)
24 changes: 24 additions & 0 deletions bot/commands/utility/__blocked_prompts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
blocked = [
"nsfw",
"pussy",
"gore",
"murder",
"penis",
"cat",
"emacs",
"porn",
"vagina",
"dick",
"sex",
"intercourse",
"bondage",
"bdsm",
"fetish",
"kink",
"pegging",
"peg",
"anal",
"vaginal",
"erotic",
"notepad",
]
192 changes: 190 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ aiohttp = "^3.8.3"
colorthief = "0.2.1"
orjson = "^3.8.5"
aiomysql = "^0.1.1"
craiyon-py = "^0.3.0"

[tool.poetry.group.dev.dependencies]
black = "^22.12.0"
Expand Down
10 changes: 10 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
aiofile==3.8.5 ; python_version >= "3.10" and python_version < "4"
aiofiles==23.1.0 ; python_version >= "3.10" and python_version < "4.0"
aiohttp==3.8.3 ; python_version >= "3.10" and python_version < "4.0"
aiomysql==0.1.1 ; python_version >= "3.10" and python_version < "4.0"
aiopath==0.6.11 ; python_version >= "3.10" and python_version < "4.0"
aiosignal==1.3.1 ; python_version >= "3.10" and python_version < "4.0"
aiosqlite==0.18.0 ; python_version >= "3.10" and python_version < "4.0"
anyio==3.6.2 ; python_version >= "3.10" and python_version < "4.0"
async-timeout==4.0.2 ; python_version >= "3.10" and python_version < "4.0"
attrs==22.2.0 ; python_version >= "3.10" and python_version < "4.0"
caio==0.9.12 ; python_version >= "3.10" and python_version < "4"
certifi==2022.12.7 ; python_version >= "3.10" and python_version < "4"
charset-normalizer==2.1.1 ; python_version >= "3.10" and python_version < "4.0"
colorthief==0.2.1 ; python_version >= "3.10" and python_version < "4.0"
craiyon-py==0.3.0 ; python_version >= "3.10" and python_version < "4.0"
discord-py==2.1.0 ; python_version >= "3.10" and python_version < "4.0"
frozenlist==1.3.3 ; python_version >= "3.10" and python_version < "4.0"
idna==3.4 ; python_version >= "3.10" and python_version < "4.0"
Expand All @@ -17,5 +24,8 @@ pillow==9.4.0 ; python_version >= "3.10" and python_version < "4.0"
pygments==2.14.0 ; python_version >= "3.10" and python_version < "4.0"
pymysql==1.0.2 ; python_version >= "3.10" and python_version < "4.0"
python-dotenv==0.21.0 ; python_version >= "3.10" and python_version < "4.0"
requests==2.28.2 ; python_version >= "3.10" and python_version < "4"
rich==13.3.1 ; python_version >= "3.10" and python_version < "4.0"
sniffio==1.3.0 ; python_version >= "3.10" and python_version < "4.0"
urllib3==1.26.15 ; python_version >= "3.10" and python_version < "4"
yarl==1.8.2 ; python_version >= "3.10" and python_version < "4.0"