Other => Presence
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from .emote import Emote, get_emote_dict
|
||||
from .frequency import Frequency
|
||||
from .composition import Composition
|
||||
from .other import Other
|
||||
from .presence import Presence
|
||||
|
||||
@@ -5,7 +5,7 @@ from collections import defaultdict
|
||||
from utils import mention, channel_mention, plural
|
||||
|
||||
|
||||
class Other:
|
||||
class Presence:
|
||||
def __init__(self):
|
||||
self.most_used_reaction = ""
|
||||
self.most_used_reaction_count = 0
|
||||
+5
-5
@@ -7,7 +7,7 @@ from scanners import (
|
||||
FullScanner,
|
||||
FrequencyScanner,
|
||||
CompositionScanner,
|
||||
OtherScanner,
|
||||
PresenceScanner,
|
||||
)
|
||||
|
||||
logging.basicConfig(
|
||||
@@ -26,10 +26,10 @@ bot.log_calls = True
|
||||
bot.client.bot = bot # TODO place in miniscord
|
||||
|
||||
bot.register_command(
|
||||
"other",
|
||||
lambda *args: OtherScanner().compute(*args),
|
||||
"other: other data analysis",
|
||||
OtherScanner.help(),
|
||||
"pres(ence)?",
|
||||
lambda *args: PresenceScanner().compute(*args),
|
||||
"pres: presence analysis",
|
||||
PresenceScanner.help(),
|
||||
)
|
||||
bot.register_command(
|
||||
"emotes",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from .emotes_scanner import EmotesScanner
|
||||
from .frequency_scanner import FrequencyScanner
|
||||
from .composition_scanner import CompositionScanner
|
||||
from .other_scanner import OtherScanner
|
||||
from .presence_scanner import PresenceScanner
|
||||
from .full_scanner import FullScanner
|
||||
|
||||
@@ -6,8 +6,8 @@ import discord
|
||||
# Custom libs
|
||||
|
||||
from .scanner import Scanner
|
||||
from . import FrequencyScanner, CompositionScanner, OtherScanner, EmotesScanner
|
||||
from data_types import Frequency, Composition, Other, Emote, get_emote_dict
|
||||
from . import FrequencyScanner, CompositionScanner, PresenceScanner, EmotesScanner
|
||||
from data_types import Frequency, Composition, Presence, Emote, get_emote_dict
|
||||
from logs import ChannelLogs, MessageLog
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class FullScanner(Scanner):
|
||||
guild = message.channel.guild
|
||||
self.freq = Frequency()
|
||||
self.comp = Composition()
|
||||
self.other = Other()
|
||||
self.pres = Presence()
|
||||
# Create emotes dict from custom emojis of the guild
|
||||
# Create emotes dict from custom emojis of the guild
|
||||
self.emotes = get_emote_dict(message.channel.guild)
|
||||
@@ -41,7 +41,7 @@ class FullScanner(Scanner):
|
||||
def compute_message(self, channel: ChannelLogs, message: MessageLog):
|
||||
FrequencyScanner.analyse_message(message, self.freq, self.raw_members)
|
||||
CompositionScanner.analyse_message(message, self.comp, self.raw_members)
|
||||
OtherScanner.analyse_message(channel, message, self.other, 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
|
||||
)
|
||||
@@ -52,14 +52,14 @@ class FullScanner(Scanner):
|
||||
def get_results(self, intro: str) -> List[str]:
|
||||
FrequencyScanner.compute_results(self.freq)
|
||||
CompositionScanner.compute_results(self.comp, self.emotes)
|
||||
OtherScanner.compute_results(self.other, self.emotes)
|
||||
PresenceScanner.compute_results(self.pres, self.emotes)
|
||||
res = [intro]
|
||||
res += ["__Frequency__:"]
|
||||
res += self.freq.to_string()
|
||||
res += ["__Composition__:"]
|
||||
res += self.comp.to_string()
|
||||
res += ["__Other__:"]
|
||||
res += self.other.to_string(
|
||||
res += ["__Presence__:"]
|
||||
res += self.pres.to_string(
|
||||
show_top_channel=len(self.channels) > 1,
|
||||
show_mentioned=(len(self.members) > 0),
|
||||
)
|
||||
|
||||
@@ -6,29 +6,29 @@ import discord
|
||||
|
||||
from .scanner import Scanner
|
||||
from . import EmotesScanner
|
||||
from data_types import Other, Emote, get_emote_dict
|
||||
from data_types import Presence, Emote, get_emote_dict
|
||||
from logs import ChannelLogs, MessageLog
|
||||
|
||||
|
||||
class OtherScanner(Scanner):
|
||||
class PresenceScanner(Scanner):
|
||||
@staticmethod
|
||||
def help() -> str:
|
||||
return "```\n"
|
||||
+"%other : Show other statistics\n"
|
||||
+"%pres : Show presence statistics\n"
|
||||
+"arguments:\n"
|
||||
+"* @member/me : filter for one or more member\n"
|
||||
+"* #channel/here : filter for one or more channel\n"
|
||||
+"Example: %other #mychannel1 @user\n"
|
||||
+"Example: %pres #mychannel1 @user\n"
|
||||
+"```"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
help=OtherScanner.help(),
|
||||
intro_context="Other data",
|
||||
help=PresenceScanner.help(),
|
||||
intro_context="Presence",
|
||||
)
|
||||
|
||||
async def init(self, message: discord.Message, *args: str) -> bool:
|
||||
self.other = Other()
|
||||
self.pres = Presence()
|
||||
# Create emotes dict from custom emojis of the guild
|
||||
self.emotes = get_emote_dict(message.channel.guild)
|
||||
return True
|
||||
@@ -37,40 +37,43 @@ class OtherScanner(Scanner):
|
||||
EmotesScanner.analyse_message(
|
||||
message, self.emotes, self.raw_members, all_emojis=True
|
||||
)
|
||||
return OtherScanner.analyse_message(
|
||||
channel, message, self.other, self.raw_members
|
||||
return PresenceScanner.analyse_message(
|
||||
channel, message, self.pres, self.raw_members
|
||||
)
|
||||
|
||||
def get_results(self, intro: str) -> List[str]:
|
||||
OtherScanner.compute_results(self.other, self.emotes)
|
||||
PresenceScanner.compute_results(self.pres, self.emotes)
|
||||
res = [intro]
|
||||
res += self.other.to_string(
|
||||
show_top_channel=len(self.channels) > 1,
|
||||
res += self.pres.to_string(
|
||||
show_top_channel=(len(self.channels) > 1),
|
||||
show_mentioned=(len(self.members) > 0),
|
||||
)
|
||||
return res
|
||||
|
||||
@staticmethod
|
||||
def analyse_message(
|
||||
channel: ChannelLogs, message: MessageLog, other: Other, raw_members: List[int]
|
||||
channel: ChannelLogs,
|
||||
message: MessageLog,
|
||||
pres: Presence,
|
||||
raw_members: List[int],
|
||||
) -> bool:
|
||||
impacted = False
|
||||
# If author is included in the selection (empty list is all)
|
||||
if not message.bot and (len(raw_members) == 0 or message.author in raw_members):
|
||||
impacted = True
|
||||
other.channel_usage[channel.id] += 1
|
||||
pres.channel_usage[channel.id] += 1
|
||||
for mention in message.mentions:
|
||||
if mention in raw_members:
|
||||
other.mentions[mention] += 1
|
||||
pres.mentions[mention] += 1
|
||||
return impacted
|
||||
|
||||
@staticmethod
|
||||
def compute_results(other: Other, emotes: Dict[str, Emote]):
|
||||
def compute_results(pres: Presence, emotes: Dict[str, Emote]):
|
||||
# calculate total reactions
|
||||
other.used_reaction_total = sum([emote.reactions for emote in emotes.values()])
|
||||
if other.used_reaction_total > 0:
|
||||
pres.used_reaction_total = sum([emote.reactions for emote in emotes.values()])
|
||||
if pres.used_reaction_total > 0:
|
||||
# calculate most used reaction
|
||||
other.most_used_reaction = sorted(
|
||||
emotes, key=lambda k: emotes[k].reactions
|
||||
)[-1]
|
||||
other.most_used_reaction_count = emotes[other.most_used_reaction].reactions
|
||||
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