Close #81, wrote custom caching in on_member_update to handle duplicates
This commit is contained in:
parent
5587bce34b
commit
f701cc9655
2 changed files with 17 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from discord import Intents
|
from discord import Intents
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
@ -19,15 +20,18 @@ intents = Intents.default()
|
||||||
intents.members = True
|
intents.members = True
|
||||||
restart_ctx = None
|
restart_ctx = None
|
||||||
|
|
||||||
|
jconfig = get_config()
|
||||||
|
|
||||||
jarvis = commands.Bot(
|
jarvis = commands.Bot(
|
||||||
command_prefix=utils.get_prefix, intents=intents, help_command=None
|
command_prefix=utils.get_prefix,
|
||||||
|
intents=intents,
|
||||||
|
help_command=None,
|
||||||
|
max_messages=jconfig.max_messages,
|
||||||
)
|
)
|
||||||
|
|
||||||
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
|
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
|
||||||
jarvis_self = Process()
|
jarvis_self = Process()
|
||||||
__version__ = "1.10.2"
|
__version__ = "1.10.3"
|
||||||
|
|
||||||
jconfig = get_config()
|
|
||||||
|
|
||||||
|
|
||||||
@jarvis.event
|
@jarvis.event
|
||||||
|
|
|
@ -15,6 +15,7 @@ from jarvis.utils.field import Field
|
||||||
class ModlogMemberCog(commands.Cog):
|
class ModlogMemberCog(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
self.cache = []
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_member_ban(self, guild: discord.Guild, user: discord.User):
|
async def on_member_ban(self, guild: discord.Guild, user: discord.User):
|
||||||
|
@ -89,7 +90,7 @@ class ModlogMemberCog(commands.Cog):
|
||||||
await channel.send(embed=embed)
|
await channel.send(embed=embed)
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_member_remove(self, user: discord.User):
|
async def on_member_remove(self, user: discord.Member):
|
||||||
modlog = Setting.objects(guild=user.guild.id, setting="modlog").first()
|
modlog = Setting.objects(guild=user.guild.id, setting="modlog").first()
|
||||||
if modlog:
|
if modlog:
|
||||||
channel = user.guild.get_channel(modlog.value)
|
channel = user.guild.get_channel(modlog.value)
|
||||||
|
@ -243,8 +244,13 @@ class ModlogMemberCog(commands.Cog):
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_member_update(
|
async def on_member_update(
|
||||||
self, before: discord.User, after: discord.User
|
self, before: discord.Member, after: discord.Member
|
||||||
):
|
):
|
||||||
|
h = hash(hash(before) * hash(after))
|
||||||
|
if h not in self.cache:
|
||||||
|
self.cache.append(h)
|
||||||
|
else:
|
||||||
|
return
|
||||||
modlog = Setting.objects(
|
modlog = Setting.objects(
|
||||||
guild=before.guild.id, setting="modlog"
|
guild=before.guild.id, setting="modlog"
|
||||||
).first()
|
).first()
|
||||||
|
@ -335,3 +341,4 @@ class ModlogMemberCog(commands.Cog):
|
||||||
embed = await self.process_rolechange(before, after)
|
embed = await self.process_rolechange(before, after)
|
||||||
if embed:
|
if embed:
|
||||||
await channel.send(embed=embed)
|
await channel.send(embed=embed)
|
||||||
|
self.cache.remove(h)
|
||||||
|
|
Loading…
Add table
Reference in a new issue