mirror of
https://gitlab.com/chicken-riders/RcGcDb.git
synced 2025-02-23 00:54:09 +00:00
Improved performance, increased timeout on requests, fixed variable overshadowing issue (aka 'a')
This commit is contained in:
parent
06f910b64e
commit
0e5a3169e2
|
@ -80,7 +80,7 @@ async def wiki_scanner():
|
||||||
if local_wiki.mw_messages is None:
|
if local_wiki.mw_messages is None:
|
||||||
extended = True
|
extended = True
|
||||||
async with aiohttp.ClientSession(headers=settings["header"],
|
async with aiohttp.ClientSession(headers=settings["header"],
|
||||||
timeout=aiohttp.ClientTimeout(2.0)) as session:
|
timeout=aiohttp.ClientTimeout(3.0)) as session:
|
||||||
try:
|
try:
|
||||||
wiki_response = await local_wiki.fetch_wiki(extended, db_wiki["wiki"], session)
|
wiki_response = await local_wiki.fetch_wiki(extended, db_wiki["wiki"], session)
|
||||||
await local_wiki.check_status(db_wiki["wiki"], wiki_response.status)
|
await local_wiki.check_status(db_wiki["wiki"], wiki_response.status)
|
||||||
|
|
|
@ -13,6 +13,10 @@ logger = logging.getLogger("rcgcdb.discord")
|
||||||
|
|
||||||
# General functions
|
# General functions
|
||||||
|
|
||||||
|
default_header = settings["header"]
|
||||||
|
default_header['Content-Type'] = 'application/json'
|
||||||
|
default_header["X-RateLimit-Precision"] = "millisecond"
|
||||||
|
|
||||||
|
|
||||||
# User facing webhook functions
|
# User facing webhook functions
|
||||||
async def wiki_removal(wiki_url, status):
|
async def wiki_removal(wiki_url, status):
|
||||||
|
@ -142,13 +146,9 @@ async def send_to_discord_webhook(data: DiscordMessage, webhook_url: str) -> tup
|
||||||
"""Sends a message to webhook
|
"""Sends a message to webhook
|
||||||
|
|
||||||
:return tuple(status code for request, rate limit info (None for can send more, string for amount of seconds to wait)"""
|
:return tuple(status code for request, rate limit info (None for can send more, string for amount of seconds to wait)"""
|
||||||
header = settings["header"]
|
async with aiohttp.ClientSession(headers=default_header, timeout=aiohttp.ClientTimeout(5.0)) as session:
|
||||||
header['Content-Type'] = 'application/json'
|
|
||||||
header["X-RateLimit-Precision"] = "millisecond"
|
|
||||||
async with aiohttp.ClientSession(headers=header, timeout=aiohttp.ClientTimeout(5.0)) as session:
|
|
||||||
try:
|
try:
|
||||||
result = await session.post("https://discord.com/api/webhooks/"+webhook_url, data=repr(data))
|
result = await session.post("https://discord.com/api/webhooks/"+webhook_url, data=repr(data))
|
||||||
logger.debug(result.headers)
|
|
||||||
rate_limit = None if int(result.headers.get('x-ratelimit-remaining', "-1")) > 0 else result.headers.get('x-ratelimit-reset-after', None)
|
rate_limit = None if int(result.headers.get('x-ratelimit-remaining', "-1")) > 0 else result.headers.get('x-ratelimit-reset-after', None)
|
||||||
except (aiohttp.ClientConnectionError, aiohttp.ServerConnectionError, TimeoutError):
|
except (aiohttp.ClientConnectionError, aiohttp.ServerConnectionError, TimeoutError):
|
||||||
logger.exception("Could not send the message to Discord")
|
logger.exception("Could not send the message to Discord")
|
||||||
|
|
|
@ -18,7 +18,7 @@ if 1 == 2: # additional translation strings in unreachable code
|
||||||
print(_("director"), _("bot"), _("editor"), _("directors"), _("sysop"), _("bureaucrat"), _("reviewer"),
|
print(_("director"), _("bot"), _("editor"), _("directors"), _("sysop"), _("bureaucrat"), _("reviewer"),
|
||||||
_("autoreview"), _("autopatrol"), _("wiki_guardian"), ngettext("second", "seconds", 1), ngettext("minute", "minutes", 1), ngettext("hour", "hours", 1), ngettext("day", "days", 1), ngettext("week", "weeks", 1), ngettext("month", "months",1), ngettext("year", "years", 1), ngettext("millennium", "millennia", 1), ngettext("decade", "decades", 1), ngettext("century", "centuries", 1))
|
_("autoreview"), _("autopatrol"), _("wiki_guardian"), ngettext("second", "seconds", 1), ngettext("minute", "minutes", 1), ngettext("hour", "hours", 1), ngettext("day", "days", 1), ngettext("week", "weeks", 1), ngettext("month", "months",1), ngettext("year", "years", 1), ngettext("millennium", "millennia", 1), ngettext("decade", "decades", 1), ngettext("century", "centuries", 1))
|
||||||
|
|
||||||
async def compact_formatter(action, change, parsed_comment, categories, recent_changes, target, _, ngettext, paths,
|
async def compact_formatter(action, change, parsed_comment, categories, recent_changes, message_target, _, ngettext, paths,
|
||||||
additional_data=None):
|
additional_data=None):
|
||||||
"""Recent Changes compact formatter, part of RcGcDw"""
|
"""Recent Changes compact formatter, part of RcGcDw"""
|
||||||
if additional_data is None:
|
if additional_data is None:
|
||||||
|
@ -328,7 +328,7 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
content = _("Unknown event `{event}` by [{author}]({author_url}), report it on the [support server](<{support}>).").format(event=action, author=author, author_url=author_url, support=settings["support"])
|
content = _("Unknown event `{event}` by [{author}]({author_url}), report it on the [support server](<{support}>).").format(event=action, author=author, author_url=author_url, support=settings["support"])
|
||||||
await send_to_discord(DiscordMessage("compact", action, target[1], content=content, wiki=WIKI_SCRIPT_PATH))
|
await send_to_discord(DiscordMessage("compact", action, message_target[1], content=content, wiki=WIKI_SCRIPT_PATH))
|
||||||
|
|
||||||
|
|
||||||
async def embed_formatter(action, change, parsed_comment, categories, recent_changes, target, _, ngettext, paths, additional_data=None):
|
async def embed_formatter(action, change, parsed_comment, categories, recent_changes, target, _, ngettext, paths, additional_data=None):
|
||||||
|
|
|
@ -52,8 +52,8 @@ class Wiki:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def safe_request(url, *keys):
|
async def safe_request(url, *keys):
|
||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession(headers=settings["header"], timeout=aiohttp.ClientTimeout(2.0)) as session:
|
async with aiohttp.ClientSession(headers=settings["header"], timeout=aiohttp.ClientTimeout(3.0)) as session:
|
||||||
request = await session.get(url, timeout=5, allow_redirects=False)
|
request = await session.get(url, allow_redirects=False)
|
||||||
request.raise_for_status()
|
request.raise_for_status()
|
||||||
json_request = await request.json(encoding="UTF-8")
|
json_request = await request.json(encoding="UTF-8")
|
||||||
except (aiohttp.ClientConnectionError, aiohttp.ServerTimeoutError, asyncio.TimeoutError):
|
except (aiohttp.ClientConnectionError, aiohttp.ServerTimeoutError, asyncio.TimeoutError):
|
||||||
|
|
Loading…
Reference in a new issue