From 44e52053de255f620267238b677340d31cbd4e8a Mon Sep 17 00:00:00 2001 From: Conatum Date: Mon, 4 Sep 2023 11:29:32 +0300 Subject: [PATCH] Add blanket cog. --- src/modules/__init__.py | 1 + src/modules/blanket/__init__.py | 9 ++++++ src/modules/blanket/cog.py | 56 +++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 src/modules/blanket/__init__.py create mode 100644 src/modules/blanket/cog.py diff --git a/src/modules/__init__.py b/src/modules/__init__.py index 45644611..561c26e3 100644 --- a/src/modules/__init__.py +++ b/src/modules/__init__.py @@ -18,6 +18,7 @@ active = [ '.moderation', '.video_channels', '.meta', + '.blanket', '.test', ] diff --git a/src/modules/blanket/__init__.py b/src/modules/blanket/__init__.py new file mode 100644 index 00000000..29ee6a35 --- /dev/null +++ b/src/modules/blanket/__init__.py @@ -0,0 +1,9 @@ +from babel.translator import LocalBabel + +babel = LocalBabel('blanket') + + +async def setup(bot): + from .cog import BlanketCog + + await bot.add_cog(BlanketCog(bot)) diff --git a/src/modules/blanket/cog.py b/src/modules/blanket/cog.py new file mode 100644 index 00000000..e132f47f --- /dev/null +++ b/src/modules/blanket/cog.py @@ -0,0 +1,56 @@ +from typing import Optional +import json +import asyncio + +import discord +from discord.ext import commands as cmds +from discord import app_commands as appcmds + +from wards import low_management, sys_admin_ward +from meta import LionBot, LionCog, LionContext +from utils.ui import AButton, AsComponents +from utils.lib import MessageArgs +from core.setting_types import MessageSetting + +from . import babel + +_p = babel._p + + +class BlanketCog(LionCog): + def __init__(self, bot: LionBot): + self.bot = bot + + @cmds.hybrid_command( + name="message", + description="Send a custom message to a channel." + ) + @appcmds.describe( + channel="Channel you want to send the message to", + content="Text of the message", + attachment="An attachement to add", + message_data="Downloaded message json, as output by the message editor." + ) + @sys_admin_ward + async def message_cmd(self, ctx: LionContext, + channel: discord.TextChannel | discord.VoiceChannel, + content: Optional[str] = None, + attachment: Optional[discord.Attachment] = None, + message_data: Optional[discord.Attachment] = None, + ): + await ctx.interaction.response.defer(thinking=True, ephemeral=True) + args = {} + if message_data: + decoded = await MessageSetting.download_attachment(message_data) + data = json.loads(decoded) + msg_args = MessageSetting.value_to_args(0, data) + args.update(msg_args.kwargs) + if content: + args['content'] = content + if attachment: + args['file'] = await attachment.to_file() + + message = await channel.send(**args) + await ctx.interaction.edit_original_response( + content="Message sent! {message.jump_url}" + )