mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
Added more type hints
This commit is contained in:
parent
8d1935bea6
commit
bcdaef8bcf
|
@ -12,7 +12,10 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with RcGcDw. If not, see <http://www.gnu.org/licenses/>.
|
# along with RcGcDw. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from src.api.context import Context
|
||||||
|
from src.discord.message import DiscordMessage, DiscordMessageMetadata
|
||||||
from src.api.hook import post_hook
|
from src.api.hook import post_hook
|
||||||
from src.configloader import settings
|
from src.configloader import settings
|
||||||
|
|
||||||
|
@ -32,29 +35,32 @@ from src.configloader import settings
|
||||||
# }
|
# }
|
||||||
action_buttons = settings.get("hooks", {}).get("buttons", {})
|
action_buttons = settings.get("hooks", {}).get("buttons", {})
|
||||||
|
|
||||||
def add_button(message, custom_id, label, style=2, emoji=None):
|
|
||||||
|
def add_button(message: DiscordMessage, custom_id: str, label, style=2, emoji: Optional[dict] = None):
|
||||||
if len(custom_id) > 100 or not len(label):
|
if len(custom_id) > 100 or not len(label):
|
||||||
return
|
return
|
||||||
if "components" not in message.webhook_object:
|
if "components" not in message.webhook_object:
|
||||||
message.webhook_object["components"] = [{"type": 1, "components": []}]
|
message.webhook_object["components"] = [{"type": 1, "components": []}]
|
||||||
if len(message.webhook_object["components"][-1]["components"]) >= 5:
|
if len(message.webhook_object["components"][-1]["components"]) >= 5:
|
||||||
message.webhook_object["components"].append({"type": 1, "components": []})
|
message.webhook_object["components"].append({"type": 1, "components": []})
|
||||||
message.webhook_object["components"][-1]["components"].append({"type": 2, "custom_id": custom_id, "style": style, "label": label, "emoji": emoji})
|
message.webhook_object["components"][-1]["components"].append(
|
||||||
|
{"type": 2, "custom_id": custom_id, "style": style, "label": label, "emoji": emoji})
|
||||||
|
|
||||||
|
|
||||||
@post_hook
|
@post_hook
|
||||||
def buttons_hook(message, metadata, context, change):
|
def buttons_hook(message: DiscordMessage, metadata: DiscordMessageMetadata, context: Context, change: dict):
|
||||||
if not len(action_buttons) or context.feed_type == "discussion":
|
if not len(action_buttons) or context.feed_type == "discussion":
|
||||||
return
|
return
|
||||||
BUTTON_PREFIX = context.client.WIKI_SCRIPT_PATH[len(context.client.WIKI_JUST_DOMAIN):]
|
BUTTON_PREFIX = context.client.WIKI_SCRIPT_PATH[len(context.client.WIKI_JUST_DOMAIN):]
|
||||||
if "block" in action_buttons and context.event != "suppressed":
|
if "block" in action_buttons and context.event != "suppressed":
|
||||||
add_button(message, BUTTON_PREFIX + " block " + ( "#" + str(change["userid"]) if change["userid"] else change["user"] ),
|
add_button(message,
|
||||||
action_buttons["block"], 4, {"id": None, "name": "🚧"})
|
BUTTON_PREFIX + " block " + ("#" + str(change["userid"]) if change["userid"] else change["user"]),
|
||||||
|
action_buttons["block"], 4, {"id": None, "name": "🚧"})
|
||||||
if context.feed_type != "recentchanges":
|
if context.feed_type != "recentchanges":
|
||||||
return
|
return
|
||||||
if "delete" in action_buttons and context.event in ("new", "upload/upload"):
|
if "delete" in action_buttons and context.event in ("new", "upload/upload"):
|
||||||
add_button(message, BUTTON_PREFIX + " delete " + str(change["pageid"]),
|
add_button(message, BUTTON_PREFIX + " delete " + str(change["pageid"]),
|
||||||
action_buttons["delete"], 4, {"id": None, "name": "🗑️"})
|
action_buttons["delete"], 4, {"id": None, "name": "🗑️"})
|
||||||
# if "filerevert" in action_buttons and context.event in ("upload/overwrite", "upload/revert"):
|
# if "filerevert" in action_buttons and context.event in ("upload/overwrite", "upload/revert"):
|
||||||
# add_button(message, BUTTON_PREFIX + " file " + str(change["pageid"]) + " " + revision["archivename"].split("!")[0],
|
# add_button(message, BUTTON_PREFIX + " file " + str(change["pageid"]) + " " + revision["archivename"].split("!")[0],
|
||||||
# action_buttons["filerevert"], 2, {"id": None, "name": "🔂"})
|
# action_buttons["filerevert"], 2, {"id": None, "name": "🔂"})
|
||||||
|
@ -64,8 +70,9 @@ def buttons_hook(message, metadata, context, change):
|
||||||
if context.event != "edit":
|
if context.event != "edit":
|
||||||
return
|
return
|
||||||
if "rollback" in action_buttons:
|
if "rollback" in action_buttons:
|
||||||
add_button(message, BUTTON_PREFIX + " rollback " + str(change["pageid"]) + " " + ( "#" + str(change["userid"]) if change["userid"] else change["user"] ),
|
add_button(message, BUTTON_PREFIX + " rollback " + str(change["pageid"]) + " " + (
|
||||||
action_buttons["rollback"], 1, {"id": None, "name": "🔁"})
|
"#" + str(change["userid"]) if change["userid"] else change["user"]),
|
||||||
|
action_buttons["rollback"], 1, {"id": None, "name": "🔁"})
|
||||||
if "undo" in action_buttons:
|
if "undo" in action_buttons:
|
||||||
add_button(message, BUTTON_PREFIX + " undo " + str(change["pageid"]) + " " + str(change["revid"]),
|
add_button(message, BUTTON_PREFIX + " undo " + str(change["pageid"]) + " " + str(change["revid"]),
|
||||||
action_buttons["undo"], 2, {"id": None, "name": "🔂"})
|
action_buttons["undo"], 2, {"id": None, "name": "🔂"})
|
||||||
|
|
|
@ -12,17 +12,18 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with RcGcDw. If not, see <http://www.gnu.org/licenses/>.
|
# along with RcGcDw. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
from src.api.context import Context
|
||||||
|
from src.discord.message import DiscordMessage, DiscordMessageMetadata
|
||||||
from src.api.hook import pre_hook, post_hook
|
from src.api.hook import pre_hook, post_hook
|
||||||
|
|
||||||
|
|
||||||
@pre_hook
|
@pre_hook
|
||||||
def example_pre_hook(context, change):
|
def example_pre_hook(context: Context, change: dict):
|
||||||
if context.event == "edit":
|
if context.event == "edit":
|
||||||
print("I'm an edit with {} bytes changed!".format(change.get("newlen", 0) - change.get("oldlen", 0)))
|
print("I'm an edit with {} bytes changed!".format(change.get("newlen", 0) - change.get("oldlen", 0)))
|
||||||
|
|
||||||
|
|
||||||
@post_hook
|
@post_hook
|
||||||
def example_post_hook(message, metadata, context, change):
|
def example_post_hook(message: DiscordMessage, metadata: DiscordMessageMetadata, context: Context, change: dict):
|
||||||
print("Our Discord message looks as follows: ")
|
print("Our Discord message looks as follows: ")
|
||||||
print(message)
|
print(message)
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with RcGcDw. If not, see <http://www.gnu.org/licenses/>.
|
# along with RcGcDw. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
from src.api.context import Context
|
||||||
|
from src.discord.message import DiscordMessage, DiscordMessageMetadata
|
||||||
from src.api.hook import post_hook
|
from src.api.hook import post_hook
|
||||||
from src.configloader import settings
|
from src.configloader import settings
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ def add_mention(message, userid):
|
||||||
message.webhook_object["allowed_mentions"]["users"] = [userid]
|
message.webhook_object["allowed_mentions"]["users"] = [userid]
|
||||||
|
|
||||||
@post_hook
|
@post_hook
|
||||||
def usertalk_hook(message, metadata, context, change):
|
def usertalk_hook(message: DiscordMessage, metadata: DiscordMessageMetadata, context: Context, change: dict):
|
||||||
if not discord_users:
|
if not discord_users:
|
||||||
return
|
return
|
||||||
if context.feed_type in ["recentchanges", "abuselog"] and change["ns"] in [2, 3, 202, 1200] and "/" not in change["title"]:
|
if context.feed_type in ["recentchanges", "abuselog"] and change["ns"] in [2, 3, 202, 1200] and "/" not in change["title"]:
|
||||||
|
|
Loading…
Reference in a new issue