factorized help and triple-quote multi-line

This commit is contained in:
Klemek
2021-04-09 15:34:03 +02:00
parent 5f903db929
commit b7a6f3313b
18 changed files with 134 additions and 185 deletions
+1 -1
View File
@@ -11,4 +11,4 @@ from .reactions_scanner import ReactionsScanner
from .first_scanner import FirstScanner
from .last_scanner import LastScanner
from .random_scanner import RandomScanner
from .words_scanner import WordsScanner
from .words_scanner import WordsScanner
+6 -10
View File
@@ -8,21 +8,17 @@ import discord
from logs import ChannelLogs, MessageLog
from .scanner import Scanner
from data_types import Counter
from utils import COMMON_HELP_ARGS, mention, channel_mention
from utils import generate_help, mention, channel_mention
class ChannelsScanner(Scanner):
@staticmethod
def help() -> str:
return (
"```\n"
+ "%chan: Rank channels by their messages\n"
+ "arguments:\n"
+ COMMON_HELP_ARGS
+ "* <n> - top <n>, default is 10\n"
+ "* all/everyone - include bots\n"
+ "Example: %chan 10 @user\n"
+ "```"
return generate_help(
"chan",
"Rank channels by their messages",
args=["<n> - top <n>, default is 10", "all/everyone - include bots"],
example="5 @user",
)
def __init__(self):
+2 -10
View File
@@ -8,21 +8,13 @@ import discord
from .scanner import Scanner
from data_types import Composition
from logs import ChannelLogs, MessageLog
from utils import emojis, COMMON_HELP_ARGS
from utils import emojis, generate_help
class CompositionScanner(Scanner):
@staticmethod
def help() -> str:
return (
"```\n"
+ "%compo: Show composition statistics\n"
+ "arguments:\n"
+ COMMON_HELP_ARGS
+ "* all/everyone - include bots\n"
+ "Example: %compo #mychannel1 @user\n"
+ "```"
)
return generate_help("compo", "Show composition statistics")
def __init__(self):
super().__init__(
+12 -13
View File
@@ -8,24 +8,23 @@ import discord
from logs import ChannelLogs, MessageLog
from data_types import Emote, get_emote_dict
from .scanner import Scanner
from utils import emojis, COMMON_HELP_ARGS, plural, precise
from utils import emojis, generate_help, plural, precise
class EmotesScanner(Scanner):
@staticmethod
def help() -> str:
return (
"```\n"
+ "%emojis: Rank emojis by their usage\n"
+ "arguments:\n"
+ COMMON_HELP_ARGS
+ "* <n> - top <n> emojis, default is 20\n"
+ "* all - list all common emojis in addition to this guild's\n"
+ "* members - show top member for each emojis\n"
+ "* sort:usage/reaction - other sorting methods\n"
+ "* everyone - include bots\n"
+ "Example: %emojis 10 all #mychannel1 #mychannel2 @user\n"
+ "```"
return generate_help(
"emojis",
"Rank emojis by their usage",
args=[
"<n> - top <n> emojis, default is 20",
"all - list all common emojis in addition to this guild's",
"members - show top member for each emojis",
"sort:usage/reaction - other sorting methods",
"everyone - include bots",
],
example="10 all #mychannel1 #mychannel2 @user",
)
def __init__(self):
+2 -3
View File
@@ -3,14 +3,13 @@ from typing import List
# Custom libs
from .history_scanner import HistoryScanner
from utils import generate_help
class FirstScanner(HistoryScanner):
@staticmethod
def help() -> str:
return super(FirstScanner, FirstScanner).help(
cmd="first", text="Read first message"
)
return generate_help("first", "Read first message")
def __init__(self):
super().__init__(help=FirstScanner.help())
+3 -11
View File
@@ -8,21 +8,13 @@ import discord
from .scanner import Scanner
from data_types import Frequency
from logs import ChannelLogs, MessageLog
from utils import COMMON_HELP_ARGS
from utils import generate_help
class FrequencyScanner(Scanner):
@staticmethod
def help() -> str:
return (
"```\n"
+ "%freq: Show frequency-related statistics\n"
+ "arguments:\n"
+ COMMON_HELP_ARGS
+ "* all/everyone - include bots\n"
+ "Example: %freq #mychannel1 @user\n"
+ "```"
)
return generate_help("freq", "Show frequency-related statistics")
def __init__(self):
super().__init__(
@@ -55,7 +47,7 @@ class FrequencyScanner(Scanner):
freq: Frequency,
raw_members: List[int],
*,
all_messages: bool
all_messages: bool,
) -> bool:
impacted = False
# If author is included in the selection (empty list is all)
+2 -10
View File
@@ -8,21 +8,13 @@ from .scanner import Scanner
from . import FrequencyScanner, CompositionScanner, PresenceScanner
from data_types import Frequency, Composition, Presence
from logs import ChannelLogs, MessageLog
from utils import COMMON_HELP_ARGS
from utils import generate_help
class FullScanner(Scanner):
@staticmethod
def help() -> str:
return (
"```\n"
+ "%scan: Show full statistics\n"
+ "arguments:\n"
+ COMMON_HELP_ARGS
+ "* all/everyone - include bots\n"
+ "Example: %scan #mychannel1 @user\n"
+ "```"
)
return generate_help("scan", "Show full statistics")
def __init__(self):
super().__init__(
-13
View File
@@ -7,22 +7,9 @@ import discord
from .scanner import Scanner
from data_types import History
from logs import ChannelLogs, MessageLog
from utils import COMMON_HELP_ARGS
class HistoryScanner(Scanner, ABC):
@staticmethod
def help(*, cmd: str, text: str) -> str:
return (
"```\n"
+ f"%{cmd}: {text}\n"
+ "arguments:\n"
+ COMMON_HELP_ARGS
+ "* all/everyone - include bots\n"
+ "Example: %{cmd} #mychannel1 @user\n"
+ "```"
)
def __init__(self, *, help: str):
super().__init__(
has_digit_args=True,
+2 -3
View File
@@ -3,14 +3,13 @@ from typing import List
# Custom libs
from .history_scanner import HistoryScanner
from utils import generate_help
class LastScanner(HistoryScanner):
@staticmethod
def help() -> str:
return super(LastScanner, LastScanner).help(
cmd="last", text="Read last message"
)
return generate_help("last", "Read last message")
def __init__(self):
super().__init__(help=LastScanner.help())
+8 -12
View File
@@ -8,22 +8,18 @@ import discord
from logs import ChannelLogs, MessageLog
from .scanner import Scanner
from data_types import Counter
from utils import COMMON_HELP_ARGS, plural, precise, mention, alt_mention
from utils import generate_help, plural, precise, mention, alt_mention
class MentionedScanner(Scanner):
@staticmethod
def help() -> str:
return (
"```\n"
+ "%mentioned: Rank specific user's mentions by their usage\n"
+ "arguments:\n"
+ "* @member/me - (required) one or more member\n"
+ "\n".join(COMMON_HELP_ARGS.split("\n")[1:])
+ "* <n> - top <n> mentions, default is 10\n"
+ "* all - include bots mentions\n"
+ "Example: %mentioned 10 @user\n"
+ "```"
return generate_help(
"mentioned",
"Rank specific user's mentions by their usage",
args=["<n> - top <n>, default is 10", "all/everyone - include bots"],
example="5 @user",
replace_args=[" @member/me - (required) one or more member"],
)
def __init__(self):
@@ -45,7 +41,7 @@ class MentionedScanner(Scanner):
"You need to mention at least one member or use `me`", reference=message
)
return False
self.all_mentions = "all" in args
self.all_mentions = "all" in args or "everyone" in args
# Create mentions dict
self.mentions = defaultdict(Counter)
return True
+10 -11
View File
@@ -9,7 +9,7 @@ from logs import ChannelLogs, MessageLog
from .scanner import Scanner
from data_types import Counter
from utils import (
COMMON_HELP_ARGS,
generate_help,
plural,
precise,
mention,
@@ -22,16 +22,15 @@ from utils import (
class MentionsScanner(Scanner):
@staticmethod
def help() -> str:
return (
"```\n"
+ "%mentions: Rank mentions by their usage\n"
+ "arguments:\n"
+ COMMON_HELP_ARGS
+ "* <n> - top <n> mentions, default is 10\n"
+ "* all - show role/channel/everyone/here mentions\n"
+ "* everyone - include bots mentions\n"
+ "Example: %mentions 10 #mychannel1 #mychannel2 @user\n"
+ "```"
return generate_help(
"mentions",
"Rank mentions by their usage",
args=[
"<n> - top <n>, default is 10",
"all - show role/channel/everyone/here mentions",
"everyone - include bots mentions",
],
example="10 #mychannel1 #mychannel2 @user",
)
def __init__(self):
+6 -10
View File
@@ -8,21 +8,17 @@ import discord
from logs import ChannelLogs, MessageLog
from .scanner import Scanner
from data_types import Counter
from utils import COMMON_HELP_ARGS, mention, channel_mention
from utils import generate_help, mention, channel_mention
class MessagesScanner(Scanner):
@staticmethod
def help() -> str:
return (
"```\n"
+ "%msg: Rank users by their messages\n"
+ "arguments:\n"
+ COMMON_HELP_ARGS
+ "* <n> - top <n>, default is 10\n"
+ "* all/everyone - include bots\n"
+ "Example: %msg 10 #channel\n"
+ "```"
return generate_help(
"msg",
"Rank users by their messages",
args=["<n> - top <n>, default is 10", "all/everyone - include bots"],
example="10 #channel",
)
def __init__(self):
+2 -10
View File
@@ -7,21 +7,13 @@ import discord
from .scanner import Scanner
from data_types import Presence
from logs import ChannelLogs, MessageLog
from utils import COMMON_HELP_ARGS
from utils import generate_help
class PresenceScanner(Scanner):
@staticmethod
def help() -> str:
return (
"```\n"
+ "%pres: Show presence statistics\n"
+ "arguments:\n"
+ COMMON_HELP_ARGS
+ "* all/everyone - include bots\n"
+ "Example: %pres #mychannel1 @user\n"
+ "```"
)
return generate_help("pres", "Show presence statistics")
def __init__(self):
super().__init__(
+2 -3
View File
@@ -3,14 +3,13 @@ from typing import List
# Custom libs
from .history_scanner import HistoryScanner
from utils import generate_help
class RandomScanner(HistoryScanner):
@staticmethod
def help() -> str:
return super(RandomScanner, RandomScanner).help(
cmd="rand", text="Read a random message"
)
return generate_help("rand", "Read a random message")
def __init__(self):
super().__init__(help=RandomScanner.help())
+6 -9
View File
@@ -8,20 +8,17 @@ import discord
from logs import ChannelLogs, MessageLog
from .scanner import Scanner
from data_types import Counter
from utils import COMMON_HELP_ARGS, mention, channel_mention
from utils import generate_help, mention, channel_mention
class ReactionsScanner(Scanner):
@staticmethod
def help() -> str:
return (
"```\n"
+ "%react: Rank users by their reactions\n"
+ "arguments:\n"
+ COMMON_HELP_ARGS
+ "* <n> - top <n>, default is 10\n"
+ "Example: %react 10 #channel\n"
+ "```"
return generate_help(
"react",
"Rank users by their reactions",
args=["<n> - top <n>, default is 10"],
example="10 #channel",
)
def __init__(self):
+10 -11
View File
@@ -9,7 +9,7 @@ from logs import ChannelLogs, MessageLog
from .scanner import Scanner
from data_types import Counter
from utils import (
COMMON_HELP_ARGS,
generate_help,
plural,
precise,
)
@@ -18,16 +18,15 @@ from utils import (
class WordsScanner(Scanner):
@staticmethod
def help() -> str:
return (
"```\n"
+ "%words: (BETA) Rank words by their usage\n"
+ "arguments:\n"
+ COMMON_HELP_ARGS
+ "* <n> - words containings <n> or more letters, default is 3\n"
+ "* <n2> - top <n2> words, default is 10\n"
+ "* everyone - include bots\n"
+ "Example: %words 5 10 #mychannel1 #mychannel2 @user\n"
+ "```"
return generate_help(
"words",
"(BETA) Rank words by their usage",
args=[
"<n> - words containings <n> or more letters, default is 3",
"<n2> - top <n2> words, default is 10",
"all/everyone - include bots",
],
example="5 10 #mychannel1 #mychannel2 @user",
)
def __init__(self):