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
+6 -10
View File
@@ -8,21 +8,17 @@ import discord
from logs import ChannelLogs, MessageLog from logs import ChannelLogs, MessageLog
from .scanner import Scanner from .scanner import Scanner
from data_types import Counter 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): class ChannelsScanner(Scanner):
@staticmethod @staticmethod
def help() -> str: def help() -> str:
return ( return generate_help(
"```\n" "chan",
+ "%chan: Rank channels by their messages\n" "Rank channels by their messages",
+ "arguments:\n" args=["<n> - top <n>, default is 10", "all/everyone - include bots"],
+ COMMON_HELP_ARGS example="5 @user",
+ "* <n> - top <n>, default is 10\n"
+ "* all/everyone - include bots\n"
+ "Example: %chan 10 @user\n"
+ "```"
) )
def __init__(self): def __init__(self):
+2 -10
View File
@@ -8,21 +8,13 @@ import discord
from .scanner import Scanner from .scanner import Scanner
from data_types import Composition from data_types import Composition
from logs import ChannelLogs, MessageLog from logs import ChannelLogs, MessageLog
from utils import emojis, COMMON_HELP_ARGS from utils import emojis, generate_help
class CompositionScanner(Scanner): class CompositionScanner(Scanner):
@staticmethod @staticmethod
def help() -> str: def help() -> str:
return ( return generate_help("compo", "Show composition statistics")
"```\n"
+ "%compo: Show composition statistics\n"
+ "arguments:\n"
+ COMMON_HELP_ARGS
+ "* all/everyone - include bots\n"
+ "Example: %compo #mychannel1 @user\n"
+ "```"
)
def __init__(self): def __init__(self):
super().__init__( super().__init__(
+12 -13
View File
@@ -8,24 +8,23 @@ import discord
from logs import ChannelLogs, MessageLog from logs import ChannelLogs, MessageLog
from data_types import Emote, get_emote_dict from data_types import Emote, get_emote_dict
from .scanner import Scanner from .scanner import Scanner
from utils import emojis, COMMON_HELP_ARGS, plural, precise from utils import emojis, generate_help, plural, precise
class EmotesScanner(Scanner): class EmotesScanner(Scanner):
@staticmethod @staticmethod
def help() -> str: def help() -> str:
return ( return generate_help(
"```\n" "emojis",
+ "%emojis: Rank emojis by their usage\n" "Rank emojis by their usage",
+ "arguments:\n" args=[
+ COMMON_HELP_ARGS "<n> - top <n> emojis, default is 20",
+ "* <n> - top <n> emojis, default is 20\n" "all - list all common emojis in addition to this guild's",
+ "* all - list all common emojis in addition to this guild's\n" "members - show top member for each emojis",
+ "* members - show top member for each emojis\n" "sort:usage/reaction - other sorting methods",
+ "* sort:usage/reaction - other sorting methods\n" "everyone - include bots",
+ "* everyone - include bots\n" ],
+ "Example: %emojis 10 all #mychannel1 #mychannel2 @user\n" example="10 all #mychannel1 #mychannel2 @user",
+ "```"
) )
def __init__(self): def __init__(self):
+2 -3
View File
@@ -3,14 +3,13 @@ from typing import List
# Custom libs # Custom libs
from .history_scanner import HistoryScanner from .history_scanner import HistoryScanner
from utils import generate_help
class FirstScanner(HistoryScanner): class FirstScanner(HistoryScanner):
@staticmethod @staticmethod
def help() -> str: def help() -> str:
return super(FirstScanner, FirstScanner).help( return generate_help("first", "Read first message")
cmd="first", text="Read first message"
)
def __init__(self): def __init__(self):
super().__init__(help=FirstScanner.help()) super().__init__(help=FirstScanner.help())
+3 -11
View File
@@ -8,21 +8,13 @@ import discord
from .scanner import Scanner from .scanner import Scanner
from data_types import Frequency from data_types import Frequency
from logs import ChannelLogs, MessageLog from logs import ChannelLogs, MessageLog
from utils import COMMON_HELP_ARGS from utils import generate_help
class FrequencyScanner(Scanner): class FrequencyScanner(Scanner):
@staticmethod @staticmethod
def help() -> str: def help() -> str:
return ( return generate_help("freq", "Show frequency-related statistics")
"```\n"
+ "%freq: Show frequency-related statistics\n"
+ "arguments:\n"
+ COMMON_HELP_ARGS
+ "* all/everyone - include bots\n"
+ "Example: %freq #mychannel1 @user\n"
+ "```"
)
def __init__(self): def __init__(self):
super().__init__( super().__init__(
@@ -55,7 +47,7 @@ class FrequencyScanner(Scanner):
freq: Frequency, freq: Frequency,
raw_members: List[int], raw_members: List[int],
*, *,
all_messages: bool all_messages: bool,
) -> bool: ) -> bool:
impacted = False impacted = False
# If author is included in the selection (empty list is all) # 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 . import FrequencyScanner, CompositionScanner, PresenceScanner
from data_types import Frequency, Composition, Presence from data_types import Frequency, Composition, Presence
from logs import ChannelLogs, MessageLog from logs import ChannelLogs, MessageLog
from utils import COMMON_HELP_ARGS from utils import generate_help
class FullScanner(Scanner): class FullScanner(Scanner):
@staticmethod @staticmethod
def help() -> str: def help() -> str:
return ( return generate_help("scan", "Show full statistics")
"```\n"
+ "%scan: Show full statistics\n"
+ "arguments:\n"
+ COMMON_HELP_ARGS
+ "* all/everyone - include bots\n"
+ "Example: %scan #mychannel1 @user\n"
+ "```"
)
def __init__(self): def __init__(self):
super().__init__( super().__init__(
-13
View File
@@ -7,22 +7,9 @@ import discord
from .scanner import Scanner from .scanner import Scanner
from data_types import History from data_types import History
from logs import ChannelLogs, MessageLog from logs import ChannelLogs, MessageLog
from utils import COMMON_HELP_ARGS
class HistoryScanner(Scanner, ABC): 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): def __init__(self, *, help: str):
super().__init__( super().__init__(
has_digit_args=True, has_digit_args=True,
+2 -3
View File
@@ -3,14 +3,13 @@ from typing import List
# Custom libs # Custom libs
from .history_scanner import HistoryScanner from .history_scanner import HistoryScanner
from utils import generate_help
class LastScanner(HistoryScanner): class LastScanner(HistoryScanner):
@staticmethod @staticmethod
def help() -> str: def help() -> str:
return super(LastScanner, LastScanner).help( return generate_help("last", "Read last message")
cmd="last", text="Read last message"
)
def __init__(self): def __init__(self):
super().__init__(help=LastScanner.help()) super().__init__(help=LastScanner.help())
+8 -12
View File
@@ -8,22 +8,18 @@ import discord
from logs import ChannelLogs, MessageLog from logs import ChannelLogs, MessageLog
from .scanner import Scanner from .scanner import Scanner
from data_types import Counter 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): class MentionedScanner(Scanner):
@staticmethod @staticmethod
def help() -> str: def help() -> str:
return ( return generate_help(
"```\n" "mentioned",
+ "%mentioned: Rank specific user's mentions by their usage\n" "Rank specific user's mentions by their usage",
+ "arguments:\n" args=["<n> - top <n>, default is 10", "all/everyone - include bots"],
+ "* @member/me - (required) one or more member\n" example="5 @user",
+ "\n".join(COMMON_HELP_ARGS.split("\n")[1:]) replace_args=[" @member/me - (required) one or more member"],
+ "* <n> - top <n> mentions, default is 10\n"
+ "* all - include bots mentions\n"
+ "Example: %mentioned 10 @user\n"
+ "```"
) )
def __init__(self): def __init__(self):
@@ -45,7 +41,7 @@ class MentionedScanner(Scanner):
"You need to mention at least one member or use `me`", reference=message "You need to mention at least one member or use `me`", reference=message
) )
return False return False
self.all_mentions = "all" in args self.all_mentions = "all" in args or "everyone" in args
# Create mentions dict # Create mentions dict
self.mentions = defaultdict(Counter) self.mentions = defaultdict(Counter)
return True return True
+10 -11
View File
@@ -9,7 +9,7 @@ from logs import ChannelLogs, MessageLog
from .scanner import Scanner from .scanner import Scanner
from data_types import Counter from data_types import Counter
from utils import ( from utils import (
COMMON_HELP_ARGS, generate_help,
plural, plural,
precise, precise,
mention, mention,
@@ -22,16 +22,15 @@ from utils import (
class MentionsScanner(Scanner): class MentionsScanner(Scanner):
@staticmethod @staticmethod
def help() -> str: def help() -> str:
return ( return generate_help(
"```\n" "mentions",
+ "%mentions: Rank mentions by their usage\n" "Rank mentions by their usage",
+ "arguments:\n" args=[
+ COMMON_HELP_ARGS "<n> - top <n>, default is 10",
+ "* <n> - top <n> mentions, default is 10\n" "all - show role/channel/everyone/here mentions",
+ "* all - show role/channel/everyone/here mentions\n" "everyone - include bots mentions",
+ "* everyone - include bots mentions\n" ],
+ "Example: %mentions 10 #mychannel1 #mychannel2 @user\n" example="10 #mychannel1 #mychannel2 @user",
+ "```"
) )
def __init__(self): def __init__(self):
+6 -10
View File
@@ -8,21 +8,17 @@ import discord
from logs import ChannelLogs, MessageLog from logs import ChannelLogs, MessageLog
from .scanner import Scanner from .scanner import Scanner
from data_types import Counter 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): class MessagesScanner(Scanner):
@staticmethod @staticmethod
def help() -> str: def help() -> str:
return ( return generate_help(
"```\n" "msg",
+ "%msg: Rank users by their messages\n" "Rank users by their messages",
+ "arguments:\n" args=["<n> - top <n>, default is 10", "all/everyone - include bots"],
+ COMMON_HELP_ARGS example="10 #channel",
+ "* <n> - top <n>, default is 10\n"
+ "* all/everyone - include bots\n"
+ "Example: %msg 10 #channel\n"
+ "```"
) )
def __init__(self): def __init__(self):
+2 -10
View File
@@ -7,21 +7,13 @@ import discord
from .scanner import Scanner from .scanner import Scanner
from data_types import Presence from data_types import Presence
from logs import ChannelLogs, MessageLog from logs import ChannelLogs, MessageLog
from utils import COMMON_HELP_ARGS from utils import generate_help
class PresenceScanner(Scanner): class PresenceScanner(Scanner):
@staticmethod @staticmethod
def help() -> str: def help() -> str:
return ( return generate_help("pres", "Show presence statistics")
"```\n"
+ "%pres: Show presence statistics\n"
+ "arguments:\n"
+ COMMON_HELP_ARGS
+ "* all/everyone - include bots\n"
+ "Example: %pres #mychannel1 @user\n"
+ "```"
)
def __init__(self): def __init__(self):
super().__init__( super().__init__(
+2 -3
View File
@@ -3,14 +3,13 @@ from typing import List
# Custom libs # Custom libs
from .history_scanner import HistoryScanner from .history_scanner import HistoryScanner
from utils import generate_help
class RandomScanner(HistoryScanner): class RandomScanner(HistoryScanner):
@staticmethod @staticmethod
def help() -> str: def help() -> str:
return super(RandomScanner, RandomScanner).help( return generate_help("rand", "Read a random message")
cmd="rand", text="Read a random message"
)
def __init__(self): def __init__(self):
super().__init__(help=RandomScanner.help()) super().__init__(help=RandomScanner.help())
+6 -9
View File
@@ -8,20 +8,17 @@ import discord
from logs import ChannelLogs, MessageLog from logs import ChannelLogs, MessageLog
from .scanner import Scanner from .scanner import Scanner
from data_types import Counter 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): class ReactionsScanner(Scanner):
@staticmethod @staticmethod
def help() -> str: def help() -> str:
return ( return generate_help(
"```\n" "react",
+ "%react: Rank users by their reactions\n" "Rank users by their reactions",
+ "arguments:\n" args=["<n> - top <n>, default is 10"],
+ COMMON_HELP_ARGS example="10 #channel",
+ "* <n> - top <n>, default is 10\n"
+ "Example: %react 10 #channel\n"
+ "```"
) )
def __init__(self): def __init__(self):
+10 -11
View File
@@ -9,7 +9,7 @@ from logs import ChannelLogs, MessageLog
from .scanner import Scanner from .scanner import Scanner
from data_types import Counter from data_types import Counter
from utils import ( from utils import (
COMMON_HELP_ARGS, generate_help,
plural, plural,
precise, precise,
) )
@@ -18,16 +18,15 @@ from utils import (
class WordsScanner(Scanner): class WordsScanner(Scanner):
@staticmethod @staticmethod
def help() -> str: def help() -> str:
return ( return generate_help(
"```\n" "words",
+ "%words: (BETA) Rank words by their usage\n" "(BETA) Rank words by their usage",
+ "arguments:\n" args=[
+ COMMON_HELP_ARGS "<n> - words containings <n> or more letters, default is 3",
+ "* <n> - words containings <n> or more letters, default is 3\n" "<n2> - top <n2> words, default is 10",
+ "* <n2> - top <n2> words, default is 10\n" "all/everyone - include bots",
+ "* everyone - include bots\n" ],
+ "Example: %words 5 10 #mychannel1 #mychannel2 @user\n" example="5 10 #mychannel1 #mychannel2 @user",
+ "```"
) )
def __init__(self): def __init__(self):
+35 -38
View File
@@ -3,45 +3,42 @@ import discord
from logs import GuildLogs from logs import GuildLogs
HELP = ( HELP = """```
"```\n" %gdpr: Displays GDPR information
+ "%gdpr: Displays GDPR information\n" arguments:
+ "arguments:\n" * agree - agree to GDPR
+ "* agree - agree to GDPR\n" * revoke - remove this server's data
+ "* revoke - remove this server's data\n" ```"""
+ "```"
)
TEXT = ( TEXT = """
"" __**About Analyst-bot's data usage**__
+ "__**About Analyst-bot's data usage**__\n" **TL;DR**
+ "**TL;DR**\n" Analyst-bot collects text message information. It does not share collected data with any third-party and data is retained 18 months or until the bot is leaving the guild/server.
+ "Analyst-bot collects text message information. It does not share collected data with any third-party and data is retained 12 months or until the bot is leaving the guild/server.\n" **Data collection**
+ "**Data collection**\n" Analyst-bot collects a Discord guild/server's history when asked to.
+ "Analyst-bot collects a Discord guild/server's history when asked to.\n" This includes:
+ "This includes:\n" - Visible text channel names
+ "- Visible text channel names\n" - Visible text messages: date and time of creation and edition, author, content, reactions and other available metadata (pinned, tts, etc.)
+ "- Visible text messages: date and time of creation and edition, author, content, reactions and other available metadata (pinned, tts, etc.)\n" This does __not__ includes:
+ "This does __not__ includes:\n" - Voice channels and not visible channels
+ "- Voice channels and not visible channels\n" - Not visible text messages
+ "- Not visible text messages\n" - Visible text messages' embedded content, images and other attachments
+ "- Visible text messages' embedded content, images and other attachments\n" **Data processing**
+ "**Data processing**\n" Any data collected is only processed in order to produce a one-time report sent to the user immediately. No temporary data are retained.
+ "Any data collected is only processed in order to produce a one-time report sent to the user immediately. No temporary data are retained.\n" **Data storage and retain policy**
+ "**Data storage and retain policy**\n" Analyst-bot stores the collected data in files that are accessible by the software and its administrator only.
+ "Analyst-bot stores the collected data in files that are accessible by the software and its administrator only.\n" Any collected data are retained maximum 18 months until deletion or when the bot is leaving a guild/server.
+ "Any collected data are retained maximum 12 months until deletion or when the bot is leaving a guild/server.\n" **Data sharing**
+ "**Data sharing**\n" Analyst-bot does not share the data collected with any third-party.
+ "Analyst-bot does not share the data collected with any third-party.\n" **Right to retract**
+ "**Right to retract**\n" If you want to have your data removed, you can use the `%gdpr revoke` command or remove this bot from your guild/server.
+ "If you want to have your data removed, you can use the `%gdpr revoke` command or remove this bot from your guild/server.\n" **Terms agreement**
+ "**Terms agreement**\n" By agreeing to these terms, you ensure having the legal age if you are in a country that does have one and you also ensure having the consent of every member involved.
+ "By agreeing to these terms, you ensure having the legal age if you are in a country that does have one and you also ensure having the consent of every member involved.\n"
+ "\n" *If you want more information, please contact the creator of this bot: <https://github.com/Klemek/discord-analyst>.*
+ "*If you want more information, please contact the creator of this bot: <https://github.com/Klemek/discord-analyst>.*\n"
+ "\n" Type `%gdpr agree` to agree to these terms, `%gdpr revoke` to remove this guild/server's collected data or `%gdpr` to see this message again.
+ "Type `%gdpr agree` to agree to these terms, `%gdpr revoke` to remove this guild/server's collected data or `%gdpr` to see this message again." """
)
AGREE_TEXT = "Thanks for agreeing for these terms, you can now run analysis on this guild/server." AGREE_TEXT = "Thanks for agreeing for these terms, you can now run analysis on this guild/server."
+25 -7
View File
@@ -7,13 +7,31 @@ from datetime import datetime
# OTHER # OTHER
COMMON_HELP_ARGS = ( COMMON_HELP_ARGS = [
"" "@member/me - filter for one or more member",
+ "* @member/me - filter for one or more member\n" "#channel/here - filter for one or more channel",
+ "* #channel/here - filter for one or more channel\n" "fast - only read cache",
+ "* fast - only read cache\n" "fresh - does not read cache (long)",
+ "* fresh - does not read cache (long)\n" ]
)
def generate_help(
cmd: str,
info: str,
*,
args=["all/everyone - include bots"],
example="#mychannel1 @user",
replace_args=[],
):
arg_list = "* " + "\n* ".join(
replace_args + COMMON_HELP_ARGS[len(replace_args) :] + args
)
return f"""```
%{cmd}: {info}
arguments:
{arg_list}
Example: %{cmd} {example}
```"""
def delta(t0: datetime): def delta(t0: datetime):