mirror of
https://github.com/yawaflua/AoyoBot.git
synced 2025-12-10 20:39:29 +02:00
Initialize project
This commit is contained in:
36
cogs/saveChannels.py
Normal file
36
cogs/saveChannels.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from disnake.ext import commands
|
||||
import disnake
|
||||
import chat_exporter
|
||||
from typing import Optional
|
||||
import io
|
||||
class saveChannel(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.slash_command(name=disnake.Localized('save-channel', key='SAVECHANNEL_NAME'),
|
||||
description=disnake.Localized('Saves channel data, and later sends them to a separate channel', key="SAVECHANNEL_DESC"))
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def save_channel(self, inter, chat: Optional[disnake.TextChannel]):
|
||||
if type(chat) == disnake.TextChannel:
|
||||
channel = chat
|
||||
else:
|
||||
channel = inter.channel
|
||||
|
||||
transcript = await chat_exporter.export(
|
||||
channel,
|
||||
bot=self.bot,
|
||||
)
|
||||
if transcript is None:
|
||||
return
|
||||
|
||||
transcript_file = disnake.File(
|
||||
io.BytesIO(transcript.encode()),
|
||||
filename=f"transcript-{inter.channel.name}.html",
|
||||
)
|
||||
|
||||
await inter.send(file=transcript_file)
|
||||
await inter.response.send_message("Готово!", ephemeral=True)
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(saveChannel(bot))
|
||||
|
||||
Reference in New Issue
Block a user