runabot/Christmas/UI/Embed.py
2023-12-02 15:03:50 +09:00

245 lines
12 KiB
Python

import wavelink
import typing
import psutil
from typing import Any, Optional
from discord import Embed, Colour, Embed, Member
from discord.types.embed import EmbedType
from datetime import datetime
from korcen import korcen
from Christmas.Module import get_gpuserver_status
start_time = datetime.now()
class ChristmasEmbed(Embed):
def __init__(self, *,
color: int | Colour | None = 0xf4f9ff,
title: Any | None = None,
type: EmbedType = "rich",
url: Any | None = None,
description: Any | None = None,
timestamp: datetime | None = None,
):
super().__init__(
color=color,
title=title,
type=type,
url=url,
description=description,
timestamp=timestamp,
)
def set_footer(self, *, text: Any | None = "ν¬λŒμ΄β›„", icon_url: Any | None = "https://discord.com/assets/6dbfff5aae6b1de2b83f.svg") -> None:
super().set_footer(text=text)
class Default_Embed:
@staticmethod
def default_join_embed():
embed = ChristmasEmbed(title="πŸŽ‰ 크돌이λ₯Ό μΆ”κ°€ν•΄μ£Όμ…”μ„œ κ°μ‚¬ν•΄μš”!", description="봇을 μ‚¬μš©ν•˜κΈ° 전에 이 μ„œλ²„μ˜ κ΄€λ¦¬μžλΌλ©΄ λ‹€μŒμ˜ 절차λ₯Ό λ”°λΌμ£Όμ„Έμš”!")
embed.add_field(name="1. μ•½κ΄€ λ™μ˜", value="λ‹€μŒμ˜ 약관을 읽고 ``/μ„œλ²„ κ°€μž…``λͺ…λ Ήμ–΄λ₯Ό μ‹€ν–‰ν•΄μ£Όμ„Έμš”", inline=False)
embed.add_field(name="2. μ„€μ •", value="``/μ„€μ •`` λͺ…λ Ήμ–΄λ₯Ό 톡해 크돌이의 μ—¬λŸ¬ κΈ°λŠ₯을 μ„€μ •ν• μˆ˜ μžˆμ–΄μš”!", inline=False)
embed.add_field(name="3. 도움말", value="``/도움말`` λͺ…λ Ήμ–΄λ₯Ό 톡해 크돌이의 λͺ…λ Ήμ–΄λ₯Ό 확인할 수 μžˆμ–΄μš”!", inline=False)
embed.set_footer()
return embed
@staticmethod
def register_sucess():
embed = ChristmasEmbed(title="πŸŽ‰ κ°€μž… 성곡!", description="μ„œλ²„κ°€μž…μ„ μ„±κ³΅ν–ˆμ–΄μš”!")
embed.add_field(name="μ•ˆλ‚΄", value="이제 크돌이λ₯Ό μ¦κ²¨λ³΄μ„Έμš”!", inline=False)
embed.set_footer()
return embed
@staticmethod
def register_failed():
embed = ChristmasEmbed(title="❌ κ°€μž… μ‹€νŒ¨!", description="μ„œλ²„κ°€μž…μ„ μ‹€νŒ¨ν–ˆμ–΄μš”!")
embed.add_field(name="μ•ˆλ‚΄", value="μ•Œμˆ˜μ—†λŠ” 였λ₯˜λ‘œ 인해 κ°€μž…μ— μ‹€νŒ¨ν–ˆμ–΄μš”! 이 ν˜„μƒμ΄ μ§€μ†λœλ‹€λ©΄ μ„œλΉ„μŠ€ μ„œλ²„μ— λ¬Έμ˜ν•΄μ£Όμ„Έμš”!", inline=False)
embed.set_footer()
return embed
@staticmethod
def already_register():
embed = ChristmasEmbed(title="❌ κ°€μž… μ‹€νŒ¨!", description="이미 κ°€μž…λœ μ„œλ²„μ—μš”!")
embed.add_field(name="μ•ˆλ‚΄", value="이미 κ°€μž…λœ μ„œλ²„μ—μš”!", inline=False)
embed.set_footer()
return embed
@staticmethod
def cooldown(sec):
return "이 λͺ…λ Ήμ–΄λŠ” " + str(sec) + "초 뒀에 λ‹€μ‹œ μ‚¬μš©ν•  수 μžˆμ–΄μš”!"
@staticmethod
def BotInfo(gpuserver: typing.Dict[str, typing.Any], bot, APIlatency) -> Embed:
current_time = datetime.now()
uptime = current_time - start_time
uptime = str(uptime).split(".")[0]
"""
gpuserver: [system_memory_usage,cuda_memory_usage,oom_count]
"""
embed = Embed(title="**봇 정보**", description="크돌이의 μ •λ³΄μ—μš”!")
embed.add_field(name="**봇 κ°œμš”**", value=f"봇 ID: {bot.user.id}\n봇 버전: 0.0.9\nκ°€λ™μ‹œκ°„: {str(uptime)}", inline=False)
orin = psutil.virtual_memory().used
orin = orin / 1024 / 1024 / 1024
if gpuserver == None or gpuserver["status"] == "offline":
embed.add_field(name="**봇 μžμ›**", value=f"GPUμ„œλ²„1 λ©”λͺ¨λ¦¬ μ‚¬μš©λŸ‰: **였λ₯˜**\nGPUμ„œλ²„1 CUDA λ©”λͺ¨λ¦¬ μ‚¬μš©λŸ‰: **였λ₯˜**\nGPUμ„œλ²„1 λ©”λͺ¨λ¦¬ 였λ₯˜ 횟수: **였λ₯˜**\n ν˜„μž¬ μƒ€λ“œ λ©”λͺ¨λ¦¬ μ‚¬μš©λŸ‰:{round(orin)}GB", inline=False)
else:
mem_usage = gpuserver["system_memory_usage"]
cuda_memory_usage = gpuserver["cuda_memory_usage"]
oom_count = gpuserver["oom_count"]
embed.add_field(name="**봇 μžμ›**", value=f"ν˜„μž¬ μƒ€λ“œ λ©”λͺ¨λ¦¬ μ‚¬μš©λŸ‰: {round(orin)}GB\n\nGPUμ„œλ²„1 λ©”λͺ¨λ¦¬ μ‚¬μš©λŸ‰: {mem_usage}GB/128GB\nGPUμ„œλ²„1 GPU λ©”λͺ¨λ¦¬ μ‚¬μš©λŸ‰: {cuda_memory_usage}GB/80GB\nGPUμ„œλ²„1 λ©”λͺ¨λ¦¬ 였λ₯˜ 횟수: {oom_count}", inline=False)
embed.add_field(name="**봇 톡계**", value=f"🏘️ **{len(bot.guilds)}**개의 μ„œλ²„μ—μ„œ 봇을 μ‚¬μš©μ€‘μ΄μ—μš”!\nπŸ€– **{len(bot.users)}**λͺ…μ˜ μœ μ €μ™€ ν•¨κ»˜ν•˜λŠ” μ€‘μ΄μ—μš”!", inline=False)
if APIlatency is None:
embed.add_field(name="**봇 ν•‘**", value=f"πŸ“ **λ””μŠ€μ½”λ“œ κ²Œμ΄νŠΈμ›¨μ΄ ν•‘**: {round(bot.latency * 1000)}ms\nπŸ“ **AI κ²Œμ΄νŠΈμ›¨μ΄ ν•‘**: 였λ₯˜", inline=False)
else:
embed.add_field(name="**봇 ν•‘**", value=f"πŸ“ **λ””μŠ€μ½”λ“œ κ²Œμ΄νŠΈμ›¨μ΄ ν•‘**: {round(bot.latency * 1000)}ms\nπŸ“ **AI κ²Œμ΄νŠΈμ›¨μ΄ ν•‘**: {APIlatency}ms", inline=False)
embed.set_footer()
return embed
class Mail_Embed:
@staticmethod
def mail_confirm(title: str, description: str, receive_user: Member) -> Embed:
embed = ChristmasEmbed(title="⚠️ 전솑전 확인", description="νŽΈμ§€λ₯Ό μ •λ§λ‘œ μ „μ†‘ν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ?")
embed.add_field(name="⚠️ μ£Όμ˜μ‚¬ν•­ ⚠️", value="νŽΈμ§€λŠ” ν•œ 번 μ „μ†‘ν•˜λ©΄ ν•œλ²ˆμ˜ μˆ˜μ • 기회 μ΄ν›„μ—λŠ” μ·¨μ†Œν•  수 μ—†μ–΄μš”!\n λ‚΄μš©μ„ 잘 읽고 ``전솑``λ²„νŠΌμ„ λˆŒλŸ¬μ£Όμ„Έμš”!", inline=False)
embed.add_field(name="λ°›λŠ”μ΄", value=f"{receive_user.mention}", inline=False)
embed.add_field(name="제λͺ©", value=title, inline=False)
embed.add_field(name="λ‚΄μš©", value=description, inline=False)
embed.set_footer()
return embed
@staticmethod
def mail_confirm_edit(title: str, description: str, receive_user: Member) -> Embed:
embed = ChristmasEmbed(title="⚠️ μˆ˜μ •μ „ 확인", description="νŽΈμ§€λ₯Ό μ •λ§λ‘œ μˆ˜μ •ν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ?")
embed.add_field(name="⚠️ μ£Όμ˜μ‚¬ν•­ ⚠️", value="μ΄λ²ˆμ— νŽΈμ§€λ₯Ό μˆ˜μ •ν•˜λ©΄ λ‹€μ‹œλŠ” μˆ˜μ •ν•  수 μ—†κ²Œ λ˜μš”!\n λ‚΄μš©μ„ 잘 읽고 ``전솑``λ²„νŠΌμ„ λˆŒλŸ¬μ£Όμ„Έμš”!", inline=False)
embed.add_field(name="λ°›λŠ”μ΄", value=f"{receive_user.mention}", inline=False)
embed.add_field(name="제λͺ©", value=title, inline=False)
embed.add_field(name="λ‚΄μš©", value=description, inline=False)
embed.set_footer()
return embed
@staticmethod
def mail_cant_edit():
embed = ChristmasEmbed(title="❌ νŽΈμ§€ μˆ˜μ • μ‹€νŒ¨!", description="νŽΈμ§€ μˆ˜μ •μ— μ‹€νŒ¨ν–ˆμ–΄μš”!")
embed.add_field(name="μ•ˆλ‚΄", value="νŽΈμ§€λŠ” ν•œ 번 μ „μ†‘ν•˜λ©΄ ν•œλ²ˆμ˜ μˆ˜μ • 기회 μ΄ν›„μ—λŠ” μ·¨μ†Œν•˜κ±°λ‚˜ μˆ˜μ • ν•  수 μ—†μ–΄μš”!", inline=False)
embed.set_footer()
return embed
@staticmethod
def mail_sended(receive_user: Member) -> Embed:
embed = ChristmasEmbed(title="βœ… μ „μ†‘μ™„λ£Œ!", description="νŽΈμ§€ 전솑을 μ™„λ£Œν–ˆμ–΄μš”!")
embed.add_field(name="μ•ˆλ‚΄", value="보낸 νŽΈμ§€λŠ” 2023λ…„ 12μ›” 25일뢀터 μ—΄λžŒ κ°€λŠ₯ν•΄μš”!", inline=False)
embed.add_field(name="λ°›λŠ”μ΄", value=f"{receive_user.mention}", inline=False)
return embed
@staticmethod
def mail_edit_sended(receive_user: Member) -> Embed:
embed = ChristmasEmbed(title="βœ… μˆ˜μ •μ™„λ£Œ!", description="νŽΈμ§€ μˆ˜μ •μ„ μ™„λ£Œν–ˆμ–΄μš”!")
embed.add_field(name="μ•ˆλ‚΄", value="μˆ˜μ •λœ νŽΈμ§€λŠ” 2023λ…„ 12μ›” 25일뢀터 μ—΄λžŒ κ°€λŠ₯ν•΄μš”!", inline=False)
embed.add_field(name="λ°›λŠ”μ΄", value=f"{receive_user.mention}", inline=False)
return embed
@staticmethod
def mail_notfound() -> Embed:
embed = ChristmasEmbed(title="❌ νŽΈμ§€ μ—†μŒ!", description="νŽΈμ§€κ°€ μ—†μ–΄μš”!")
embed.add_field(name="μ•ˆλ‚΄", value="받은 νŽΈμ§€κ°€ μ—†μ–΄μš”!", inline=False)
embed.set_footer()
return embed
@staticmethod
def mail_already_sended() -> Embed:
embed = ChristmasEmbed(title="❌ νŽΈμ§€ 전솑 μ‹€νŒ¨!", description="이미 νŽΈμ§€λ₯Ό λ³΄λƒˆμ–΄μš”!")
embed.add_field(name="μ•ˆλ‚΄", value="이미 νŽΈμ§€λ₯Ό λ³΄λƒˆμ–΄μš”!", inline=False)
embed.set_footer()
return embed
@staticmethod
def mail_page(data) -> Embed:
embed = ChristmasEmbed(title="πŸ“¨ νŽΈμ§€", description="νŽΈμ§€λ₯Ό ν™•μΈν•΄λ³΄μ„Έμš”!(μš•μ„€λ“± λ―Όκ°ν•œ λ‚΄μš©μ΄ ν¬ν•¨λœ λ‚΄μš©μ€ μžλ™μœΌλ‘œ μŠ€ν¬μΌλŸ¬μ²˜λ¦¬λ˜μš”!)")
username = data["username"]
userid = data["userid"]
title = data["title"]
description = data["content"]
if korcen.check(title) == True:
title = "||" + title + "||"
if korcen.check(description) == True:
description = "||" + description + "||"
embed.add_field(name="보낸이", value=f"{username}({userid})", inline=False)
embed.add_field(name="제λͺ©", value=title, inline=False)
embed.add_field(name="λ‚΄μš©", value=description, inline=False)
embed.set_footer()
return embed
class Aiart_Embed:
@staticmethod
def failed_generate() -> Embed:
embed = ChristmasEmbed(title="❌ κ·Έλ¦Ό 생성 μ‹€νŒ¨!", description="κ·Έλ¦Ό 생성에 μ‹€νŒ¨ν–ˆμ–΄μš”!")
embed.add_field(name="μ•ˆλ‚΄", value="κ·Έλ¦Ό 생성에 μ‹€νŒ¨ν–ˆμ–΄μš”! 이 ν˜„μƒμ΄ μ§€μ†λœλ‹€λ©΄ μ„œλΉ„μŠ€ μ„œλ²„μ— λ¬Έμ˜ν•΄μ£Όμ„Έμš”!", inline=False)
embed.set_footer()
return embed
@staticmethod
def sucess_generate(prompt: str, remove: str) -> Embed:
embed = ChristmasEmbed(title="βœ… κ·Έλ¦Ό 생성 성곡!", description="κ·Έλ¦Ό 생성에 μ„±κ³΅ν–ˆμ–΄μš”!")
embed.add_field(name="ν”„λ‘¬ν¬νŠΈ", value=prompt, inline=False)
embed.add_field(name="μ§€μš΄ ν”„λ‘¬ν¬νŠΈ", value=remove, inline=False)
embed.set_image(url="attachment://image.png")
embed.set_footer()
return embed
@staticmethod
def generating() -> Embed:
embed = ChristmasEmbed(title="κ·Έλ¦Ό 생성쀑...", description="그림을 μƒμ„±ν•˜λŠ” μ€‘μ΄μ—μš”!")
embed.add_field(name="μ•ˆλ‚΄", value="κ·Έλ¦Ό μƒμ„±μ—λŠ” μ΅œλŒ€ 2뢄이 μ†Œμš”λ  수 μžˆμ–΄μš”!(ν¬λŒμ΄λŠ” 돈이 μ—†μ–΄μš”...)", inline=False)
embed.set_footer()
return embed
@staticmethod
def evalate(tags, rating) -> ChristmasEmbed:
if tags == None:
embed = ChristmasEmbed(name="**였λ₯˜**", value="κ·Έλ¦Ό 뢄석에 μ‹€νŒ¨ν–ˆμ–΄μš”. λ‚˜μ€‘μ— λ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”", inline=False)
return embed
else:
embed = ChristmasEmbed(title="**κ·Έλ¦Ό 뢄석 μ™„λ£Œ**", description="κ·Έλ¦Ό 뢄석이 μ™„λ£Œλ˜μ—ˆμ–΄μš”!")
embed.set_image(url="attachment://image.png")
embed.add_field(name="**λ“±κΈ‰**", value=f"{rating}", inline=False)
texts = ""
for tag, score in tags:
percentage = score * 100
texts = texts + f"{tag} : {percentage:.1f}%\n"
embed.add_field(name="**λΆ„μ„λœ μš”μ†Œ**", value=f"{texts}", inline=False)
embed.set_footer()
return embed
class Music_Embed:
@staticmethod
def music_notenable():
embed = ChristmasEmbed(title="❌ μŒμ•… μž¬μƒ μ‹€νŒ¨!", description="μŒμ•… μž¬μƒμ— μ‹€νŒ¨ν–ˆμ–΄μš”!")
embed.add_field(name="μ•ˆλ‚΄", value="이 μ„œλ²„μ—μ„œλŠ” μŒμ•…μ„ μž¬μƒν• μˆ˜ μ—†μ–΄μš”! \nλ§Œμ•½ μ„œλ²„μ˜ κ΄€λ¦¬μžλΌλ©΄ ``/μ„€μ •`` λͺ…λ Ήμ–΄λ‘œ μŒμ•… κΈ°λŠ₯을 λ‹€μ‹œ ν™œμ„±ν™”μ‚¬ν‚¬μˆ˜ μžˆμ–΄μš”!", inline=False)
embed.set_footer()
return embed
@staticmethod
def author_not_voice():
embed = ChristmasEmbed(title="❌ μŒμ•… μž¬μƒ μ‹€νŒ¨!", description="μŒμ•… μž¬μƒμ— μ‹€νŒ¨ν–ˆμ–΄μš”!")
embed.add_field(name="μ•ˆλ‚΄", value="μŒμ•…μ„ μž¬μƒν•˜λ €λ©΄ μŒμ„±μ±„λ„μ— λ“€μ–΄κ°€μ•Ό ν•΄μš”!", inline=False)
embed.set_footer()
return embed
@staticmethod
def author_diffrent_voice():
embed = ChristmasEmbed(title="❌ μŒμ•… μž¬μƒ μ‹€νŒ¨!", description="μŒμ•… μž¬μƒμ— μ‹€νŒ¨ν–ˆμ–΄μš”!")
embed.add_field(name="μ•ˆλ‚΄", value="이미 λ‹€λ₯Έ 채널에 μ ‘μ†λ˜μ–΄μžˆμ–΄μš”!", inline=False)
embed.set_footer()
return embed
#@staticmethod
#def music_queue(music: wavelink.Playable):
#μŒμ•…μ„ queue에 λ„£μŒ
#embed = ChristmasEmbed(title="βœ… μŒμ•… μž¬μƒ 성곡!", description="μŒμ•… μž¬μƒμ— μ„±κ³΅ν–ˆμ–΄μš”!")
#embed =