From 18aae9eabeb781eb5a4b9b48c5e0a7e2b40c00bb Mon Sep 17 00:00:00 2001 From: Frisk Date: Sun, 25 Apr 2021 15:03:04 +0200 Subject: [PATCH] Fixes --- extensions/base/mediawiki.py | 4 ++-- src/api/formatter.py | 13 ++++++------- src/api/hooks.py | 17 +++++++++++++++++ src/rcgcdw.py | 5 ++--- 4 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 src/api/hooks.py diff --git a/extensions/base/mediawiki.py b/extensions/base/mediawiki.py index 50d6ecc..9dfdd7e 100644 --- a/extensions/base/mediawiki.py +++ b/extensions/base/mediawiki.py @@ -94,6 +94,6 @@ class base(): logger.warning("Unable to download data on the edit content!") return embed - @formatter.compact(event="edit", mode="embed") - def compact_edit(self, change: dict): + @formatter.compact(event="edit", mode="compact") + def compact_edit(self, ctx: Context, change: dict): return DiscordMessage() diff --git a/src/api/formatter.py b/src/api/formatter.py index 318a4f8..36c3dd3 100644 --- a/src/api/formatter.py +++ b/src/api/formatter.py @@ -12,8 +12,7 @@ # You should have received a copy of the GNU General Public License # along with RcGcDw. If not, see . - -import src.rcgcdw +import src.api.hooks import logging from src.configloader import settings from src.exceptions import FormatterBreaksAPISpec @@ -37,11 +36,11 @@ def _register_formatter(func: Callable[[dict], DiscordMessage], kwargs: dict[str if action_type is None: raise FormatterBreaksAPISpec("event type") if settings["appearance"]["mode"] == formatter_type: - if action_type in src.rcgcdw.formatter_hooks: + if action_type in src.api.hooks.formatter_hooks: logger.warning(f"Action {action_type} is already defined inside of " - f"{src.rcgcdw.formatter_hooks[action_type].__module__}! " + f"{src.api.hooks.formatter_hooks[action_type].__module__}! " f"Overwriting it with one from {func.__module__}") - src.rcgcdw.formatter_hooks[action_type] = func + src.api.hooks.formatter_hooks[action_type] = func def embed(**kwargs): @@ -59,7 +58,7 @@ def embed(**kwargs): return decorator_cont -def compact(func: Callable[[dict], DiscordMessage], **kwargs): +def compact(**kwargs): """ Decorator to register a formatter are return a function @@ -72,4 +71,4 @@ def compact(func: Callable[[dict], DiscordMessage], **kwargs): _register_formatter(func, kwargs, "compact") return func - return decorator_cont \ No newline at end of file + return decorator_cont diff --git a/src/api/hooks.py b/src/api/hooks.py new file mode 100644 index 0000000..5c7157e --- /dev/null +++ b/src/api/hooks.py @@ -0,0 +1,17 @@ +# 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 . + +# Made just to avoid circular imports +formatter_hooks = {} diff --git a/src/rcgcdw.py b/src/rcgcdw.py index f3da4d7..08f77a4 100644 --- a/src/rcgcdw.py +++ b/src/rcgcdw.py @@ -19,7 +19,7 @@ # WARNING! SHITTY CODE AHEAD. ENTER ONLY IF YOU ARE SURE YOU CAN TAKE IT # You have been warned -import time, logging.config, requests, datetime, gettext, math, os.path, schedule, sys, re +import time, logging.config, requests, datetime, math, os.path, schedule, sys, re import src.misc from collections import defaultdict, Counter @@ -27,6 +27,7 @@ from collections import defaultdict, Counter from typing import Optional import src.api.client from src.api.context import Context +from src.api.hooks import formatter_hooks from src.configloader import settings from src.misc import add_to_dict, datafile, \ WIKI_API_PATH @@ -44,13 +45,11 @@ if settings["fandom_discussions"]["enabled"]: import src.discussions TESTING = True if "--test" in sys.argv else False # debug mode, pipeline testing -formatter_hooks = {} # Prepare logging logging.config.dictConfig(settings["logging"]) logger = logging.getLogger("rcgcdw") logger.debug("Current settings: {settings}".format(settings=settings)) -from src.migrations import * # migrations after logging def load_extensions():