mirror of
https://gitlab.com/chicken-riders/RcGcDb.git
synced 2025-02-23 00:54:09 +00:00
Added category fixes
This commit is contained in:
parent
bcad172bbb
commit
c9a8396583
|
@ -140,7 +140,7 @@ def shutdown(loop, signal=None):
|
|||
def global_exception_handler(loop, context):
|
||||
"""Global exception handler for asyncio, lets us know when something crashes"""
|
||||
msg = context.get("exception", context["message"])
|
||||
logger.error("Global exception handler:" + msg)
|
||||
logger.error("Global exception handler: {}".format(msg))
|
||||
requests.post("https://discord.com/api/webhooks/" + settings["monitoring_webhook"], data={"content": "test"})
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ from src.misc import logger
|
|||
from src.config import settings
|
||||
from src.database import db_cursor
|
||||
from src.i18n import langs
|
||||
from asyncio.exceptions import TimeoutError
|
||||
import aiohttp
|
||||
|
||||
logger = logging.getLogger("rcgcdb.discord")
|
||||
|
@ -121,7 +122,7 @@ async def send_to_discord_webhook(data: DiscordMessage, webhook_url: str):
|
|||
async with aiohttp.ClientSession(headers=header, timeout=aiohttp.ClientTimeout(5.0)) as session:
|
||||
try:
|
||||
result = await session.post("https://discord.com/api/webhooks/"+webhook_url, data=repr(data))
|
||||
except (aiohttp.ClientConnectionError, aiohttp.ServerConnectionError):
|
||||
except (aiohttp.ClientConnectionError, aiohttp.ServerConnectionError, TimeoutError):
|
||||
logger.exception("Could not send the message to Discord")
|
||||
return 3
|
||||
return await handle_discord_http(result.status, repr(data), await result.text(), data)
|
||||
|
|
|
@ -117,17 +117,17 @@ async def process_cats(event: dict, local_wiki: Wiki, category_msgs: dict, categ
|
|||
"""Process categories based on local MW messages. """
|
||||
if event["type"] == "categorize":
|
||||
if "commenthidden" not in event:
|
||||
if local_wiki.mw_messages:
|
||||
if local_wiki.mw_messages is not None:
|
||||
cat_title = event["title"].split(':', 1)[1]
|
||||
# I so much hate this, blame Markus for making me do this
|
||||
if event["revid"] not in categorize_events:
|
||||
categorize_events[event["revid"]] = {"new": set(), "removed": set()}
|
||||
comment_to_match = re.sub(r'<.*?a>', '', event["parsedcomment"])
|
||||
wiki_cat_mw_messages = category_msgs[local_wiki.mw_messages]
|
||||
if wiki_cat_mw_messages[0] in comment_to_match or wiki_cat_mw_messages[2] in comment_to_match: # Added to category
|
||||
if wiki_cat_mw_messages[0][1] in comment_to_match or wiki_cat_mw_messages[2][1] in comment_to_match: # Added to category
|
||||
categorize_events[event["revid"]]["new"].add(cat_title)
|
||||
logger.debug("Matched {} to added category for {}".format(cat_title, event["revid"]))
|
||||
elif wiki_cat_mw_messages[1] in comment_to_match or wiki_cat_mw_messages[3] in comment_to_match: # Removed from category
|
||||
elif wiki_cat_mw_messages[1][1] in comment_to_match or wiki_cat_mw_messages[3][1] in comment_to_match: # Removed from category
|
||||
categorize_events[event["revid"]]["removed"].add(cat_title)
|
||||
logger.debug("Matched {} to removed category for {}".format(cat_title, event["revid"]))
|
||||
else:
|
||||
|
@ -193,6 +193,7 @@ async def essential_info(change: dict, changed_categories, local_wiki: Wiki, db_
|
|||
if not parsed_comment:
|
||||
parsed_comment = None
|
||||
if change["type"] in ["edit", "new"]:
|
||||
changed_categories = changed_categories.get(change["revid"], None)
|
||||
logger.debug("List of categories in essential_info: {}".format(changed_categories))
|
||||
if "userhidden" in change:
|
||||
change["user"] = _("hidden")
|
||||
|
|
Loading…
Reference in a new issue