mirror of
https://gitlab.com/chicken-riders/RcGcDb.git
synced 2025-02-23 00:54:09 +00:00
Added wiki removal function and associated pub/sub command
This commit is contained in:
parent
56f6ef1887
commit
c6e9a92c94
|
@ -84,6 +84,14 @@ class DomainManager:
|
|||
elif split_payload[0] == "UPDATE":
|
||||
await self.return_domain(self.get_domain(split_payload[1])).get_wiki(split_payload[1]).update_targets()
|
||||
logger.info("Successfully force updated information about {}".format(split_payload[1]))
|
||||
elif split_payload[0] == "ERASE" and len(split_payload) > 2:
|
||||
logger.info(f"Received {' '.join(split_payload)} on pub/sub.")
|
||||
domain = self.return_domain(self.get_domain(split_payload[1]))
|
||||
wiki = domain.get_wiki(split_payload[1])
|
||||
reason = " ".join(split_payload[2:])
|
||||
if wiki is not None:
|
||||
logger.debug("Wiki specified in pub/sub message has been found. Erasing the wiki from DB.")
|
||||
await wiki.remove_wiki_from_db(reason, send_reason=True if reason else False)
|
||||
elif split_payload[0] == "DEBUG":
|
||||
asyncio.current_task().set_name("webhook_update")
|
||||
if split_payload[1] == "INFO":
|
||||
|
|
22
src/wiki.py
22
src/wiki.py
|
@ -500,7 +500,8 @@ class Wiki:
|
|||
if not send_reason:
|
||||
return
|
||||
lang = "en"
|
||||
for combination, webhooks in self.rc_targets.items():
|
||||
rc_targets_long_lived = self.rc_targets.copy() # Create a copy since those will be updated and we live in async world
|
||||
for combination, webhooks in rc_targets_long_lived.items():
|
||||
if webhook_url in webhooks:
|
||||
lang = combination.lang
|
||||
lang = langs[lang]["wiki"]
|
||||
|
@ -511,8 +512,23 @@ class Wiki:
|
|||
except:
|
||||
logger.exception("Webhook removal send_reason failure.")
|
||||
|
||||
async def remove_wiki_from_db(self, reason: str):
|
||||
raise NotImplementedError # TODO
|
||||
async def remove_wiki_from_db(self, reason: str, send_reason=False):
|
||||
logger.info(f"Removing a wiki with script_url of {self.script_url} from the database due to {reason}.")
|
||||
dbmanager.add(("DELETE FROM rcgcdb WHERE wiki = $1", (self.script_url,)))
|
||||
if not send_reason:
|
||||
return
|
||||
rc_targets_long_lived = self.rc_targets.copy() # Create a copy since those will be updated and we live in async world
|
||||
for combination, webhooks in rc_targets_long_lived.items():
|
||||
lang = combination.lang
|
||||
try: # This is best effort scenario, but I don't plan to add re-tries to this
|
||||
dc_msg = DiscordMessage("compact", "custom/webhook_removal",
|
||||
webhooks, content=lang.gettext(
|
||||
"This recent changes webhook has been removed for `{reason}`!".format(reason=reason)))
|
||||
for webhook in webhooks:
|
||||
await send_to_discord_webhook(dc_msg, webhook, "POST")
|
||||
except:
|
||||
logger.exception("Webhook removal send_reason failure.")
|
||||
|
||||
|
||||
async def fetch_discussions(self, params: dict) -> tuple[aiohttp.ClientResponse, dict]:
|
||||
header = settings["header"]
|
||||
|
|
Loading…
Reference in a new issue