mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 01:06:19 +00:00
✨ feat(server.ts): add support for process.env.PORT environment variable to be able to run app on a configurable port 🐛 fix(main.py): remove duplicate cog addition in main.py ✨ feat(main.py): add cogs.Help(bot) to the list of cogs in main.py 🐛 fix(main.py): remove redundant import statements in main.py ✨ feat(main.py): add on_guild_remove event handler in main.py ✨ feat(main.py): add on_guild_join event handler in main.py ✨ feat(main.py): add support for discord.Intents in main.py ✨ feat(main.py): add intents.message_content = True in main.py ✨ feat(main.py): add intents.default() in main.py ✨ feat(main.py): add discord.Bot(intents=intents, help_command=None) in main.py ✨ feat(main.py): add import statements in main.py ✨ feat(main.py): add from src.config import debug, discord_token in main.py ✨ feat(main.py): add import discord in main.py ✨ feat(main.py): add import src.config in main.py ✨ feat(main.py): add import src.cogs in main.py ✨ feat(main.py): add import src.cogs.chat in main.py ✨ feat(main.py): add import src.cogs.manage_chat in main.py ✨ feat(main.py): add import src.cogs.moderation in main.py ✨ feat(main.py): add import src.cogs.channelSetup in main.py ✨ feat(main.py): add import src.cogs.help in main.py ✨ feat(main.py): add import src.cogs.Chat in main.py ✨ feat(main.py): add import src.cogs.ManageChat in main.py ✨ feat(main.py): add import src.cogs.Moderation in main.py ✨ feat(main.py): add import src.cogs.ChannelSetup in main.py ✨ feat(main.py): add import src.cogs.Help in main.py ✨ feat(main.py): add import src.cogs.chat in main.py ✨ feat(main.py): add import src.cogs.manage_chat in main.py ✨ feat(main.py): add import src.cogs.moderation in main.py ✨ feat(main.py): add
154 lines
5.6 KiB
Python
154 lines
5.6 KiB
Python
import discord
|
|
from discord.ext import commands
|
|
from src.config import (
|
|
debug,
|
|
webhook_url,
|
|
)
|
|
import asyncio
|
|
from src.ChatProcess import Chat as ChatClass
|
|
import aiohttp
|
|
|
|
from src.utils import banusr
|
|
|
|
|
|
class MyModal(discord.ui.Modal):
|
|
def __init__(self, message):
|
|
super().__init__(title="Downvote")
|
|
self.add_item(
|
|
discord.ui.InputText(label="Reason", style=discord.InputTextStyle.long)
|
|
)
|
|
self.message = message
|
|
|
|
async def callback(self, interaction: discord.Interaction):
|
|
debug("Downvote sent !")
|
|
embed = discord.Embed(
|
|
title="Thanks for your feedback !",
|
|
description="Your downvote has been sent to the developers. Thanks for your help !",
|
|
color=discord.Color.og_blurple(),
|
|
)
|
|
embed.add_field(name="Message", value=self.children[0].value)
|
|
await interaction.response.send_message(embed=embed, ephemeral=True)
|
|
if webhook_url != "" and webhook_url != None:
|
|
session = aiohttp.ClientSession()
|
|
webhook = discord.Webhook.from_url(webhook_url, session=session)
|
|
embed = discord.Embed(
|
|
title="Downvote",
|
|
description=f"Downvote recieved!",
|
|
color=discord.Color.og_blurple(),
|
|
)
|
|
|
|
embed.add_field(name="Reason", value=self.children[0].value, inline=True)
|
|
embed.add_field(name="Author", value=interaction.user.mention, inline=True)
|
|
embed.add_field(
|
|
name="Channel", value=self.message.channel.name, inline=True
|
|
)
|
|
embed.add_field(name="Guild", value=self.message.guild.name, inline=True)
|
|
|
|
history = await self.message.channel.history(
|
|
limit=5, before=self.message
|
|
).flatten()
|
|
history.reverse()
|
|
|
|
users = []
|
|
fake_users = []
|
|
|
|
for user in history:
|
|
if user.author not in users:
|
|
# we anonimize the user, so user1, user2, user3, etc
|
|
fake_users.append(f"user{len(fake_users)+1}")
|
|
users.append(user.author)
|
|
|
|
if self.message.author not in users:
|
|
fake_users.append(f"user{len(fake_users)+1}")
|
|
users.append(self.message.author)
|
|
|
|
for msg in history:
|
|
uname = fake_users[users.index(msg.author)]
|
|
|
|
if len(msg.content) > 1023:
|
|
embed.add_field(
|
|
name=f"{uname} said", value=msg.content[:1023], inline=False
|
|
)
|
|
else:
|
|
embed.add_field(
|
|
name=f"{uname} said", value=msg.content, inline=False
|
|
)
|
|
|
|
uname = fake_users[users.index(self.message.author)]
|
|
embed.add_field(
|
|
name=f"{uname} said",
|
|
value="*" + self.message.content[:1021] + "*"
|
|
if len(self.message.content) > 1021
|
|
else "*"
|
|
+ self.message.content
|
|
+ "*", # [:1021] if len(self.message.content) > 1021,
|
|
inline=False,
|
|
)
|
|
await webhook.send(embed=embed)
|
|
else:
|
|
debug(
|
|
"Error while sending webhook, probably no webhook is set up in the .env file"
|
|
)
|
|
|
|
|
|
class Chat(discord.Cog):
|
|
def __init__(self, bot: discord.Bot):
|
|
super().__init__()
|
|
self.bot = bot
|
|
|
|
@discord.Cog.listener()
|
|
async def on_message(self, message: discord.Message):
|
|
if await self.bot.is_owner(message.author):
|
|
if message.content.startswith("botator!ban"):
|
|
user2ban = message.content.split(" ")[1]
|
|
await banusr.banuser(user2ban)
|
|
await message.channel.send(f"User {user2ban} banned !")
|
|
return
|
|
if message.content.startswith("botator!unban"):
|
|
user2ban = message.content.split(" ")[1]
|
|
await banusr.unbanuser(user2ban)
|
|
await message.chafnnel.send(f"User {user2ban} unbanned !")
|
|
return
|
|
if str(message.author.id) in banusr.banend_users:
|
|
await asyncio.sleep(2)
|
|
await message.channel.send(message.content)
|
|
return
|
|
if message.guild == None:
|
|
return
|
|
chatclass = ChatClass(self.bot, message)
|
|
await chatclass.process()
|
|
|
|
|
|
"""
|
|
@discord.slash_command(name="redo", description="Redo a message")
|
|
async def redo(self, ctx: discord.ApplicationContext):
|
|
history = await ctx.channel.history(limit=2).flatten()
|
|
message_to_delete = history[0]
|
|
message_to_redo = history[1]
|
|
if message_to_delete.author.id == self.bot.user.id:
|
|
await message_to_delete.delete()
|
|
else:
|
|
message_to_redo = history[0]
|
|
await ctx.respond("Message redone !", ephemeral=True)
|
|
await mp.chat_process(self, message_to_redo)
|
|
|
|
@discord.message_command(name="Downvote", description="Downvote a message")
|
|
@commands.cooldown(1, 60, commands.BucketType.user)
|
|
async def downvote(self, ctx: discord.ApplicationContext, message: discord.Message):
|
|
if message.author.id == self.bot.user.id:
|
|
modal = MyModal(message)
|
|
await ctx.send_modal(modal)
|
|
else:
|
|
await ctx.respond(
|
|
"You can't downvote a message that is not from me !", ephemeral=True
|
|
)
|
|
|
|
@downvote.error
|
|
async def downvote_error(self, ctx, error):
|
|
if isinstance(error, commands.CommandOnCooldown):
|
|
await ctx.respond("You are on cooldown !", ephemeral=True)
|
|
else:
|
|
debug(error)
|
|
raise error
|
|
"""
|