초기 모듈 구현

This commit is contained in:
tmddn3070 2023-11-26 02:28:48 +09:00
parent 657bd5f563
commit a6fcd2b1f6
12 changed files with 197 additions and 3 deletions

View File

@ -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))

View File

@ -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))

View File

View File

@ -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))

22
Christmas/Cogs/Event.py Normal file
View File

@ -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))

7
Christmas/Module.py Normal file
View File

@ -0,0 +1,7 @@
import korcen
korcen_checker = korcen.Korcen()
def check_curse(text: str):
return korcen_checker.check(text)

14
Christmas/UI/Buttons.py Normal file
View File

@ -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()

45
Christmas/UI/Embed.py Normal file
View File

@ -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

20
Christmas/UI/Modal.py Normal file
View File

@ -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))

View File

@ -4,7 +4,8 @@ from typing import Any, cast
from discord import AutoShardedBot, Intents from discord import AutoShardedBot, Intents
from discord.ext import commands, tasks from discord.ext import commands, tasks
from Christmas.discord import Christmas from Christmas.discord import Christmas, load_cogs, apply_uvloop
if __name__ == "__main__": if __name__ == "__main__":
bot = Christmas( bot = Christmas(
@ -15,4 +16,6 @@ if __name__ == "__main__":
), ),
intents=Intents.all(), intents=Intents.all(),
) )
load_cogs(bot)
apply_uvloop()
bot.run() bot.run()

View File

@ -5,6 +5,10 @@ class ChristmasConfig:
def __init__(self): def __init__(self):
self.json = json.load(open("Christmas/config.json", "r")) self.json = json.load(open("Christmas/config.json", "r"))
@property
def MODE(self):
return self.json["MODE"]
@property @property
def TOKEN(self): def TOKEN(self):
return self.json["TOKEN"] return self.json["TOKEN"]

View File

@ -1,3 +1,5 @@
import os
from types import SimpleNamespace from types import SimpleNamespace
from typing import Any, cast from typing import Any, cast
@ -13,6 +15,25 @@ class Christmas(AutoShardedBot):
def run(self, *args: Any, **kwargs: Any) -> None: def run(self, *args: Any, **kwargs: Any) -> None:
kwargs.update({"token": self.ctx.config.TOKEN}) 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) super().run(*args, **kwargs)
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())