mirror of
https://gitlab.com/chicken-riders/RcGcDb.git
synced 2025-02-23 00:54:09 +00:00
Fix generic hook as well as behavior to use them and behavior when Discord rejects a message
This commit is contained in:
parent
e1c7d30b6f
commit
47c5aabd88
|
@ -7,17 +7,16 @@ from src.api.util import embed_helper, compact_author, sanitize_to_markdown
|
|||
|
||||
@formatter.embed(event="generic")
|
||||
def embed_generic(ctx: Context, change: dict):
|
||||
embed = DiscordMessage(ctx.message_type, ctx.event)
|
||||
embed = DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url)
|
||||
embed_helper(ctx, embed, change)
|
||||
embed["title"] = ctx._("Unknown event `{event}`").format(
|
||||
event="{type}/{action}".format(type=change.get("type", ""), action=change.get("action", "")))
|
||||
embed["title"] = ctx._("Unknown event `{event}`").format( event=ctx.event)
|
||||
embed["url"] = ctx.client.create_article_path("Special:RecentChanges")
|
||||
change_params = "{support}\n```json\n{params}\n```".format(params=json.dumps(change, indent=2),
|
||||
support=ctx.settings["support"])
|
||||
if len(change_params) > 1000:
|
||||
embed.add_field(_("Report this on the support server"), ctx.settings["support"])
|
||||
embed.add_field(ctx._("Report this on the support server"), ctx.settings["support"])
|
||||
else:
|
||||
embed.add_field(_("Report this on the support server"), change_params)
|
||||
embed.add_field(ctx._("Report this on the support server"), change_params)
|
||||
return embed
|
||||
|
||||
|
||||
|
@ -25,6 +24,5 @@ def embed_generic(ctx: Context, change: dict):
|
|||
def compact_generic(ctx: Context, change: dict):
|
||||
author, author_url = compact_author(ctx, change)
|
||||
content = ctx._("Unknown event `{event}` by [{author}]({author_url}), report it on the [support server](<{support}>).").format(
|
||||
event="{type}/{action}".format(type=change.get("type", ""), action=change.get("action", "")),
|
||||
author=author, support=ctx.settings["support"], author_url=author_url)
|
||||
return DiscordMessage(ctx.message_type, ctx.event, content=content)
|
||||
event=ctx.event, author=author, support=ctx.settings["support"], author_url=author_url)
|
||||
return DiscordMessage(ctx.message_type, ctx.event, ctx.webhook_url, content=content)
|
||||
|
|
|
@ -31,7 +31,8 @@ logger = logging.getLogger("src.api.util")
|
|||
|
||||
def default_message(event: str, display: str, formatter_hooks: dict) -> Callable:
|
||||
"""Returns a method of a formatter responsible for the event or None if such does not exist."""
|
||||
return formatter_hooks.get(display, {}).get(event, formatter_hooks.get("generic", formatter_hooks.get("no_formatter")))
|
||||
mode_hooks = formatter_hooks.get(display, {})
|
||||
return mode_hooks.get(event, mode_hooks.get("generic", mode_hooks.get("no_formatter")))
|
||||
|
||||
|
||||
def clean_link(link: str) -> str:
|
||||
|
|
|
@ -218,9 +218,11 @@ class MessageQueue:
|
|||
message.metadata.domain.register_message_timing_report(message.metadata.time_of_change)
|
||||
if message and message.metadata.domain is not None:
|
||||
message.metadata.domain.discord_message_registration()
|
||||
if status == 1:
|
||||
logger.debug(f"Ignoring message for {msg.wiki.script_url} because the returned status is 1.")
|
||||
if client_error is False:
|
||||
self.track_discord_error_rate(-0.2) # decay on successful sends
|
||||
if method == "POST":
|
||||
if method == "POST" and status != 1:
|
||||
msg.webhook = webhook_url
|
||||
msg.wiki.add_message(msg)
|
||||
for queue_message in messages[max(index-len(msg.message_list), 0):index+1]: # This likely breaks when there are messages from suspended webhooks awaiting sending and a new working webhook is added
|
||||
|
@ -268,7 +270,7 @@ async def handle_discord_http(code: int, formatted_embed: str, result: ClientRes
|
|||
"Following message has been rejected by Discord, please submit a bug on our bugtracker adding it:")
|
||||
logger.error(formatted_embed)
|
||||
logger.error(text)
|
||||
raise aiohttp.ClientError("Message rejected.")
|
||||
return 1
|
||||
elif code == 401 or code == 404: # HTTP UNAUTHORIZED AND NOT FOUND
|
||||
if result.method == "POST": # Ignore not found for DELETE and PATCH requests since the message could already be removed by admin
|
||||
logger.error("Webhook URL is invalid or no longer in use, please replace it with proper one.")
|
||||
|
|
Loading…
Reference in a new issue