A class allowing to change the raw event values obtained for a change via query.recentchanges endpoint on the wiki and/or execute additional actions each time given event gets read. This type of hook executes before a formatter.
Formatters allow specifying how does a Discord message look like depending on message mode (embed, compact) and type of the event that had happened on the wiki (new, edit etc).
If formatter for given event is not registered, the script will look for formatter for event "generic" and if this is also not found it will throw a warning.
A class allowing to change the message content and/or execute additional actions after message has been processed by the formatter. This type of hook executes after a formatter.
Directory with extensions is specified by setting `extensions_dir` in settings.json.
The directory with hooks and formatters needs to be below root directory (directory in which start.py is located) and every directory inside it needs to be a Python package importing its child packages and modules.
_Formatter module implements two decorators: `embed` and `compact`. Both of them can take the following keyword arguments:_
-`event` - string - event type for formatter, in case the event is a [log event](https://www.mediawiki.org/wiki/Manual:Log_actions) it's constructed by taking log_type and combining it with log_action with / character in between (for example `upload/overwrite`). If the event however is not a log event but action like edit, the type will consist only of `type` value.
-`aliases` - list[str] - list of strings containing all the events given event should alias for, it helps in case you want the same function be used for multiple event types.
Both `event` and `aliases` arguments are optional in formatters. However, every formatter needs to have some kind of event specified. If it's not specified in the decorator, a fallback method will be used which constructs event type in format `{func.__module__}/{func.__name__.split("_", 1)[1]}`, in other terms taking the name of the file in which formatter is defined as first part and entire function name after first _ character as second part. Note that this fallback works only for log events.
There are also additional, made up event types that are special cases, they are listed below:
-`abuselog`– reserved for AbuseFilter filter logs
-`discussion/{post_type.lower()}`– reserved for Fandom's Discussion/Feeds integration
-`suppressed`– reserved for logs that were [suppressed](https://www.mediawiki.org/wiki/Special:MyLanguage/Help:RevisionDelete) and cannot be read by the script
Formatter decorator registers a Python function and calls it each time a specific event is being processed from the wiki. Function is then called with Context and change arguments where context is [Context object](#Context) and change is a dict object containing the body of a change.
Every formatter **must** return a DiscordMessage object.
# embed_helper function can be used to automatically populate DiscordMessage object with some common useful information such as setting author name/url, adding fields for tags/categories, or setting default description
_Client is a class containing most of usable methods and communication layer with the core functionality._
Client consists of the following fields:
-`WIKI_API_PATH` - string - URL path leading to API (`WIKI_DOMAIN/api.php`)
-`WIKI_ARTICLE_PATH` - string - URL path leading to article path (`WIKI_DOMAIN/articlepath`)
-`WIKI_SCRIPT_PATH` - string - URL path leading to script path of the wiki (`WIKI_DOMAIN/`)
-`WIKI_JUST_DOMAIN` - string - URL path leading just to the wiki domain (`WIKI_DOMAIN`)
-`content_parser` - class - a reference to HTMLParser implementation that parses edit diffs
-`tags` - dict - a container storing all [tags](https://www.mediawiki.org/wiki/Manual:Tags) the wiki has configured
-`namespaces` - dict - a dictionary of [namespaces](https://www.mediawiki.org/wiki/Manual:Namespace) on the wiki
-`LinkParser` - class - a class of LinkParser which is usually used to parse parsed_comment from events including turning URLs into Markdown links
Client consists of the following methods:
-`refresh_internal_data()` - requests namespaces, tags and MediaWiki messages to be retrieved and updated in internal storage
-`parse_links(text: str)` - parses links using LinkParser object
-`pull_curseprofile_comment(comment_id: Union[str, int])` - allows retrieving CurseProfile comment from wikis originated from Gamepedia
-`make_api_request(params: Union[str, OrderedDict], *json_path: str, timeout: int = 10, allow_redirects: bool = False)` - allows to make a request to the wiki with parameters specified in params argument, json_path additionally allows to provide a list of strings that will be iterated over and json path of the result of this iteration returned. Timeout in float (seconds) can be added to limit the time for response, allow_redirects can be set to disallow or allow redirects
-`get_formatters()` - returns a dictionary of all formatters in format of `{'eventtype': func}`
-`get_ipmapper()` - returns ip mapper which tracks edit counts of IP editors
RcGcDw implements i18n with gettext and already exposes Translations instance with its `src.i18` module. formatters_i18n variable is used for instance of all formatters inside base directory.