runabot/Christmas/Cogs/Commands_Mail.py

57 lines
3.0 KiB
Python
Raw Normal View History

import pendulum
2023-12-03 10:06:21 +00:00
from discord import Member, SlashCommandGroup, Option, Color
2023-11-25 17:28:48 +00:00
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-12-03 10:06:21 +00:00
from Christmas.UI.Embed import Mail_Embed, ChristmasEmbed
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-12-02 06:03:50 +00:00
christmas = pendulum.datetime(2023, 12, 25, 0, 0, 0)
if pendulum.now() > christmas:
await ctx.respond("이미 편지를 보낼수 있는 기간이 지났어요! 받은 편지가 있다면 확인해보세요!", ephemeral=True)
return
2023-12-03 10:06:21 +00:00
if ctx.author == member: return await ctx.respond(embed=ChristmasEmbed(title="❌ 에러!", description="자기 자신에게 편지를 보낼수 없어요!", color=Color.red()),ephemeral=True)
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
2023-12-02 06:03:50 +00:00
else:
modal = Send_Mail_Modal(editmode=False, reciveuser=member, title="편지 보내기")
await ctx.send_modal(modal)
2023-11-25 17:28:48 +00:00
@MAIL.command(name="확인", description="받은 편지를 확인합니다.")
@cooldown(1, 10, BucketType.user)
async def _check(self, ctx: Context):
2023-12-02 06:03:50 +00:00
#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)
2023-11-25 17:28:48 +00:00
def setup(bot):
bot.add_cog(CMail(bot))