mention => counter
This commit is contained in:
@@ -2,4 +2,4 @@ from .emote import Emote, get_emote_dict
|
|||||||
from .frequency import Frequency
|
from .frequency import Frequency
|
||||||
from .composition import Composition
|
from .composition import Composition
|
||||||
from .presence import Presence
|
from .presence import Presence
|
||||||
from .mention import Mention
|
from .counter import Counter
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from datetime import datetime
|
|||||||
from utils import plural, from_now, percent
|
from utils import plural, from_now, percent
|
||||||
|
|
||||||
|
|
||||||
class Mention:
|
class Counter:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.usages = 0
|
self.usages = 0
|
||||||
self.last_used = None
|
self.last_used = None
|
||||||
@@ -25,11 +25,7 @@ class Mention:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def to_string(
|
def to_string(
|
||||||
self,
|
self, i: int, name: str, *, total_usage: int, counted: str = "time"
|
||||||
i: int,
|
|
||||||
name: str,
|
|
||||||
*,
|
|
||||||
total_usage: int,
|
|
||||||
) -> str:
|
) -> str:
|
||||||
# place
|
# place
|
||||||
output = ""
|
output = ""
|
||||||
@@ -41,5 +37,5 @@ class Mention:
|
|||||||
output += ":third_place:"
|
output += ":third_place:"
|
||||||
else:
|
else:
|
||||||
output += f"**#{i + 1}**"
|
output += f"**#{i + 1}**"
|
||||||
output += f" {name} - {plural(self.usages, 'time')} ({percent(self.usages/total_usage)}) (last {from_now(self.last_used)})"
|
output += f" {name} - {plural(self.usages, counted)} ({percent(self.usages/total_usage)}) (last {from_now(self.last_used)})"
|
||||||
return output
|
return output
|
||||||
@@ -7,16 +7,8 @@ import discord
|
|||||||
|
|
||||||
from logs import ChannelLogs, MessageLog
|
from logs import ChannelLogs, MessageLog
|
||||||
from .scanner import Scanner
|
from .scanner import Scanner
|
||||||
from data_types import Mention
|
from data_types import Counter
|
||||||
from utils import (
|
from utils import COMMON_HELP_ARGS, plural, precise, mention, alt_mention
|
||||||
COMMON_HELP_ARGS,
|
|
||||||
plural,
|
|
||||||
precise,
|
|
||||||
mention,
|
|
||||||
alt_mention,
|
|
||||||
role_mention,
|
|
||||||
channel_mention,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class MentionedScanner(Scanner):
|
class MentionedScanner(Scanner):
|
||||||
@@ -55,7 +47,7 @@ class MentionedScanner(Scanner):
|
|||||||
return False
|
return False
|
||||||
self.all_mentions = "all" in args
|
self.all_mentions = "all" in args
|
||||||
# Create mentions dict
|
# Create mentions dict
|
||||||
self.mentions = defaultdict(Mention)
|
self.mentions = defaultdict(Counter)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def compute_message(self, channel: ChannelLogs, message: MessageLog):
|
def compute_message(self, channel: ChannelLogs, message: MessageLog):
|
||||||
@@ -86,7 +78,7 @@ class MentionedScanner(Scanner):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def analyse_message(
|
def analyse_message(
|
||||||
message: MessageLog,
|
message: MessageLog,
|
||||||
mentions: Dict[str, Mention],
|
mentions: Dict[str, Counter],
|
||||||
raw_members: List[int],
|
raw_members: List[int],
|
||||||
*,
|
*,
|
||||||
all_mentions: bool,
|
all_mentions: bool,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import discord
|
|||||||
|
|
||||||
from logs import ChannelLogs, MessageLog
|
from logs import ChannelLogs, MessageLog
|
||||||
from .scanner import Scanner
|
from .scanner import Scanner
|
||||||
from data_types import Mention
|
from data_types import Counter
|
||||||
from utils import (
|
from utils import (
|
||||||
COMMON_HELP_ARGS,
|
COMMON_HELP_ARGS,
|
||||||
plural,
|
plural,
|
||||||
@@ -51,7 +51,7 @@ class MentionsScanner(Scanner):
|
|||||||
# check other args
|
# check other args
|
||||||
self.all_mentions = "all" in args
|
self.all_mentions = "all" in args
|
||||||
# Create mentions dict
|
# Create mentions dict
|
||||||
self.mentions = defaultdict(Mention)
|
self.mentions = defaultdict(Counter)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def compute_message(self, channel: ChannelLogs, message: MessageLog):
|
def compute_message(self, channel: ChannelLogs, message: MessageLog):
|
||||||
@@ -82,7 +82,7 @@ class MentionsScanner(Scanner):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def analyse_message(
|
def analyse_message(
|
||||||
message: MessageLog,
|
message: MessageLog,
|
||||||
mentions: Dict[str, Mention],
|
mentions: Dict[str, Counter],
|
||||||
raw_members: List[int],
|
raw_members: List[int],
|
||||||
*,
|
*,
|
||||||
all_mentions: bool,
|
all_mentions: bool,
|
||||||
|
|||||||
Reference in New Issue
Block a user