From 8b95461fd7a43579108665a59e62b9cfa0ef737a Mon Sep 17 00:00:00 2001 From: MarkusRost <2701034-MarkusRost@users.noreply.gitlab.com> Date: Wed, 12 Oct 2022 13:41:22 +0200 Subject: [PATCH 1/3] Send welcome message (#259) --- settings.json.example | 1 + src/argparser.py | 1 + src/misc.py | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/settings.json.example b/settings.json.example index f2040e5..f9180d3 100644 --- a/settings.json.example +++ b/settings.json.example @@ -13,6 +13,7 @@ "avatars": { "connection_failed": "https://i.imgur.com/2jWQEt1.png", "connection_restored": "", + "welcome": "", "no_event": "", "embed": "", "compact": "" diff --git a/src/argparser.py b/src/argparser.py index 6bb0b96..728928b 100644 --- a/src/argparser.py +++ b/src/argparser.py @@ -17,6 +17,7 @@ import argparse parser = argparse.ArgumentParser(description="Start RcGcDw") parser.add_argument("--test", action='store_true', help="mode used for testing, sends only 5 entries of both rc and discussion changes and sends daily overview") +parser.add_argument("--nowelcome", action='store_true', help="don't send a welcome message when a new data file is created") parser.add_argument("--settings", default="settings.json", type=argparse.FileType(encoding='utf8'), help="provides a path to settings file (default ./settings.json)") command_args, unknown = parser.parse_known_args() diff --git a/src/misc.py b/src/misc.py index c744280..3abdac6 100644 --- a/src/misc.py +++ b/src/misc.py @@ -20,6 +20,7 @@ from html.parser import HTMLParser from urllib.parse import urlparse, urlunparse import requests +from src.argparser import command_args from src.configloader import settings import src.api.util from src.discord.message import DiscordMessage, DiscordMessageMetadata @@ -72,6 +73,9 @@ class DataFile: except FileNotFoundError: self.generate_datafile() misc_logger.info("The data file could not be found. Generating a new one...") + if not command_args.nowelcome: + send_simple("welcome", _("RcGcDw is now running and checking {wiki}.").format(wiki=settings["wikiname"]), + _("Welcome"), settings["avatars"].get("welcome", "")) return data_template def save_datafile(self): From a06b37656bb83a75ce3b0100ab6c7e8ab139dae7 Mon Sep 17 00:00:00 2001 From: MarkusRost <2701034-MarkusRost@users.noreply.gitlab.com> Date: Thu, 10 Nov 2022 14:42:20 +0100 Subject: [PATCH 2/3] add templateclassification/tc-changed --- extensions/base/datadump.py | 4 +- extensions/base/templateclassification.py | 47 +++++++++++++++++++++++ settings.json.example | 5 +++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 extensions/base/templateclassification.py diff --git a/extensions/base/datadump.py b/extensions/base/datadump.py index 6b30b37..7874db3 100644 --- a/extensions/base/datadump.py +++ b/extensions/base/datadump.py @@ -34,7 +34,7 @@ def embed_datadump_generate(ctx: Context, change: dict) -> DiscordMessage: return embed -@formatter.compact(event="mdatadump/generate") +@formatter.compact(event="datadump/generate") def compact_datadump_generate(ctx: Context, change: dict): author, author_url = compact_author(ctx, change) parsed_comment = compact_summary(ctx) @@ -56,7 +56,7 @@ def embed_datadump_delete(ctx: Context, change: dict) -> DiscordMessage: return embed -@formatter.compact(event="mdatadump/delete") +@formatter.compact(event="datadump/delete") def compact_datadump_delete(ctx: Context, change: dict) -> DiscordMessage: author, author_url = compact_author(ctx, change) parsed_comment = compact_summary(ctx) diff --git a/extensions/base/templateclassification.py b/extensions/base/templateclassification.py new file mode 100644 index 0000000..1b871ae --- /dev/null +++ b/extensions/base/templateclassification.py @@ -0,0 +1,47 @@ +# This file is part of Recent changes Goat compatible Discord webhook (RcGcDw). +# +# RcGcDw is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# RcGcDw is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with RcGcDw. If not, see . + + +import logging +from src.discord.message import DiscordMessage +from src.api import formatter +from src.api.context import Context +from src.api.util import embed_helper, compact_author, clean_link, sanitize_to_markdown, sanitize_to_url + + +# TemplateClassification - https://community.fandom.com/wiki/Help:Template_types +# templateclassification/tc-changed - Changing the type of a template + + +@formatter.embed(event="templateclassification/tc-changed") +def embed_templateclassification_changed(ctx: Context, change: dict) -> DiscordMessage: + embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url) + embed_helper(ctx, embed, change, set_desc=False) + embed["url"] = ctx.client.create_article_path(sanitize_to_url(change["title"])) + embed["title"] = ctx._("Changed the type of {article}").format(article=sanitize_to_markdown(change["title"])) + embed["description"] = ctx._("Type changed from {old} to {new}").format( + old=change["logparams"]["oldtype"], new=change["logparams"]["newtype"]) + return embed + + +@formatter.compact(event="templateclassification/tc-changed") +def compact_templateclassification_changed(ctx: Context, change: dict): + author, author_url = compact_author(ctx, change) + link = clean_link(ctx.client.create_article_path(sanitize_to_url(change["title"]))) + content = ctx._( + "[{author}]({author_url}) changed the type of [{article}]({article_url}) from {old} to {new}").format( + author=author, author_url=author_url, article=sanitize_to_markdown(change["title"]), article_url=link, + old=change["logparams"]["oldtype"], new=change["logparams"]["newtype"]) + return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content) diff --git a/settings.json.example b/settings.json.example index f2040e5..3d9dffd 100644 --- a/settings.json.example +++ b/settings.json.example @@ -511,6 +511,11 @@ "color": 8421504, "emoji": "📛" }, + "templateclassification/tc-changed": { + "icon": "", + "color": 8750469, + "emoji": "📱" + }, "suppressed": { "icon": "https://i.imgur.com/1gps6EZ.png", "color": 1, From 08734ce456b1af2661e39dd60a4592819d4f8cb4 Mon Sep 17 00:00:00 2001 From: MarkusRost <2701034-MarkusRost@users.noreply.gitlab.com> Date: Thu, 10 Nov 2022 15:39:29 +0100 Subject: [PATCH 3/3] move send_simple above DataFile --- src/misc.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/misc.py b/src/misc.py index 3abdac6..93a0df3 100644 --- a/src/misc.py +++ b/src/misc.py @@ -46,6 +46,14 @@ WIKI_JUST_DOMAIN: str = "" profile_fields = {"profile-location": _("Location"), "profile-aboutme": _("About me"), "profile-link-google": _("Google link"), "profile-link-facebook":_("Facebook link"), "profile-link-twitter": _("Twitter link"), "profile-link-reddit": _("Reddit link"), "profile-link-twitch": _("Twitch link"), "profile-link-psn": _("PSN link"), "profile-link-vk": _("VK link"), "profile-link-xbl": _("XBL link"), "profile-link-steam": _("Steam link"), "profile-link-discord": _("Discord handle"), "profile-link-battlenet": _("Battle.net handle")} +def send_simple(msgtype, message, name, avatar): + discord_msg = DiscordMessage("compact", msgtype, settings["webhookURL"], content=message) + discord_msg.set_avatar(avatar) + discord_msg.set_name(name) + messagequeue.resend_msgs() + send_to_discord(discord_msg, meta=DiscordMessageMetadata("POST")) + + class DataFile: """Data class which instance of is shared by multiple modules to remain consistent and do not cause too many IO operations.""" def __init__(self): @@ -307,14 +315,6 @@ def prepare_paths(path: str, dry=False): prepare_paths(settings["wiki_url"]) -def send_simple(msgtype, message, name, avatar): - discord_msg = DiscordMessage("compact", msgtype, settings["webhookURL"], content=message) - discord_msg.set_avatar(avatar) - discord_msg.set_name(name) - messagequeue.resend_msgs() - send_to_discord(discord_msg, meta=DiscordMessageMetadata("POST")) - - def run_hooks(hooks, *arguments): for hook in hooks: try: