mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
Merge branch 'horse-notifications' into 'testing'
Horse noticiations See merge request piotrex43/RcGcDw!90
This commit is contained in:
commit
6c1d786d19
37
extensions/hooks/usertalk.py
Normal file
37
extensions/hooks/usertalk.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
# 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 post_hook
|
||||
from src.configloader import settings
|
||||
|
||||
# {
|
||||
# "hooks": {
|
||||
# "usertalk": {
|
||||
# "USERNAME": "USERID"
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
discord_users = settings.get("hooks", {}).get("usertalk", {})
|
||||
|
||||
@post_hook
|
||||
def example_post_hook(message, metadata, context, change):
|
||||
if discord_users and change["ns"] in [2, 3, 202] and not "/" in change["title"]:
|
||||
username = change["title"].split(':', 1)[1]
|
||||
if discord_users.get(username, "") and username != change["user"]:
|
||||
message.webhook_object["content"] = (content or "") + " <@{}>".format(discord_users[username])
|
||||
if message.webhook_object["allowed_mentions"].get("users", []):
|
||||
message.webhook_object["allowed_mentions"]["users"].append(discord_users[username])
|
||||
else:
|
||||
message.webhook_object["allowed_mentions"]["users"] = [discord_users[username]]
|
|
@ -34,6 +34,7 @@ class DiscordMessage:
|
|||
content = settings["event_appearance"][event_type]["emoji"] + " " + content
|
||||
self.webhook_object["content"] = content
|
||||
|
||||
self.message_type = message_type
|
||||
self.event_type = event_type
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
|
@ -63,6 +64,8 @@ class DiscordMessage:
|
|||
self.__setup_embed()
|
||||
|
||||
def finish_embed(self):
|
||||
if self.message_type != "embed":
|
||||
return
|
||||
if self.embed["color"] is None:
|
||||
if settings["event_appearance"].get(self.event_type, {"color": None})["color"] is None:
|
||||
self.embed["color"] = random.randrange(1, 16777215)
|
||||
|
@ -110,4 +113,4 @@ class DiscordMessageMetadata:
|
|||
self.new_data = new_data
|
||||
|
||||
def dump_ids(self) -> (int, int, int):
|
||||
return self.page_id, self.rev_id, self.log_id
|
||||
return self.page_id, self.rev_id, self.log_id
|
||||
|
|
|
@ -21,6 +21,7 @@ from urllib.parse import urlparse, urlunparse
|
|||
import requests
|
||||
|
||||
from src.configloader import settings
|
||||
from src.api.util import sanitize_to_markdown
|
||||
from src.discord.message import DiscordMessage, DiscordMessageMetadata
|
||||
from src.discord.queue import messagequeue, send_to_discord
|
||||
from src.exceptions import MediaWikiError
|
||||
|
@ -344,13 +345,13 @@ class LinkParser(HTMLParser):
|
|||
|
||||
def handle_data(self, data):
|
||||
if self.recent_href:
|
||||
self.new_string = self.new_string + "[{}](<{}>)".format(data.replace("//", "/\\/"), self.recent_href)
|
||||
self.new_string = self.new_string + "[{}](<{}>)".format(sanitize_to_markdown(data), self.recent_href)
|
||||
self.recent_href = ""
|
||||
else:
|
||||
self.new_string = self.new_string + data.replace("//", "/\\/")
|
||||
self.new_string = self.new_string + sanitize_to_markdown(data)
|
||||
|
||||
def handle_comment(self, data):
|
||||
self.new_string = self.new_string + data.replace("//", "/\\/")
|
||||
self.new_string = self.new_string + sanitize_to_markdown(data)
|
||||
|
||||
def handle_endtag(self, tag):
|
||||
misc_logger.debug(self.new_string)
|
||||
|
|
|
@ -30,7 +30,7 @@ from src.api.context import Context
|
|||
from src.api.hooks import formatter_hooks, pre_hooks, post_hooks
|
||||
from src.configloader import settings
|
||||
from src.misc import add_to_dict, datafile, WIKI_API_PATH, LinkParser, run_hooks
|
||||
from src.api.util import create_article_path, default_message, sanitize_to_markdown
|
||||
from src.api.util import create_article_path, default_message
|
||||
from src.discord.queue import send_to_discord
|
||||
from src.discord.message import DiscordMessage, DiscordMessageMetadata
|
||||
from src.exceptions import MWError, ServerError, MediaWikiError, BadRequest, ClientError
|
||||
|
@ -210,7 +210,6 @@ def rc_processor(change, changed_categories):
|
|||
if "commenthidden" not in change:
|
||||
LinkParser.feed(change.get("parsedcomment", ""))
|
||||
parsed_comment = LinkParser.new_string
|
||||
parsed_comment = sanitize_to_markdown(parsed_comment)
|
||||
else:
|
||||
parsed_comment = _("~~hidden~~")
|
||||
if not parsed_comment and context.message_type == "embed" and settings["appearance"].get("embed", {}).get("show_no_description_provided", True):
|
||||
|
@ -257,6 +256,7 @@ def rc_processor(change, changed_categories):
|
|||
for revid in logparams.get("ids", []):
|
||||
delete_messages(dict(revid=revid))
|
||||
run_hooks(post_hooks, discord_message, metadata, context, change)
|
||||
discord_message.finish_embed()
|
||||
send_to_discord(discord_message, metadata)
|
||||
|
||||
|
||||
|
@ -270,6 +270,7 @@ def abuselog_processing(entry):
|
|||
discord_message: Optional[DiscordMessage] = default_message(action, formatter_hooks)(context, entry)
|
||||
metadata = DiscordMessageMetadata("POST")
|
||||
run_hooks(post_hooks, discord_message, metadata, context, entry)
|
||||
discord_message.finish_embed()
|
||||
send_to_discord(discord_message, metadata)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue