Update dependencies and add KoreanBots integration

This commit is contained in:
tmddn3070 2023-12-05 22:30:58 +09:00
parent fd2336a555
commit de8f12a4b0
10 changed files with 44 additions and 94 deletions

View File

@ -39,7 +39,7 @@ class CAiart(Cog):
@cooldown(1, 10, BucketType.user)
@guild_only()
async def _분석(self, ctx: Context, file: Option(Attachment, name="파일", description="분석할 그림을 업로드해주세요.", required=True)):
await ctx.defer(ephemeral=True)
await ctx.defer(ephemeral=False)
if not await database.get_guild(ctx.guild.id): return await ctx.respond(embed=ChristmasEmbed(title="❌ 에러!", description="서버가 가입되어있지 않아요! 서버를 가입해주세요!", color=Color.red()),ephemeral=True)
if not file.content_type.startswith("image/"): return await ctx.respond(embed=ChristmasEmbed(title="❌ 에러!", description="그림 파일만 업로드해주세요!", color=Color.red()),ephemeral=True)
buffer = await file.read()
@ -57,7 +57,7 @@ class CAiart(Cog):
rating = hangul[ratings]
sorted_tags = sorted(tags.items(), key=lambda x: x[1], reverse=True)[:8]
# UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
await ctx.respond(embed=Aiart_Embed.evalate(sorted_tags, rating), ephemeral=True, file=File(fp=io.BytesIO(buffer), filename="image.png"))
await ctx.respond(embed=Aiart_Embed.evalate(sorted_tags, rating), ephemeral=False, file=File(fp=io.BytesIO(buffer), filename="image.png"))
def setup(bot):
bot.add_cog(CAiart(bot))

View File

@ -1,53 +0,0 @@
import io
from discord import SlashCommandGroup, Option, Member, Color, File, Attachment
from discord.utils import basic_autocomplete
from discord.ext.commands import Cog, BucketType, cooldown, guild_only, Context, has_permissions
from Christmas.Database import database
from Christmas.UI.Embed import ChristmasEmbed, Arcade_Embed, Default_Embed
from Christmas.UI.Buttons import Arcade_Register_Agree
from Christmas.Cogs.Event import model
from Christmas.UI.AutoComplete import Guild_Autocomplete
class CArcade(Cog):
def __init__(self, bot):
self.bot = bot
#ARCADE = SlashCommandGroup(name="눈싸움", description="눈싸움 관련 명령어")
#
# @cooldown(1, 5, BucketType.user)
# @has_permissions(administrator=True)
# @guild_only()
# @ARCADE.command(name="등록", description="눈싸움 등록")
# async def _등록(self, ctx: Context):
# if not await database.get_guild(ctx.guild.id): return await ctx.respond(embed=ChristmasEmbed(title="❌ 에러!", description="서버가 가입되어있지 않아요! 서버를 가입해주세요!", color=Color.red()),ephemeral=True)
# #if await database.get_arcade(ctx.guild.id): return await ctx.respond(embed=Arcade_Embed.register_already(), ephemeral=True)
# await ctx.respond(embed=Arcade_Embed.register_inital(), view=Arcade_Register_Agree(), ephemeral=True)
#
# @guild_only()
# @cooldown(1, 10, BucketType.user)
# @ARCADE.command(name="정보", description="눈싸움 정보")
# async def _정보(self, ctx: Context):
# if not await database.get_guild(ctx.guild.id): return await ctx.respond(embed=ChristmasEmbed(title="❌ 에러!", description="서버가 가입되어있지 않아요! 서버를 가입해주세요!", color=Color.red()),ephemeral=True)
# if await database.get_arcade(ctx.guild.id): return await ctx.respond(embed=Arcade_Embed.register_already(), ephemeral=True)
# pass
#
# @guild_only()
# @cooldown(1, 10, BucketType.user)
# @ARCADE.command(name="돈벌기", description="눈싸움 돈벌기")
# async def _돈벌기(self, ctx: Context):
# pass
#
# @guild_only()
# @cooldown(1, 10, BucketType.user)
# @ARCADE.command(name="레이드", description="눈싸움 레이드")
# async def _레이드(self, ctx: Context):
# pass
#
### @guild_only()
# @cooldown(1, 10, BucketType.user)
# @ARCADE.command(name="연합요청", description="눈싸움 연합요청")
# async def _연합요청(self, ctx: Context, guild: Option(str, "연합할 서버를 입력해주세요!", autocomplete=basic_autocomplete(Guild_Autocomplete))):
# pass
#
def setup(bot):
bot.add_cog(CArcade(bot))

View File

@ -9,7 +9,7 @@ from discord.ext.commands import Cog
from discord.ext import tasks
from discord.ext.commands import CommandOnCooldown
from Christmas.UI.Embed import Default_Embed
from Christmas.UI.Embed import Default_Embed, Music_Embed
from Christmas.config import ChristmasConfig
from Christmas.Database import database
@ -53,12 +53,19 @@ class Event(Cog):
if before.name != after.name:
await database.update_guild_name(after.id, after.name)
#@Cog.listener()
#async def on_wavelink_track_end(self, payload):
#@Cog.listener()
#async def on_wavelink_node_ready(self, node: wavelink.Node):
# print(f"Node {node.id} is ready!")
@tasks.loop(seconds=600)
async def notify_all_guild_christmas(self) -> None:
if pendulum.now() > pendulum.datetime(2023, 12, 24, 12, 0, 0):
self.notify_all_guild_christmas.cancel()
return
for guild in self.bot.guilds:
if not await database.get_guild(guild.id): continue
if not await database.get_guild_christmas(guild.id):
await database.update_guild_christmas(guild.id, True)
if guild.system_channel is not None:
await guild.system_channel.send(embed=Music_Embed.changed_christmas())
else:
await random.choice(guild.text_channels).send(embed=Music_Embed.changed_christmas())
def setup(bot):
bot.add_cog(Event(bot))

View File

@ -42,8 +42,8 @@ async def process_prompt(prompt: str, remove: str, res: list, isnsfw: bool, styl
prompt = prompt + "," + "(1boy)"
negative_prompt = negative_prompt + "," + "(1girl)"
add_prompt = random.choice([True, False])
if add_prompt == True:
qprompt = prompt + f"<lora:canistermix1.1:{random.choice(weight)}>"
#if add_prompt == True:
prompt = prompt + f"<lora:canistermix1.1:{random.choice(weight)}>"
payloads = {
"prompt": prompt,
"negative_prompt": negative_prompt,
@ -96,19 +96,16 @@ async def base64_to_image(base642) -> File:
async def get_gpuserver_status(url) -> Dict:
async with aiohttp.ClientSession() as session:
try:
# latency도 측정
async with session.get("http://172.30.1.49:7860/sdapi/v1/memory", timeout=10) as response:
async with session.get(f"{url}/sdapi/v1/memory", timeout=10) as response:
if response.status == 200:
# latency 측정
#latency = response.headers["X-Response-Time"]
result = await response.json()
memstatus = result["ram"]["used"]
cudamemstatus = result["cuda"]["system"]["used"]
oomcount = result["cuda"]["events"]["oom"]
return {"status": "online", "system_memory_usage": bytes_to_gb(memstatus), "cuda_memory_usage": bytes_to_gb(cudamemstatus), "oom_count": oomcount}
except Exception as e:
print(e)
return {"status": "offline"}
def bytes_to_gb(bytes: int) -> float:
@ -125,4 +122,5 @@ async def Get_Backend_latency():
else:
return None
except Exception as e:
return None

View File

@ -84,7 +84,8 @@ class Aiart(Modal):
await interaction.response.send_message(embed=Aiart_Embed.generating(), ephemeral=self.show)
#prompt: str, remove: str, res: list, isnsfw: bool, style1: float, style2: float, afterprocess: float
payload = await process_prompt(prompt, remove, self.res, self.allownsfw, self.style1, self.style2, self.afterprocess)
result = await post_gpu_server(f"{ChristmasConfig.AI()}/sdapi/v1/txt2img", payload)
config = ChristmasConfig()
result = await post_gpu_server(f"{config.AI}/sdapi/v1/txt2img", payload)
if result["status"] != True:
return await interaction.edit_original_response(embed=Aiart_Embed.failed_generate())
else:

View File

@ -5,7 +5,8 @@ from discord import AutoShardedBot, Intents
from discord.ext import commands, tasks
from Christmas.discord import Christmas, load_cogs, apply_uvloop
from Christmas.config import ChristmasConfig
from koreanbots.integrations.discord import DiscordpyKoreanbots
if __name__ == "__main__":
bot = Christmas(
@ -13,6 +14,8 @@ if __name__ == "__main__":
case_insensitive=True,
intents=Intents.all()
)
config = ChristmasConfig()
DiscordpyKoreanbots(bot, config.KOREANBOT_TOKEN, run_task=True)
load_cogs(bot)
apply_uvloop()
bot.run()

View File

@ -53,4 +53,6 @@ class ChristmasConfig:
def SEARCH_ENGINE(self):
return self.json["SEARCH_ENGINE"]
@property
def KOREANBOT_TOKEN(self):
return self.json["KOREANBOT_TOKEN"]

View File

@ -1,26 +1,15 @@
FROM python:3.12-alpine AS Prepare
RUN apk add --no-cache \
build-base \
libffi-dev \
openssl-dev \
python3-dev \
rust \
cargo
FROM python:3.11.5-slim
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
FROM python:3.12-alpine AS Main
COPY --from=Prepare /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=Prepare /usr/local/bin /usr/local/bin
RUN pip install uvloop
COPY . /app
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
RUN pip uninstall -y discord.py py-cord
RUN pip install --no-cache-dir py-cord[speed] py-cord[voice]
RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
COPY . .
CMD ["python", "-m", "Christmas"]

View File

View File

@ -7,4 +7,7 @@ pendulum
Wavelink
onnxruntime
psutil
meilisearch_python_sdk
meilisearch_python_sdk
Pillow
aiogoogletrans
koreanbots