moved scan to static
This commit is contained in:
@@ -49,7 +49,7 @@ class EmotesScanner(Scanner):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def compute_message(self, channel: ChannelLogs, message: MessageLog):
|
def compute_message(self, channel: ChannelLogs, message: MessageLog):
|
||||||
return analyse_message(
|
return EmotesScanner.analyse_message(
|
||||||
message, self.emotes, self.raw_members, all_emojis=self.all_emojis
|
message, self.emotes, self.raw_members, all_emojis=self.all_emojis
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -79,42 +79,39 @@ class EmotesScanner(Scanner):
|
|||||||
res[-1] += f" and {reaction_count:,} reactions"
|
res[-1] += f" and {reaction_count:,} reactions"
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
# ANALYSIS
|
def analyse_message(
|
||||||
|
message: MessageLog,
|
||||||
|
emotes: Dict[str, Emote],
|
||||||
def analyse_message(
|
raw_members: List[int],
|
||||||
message: MessageLog,
|
*,
|
||||||
emotes: Dict[str, Emote],
|
all_emojis: bool,
|
||||||
raw_members: List[int],
|
) -> bool:
|
||||||
*,
|
impacted = False
|
||||||
all_emojis: bool,
|
# If author is included in the selection (empty list is all)
|
||||||
) -> bool:
|
if not message.bot and (len(raw_members) == 0 or message.author in raw_members):
|
||||||
impacted = False
|
impacted = True
|
||||||
# If author is included in the selection (empty list is all)
|
# Find all emotes un the current message in the form "<:emoji:123456789>"
|
||||||
if not message.bot and (len(raw_members) == 0 or message.author in raw_members):
|
# Filter for known emotes
|
||||||
impacted = True
|
found = emojis.regex.findall(message.content)
|
||||||
# Find all emotes un the current message in the form "<:emoji:123456789>"
|
# For each emote, update its usage
|
||||||
# Filter for known emotes
|
for name in found:
|
||||||
found = emojis.regex.findall(message.content)
|
if name not in emotes:
|
||||||
# For each emote, update its usage
|
if not all_emojis or name not in emojis.unicode_list:
|
||||||
for name in found:
|
continue
|
||||||
|
emotes[name].usages += 1
|
||||||
|
emotes[name].update_use(message.created_at, [message.author])
|
||||||
|
# For each reaction of this message, test if known emote and update when it's the case
|
||||||
|
for name in message.reactions:
|
||||||
if name not in emotes:
|
if name not in emotes:
|
||||||
if not all_emojis or name not in emojis.unicode_list:
|
if not all_emojis or name not in emojis.unicode_list:
|
||||||
continue
|
continue
|
||||||
emotes[name].usages += 1
|
if len(raw_members) == 0:
|
||||||
emotes[name].update_use(message.created_at, [message.author])
|
emotes[name].reactions += len(message.reactions[name])
|
||||||
# For each reaction of this message, test if known emote and update when it's the case
|
emotes[name].update_use(message.created_at, message.reactions[name])
|
||||||
for name in message.reactions:
|
else:
|
||||||
if name not in emotes:
|
for member in raw_members:
|
||||||
if not all_emojis or name not in emojis.unicode_list:
|
if member in message.reactions[name]:
|
||||||
continue
|
emotes[name].reactions += 1
|
||||||
if len(raw_members) == 0:
|
emotes[name].update_use(message.created_at, [member])
|
||||||
emotes[name].reactions += len(message.reactions[name])
|
return impacted
|
||||||
emotes[name].update_use(message.created_at, message.reactions[name])
|
|
||||||
else:
|
|
||||||
for member in raw_members:
|
|
||||||
if member in message.reactions[name]:
|
|
||||||
emotes[name].reactions += 1
|
|
||||||
emotes[name].update_use(message.created_at, [member])
|
|
||||||
return impacted
|
|
||||||
|
|||||||
Reference in New Issue
Block a user