mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Mod] [p]filter: Performance improvements (#1233)
This commit is contained in:
parent
d1df453a75
commit
6acc43c8ff
16
cogs/mod.py
16
cogs/mod.py
@ -4,7 +4,7 @@ from .utils.dataIO import dataIO
|
|||||||
from .utils import checks
|
from .utils import checks
|
||||||
from __main__ import send_cmd_help, settings
|
from __main__ import send_cmd_help, settings
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from collections import deque, defaultdict
|
from collections import deque, defaultdict, OrderedDict
|
||||||
from cogs.utils.chat_formatting import escape_mass_mentions, box, pagify
|
from cogs.utils.chat_formatting import escape_mass_mentions, box, pagify
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -100,7 +100,7 @@ class Mod:
|
|||||||
self.past_nicknames = dataIO.load_json("data/mod/past_nicknames.json")
|
self.past_nicknames = dataIO.load_json("data/mod/past_nicknames.json")
|
||||||
settings = dataIO.load_json("data/mod/settings.json")
|
settings = dataIO.load_json("data/mod/settings.json")
|
||||||
self.settings = defaultdict(lambda: default_settings.copy(), settings)
|
self.settings = defaultdict(lambda: default_settings.copy(), settings)
|
||||||
self.cache = defaultdict(lambda: deque(maxlen=3))
|
self.cache = OrderedDict()
|
||||||
self.cases = dataIO.load_json("data/mod/modlog.json")
|
self.cases = dataIO.load_json("data/mod/modlog.json")
|
||||||
self.last_case = defaultdict(dict)
|
self.last_case = defaultdict(dict)
|
||||||
self.temp_cache = TempCache(bot)
|
self.temp_cache = TempCache(bot)
|
||||||
@ -1516,10 +1516,14 @@ class Mod:
|
|||||||
if self.settings[server.id]["delete_repeats"]:
|
if self.settings[server.id]["delete_repeats"]:
|
||||||
if not message.content:
|
if not message.content:
|
||||||
return False
|
return False
|
||||||
self.cache[author].append(message)
|
if author.id not in self.cache:
|
||||||
msgs = self.cache[author]
|
self.cache[author.id] = deque(maxlen=3)
|
||||||
if len(msgs) == 3 and \
|
self.cache.move_to_end(author.id)
|
||||||
msgs[0].content == msgs[1].content == msgs[2].content:
|
while len(self.cache) > 100000:
|
||||||
|
self.cache.popitem(last=False) # the oldest gets discarded
|
||||||
|
self.cache[author.id].append(message.content)
|
||||||
|
msgs = self.cache[author.id]
|
||||||
|
if len(msgs) == 3 and msgs[0] == msgs[1] == msgs[2]:
|
||||||
try:
|
try:
|
||||||
await self.bot.delete_message(message)
|
await self.bot.delete_message(message)
|
||||||
return True
|
return True
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user