Update dependencies and add KoreanBots integration
This commit is contained in:
parent
fd2336a555
commit
de8f12a4b0
@ -39,7 +39,7 @@ class CAiart(Cog):
|
|||||||
@cooldown(1, 10, BucketType.user)
|
@cooldown(1, 10, BucketType.user)
|
||||||
@guild_only()
|
@guild_only()
|
||||||
async def _분석(self, ctx: Context, file: Option(Attachment, name="파일", description="분석할 그림을 업로드해주세요.", required=True)):
|
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 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)
|
if not file.content_type.startswith("image/"): return await ctx.respond(embed=ChristmasEmbed(title="❌ 에러!", description="그림 파일만 업로드해주세요!", color=Color.red()),ephemeral=True)
|
||||||
buffer = await file.read()
|
buffer = await file.read()
|
||||||
@ -57,7 +57,7 @@ class CAiart(Cog):
|
|||||||
rating = hangul[ratings]
|
rating = hangul[ratings]
|
||||||
sorted_tags = sorted(tags.items(), key=lambda x: x[1], reverse=True)[:8]
|
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
|
# 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):
|
def setup(bot):
|
||||||
bot.add_cog(CAiart(bot))
|
bot.add_cog(CAiart(bot))
|
@ -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))
|
|
@ -9,7 +9,7 @@ from discord.ext.commands import Cog
|
|||||||
from discord.ext import tasks
|
from discord.ext import tasks
|
||||||
|
|
||||||
from discord.ext.commands import CommandOnCooldown
|
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.config import ChristmasConfig
|
||||||
from Christmas.Database import database
|
from Christmas.Database import database
|
||||||
|
|
||||||
@ -53,12 +53,19 @@ class Event(Cog):
|
|||||||
if before.name != after.name:
|
if before.name != after.name:
|
||||||
await database.update_guild_name(after.id, after.name)
|
await database.update_guild_name(after.id, after.name)
|
||||||
|
|
||||||
#@Cog.listener()
|
@tasks.loop(seconds=600)
|
||||||
#async def on_wavelink_track_end(self, payload):
|
async def notify_all_guild_christmas(self) -> None:
|
||||||
|
if pendulum.now() > pendulum.datetime(2023, 12, 24, 12, 0, 0):
|
||||||
#@Cog.listener()
|
self.notify_all_guild_christmas.cancel()
|
||||||
#async def on_wavelink_node_ready(self, node: wavelink.Node):
|
return
|
||||||
# print(f"Node {node.id} is ready!")
|
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):
|
def setup(bot):
|
||||||
bot.add_cog(Event(bot))
|
bot.add_cog(Event(bot))
|
@ -42,8 +42,8 @@ async def process_prompt(prompt: str, remove: str, res: list, isnsfw: bool, styl
|
|||||||
prompt = prompt + "," + "(1boy)"
|
prompt = prompt + "," + "(1boy)"
|
||||||
negative_prompt = negative_prompt + "," + "(1girl)"
|
negative_prompt = negative_prompt + "," + "(1girl)"
|
||||||
add_prompt = random.choice([True, False])
|
add_prompt = random.choice([True, False])
|
||||||
if add_prompt == True:
|
#if add_prompt == True:
|
||||||
qprompt = prompt + f"<lora:canistermix1.1:{random.choice(weight)}>"
|
prompt = prompt + f"<lora:canistermix1.1:{random.choice(weight)}>"
|
||||||
payloads = {
|
payloads = {
|
||||||
"prompt": prompt,
|
"prompt": prompt,
|
||||||
"negative_prompt": negative_prompt,
|
"negative_prompt": negative_prompt,
|
||||||
@ -96,19 +96,16 @@ async def base64_to_image(base642) -> File:
|
|||||||
async def get_gpuserver_status(url) -> Dict:
|
async def get_gpuserver_status(url) -> Dict:
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
try:
|
try:
|
||||||
# latency도 측정
|
async with session.get(f"{url}/sdapi/v1/memory", timeout=10) as response:
|
||||||
|
|
||||||
async with session.get("http://172.30.1.49:7860/sdapi/v1/memory", timeout=10) as response:
|
|
||||||
|
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
# latency 측정
|
|
||||||
#latency = response.headers["X-Response-Time"]
|
|
||||||
result = await response.json()
|
result = await response.json()
|
||||||
memstatus = result["ram"]["used"]
|
memstatus = result["ram"]["used"]
|
||||||
cudamemstatus = result["cuda"]["system"]["used"]
|
cudamemstatus = result["cuda"]["system"]["used"]
|
||||||
oomcount = result["cuda"]["events"]["oom"]
|
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}
|
return {"status": "online", "system_memory_usage": bytes_to_gb(memstatus), "cuda_memory_usage": bytes_to_gb(cudamemstatus), "oom_count": oomcount}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return {"status": "offline"}
|
return {"status": "offline"}
|
||||||
|
|
||||||
def bytes_to_gb(bytes: int) -> float:
|
def bytes_to_gb(bytes: int) -> float:
|
||||||
@ -125,4 +122,5 @@ async def Get_Backend_latency():
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
return None
|
return None
|
@ -84,7 +84,8 @@ class Aiart(Modal):
|
|||||||
await interaction.response.send_message(embed=Aiart_Embed.generating(), ephemeral=self.show)
|
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
|
#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)
|
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:
|
if result["status"] != True:
|
||||||
return await interaction.edit_original_response(embed=Aiart_Embed.failed_generate())
|
return await interaction.edit_original_response(embed=Aiart_Embed.failed_generate())
|
||||||
else:
|
else:
|
||||||
|
@ -5,7 +5,8 @@ from discord import AutoShardedBot, Intents
|
|||||||
from discord.ext import commands, tasks
|
from discord.ext import commands, tasks
|
||||||
|
|
||||||
from Christmas.discord import Christmas, load_cogs, apply_uvloop
|
from Christmas.discord import Christmas, load_cogs, apply_uvloop
|
||||||
|
from Christmas.config import ChristmasConfig
|
||||||
|
from koreanbots.integrations.discord import DiscordpyKoreanbots
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
bot = Christmas(
|
bot = Christmas(
|
||||||
@ -13,6 +14,8 @@ if __name__ == "__main__":
|
|||||||
case_insensitive=True,
|
case_insensitive=True,
|
||||||
intents=Intents.all()
|
intents=Intents.all()
|
||||||
)
|
)
|
||||||
|
config = ChristmasConfig()
|
||||||
|
DiscordpyKoreanbots(bot, config.KOREANBOT_TOKEN, run_task=True)
|
||||||
load_cogs(bot)
|
load_cogs(bot)
|
||||||
apply_uvloop()
|
apply_uvloop()
|
||||||
bot.run()
|
bot.run()
|
@ -53,4 +53,6 @@ class ChristmasConfig:
|
|||||||
def SEARCH_ENGINE(self):
|
def SEARCH_ENGINE(self):
|
||||||
return self.json["SEARCH_ENGINE"]
|
return self.json["SEARCH_ENGINE"]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def KOREANBOT_TOKEN(self):
|
||||||
|
return self.json["KOREANBOT_TOKEN"]
|
31
Dockerfile
31
Dockerfile
@ -1,26 +1,15 @@
|
|||||||
FROM python:3.12-alpine AS Prepare
|
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
FROM python:3.11.5-slim
|
||||||
build-base \
|
|
||||||
libffi-dev \
|
|
||||||
openssl-dev \
|
|
||||||
python3-dev \
|
|
||||||
rust \
|
|
||||||
cargo
|
|
||||||
|
|
||||||
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
|
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"]
|
CMD ["python", "-m", "Christmas"]
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,4 +7,7 @@ pendulum
|
|||||||
Wavelink
|
Wavelink
|
||||||
onnxruntime
|
onnxruntime
|
||||||
psutil
|
psutil
|
||||||
meilisearch_python_sdk
|
meilisearch_python_sdk
|
||||||
|
Pillow
|
||||||
|
aiogoogletrans
|
||||||
|
koreanbots
|
Loading…
Reference in New Issue
Block a user