2023-11-26 15:27:32 +00:00
import pendulum
2023-11-25 17:28:48 +00:00
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
2023-11-26 04:27:34 +00:00
from Christmas . UI . Modal import Send_Mail_Modal
2023-11-26 15:27:32 +00:00
from Christmas . UI . Embed import Mail_Embed
from Christmas . Database import database
from Christmas . UI . Paginator import Mail_Paginator
2023-11-25 17:28:48 +00:00
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 ( )
2023-11-26 04:27:34 +00:00
async def _send ( self , ctx : Context , member : Option ( Member , name = " 보낼사람 " , description = " 편지를 받을 사람을 선택해주세요. " , required = True ) ) :
2023-11-26 15:27:32 +00:00
if pendulum . now ( ) . year > = 2023 and pendulum . now ( ) . month > = 12 and pendulum . now ( ) . day > = 24 and pendulum . now ( ) . hour > = 11 and pendulum . now ( ) . minute > = 59 and pendulum . now ( ) . second > = 59 :
await ctx . respond ( " 이미 편지를 보낼수 있는 기간이 지났어요! 받은 편지가 있다면 확인해보세요! " , ephemeral = True )
return
if await database . get_mail_user ( member . id , ctx . author . id ) :
if await database . get_instered_mail_edited ( member . id , ctx . author . id ) :
await ctx . respond ( embed = Mail_Embed . mail_cant_edit ( ) , ephemeral = True )
return
else :
modal = Send_Mail_Modal ( reciveuser = member , editmode = True , title = " 편지 수정하기 " )
await ctx . send_modal ( modal )
return
modal = Send_Mail_Modal ( editmode = False , reciveuser = member , title = " 편지 보내기 " )
2023-11-26 04:27:34 +00:00
await ctx . send_modal ( modal )
2023-11-25 17:28:48 +00:00
2023-11-26 15:27:32 +00:00
@MAIL.command ( name = " 확인 " , description = " 받은 편지를 확인합니다. " )
@cooldown ( 1 , 10 , BucketType . user )
async def _check ( self , ctx : Context ) :
#관리자를 제외하고는 2023년 12월 25일 00시 00분 00초 이후부터 확인 가능
#if pendulum.now().year >= 2023 and pendulum.now().month >= 12 and pendulum.now().day >= 25 and pendulum.now().hour >= 00 and pendulum.now().minute >= 00 and pendulum.now().second >= 00:
# await ctx.respond("아직 편지를 확인할수 있는 기간이 아니에요! 조금만 기다려주세요!")
# return
mails = await database . get_mail ( ctx . author . id )
if mails == None :
await ctx . respond ( embed = Mail_Embed . mail_notfound ( ) , ephemeral = True )
return
else :
mails = mails [ " mails " ]
embeds = [ ]
for data in mails :
embeds . append ( Mail_Embed . mail_page ( data ) )
print ( embeds )
paginator = Mail_Paginator ( embeds = embeds , senduser = ctx . author , timeout = None )
await ctx . respond ( embed = embeds [ 0 ] , view = paginator , ephemeral = True )
2023-11-25 17:28:48 +00:00
def setup ( bot ) :
bot . add_cog ( CMail ( bot ) )