Added code

This commit is contained in:
Frisk 2020-07-20 01:40:20 +02:00
parent 19730dfcdb
commit 33a317145e
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
23 changed files with 3753 additions and 74 deletions

Binary file not shown.

View file

@ -0,0 +1,105 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-07-04 00:58+0200\n"
"PO-Revision-Date: 2020-07-04 01:04+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.3\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: discussions.py:56
#, python-brace-format
msgid "Replied to \"{title}\""
msgstr "Antwortete auf „{title}“"
#: discussions.py:63 discussions.py:79 discussions.py:127 discussions.py:143
msgid "unknown"
msgstr "Unbekannt"
#: discussions.py:68
#, python-brace-format
msgid "Replied to \"{title}\" on {user}'s Message Wall"
msgstr "Antwortete auf „{title}“ auf der Nachrichtenseite von {user}"
#: discussions.py:72
#, python-brace-format
msgid "Created \"{title}\""
msgstr "Erstellte „{title}“"
#: discussions.py:86
#, python-brace-format
msgid "Created \"{title}\" on {user}'s Message Wall"
msgstr "Erstellte „{title}“ auf der Nachrichtenseite von {user}"
#: discussions.py:99
#, python-brace-format
msgid "Created a poll titled \"{title}\""
msgstr "Erstellte eine Umfrage „{title}“"
#: discussions.py:104
msgid "Option {}"
msgstr "Option {}"
#: discussions.py:105
#, python-brace-format
msgid "__[View image]({image_url})__"
msgstr "__[Bild öffnen]({image_url})__"
#: discussions.py:121
#, python-brace-format
msgid ""
"[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}>) "
"in {forumName}"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) erstellte [{title}](<{url}f/p/{threadId}"
">) in {forumName}"
#: discussions.py:130
#, python-brace-format
msgid ""
"[{author}](<{url}f/u/{creatorId}>) created [{title}](<{wikiurl}wiki/"
"Message_Wall:{user_wall}?threadId={threadid}>) on {user}'s Message Wall"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) erstellte [{title}](<{wikiurl}wiki/"
"Message_Wall:{user_wall}?threadId={threadid}>) auf der Nachrichtenseite von "
"{user}"
#: discussions.py:136
#, python-brace-format
msgid ""
"[{author}](<{url}f/u/{creatorId}>) created a [reply](<{url}f/p/{threadId}/r/"
"{postId}>) to [{title}](<{url}f/p/{threadId}>) in {forumName}"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) erstellte eine [Antwork](<{url}f/p/"
"{threadId}/r/{postId}>) zu [{title}](<{url}f/p/{threadId}>) in {forumName}"
#: discussions.py:147
#, python-brace-format
msgid ""
"[{author}](<{url}f/u/{creatorId}>) replied to [{title}](<{wikiurl}wiki/"
"Message_Wall:{user_wall}?threadId={threadid}#{replyId}>) on {user}'s Message "
"Wall"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) antwortete auf [{title}](<{wikiurl}wiki/"
"Message_Wall:{user_wall}?threadId={threadid}#{replyId}>) auf der "
"Nachrichtenseite von {user}"
#: discussions.py:153
#, python-brace-format
msgid ""
"[{author}](<{url}f/u/{creatorId}>) created a poll [{title}](<{url}f/p/"
"{threadId}>) in {forumName}"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) erstellte eine Umfrage [{title}](<{url}f/"
"p/{threadId}>) in {forumName}"

Binary file not shown.

View file

@ -0,0 +1,27 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-05-20 17:18+0200\n"
"PO-Revision-Date: 2019-05-20 17:25+0200\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.2.1\n"
"Last-Translator: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: de\n"
#: misc.py:76
msgid ""
"\n"
"__And more__"
msgstr ""
"\n"
"__Und mehr__"

Binary file not shown.

File diff suppressed because it is too large Load diff

Binary file not shown.

View file

@ -0,0 +1,90 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-06-23 14:54+0200\n"
"PO-Revision-Date: 2020-06-23 14:57+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.3\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: discussions.py:56
#, python-brace-format
msgid "Replied to \"{title}\""
msgstr "Replied to \"{title}\""
#: discussions.py:63 discussions.py:79
msgid "unknown"
msgstr "unknown"
#: discussions.py:68
#, python-brace-format
msgid "Replied to \"{title}\" on {user}'s Message Wall"
msgstr "Replied to \"{title}\" on {user}'s Message Wall"
#: discussions.py:72
#, python-brace-format
msgid "Created \"{title}\""
msgstr "Created \"{title}\""
#: discussions.py:86
#, python-brace-format
msgid "Created \"{title}\" on {user}'s Message Wall"
msgstr "Created \"{title}\" on {user}'s Message Wall"
#: discussions.py:99
#, python-brace-format
msgid "Created a poll titled \"{title}\""
msgstr "Created a poll titled \"{title}\""
#: discussions.py:104
msgid "Option {}"
msgstr "Option {}"
#: discussions.py:105
#, python-brace-format
msgid "__[View image]({image_url})__"
msgstr "__[View image]({image_url})__"
#: discussions.py:118
#, python-brace-format
#| msgid ""
#| "[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}"
#| ">) in ${forumName}"
msgid ""
"[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}>) "
"in {forumName}"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}>) "
"in {forumName}"
#: discussions.py:121
#, python-brace-format
msgid ""
"[{author}](<{url}f/u/{creatorId}>) created a [reply](<{url}f/p/{threadId}/r/"
"{postId}>) to [{title}](<{url}f/p/{threadId}>) in {forumName}"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) created a [reply](<{url}f/p/{threadId}/r/"
"{postId}>) to [{title}](<{url}f/p/{threadId}>) in {forumName}"
#: discussions.py:126
#, python-brace-format
#| msgid ""
#| "[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}"
#| ">) in ${forumName}"
msgid ""
"[{author}](<{url}f/u/{creatorId}>) created a poll [{title}](<{url}f/p/"
"{threadId}>) in {forumName}"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) created a poll [{title}](<{url}f/p/"
"{threadId}>) in {forumName}"

Binary file not shown.

View file

@ -0,0 +1,27 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-05-20 17:18+0200\n"
"PO-Revision-Date: 2019-05-20 17:32+0200\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.2.1\n"
"Last-Translator: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: en\n"
#: misc.py:76
msgid ""
"\n"
"__And more__"
msgstr ""
"\n"
"__And more__"

Binary file not shown.

File diff suppressed because it is too large Load diff

Binary file not shown.

View file

@ -0,0 +1,110 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-07-04 00:58+0200\n"
"PO-Revision-Date: 2020-07-04 01:12+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: pl\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.3\n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 "
"|| n%100>14) ? 1 : 2);\n"
#: discussions.py:56
#, python-brace-format
msgid "Replied to \"{title}\""
msgstr "Odpowiedział(a) w „{title}”"
#: discussions.py:63 discussions.py:79 discussions.py:127 discussions.py:143
msgid "unknown"
msgstr "nieznany"
#: discussions.py:68
#, python-brace-format
msgid "Replied to \"{title}\" on {user}'s Message Wall"
msgstr ""
"Odpowiedział(a) na „{title}” z tablicy wiadomości użytkownika/użytkowniczki "
"{user}"
#: discussions.py:72
#, python-brace-format
msgid "Created \"{title}\""
msgstr "Utworzył(a) „{title}”"
#: discussions.py:86
#, python-brace-format
msgid "Created \"{title}\" on {user}'s Message Wall"
msgstr ""
"Utworzył(a) „{title}” na tablicy wiadomości użytkownika/użytkowniczki {user}"
#: discussions.py:99
#, python-brace-format
msgid "Created a poll titled \"{title}\""
msgstr "Utworzył(a) ankietę zatytułowaną „{title}”"
#: discussions.py:104
msgid "Option {}"
msgstr "Opcja {}"
#: discussions.py:105
#, python-brace-format
msgid "__[View image]({image_url})__"
msgstr "__[Zobacz zdjęcie]({image_url})__"
#: discussions.py:121
#, python-brace-format
msgid ""
"[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}>) "
"in {forumName}"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) utworzył(a) [{title}](<{url}f/p/{threadId}"
">) w {forumName}"
#: discussions.py:130
#, python-brace-format
msgid ""
"[{author}](<{url}f/u/{creatorId}>) created [{title}](<{wikiurl}wiki/"
"Message_Wall:{user_wall}?threadId={threadid}>) on {user}'s Message Wall"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) utworzył(a) [{title}](<{wikiurl}wiki/"
"Message_Wall:{user_wall}?threadId={threadid}>) na tablicy wiadomości "
"użytkownika/użytkowniczki {user}"
#: discussions.py:136
#, python-brace-format
msgid ""
"[{author}](<{url}f/u/{creatorId}>) created a [reply](<{url}f/p/{threadId}/r/"
"{postId}>) to [{title}](<{url}f/p/{threadId}>) in {forumName}"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) utworzył(a) [odpowiedź](<{url}f/p/"
"{threadId}/r/{postId}>) pod tematem [{title}](<{url}f/p/{threadId}>) w "
"{forumName}"
#: discussions.py:147
#, python-brace-format
msgid ""
"[{author}](<{url}f/u/{creatorId}>) replied to [{title}](<{wikiurl}wiki/"
"Message_Wall:{user_wall}?threadId={threadid}#{replyId}>) on {user}'s Message "
"Wall"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) odpowiedział(a) na[{title}](<{wikiurl}"
"wiki/Message_Wall:{user_wall}?threadId={threadid}#{replyId}>) na tablicy "
"wiadomości użytkownika/użytkowniczki {user}"
#: discussions.py:153
#, python-brace-format
msgid ""
"[{author}](<{url}f/u/{creatorId}>) created a poll [{title}](<{url}f/p/"
"{threadId}>) in {forumName}"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) utworzył(a) ankietę [{title}](<{url}f/p/"
"{threadId}>) w {forumName}"

Binary file not shown.

View file

@ -0,0 +1,27 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-05-20 17:18+0200\n"
"PO-Revision-Date: 2019-05-20 17:23+0200\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.2.1\n"
"Last-Translator: \n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);\n"
"Language: pl\n"
#: misc.py:76
msgid ""
"\n"
"__And more__"
msgstr ""
"\n"
"__Oraz więcej__"

Binary file not shown.

File diff suppressed because it is too large Load diff

View file

@ -5,6 +5,7 @@ from src.wiki import Wiki, process_cats, process_mwmsgs, essential_info
import asyncio, aiohttp import asyncio, aiohttp
from src.exceptions import * from src.exceptions import *
from src.database import db_cursor from src.database import db_cursor
from collections import defaultdict
from queue_handler import DBHandler from queue_handler import DBHandler
logging.config.dictConfig(settings["logging"]) logging.config.dictConfig(settings["logging"])
@ -19,11 +20,12 @@ mw_msgs: dict = {} # will have the type of id: tuple
# Reasons for this: 1. we require amount of wikis to calculate the cooldown between requests # Reasons for this: 1. we require amount of wikis to calculate the cooldown between requests
# 2. Easier to code # 2. Easier to code
for wiki in db_cursor.execute('SELECT ROWID, * FROM rcgcdw'): for wiki in db_cursor.execute('SELECT DISTINCT wiki FROM rcgcdw'):
all_wikis[wiki[0]] = Wiki() all_wikis[wiki] = Wiki()
# Start queueing logic # Start queueing logic
def calculate_delay() -> float: def calculate_delay() -> float:
min_delay = 60/settings["max_requests_per_minute"] min_delay = 60/settings["max_requests_per_minute"]
if (len(all_wikis) * min_delay) < settings["minimal_cooldown_per_wiki_in_sec"]: if (len(all_wikis) * min_delay) < settings["minimal_cooldown_per_wiki_in_sec"]:
@ -31,20 +33,30 @@ def calculate_delay() -> float:
else: else:
return min_delay return min_delay
def generate_targets(wiki_url: str) -> defaultdict[list]:
combinations = defaultdict(list)
for webhook in db_cursor.execute('SELECT ROWID, * FROM rcgcdw WHERE wiki = ?', wiki_url):
# rowid, guild, configid, webhook, wiki, lang, display, rcid, wikiid, postid
combination = (webhook[5], webhook[6]) # lang, display
combinations[combination].append(webhook[3])
return combinations
async def wiki_scanner(): async def wiki_scanner():
calc_delay = calculate_delay() calc_delay = calculate_delay()
# db_cursor.execute('SELECT DISTINCT wiki FROM rcgcdw'):
for db_wiki in db_cursor.execute('SELECT ROWID, * FROM rcgcdw'): for db_wiki in db_cursor.execute('SELECT * FROM rcgcdw GROUP BY wiki'):
extended = False extended = False
if wiki[0] not in all_wikis: if db_wiki[3] not in all_wikis:
logger.debug("New wiki: {}".format(wiki[1])) logger.debug("New wiki: {}".format(wiki[1]))
all_wikis[wiki[0]] = Wiki() all_wikis[db_wiki[3]] = Wiki()
local_wiki = all_wikis[wiki[0]] # set a reference to a wiki object from memory local_wiki = all_wikis[db_wiki[3]] # set a reference to a wiki object from memory
if local_wiki.mw_messages is None: if local_wiki.mw_messages is None:
extended = True extended = True
try: try:
wiki_response = await local_wiki.fetch_wiki(extended, db_wiki[4]) wiki_response = await local_wiki.fetch_wiki(extended, db_wiki[0])
await local_wiki.check_status(wiki[0], wiki_response.status, db_wiki[1]) await local_wiki.check_status(wiki[3], wiki_response.status)
except (WikiServerError, WikiError): except (WikiServerError, WikiError):
continue # ignore this wiki if it throws errors continue # ignore this wiki if it throws errors
try: try:
@ -55,19 +67,21 @@ async def wiki_scanner():
continue continue
if extended: if extended:
await process_mwmsgs(recent_changes_resp, local_wiki, mw_msgs) await process_mwmsgs(recent_changes_resp, local_wiki, mw_msgs)
categorize_events = {} if db_wiki[6] is None: # new wiki, just get the last rc to not spam the channel
if db_wiki[7] is None: # new wiki, just get the last rc to not spam the channel
if len(recent_changes) > 0: if len(recent_changes) > 0:
DBHandler.add(db_wiki[0], recent_changes[-1]["rcid"]) DBHandler.add(db_wiki[0], recent_changes[-1]["rcid"])
continue continue
else: else:
DBHandler.add(db_wiki[0], 0) DBHandler.add(db_wiki[0], 0)
continue continue
categorize_events = {}
targets = generate_targets(db_wiki[0])
for change in recent_changes: for change in recent_changes:
await process_cats(change, local_wiki, mw_msgs, categorize_events) await process_cats(change, local_wiki, mw_msgs, categorize_events)
for change in recent_changes: # Yeah, second loop since the categories require to be all loaded up for change in recent_changes: # Yeah, second loop since the categories require to be all loaded up
if change["rcid"] < db_wiki[7]: if change["rcid"] < db_wiki[6]:
await essential_info(change, categorize_events, local_wiki, db_wiki) for target in targets.items():
await essential_info(change, categorize_events, local_wiki, db_wiki, target)
await asyncio.sleep(delay=calc_delay) await asyncio.sleep(delay=calc_delay)

View file

@ -20,7 +20,7 @@ from src.i18n import langs
logger = logging.getLogger("rcgcdw.rc_formatters") logger = logging.getLogger("rcgcdw.rc_formatters")
#from src.rcgcdw import recent_changes, ngettext, logger, profile_field_name, LinkParser, pull_comment #from src.rcgcdw import recent_changes, ngettext, logger, profile_field_name, LinkParser, pull_comment
def compact_formatter(action, change, parsed_comment, categories, recent_changes): def compact_formatter(action, change, parsed_comment, categories, recent_changes, _):
LinkParser = LinkParser("domain") LinkParser = LinkParser("domain")
if action != "suppressed": if action != "suppressed":
author_url = link_formatter(create_article_path("User:{user}".format(user=change["user"]))) author_url = link_formatter(create_article_path("User:{user}".format(user=change["user"])))
@ -309,7 +309,7 @@ def compact_formatter(action, change, parsed_comment, categories, recent_changes
send_to_discord(DiscordMessage("compact", action, settings["webhookURL"], content=content)) send_to_discord(DiscordMessage("compact", action, settings["webhookURL"], content=content))
def embed_formatter(action, change, parsed_comment, categories, recent_changes): def embed_formatter(action, change, parsed_comment, categories, recent_changes, _):
LinkParser = LinkParser() LinkParser = LinkParser()
embed = DiscordMessage("embed", action, settings["webhookURL"]) embed = DiscordMessage("embed", action, settings["webhookURL"])
WIKI_API_PATH = WIKI_API_PATH =

View file

@ -3,13 +3,13 @@ import sys, logging, gettext
logger = logging.getLogger("rcgcdb.i18n") logger = logging.getLogger("rcgcdb.i18n")
try: try:
en = gettext.translation('rcgcdb', localedir='locale', languages=["en"]) en = gettext.translation('rcgcdw', localedir='locale', languages=["en"])
de = gettext.translation('rcgcdb', localedir='locale', languages=["de"]) de = gettext.translation('rcgcdw', localedir='locale', languages=["de"])
pl = gettext.translation('rcgcdb', localedir='locale', languages=["pl"]) pl = gettext.translation('rcgcdw', localedir='locale', languages=["pl"])
pt = gettext.translation('rcgcdb', localedir='locale', languages=["pt"]) pt = gettext.translation('rcgcdw', localedir='locale', languages=["pt-br"])
ru = gettext.translation('rcgcdb', localedir='locale', languages=["ru"]) ru = gettext.translation('rcgcdw', localedir='locale', languages=["ru"])
uk = gettext.translation('rcgcdb', localedir='locale', languages=["uk"]) uk = gettext.translation('rcgcdw', localedir='locale', languages=["uk"])
fr = gettext.translation('rcgcdb', localedir='locale', languages=["fr"]) fr = gettext.translation('rcgcdw', localedir='locale', languages=["fr"])
langs = {"en": en, "de": de, "pl": pl, "pt": pt, "ru": ru, "uk": uk, "fr": fr} langs = {"en": en, "de": de, "pl": pl, "pt": pt, "ru": ru, "uk": uk, "fr": fr}
except FileNotFoundError: except FileNotFoundError:
logger.critical("No language files have been found. Make sure locale folder is located in the directory.") logger.critical("No language files have been found. Make sure locale folder is located in the directory.")

View file

@ -205,43 +205,43 @@ class ContentParser(HTMLParser):
self.current_tag = "" self.current_tag = ""
class RecentChangesClass(): # class RecentChangesClass():
"""Store verious data and functions related to wiki and fetching of Recent Changes""" # """Store verious data and functions related to wiki and fetching of Recent Changes"""
def __init__(self): # def __init__(self):
self.tags = {} # self.tags = {}
self.mw_messages = {} # self.mw_messages = {}
self.namespaces = None # self.namespaces = None
self.session = session # self.session = session
#
@staticmethod # @staticmethod
def handle_mw_errors(request): # def handle_mw_errors(request):
if "errors" in request: # if "errors" in request:
logger.error(request["errors"]) # logger.error(request["errors"])
raise MWError # raise MWError
return request # return request
#
def safe_request(self, url): # def safe_request(self, url):
try: # try:
request = self.session.get(url, timeout=10, allow_redirects=False) # request = self.session.get(url, timeout=10, allow_redirects=False)
except requests.exceptions.Timeout: # except requests.exceptions.Timeout:
logger.warning("Reached timeout error for request on link {url}".format(url=url)) # logger.warning("Reached timeout error for request on link {url}".format(url=url))
self.downtime_controller() # self.downtime_controller()
return None # return None
except requests.exceptions.ConnectionError: # except requests.exceptions.ConnectionError:
logger.warning("Reached connection error for request on link {url}".format(url=url)) # logger.warning("Reached connection error for request on link {url}".format(url=url))
self.downtime_controller() # self.downtime_controller()
return None # return None
except requests.exceptions.ChunkedEncodingError: # except requests.exceptions.ChunkedEncodingError:
logger.warning("Detected faulty response from the web server for request on link {url}".format(url=url)) # logger.warning("Detected faulty response from the web server for request on link {url}".format(url=url))
self.downtime_controller() # self.downtime_controller()
return None # return None
else: # else:
if 499 < request.status_code < 600: # if 499 < request.status_code < 600:
self.downtime_controller() # self.downtime_controller()
return None # return None
elif request.status_code == 302: # elif request.status_code == 302:
logger.warning("Redirect detected! Either the wiki given in the script settings (wiki field) is incorrect/the wiki got removed or Gamepedia is giving us the false value. Please provide the real URL to the wiki, current URL redirects to {}".format(request.next.url)) # logger.warning("Redirect detected! Either the wiki given in the script settings (wiki field) is incorrect/the wiki got removed or Gamepedia is giving us the false value. Please provide the real URL to the wiki, current URL redirects to {}".format(request.next.url))
return request # return request
#
def init_info(self): # def init_info(self):
return # return

View file

@ -44,25 +44,25 @@ class Wiki:
raise WikiServerError raise WikiServerError
return response return response
async def check_status(self, wiki_id, status, name): async def check_status(self, wiki_url, status):
if 199 < status < 300: if 199 < status < 300:
self.fail_times = 0 self.fail_times = 0
pass pass
elif 400 < status < 500: # ignore 400 error since this might be our fault elif 400 < status < 500: # ignore 400 error since this might be our fault
self.fail_times += 1 self.fail_times += 1
logger.warning("Wiki {} responded with HTTP code {}, increased fail_times to {}, skipping...".format(name, status, self.fail_times)) logger.warning("Wiki {} responded with HTTP code {}, increased fail_times to {}, skipping...".format(wiki_url, status, self.fail_times))
if self.fail_times > 3: if self.fail_times > 3:
await self.remove(wiki_id, status) await self.remove(wiki_url, status)
raise WikiError raise WikiError
elif 499 < status < 600: elif 499 < status < 600:
logger.warning("Wiki {} responded with HTTP code {}, skipping...".format(name, status, self.fail_times)) logger.warning("Wiki {} responded with HTTP code {}, skipping...".format(wiki_url, status, self.fail_times))
raise WikiServerError raise WikiServerError
async def remove(self, wiki_id, reason): async def remove(self, wiki_id, reason):
src.discord.wiki_removal(wiki_id, reason) src.discord.wiki_removal(wiki_id, reason)
src.discord.wiki_removal_monitor(wiki_id, reason) src.discord.wiki_removal_monitor(wiki_id, reason)
db_cursor.execute("DELETE FROM observers WHERE wiki_id = ?", wiki_id) db_cursor.execute("DELETE FROM rcgcdw WHERE wiki = ?", wiki_id)
db_cursor.execute("DELETE FROM wikis WHERE ROWID = ?", wiki_id) logger.warning("{} rows affected by DELETE FROM rcgcdw WHERE wiki = {}".format(db_cursor.rowcount, wiki_id))
db_connection.commit() db_connection.commit()
@ -118,20 +118,24 @@ async def process_mwmsgs(wiki_response: dict, local_wiki: Wiki, mw_msgs: dict):
if msgs == set: if msgs == set:
local_wiki.mw_messages = key local_wiki.mw_messages = key
return return
# if same entry is not in mw_msgs
key = len(mw_msgs) key = len(mw_msgs)
mw_msgs[key] = msgs # it may be a little bit messy for sure, however I don't expect any reason to remove mw_msgs entries by one mw_msgs[key] = msgs # it may be a little bit messy for sure, however I don't expect any reason to remove mw_msgs entries by one
local_wiki.mw_messages = key local_wiki.mw_messages = key
async def essential_info(change, changed_categories, local_wiki, db_wiki): async def essential_info(change: dict, changed_categories, local_wiki: Wiki, db_wiki: tuple, target: tuple):
"""Prepares essential information for both embed and compact message format.""" """Prepares essential information for both embed and compact message format."""
recent_changes = RecentChangesClass() def _(string: str) -> str:
"""Our own translation string to make it compatible with async"""
return lang.gettext(string)
recent_changes = RecentChangesClass() # TODO Look into replacing RecentChangesClass with local_wiki
LinkParser = LinkParser("domain") LinkParser = LinkParser("domain")
logger.debug(change) logger.debug(change)
lang = langs[db_wiki[1]] appearance_mode = embed_formatter if target[0][1] > 0 else compact_formatter
appearance_mode = embed_formatter # TODO Add chanding depending on the DB entry
if ("actionhidden" in change or "suppressed" in change): # if event is hidden using suppression if ("actionhidden" in change or "suppressed" in change): # if event is hidden using suppression
appearance_mode("suppressed", change, "", changed_categories, recent_changes) appearance_mode("suppressed", change, "", changed_categories, recent_changes, target, _)
return return
lang = langs[target[0][0]]
if "commenthidden" not in change: if "commenthidden" not in change:
LinkParser.feed(change["parsedcomment"]) LinkParser.feed(change["parsedcomment"])
parsed_comment = LinkParser.new_string parsed_comment = LinkParser.new_string
@ -158,4 +162,4 @@ async def essential_info(change, changed_categories, local_wiki, db_wiki):
else: else:
logger.warning("This event is not implemented in the script. Please make an issue on the tracker attaching the following info: wiki url, time, and this information: {}".format(change)) logger.warning("This event is not implemented in the script. Please make an issue on the tracker attaching the following info: wiki url, time, and this information: {}".format(change))
return return
appearance_mode(identification_string, change, parsed_comment, changed_categories, recent_changes) appearance_mode(identification_string, change, parsed_comment, changed_categories, recent_changes, target, _)