This commit is contained in:
Frisk 2021-04-25 15:03:04 +02:00
parent 2b2eeaafba
commit 18aae9eabe
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
4 changed files with 27 additions and 12 deletions

View file

@ -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()

View file

@ -12,8 +12,7 @@
# You should have received a copy of the GNU General Public License
# along with RcGcDw. If not, see <http://www.gnu.org/licenses/>.
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

17
src/api/hooks.py Normal file
View file

@ -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 <http://www.gnu.org/licenses/>.
# Made just to avoid circular imports
formatter_hooks = {}

View file

@ -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():