Resolved TODO with sending a removal reason to the webhook

This commit is contained in:
Frisk 2024-09-10 11:19:02 +02:00
parent fab76d7355
commit 56f6ef1887

View file

@ -13,7 +13,7 @@ import requests
from src.api.util import default_message
from src.misc import prepare_settings, run_hooks
from src.discord.queue import messagequeue, QueueEntry
from src.discord.queue import messagequeue, QueueEntry, send_to_discord_webhook
from src.mw_messages import MWMessages
from src.exceptions import *
from src.queue_handler import dbmanager
@ -496,8 +496,20 @@ class Wiki:
async def remove_webhook_from_db(self, webhook_url: str, reason: str, send_reason=False):
logger.info(f"Removing a webhook with ID of {webhook_url.split('/')[0]} from the database due to {reason}.")
# TODO Write a reason for removal to a webhook if send_reason
dbmanager.add(("DELETE FROM rcgcdb WHERE webhook = $1", (webhook_url,)))
if not send_reason:
return
lang = "en"
for combination, webhooks in self.rc_targets.items():
if webhook_url in webhooks:
lang = combination.lang
lang = langs[lang]["wiki"]
try: # This is best effort scenario, but I don't plan to add re-tries to this
dc_msg = DiscordMessage("compact", "custom/webhook_removal",
[webhook_url], content=lang.gettext("This recent changes webhook has been removed for `{reason}`!".format(reason=reason)))
await send_to_discord_webhook(dc_msg, webhook_url, "POST")
except:
logger.exception("Webhook removal send_reason failure.")
async def remove_wiki_from_db(self, reason: str):
raise NotImplementedError # TODO