Snipe, fixes #43

This commit is contained in:
Stijn De Clercq 2021-06-22 00:36:22 +02:00
parent ce1e2e7272
commit 01266b1346
6 changed files with 117 additions and 10 deletions

View file

@ -1,4 +1,5 @@
from data import constants
from data.snipe import Snipe, Action
import datetime
import discord
from discord.ext import commands
@ -6,14 +7,15 @@ from functions import checks, easterEggResponses
from functions.database import stats, muttn, custom_commands, commands as command_stats
import pytz
from settings import READY_MESSAGE, SANDBOX, STATUS_MESSAGE
from startup.didier import Didier
import time
import traceback
class Events(commands.Cog):
def __init__(self, client):
self.client = client
def __init__(self, client: Didier):
self.client: Didier = client
self.utilsCog = self.client.get_cog("Utils")
self.failedChecksCog = self.client.get_cog("FailedChecks")
self.lastFeatureRequest = 0
@ -263,7 +265,7 @@ class Events(commands.Cog):
await msg.add_reaction("")
@commands.Cog.listener()
async def on_message_edit(self, before, after):
async def on_message_edit(self, before: discord.Message, after: discord.Message):
"""
Function called when a message is edited,
so people can't edit messages in FreeGames to cheat the system.
@ -272,7 +274,17 @@ class Events(commands.Cog):
"""
# Run the message through the checks again
if not checks.freeGamesCheck(after):
await self.failedChecksCog.freeGames(after)
return await self.failedChecksCog.freeGames(after)
if before.guild is not None and not before.author.bot:
self.client.snipe[before.channel.id] = Snipe(before.author.id, before.channel.id, before.guild.id, Action.Edit,
before.content, after.content)
@commands.Cog.listener()
async def on_message_delete(self, message: discord.Message):
if message.guild is not None and not message.author.bot:
self.client.snipe[message.channel.id] = Snipe(message.author.id, message.channel.id, message.guild.id,
Action.Remove, message.content)
async def sendErrorEmbed(self, ctx, error: Exception, trace):
"""

View file

@ -1,18 +1,23 @@
from discord.ext import commands
from data.embeds.snipe import EditSnipe, DeleteSnipe
from data.menus import custom_commands
from data.snipe import Action, Snipe
from decorators import help
from enums.help_categories import Category
from functions.database.custom_commands import get_all
from functions.stringFormatters import capitalize
from startup.didier import Didier
class Other(commands.Cog):
def __init__(self, client):
self.client = client
def __init__(self, client: Didier):
self.client: Didier = client
# Don't allow any commands to work when locked
def cog_check(self, ctx):
return not self.client.locked
# TODO add locked field to Didier instead of client
# # Don't allow any commands to work when locked
# def cog_check(self, ctx):
# return not self.client.locked
@commands.command(name="Custom")
@help.Category(category=Category.Didier)
@ -25,6 +30,25 @@ class Other(commands.Cog):
src = custom_commands.CommandsList(formatted)
await custom_commands.Pages(source=src, clear_reactions_after=True).start(ctx)
@commands.command(name="Snipe")
@help.Category(category=Category.Other)
async def snipe(self, ctx):
"""
Shame people for editing & removing messages.
The dict is stored in memory so it will be cleared whenever the bot restarts.
"""
if ctx.guild is None:
return
if ctx.channel.id not in self.client.snipe:
return await ctx.send("Er is hier niemand om uit te lachen.")
s: Snipe = self.client.snipe[ctx.channel.id]
embed_class = (EditSnipe(s) if s.action == Action.Edit else DeleteSnipe(s))
return await ctx.send(embed=embed_class.to_embed(self.client))
def setup(client):
client.add_cog(Other(client))