reworked presence to get rid of useless emote analysis
This commit is contained in:
@@ -33,41 +33,28 @@ class FullScanner(Scanner):
|
||||
async def init(self, message: discord.Message, *args: str) -> bool:
|
||||
guild = message.channel.guild
|
||||
self.freq = Frequency()
|
||||
self.comp = Composition()
|
||||
self.compo = Composition()
|
||||
self.pres = Presence()
|
||||
self.member_specific = len(self.members) > 0
|
||||
# Create emotes dict from custom emojis of the guild
|
||||
self.emotes = get_emote_dict(message.channel.guild)
|
||||
self.total_msg = 0
|
||||
if self.member_specific:
|
||||
self.emotes_all = get_emote_dict(message.channel.guild)
|
||||
else:
|
||||
self.emotes_all = {}
|
||||
return True
|
||||
|
||||
def compute_message(self, channel: ChannelLogs, message: MessageLog):
|
||||
self.total_msg += 1
|
||||
FrequencyScanner.analyse_message(message, self.freq, self.raw_members)
|
||||
CompositionScanner.analyse_message(message, self.comp, self.raw_members)
|
||||
CompositionScanner.analyse_message(message, self.compo, self.raw_members)
|
||||
PresenceScanner.analyse_message(channel, message, self.pres, self.raw_members)
|
||||
EmotesScanner.analyse_message(
|
||||
message, self.emotes, self.raw_members, all_emojis=True
|
||||
)
|
||||
if self.member_specific:
|
||||
EmotesScanner.analyse_message(message, self.emotes_all, [], all_emojis=True)
|
||||
return not message.bot and (
|
||||
len(self.raw_members) == 0 or message.author in self.raw_members
|
||||
)
|
||||
|
||||
def get_results(self, intro: str) -> List[str]:
|
||||
FrequencyScanner.compute_results(self.freq)
|
||||
CompositionScanner.compute_results(self.comp, self.emotes)
|
||||
PresenceScanner.compute_results(self.pres, self.emotes, self.emotes_all)
|
||||
res = [intro]
|
||||
res += ["__Frequency__:"]
|
||||
res += self.freq.to_string()
|
||||
res += ["__Composition__:"]
|
||||
res += self.comp.to_string(self.msg_count)
|
||||
res += self.compo.to_string(self.msg_count)
|
||||
res += ["__Presence__:"]
|
||||
res += self.pres.to_string(
|
||||
self.msg_count,
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
from typing import List, Dict
|
||||
from typing import List
|
||||
import discord
|
||||
|
||||
|
||||
# Custom libs
|
||||
|
||||
from .scanner import Scanner
|
||||
from . import EmotesScanner
|
||||
from data_types import Presence, Emote, get_emote_dict
|
||||
from data_types import Presence
|
||||
from logs import ChannelLogs, MessageLog
|
||||
from utils import COMMON_HELP_ARGS
|
||||
|
||||
@@ -33,27 +32,15 @@ class PresenceScanner(Scanner):
|
||||
self.pres = Presence()
|
||||
self.total_msg = 0
|
||||
self.member_specific = len(self.members) > 0
|
||||
# Create emotes dict from custom emojis of the guild
|
||||
self.emotes = get_emote_dict(message.channel.guild)
|
||||
if self.member_specific:
|
||||
self.emotes_all = get_emote_dict(message.channel.guild)
|
||||
else:
|
||||
self.emotes_all = {}
|
||||
return True
|
||||
|
||||
def compute_message(self, channel: ChannelLogs, message: MessageLog):
|
||||
self.total_msg += 1
|
||||
EmotesScanner.analyse_message(
|
||||
message, self.emotes, self.raw_members, all_emojis=True
|
||||
)
|
||||
if self.member_specific:
|
||||
EmotesScanner.analyse_message(message, self.emotes_all, [], all_emojis=True)
|
||||
return PresenceScanner.analyse_message(
|
||||
channel, message, self.pres, self.raw_members
|
||||
)
|
||||
|
||||
def get_results(self, intro: str) -> List[str]:
|
||||
PresenceScanner.compute_results(self.pres, self.emotes, self.emotes_all)
|
||||
res = [intro]
|
||||
res += self.pres.to_string(
|
||||
self.msg_count,
|
||||
@@ -75,29 +62,22 @@ class PresenceScanner(Scanner):
|
||||
if not message.bot and (len(raw_members) == 0 or message.author in raw_members):
|
||||
impacted = True
|
||||
pres.channel_usage[channel.id] += 1
|
||||
pres.msg_count += 1
|
||||
for mention in message.mentions:
|
||||
pres.mention_others[mention] += 1
|
||||
pres.channel_total[channel.id] += 1
|
||||
for mention in message.mentions:
|
||||
if mention in raw_members:
|
||||
pres.mentions[message.author] += 1
|
||||
pres.mention_count += 1
|
||||
if len(raw_members) > 0:
|
||||
for mention in message.mentions:
|
||||
if mention in raw_members:
|
||||
pres.mentions[message.author] += 1
|
||||
pres.mention_count += 1
|
||||
for reaction in message.reactions:
|
||||
pres.used_reaction_total += len(message.reactions[reaction])
|
||||
for member_id in message.reactions[reaction]:
|
||||
if member_id in raw_members:
|
||||
pres.reactions[reaction] += 1
|
||||
else:
|
||||
pres.mention_count += len(message.mentions)
|
||||
for reaction in message.reactions:
|
||||
pres.used_reaction_total += len(message.reactions[reaction])
|
||||
pres.reactions[reaction] += len(message.reactions[reaction])
|
||||
return impacted
|
||||
|
||||
@staticmethod
|
||||
def compute_results(
|
||||
pres: Presence, emotes: Dict[str, Emote], emotes_all: Dict[str, Emote]
|
||||
):
|
||||
# calculate total reactions
|
||||
pres.used_reaction_total = sum([emote.reactions for emote in emotes.values()])
|
||||
if len(emotes_all) > 0:
|
||||
pres.used_reaction_all_total = sum(
|
||||
[emote.reactions for emote in emotes_all.values()]
|
||||
)
|
||||
if pres.used_reaction_total > 0:
|
||||
# calculate most used reaction
|
||||
pres.most_used_reaction = sorted(emotes, key=lambda k: emotes[k].reactions)[
|
||||
-1
|
||||
]
|
||||
pres.most_used_reaction_count = emotes[pres.most_used_reaction].reactions
|
||||
|
||||
Reference in New Issue
Block a user