-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathcog.py
76 lines (63 loc) · 2.81 KB
/
cog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
Cog for sending and managing messages sent by bot.
"""
import disnake
from disnake.ext import commands
from cogs.base import Base
from rubbergod import Rubbergod
from utils import cooldowns
from utils.checks import PermissionsCheck
from .messages_cz import MessagesCZ
from .modals import MessageModal
class Message(Base, commands.Cog):
def __init__(self, bot: Rubbergod):
super().__init__()
self.bot = bot
@PermissionsCheck.is_submod_plus()
@cooldowns.default_cooldown
@commands.slash_command(name="message")
async def message(self, inter: disnake.ApplicationCommandInteraction):
pass
@message.sub_command(name="send", description=MessagesCZ.send_brief)
async def send(
self,
inter: disnake.ApplicationCommandInteraction,
channel: disnake.TextChannel = commands.Param(description=MessagesCZ.channel_param),
attachment: disnake.Attachment = commands.Param(
default=None, description=MessagesCZ.attachment_param
),
):
if not attachment:
message_modal = MessageModal(self.bot, title="Send message", files=[], channel=channel)
await inter.response.send_modal(modal=message_modal)
return
if attachment.size > 25_000_000:
await inter.send(MessagesCZ.attachment_too_big, ephemeral=True)
return
file = await attachment.to_file()
message_modal = MessageModal(self.bot, title="Send message", files=[file], channel=channel)
await inter.response.send_modal(modal=message_modal)
@message.sub_command(name="resend", description=MessagesCZ.resend_brief)
async def resend(
self,
inter: disnake.ApplicationCommandInteraction,
channel: disnake.TextChannel = commands.Param(description=MessagesCZ.channel_param),
message_url: disnake.Message = commands.Param(description=MessagesCZ.url_param),
):
if len(message_url.content) > 2000:
await inter.send(MessagesCZ.message_too_long, ephemeral=True)
return
files = [await attachment.to_file() for attachment in message_url.attachments]
await inter.send(MessagesCZ.message_sent(channel=channel.mention), ephemeral=True)
await channel.send(message_url.content, files=files)
@message.sub_command(name="edit", description=MessagesCZ.edit_brief)
async def edit(
self,
inter: disnake.ApplicationCommandInteraction,
message_url: disnake.Message = commands.Param(description=MessagesCZ.url_param),
):
if len(message_url.content) > 2000:
await inter.send(MessagesCZ.message_too_long, ephemeral=True)
return
message_modal = MessageModal(self.bot, title="Edit message", message=message_url, edit=True)
await inter.response.send_modal(modal=message_modal)