This commit is contained in:
Frisk 2021-05-19 16:27:01 +02:00
parent 8852cac7a3
commit 0a9c86cbef
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
5 changed files with 53 additions and 1 deletions

View file

@ -143,3 +143,9 @@ DiscordMessage consists of the following:
### Language support
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.
### Pre/post hooks
**Path**: `src.api.hook`
There are two decorator functions available in the module: `pre_hook` and `post_hook`. They don't take arguments and simply register the function as a hook.
Pre-hook functions take the following arguments: `context` ([Context object](#Context)) and `change` (dict object with change).
Post-hook functions take the following arguments: `message` ([Discord message object](#DiscordMessage)), `metadata` ([Discord message metadata](#DiscordMessageMetadata)) and `context` ([Context object](#Context))

View file

@ -13,4 +13,5 @@
# You should have received a copy of the GNU General Public License
# along with RcGcDw. If not, see <http://www.gnu.org/licenses/>.
import extensions.base
import extensions.base
import extensions.hooks

View file

@ -0,0 +1,16 @@
# 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/>.
import extensions.hooks.example_hook

View file

@ -0,0 +1,28 @@
# 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/>.
from src.api.hook import pre_hook, post_hook
@pre_hook
def example_pre_hook(context, change):
if context.event == "edit":
print("I'm an edit with {} bytes changed!".format(change.get("newlen", 0) - change.get("oldlen", 0)))
@post_hook
def example_post_hook(message, metadata, context):
print("Our Discord message looks as follows: ")
print(message)

View file

@ -58,6 +58,7 @@ def load_extensions():
importlib.import_module(settings.get('extensions_dir', 'extensions'), 'extensions')
except ImportError:
logger.critical("No extensions module found. What's going on?")
logger.exception("Error:")
sys.exit(1)
storage = datafile