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

56 lines
2.7 KiB
Python

import pendulum
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
from Christmas.UI.Modal import Send_Mail_Modal
from Christmas.UI.Embed import Mail_Embed
from Christmas.Database import database
from Christmas.UI.Paginator import Mail_Paginator
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="보낼사람", description="편지를 받을 사람을 선택해주세요.", required=True)):
christmas = pendulum.datetime(2023, 12, 25, 0, 0, 0)
if pendulum.now() > christmas:
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
else:
modal = Send_Mail_Modal(editmode=False, reciveuser=member, title="편지 보내기")
await ctx.send_modal(modal)
@MAIL.command(name="확인", description="받은 편지를 확인합니다.")
@cooldown(1, 10, BucketType.user)
async def _check(self, ctx: Context):
#2023년 12월 25일 00시 00분 00초 이후부터 확인 가능
christmas = pendulum.datetime(2023, 12, 25, 0, 0, 0)
if pendulum.now() < christmas:
await ctx.respond("아직 편지를 확인할수 있는 기간이 아니에요! 조금만 기다려주세요!", ephemeral=True)
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))
paginator = Mail_Paginator(embeds=embeds, senduser=ctx.author, timeout=None)
await ctx.respond(embed=embeds[0], view=paginator, ephemeral=True)
def setup(bot):
bot.add_cog(CMail(bot))