From de8f12a4b0c4e4314ff29a03888f5236d56b9916 Mon Sep 17 00:00:00 2001 From: tmddn3070 Date: Tue, 5 Dec 2023 22:30:58 +0900 Subject: [PATCH] Update dependencies and add KoreanBots integration --- Christmas/Cogs/Commands_Aiart.py | 4 +-- Christmas/Cogs/Commands_Arcade.py | 53 ------------------------------- Christmas/Cogs/Event.py | 21 ++++++++---- Christmas/Module.py | 12 +++---- Christmas/UI/Modal.py | 3 +- Christmas/__main__.py | 5 ++- Christmas/config.py | 4 ++- Dockerfile | 31 ++++++------------ Scheduler.py | 0 requirement.txt | 5 ++- 10 files changed, 44 insertions(+), 94 deletions(-) delete mode 100644 Christmas/Cogs/Commands_Arcade.py delete mode 100644 Scheduler.py diff --git a/Christmas/Cogs/Commands_Aiart.py b/Christmas/Cogs/Commands_Aiart.py index 45e5f51..40bc712 100644 --- a/Christmas/Cogs/Commands_Aiart.py +++ b/Christmas/Cogs/Commands_Aiart.py @@ -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)) \ No newline at end of file diff --git a/Christmas/Cogs/Commands_Arcade.py b/Christmas/Cogs/Commands_Arcade.py deleted file mode 100644 index af2ebc1..0000000 --- a/Christmas/Cogs/Commands_Arcade.py +++ /dev/null @@ -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)) \ No newline at end of file diff --git a/Christmas/Cogs/Event.py b/Christmas/Cogs/Event.py index 3c16504..35e9f25 100644 --- a/Christmas/Cogs/Event.py +++ b/Christmas/Cogs/Event.py @@ -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)) \ No newline at end of file diff --git a/Christmas/Module.py b/Christmas/Module.py index 3b460dd..15c6290 100644 --- a/Christmas/Module.py +++ b/Christmas/Module.py @@ -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"" + #if add_prompt == True: + prompt = prompt + f"" 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 \ No newline at end of file diff --git a/Christmas/UI/Modal.py b/Christmas/UI/Modal.py index 9e321fd..efc6d53 100644 --- a/Christmas/UI/Modal.py +++ b/Christmas/UI/Modal.py @@ -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: diff --git a/Christmas/__main__.py b/Christmas/__main__.py index 3731c6a..0f27e5b 100644 --- a/Christmas/__main__.py +++ b/Christmas/__main__.py @@ -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() \ No newline at end of file diff --git a/Christmas/config.py b/Christmas/config.py index 70b1d7b..d2eef0d 100644 --- a/Christmas/config.py +++ b/Christmas/config.py @@ -53,4 +53,6 @@ class ChristmasConfig: def SEARCH_ENGINE(self): return self.json["SEARCH_ENGINE"] - \ No newline at end of file + @property + def KOREANBOT_TOKEN(self): + return self.json["KOREANBOT_TOKEN"] \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8b16b9d..99b731e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] - - diff --git a/Scheduler.py b/Scheduler.py deleted file mode 100644 index e69de29..0000000 diff --git a/requirement.txt b/requirement.txt index 4cd321a..d02152e 100644 --- a/requirement.txt +++ b/requirement.txt @@ -7,4 +7,7 @@ pendulum Wavelink onnxruntime psutil -meilisearch_python_sdk \ No newline at end of file +meilisearch_python_sdk +Pillow +aiogoogletrans +koreanbots \ No newline at end of file