Added more debug + fixed disconnect logic and handling of encoding issues

This commit is contained in:
Frisk 2021-03-17 14:48:05 +01:00
parent 8a1a61dbac
commit 23043934cd
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
2 changed files with 11 additions and 1 deletions

View file

@ -169,10 +169,13 @@ class RcQueue:
if db_wiki["wiki"] in current_domain["irc"].updated: # Priority wikis are the ones with IRC, if they get updated forcefully add them to queue
current_domain["irc"].updated.remove(db_wiki["wiki"])
current_domain["query"].append(QueuedWiki(db_wiki["wiki"], 20), forced=True)
logger.debug("Updated in IRC so adding to queue.")
continue
elif all_wikis[db_wiki["wiki"]].last_check+settings["irc_overtime"] > time.time(): # if time went by and wiki should be updated now use default mechanics
logger.debug("Overtime so adding to queue.")
pass
else: # Continue without adding
logger.debug("No condition fulfilled so skipping.")
continue
if not db_wiki["ROWID"] < current_domain["last_rowid"]:
current_domain["query"].append(QueuedWiki(db_wiki["wiki"], 20))

View file

@ -7,12 +7,18 @@ logger = logging.getLogger("rcgcdw.irc_feed")
class AioIRCCat(irc.client_aio.AioSimpleIRCClient):
def connect(self, *args, **kwargs):
super().connect(*args, **kwargs)
self.connection_details = (args, kwargs)
def __init__(self, targets, all_wikis):
irc.client_aio.SimpleIRCClient.__init__(self)
self.targets = targets
self.updated = set() # Storage for edited wikis
self.updated_discussions = set()
self.wikis = all_wikis
self.connection.buffer_class.errors = "replace" # Ignore encoding errors
self.connection_details = None
def on_welcome(self, connection, event): # Join IRC channels
for channel in self.targets.values():
@ -28,7 +34,7 @@ class AioIRCCat(irc.client_aio.AioSimpleIRCClient):
c.nick(c.get_nickname() + "_")
def on_disconnect(self, connection, event):
connection.reconnect()
self.connect(*self.connection_details[0], **self.connection_details[1]) # attempt to reconnect
def parse_fandom_message(self, message: str):
message = message.split("\x035*\x03")
@ -44,6 +50,7 @@ class AioIRCCat(irc.client_aio.AioSimpleIRCClient):
self.updated.add(full_url)
logger.debug("New website appended to the list! {}".format(full_url))
def parse_fandom_discussion(self, message: str):
try:
post = json.loads(message)