From a6fcd2b1f68c14ad0531a80517f639997b7a9c59 Mon Sep 17 00:00:00 2001 From: tmddn3070 Date: Sun, 26 Nov 2023 02:28:48 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B4=88=EA=B8=B0=20=EB=AA=A8=EB=93=88=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Christmas/Cogs/Commands_Aiart.py | 19 ++++++++++++++ Christmas/Cogs/Commands_Mail.py | 20 ++++++++++++++ Christmas/Cogs/Commands_Music.py | 0 Christmas/Cogs/Commands_Util.py | 19 ++++++++++++++ Christmas/Cogs/Event.py | 22 ++++++++++++++++ Christmas/Module.py | 7 +++++ Christmas/UI/Buttons.py | 14 ++++++++++ Christmas/UI/Embed.py | 45 ++++++++++++++++++++++++++++++++ Christmas/UI/Modal.py | 20 ++++++++++++++ Christmas/__main__.py | 5 +++- Christmas/config.py | 6 ++++- Christmas/discord.py | 23 +++++++++++++++- 12 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 Christmas/Cogs/Commands_Aiart.py create mode 100644 Christmas/Cogs/Commands_Mail.py create mode 100644 Christmas/Cogs/Commands_Music.py create mode 100644 Christmas/Cogs/Commands_Util.py create mode 100644 Christmas/Cogs/Event.py create mode 100644 Christmas/Module.py create mode 100644 Christmas/UI/Buttons.py create mode 100644 Christmas/UI/Embed.py create mode 100644 Christmas/UI/Modal.py diff --git a/Christmas/Cogs/Commands_Aiart.py b/Christmas/Cogs/Commands_Aiart.py new file mode 100644 index 0000000..2ba5290 --- /dev/null +++ b/Christmas/Cogs/Commands_Aiart.py @@ -0,0 +1,19 @@ +from discord import ApplicationContext, DiscordException +from discord.ext.commands import Cog + + + +class CAiart(Cog): + def __init__(self, bot): + self.bot = bot + + + + @Cog.listener() + async def on_application_command_error(ctx: ApplicationContext, exception: DiscordException) -> None: + pass + + + +def setup(bot): + bot.add_cog(CAiart(bot)) \ No newline at end of file diff --git a/Christmas/Cogs/Commands_Mail.py b/Christmas/Cogs/Commands_Mail.py new file mode 100644 index 0000000..a9e67d0 --- /dev/null +++ b/Christmas/Cogs/Commands_Mail.py @@ -0,0 +1,20 @@ +from discord import Member, SlashCommandGroup, Option +from discord.ext.commands import Cog, cooldown, BucketType, command, has_permissions, bot_has_permissions, Context, guild_only, bot_has_guild_permissions, check + + + +class CMail(Cog): + def __init__(self, bot): + self.bot = bot + + MAIL = SlashCommandGroup(name="편지", description="편지를 보내거나 확인합니다.") + + @MAIL.command(name="보내기", description="편지를 보냅니다.") + @cooldown(1, 10, BucketType.user) + @guild_only() + async def _send(self, ctx: Context, member: Option(Member, name="member", description="편지를 받을 사람을 선택해주세요.", required=True)): + + + +def setup(bot): + bot.add_cog(CMail(bot)) \ No newline at end of file diff --git a/Christmas/Cogs/Commands_Music.py b/Christmas/Cogs/Commands_Music.py new file mode 100644 index 0000000..e69de29 diff --git a/Christmas/Cogs/Commands_Util.py b/Christmas/Cogs/Commands_Util.py new file mode 100644 index 0000000..aa0bb1c --- /dev/null +++ b/Christmas/Cogs/Commands_Util.py @@ -0,0 +1,19 @@ +from discord import ApplicationContext, DiscordException +from discord.ext.commands import Cog + + + +class CUtil(Cog): + def __init__(self, bot): + self.bot = bot + + + + @Cog.listener() + async def on_application_command_error(ctx: ApplicationContext, exception: DiscordException) -> None: + pass + + + +def setup(bot): + bot.add_cog(CUtil(bot)) \ No newline at end of file diff --git a/Christmas/Cogs/Event.py b/Christmas/Cogs/Event.py new file mode 100644 index 0000000..5db75b6 --- /dev/null +++ b/Christmas/Cogs/Event.py @@ -0,0 +1,22 @@ +from discord import ApplicationContext, DiscordException, Game +from discord.ext.commands import Cog + + + +class Event(Cog): + def __init__(self, bot): + self.bot = bot + + + @Cog.listener() + async def on_application_command_error(ctx: ApplicationContext, exception: DiscordException) -> None: + pass + + @Cog.listener() + async def on_ready(self): + print("Ready!") + await self.bot.change_presence(activity=Game(name="크리스마스에 함께!")) + + +def setup(bot): + bot.add_cog(Event(bot)) \ No newline at end of file diff --git a/Christmas/Module.py b/Christmas/Module.py new file mode 100644 index 0000000..c751537 --- /dev/null +++ b/Christmas/Module.py @@ -0,0 +1,7 @@ +import korcen + +korcen_checker = korcen.Korcen() + + +def check_curse(text: str): + return korcen_checker.check(text) \ No newline at end of file diff --git a/Christmas/UI/Buttons.py b/Christmas/UI/Buttons.py new file mode 100644 index 0000000..d4886de --- /dev/null +++ b/Christmas/UI/Buttons.py @@ -0,0 +1,14 @@ +from discord.ui import View, button +from discord import Interaction, ButtonStyle, Embed, Color, TextChannel, Forbidden, Message, Member, User, File, HTTPException + + + +class Mail_Confirm_Button(View): + def __init__(self, recive_user: Member, *args, **kwargs): + self.recive_user = recive_user + super().__init__(timeout=None) + + @button(label="전송", style=ButtonStyle.green, custom_id="mail_send") + async def send(self, button, interaction: Interaction): + await interaction.response.defer() + \ No newline at end of file diff --git a/Christmas/UI/Embed.py b/Christmas/UI/Embed.py new file mode 100644 index 0000000..b88342a --- /dev/null +++ b/Christmas/UI/Embed.py @@ -0,0 +1,45 @@ +from typing import Any, Optional +from discord import Embed, Colour, Embed, Member +from discord.types.embed import EmbedType +from datetime import datetime + +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 = None) -> None: + super().set_footer(text=text, icon_url=icon_url) + + +class Mail_Embed: + + @staticmethod + def mail_confirm(title: str, description: str) -> Embed: + embed = ChristmasEmbed(title="⚠️|전송전 확인", description="메일을 정말로 전송하시겠습니까?") + embed.add_field(name="⚠️ 주의사항 ⚠️", value="메일은 한 번 전송하면 취소할 수 없어요!\n 내용을 잘 읽고 ``전송``버튼을 눌러주세요!") + embed.add_field(name="받는이", value="크돌이 ⛄") + embed.add_field(name="제목", value=title) + embed.add_field(name="내용", value=description) + 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일부터 열람 가능해요") + embed.add_field(name="받는이", value=f"{receive_user.mention}") + return embed \ No newline at end of file diff --git a/Christmas/UI/Modal.py b/Christmas/UI/Modal.py new file mode 100644 index 0000000..4f6841b --- /dev/null +++ b/Christmas/UI/Modal.py @@ -0,0 +1,20 @@ +from discord import InputTextStyle, Interaction, Member +from discord.ui import Modal, InputText + +from Christmas.Module import check_curse + +from Christmas.UI.Embed import Mail_Embed +from Christmas.UI.Buttons import Mail_Confirm_Button +class Send_Mail_Modal(Modal): + def __init__(self, reciveuser: Member, *args, **kwargs): + self.reciveuser = reciveuser + super().__init__(timeout=None, *args, **kwargs) + + self.add_item(InputText("제목", placeholder="제목을 입력해주세요.", style=InputTextStyle.short, required=True, custom_id="mail_title")) + self.add_item(InputText("내용", placeholder="내용을 입력해주세요.", style=InputTextStyle.long, required=True, custom_id="mail_content")) + + + async def callback(self, interaction: Interaction): + await interaction.response.defer() + await interaction.edit_original_message(embed=Mail_Embed.mail_confirm(self.items[0].value, self.items[1].value), view=Mail_Confirm_Button(self.reciveuser)) + \ No newline at end of file diff --git a/Christmas/__main__.py b/Christmas/__main__.py index 53da93d..4901b2e 100644 --- a/Christmas/__main__.py +++ b/Christmas/__main__.py @@ -4,7 +4,8 @@ from typing import Any, cast from discord import AutoShardedBot, Intents from discord.ext import commands, tasks -from Christmas.discord import Christmas +from Christmas.discord import Christmas, load_cogs, apply_uvloop + if __name__ == "__main__": bot = Christmas( @@ -15,4 +16,6 @@ if __name__ == "__main__": ), intents=Intents.all(), ) + load_cogs(bot) + apply_uvloop() bot.run() \ No newline at end of file diff --git a/Christmas/config.py b/Christmas/config.py index 0261919..4b0bd15 100644 --- a/Christmas/config.py +++ b/Christmas/config.py @@ -4,7 +4,11 @@ import json class ChristmasConfig: def __init__(self): self.json = json.load(open("Christmas/config.json", "r")) - + + @property + def MODE(self): + return self.json["MODE"] + @property def TOKEN(self): return self.json["TOKEN"] diff --git a/Christmas/discord.py b/Christmas/discord.py index a26e932..07d3869 100644 --- a/Christmas/discord.py +++ b/Christmas/discord.py @@ -1,3 +1,5 @@ +import os + from types import SimpleNamespace from typing import Any, cast @@ -13,6 +15,25 @@ class Christmas(AutoShardedBot): def run(self, *args: Any, **kwargs: Any) -> None: kwargs.update({"token": self.ctx.config.TOKEN}) + if self.config.MODE == "dev": + kwargs.update({"debug_guilds": [1090621667778244638,1015236495910649926,957142859629342790,1125370139165081612,1170310470503247993]}) super().run(*args, **kwargs) - \ No newline at end of file + +def load_cogs(bot) -> None: + for filename in os.listdir("Christmas/Cogs"): + if filename == "__pycache__": + continue + if filename.endswith(".py"): + bot.load_extension(f"Christmas.cogs.{filename[:-3]}") + + +def apply_uvloop() -> None: + try: + import uvloop + import asyncio + except ImportError: + pass + else: + uvloop.install() + asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) \ No newline at end of file