RcGcDw/extensions/hooks/example_hook.py

47 lines
1.8 KiB
Python
Raw Permalink Normal View History

2021-05-19 14:27:01 +00:00
# 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/>.
2023-09-16 18:23:03 +00:00
from src.api.context import Context
from src.discord.message import DiscordMessage, DiscordMessageMetadata
2021-05-19 14:27:01 +00:00
from src.api.hook import pre_hook, post_hook
@pre_hook
2023-09-16 18:23:03 +00:00
def example_pre_hook(context: Context, change: dict):
2021-05-19 14:27:01 +00:00
if context.event == "edit":
print("I'm an edit with {} bytes changed!".format(change.get("newlen", 0) - change.get("oldlen", 0)))
@post_hook
2023-09-16 18:23:03 +00:00
def example_post_hook(message: DiscordMessage, metadata: DiscordMessageMetadata, context: Context, change: dict):
2021-05-19 14:27:01 +00:00
print("Our Discord message looks as follows: ")
print(message)
def verify_upload(context: Context, change: dict) -> bool:
return hasattr(context, "event") and context.event.startswith("upload")
@pre_hook(priority=105, condition=verify_upload)
def example_pre_hook_with_args(context: Context, change: dict):
print("I'm an upload! Also I'm using a fancy decorator!")
def never_register_this_one(settings):
return False
@pre_hook(priority=2, register=never_register_this_one)
def example_pre_hook_that_will_never_register(context: Context, change: dict):
print("EVIL THINGS HAPPENING IN HERE MUHAHHAHAHHA")