mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-22 00:14:10 +00:00
added #210
This commit is contained in:
parent
8852cac7a3
commit
0a9c86cbef
|
@ -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))
|
|
@ -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
|
16
extensions/hooks/__init__.py
Normal file
16
extensions/hooks/__init__.py
Normal 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
|
28
extensions/hooks/example_hook.py
Normal file
28
extensions/hooks/example_hook.py
Normal 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)
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue