mirror of
https://gitlab.com/chicken-riders/RcGcDb.git
synced 2025-02-23 00:54:09 +00:00
Some sort of progress
This commit is contained in:
parent
0459e3fd68
commit
1d5026a553
14
src/bot.py
14
src/bot.py
|
@ -4,6 +4,7 @@ import logging.config
|
||||||
import signal
|
import signal
|
||||||
import traceback
|
import traceback
|
||||||
import nest_asyncio
|
import nest_asyncio
|
||||||
|
import time
|
||||||
from collections import defaultdict, namedtuple
|
from collections import defaultdict, namedtuple
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
|
|
||||||
|
@ -65,12 +66,14 @@ class RcQueue:
|
||||||
async def start_group(self, group, initial_wikis):
|
async def start_group(self, group, initial_wikis):
|
||||||
"""Starts a task for given domain group"""
|
"""Starts a task for given domain group"""
|
||||||
if group not in self.domain_list:
|
if group not in self.domain_list:
|
||||||
if group in settings["irc_servers"]:
|
for irc_server in settings["irc_servers"].keys():
|
||||||
|
if group in settings["irc_servers"]["irc_server"]["domains"]:
|
||||||
irc_connection = AioIRCCat(settings["irc_servers"]["group"]["irc_channel_mapping"], all_wikis)
|
irc_connection = AioIRCCat(settings["irc_servers"]["group"]["irc_channel_mapping"], all_wikis)
|
||||||
irc_connection.connect(settings["irc_servers"][group]["irc_host"], settings["irc_servers"][group]["irc_port"], "RcGcDb")
|
irc_connection.connect(settings["irc_servers"][irc_server]["irc_host"], settings["irc_servers"][irc_server]["irc_port"], settings["irc_servers"][irc_server]["irc_name"])
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
irc_connection = None
|
irc_connection = None
|
||||||
self.domain_list[group] = {"task": asyncio.create_task(scan_group(group)), "last_rowid": 0, "query": LimitedList(initial_wikis), "rate_limiter": RateLimiter()}
|
self.domain_list[group] = {"task": asyncio.create_task(scan_group(group)), "last_rowid": 0, "query": LimitedList(initial_wikis), "rate_limiter": RateLimiter(), "irc": irc_connection}
|
||||||
logger.debug(self.domain_list[group])
|
logger.debug(self.domain_list[group])
|
||||||
else:
|
else:
|
||||||
raise KeyError
|
raise KeyError
|
||||||
|
@ -149,6 +152,11 @@ class RcQueue:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
current_domain: dict = self[domain]
|
current_domain: dict = self[domain]
|
||||||
|
if current_domain["irc"]:
|
||||||
|
if db_wiki["wiki"] not in current_domain["irc"].updated and all_wikis[db_wiki["wiki"]].last_updated+settings["irc_overtime"] > time.time():
|
||||||
|
continue # if domain has IRC, has not been updated, and it was updated less than an hour ago
|
||||||
|
else: # otherwise remove it from the list
|
||||||
|
current_domain["irc"].updated.remove(db_wiki["wiki"])
|
||||||
if not db_wiki["ROWID"] < current_domain["last_rowid"]:
|
if not db_wiki["ROWID"] < current_domain["last_rowid"]:
|
||||||
current_domain["query"].append(QueuedWiki(db_wiki["wiki"], 20))
|
current_domain["query"].append(QueuedWiki(db_wiki["wiki"], 20))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
|
@ -13,18 +13,16 @@ class AioIRCCat(irc.client_aio.AioSimpleIRCClient):
|
||||||
connection.join(channel)
|
connection.join(channel)
|
||||||
|
|
||||||
def on_pubmsg(self, channel, event):
|
def on_pubmsg(self, channel, event):
|
||||||
|
if channel == self.targets["rc"]:
|
||||||
|
self.parse_fandom_message(' '.join(event.arguments))
|
||||||
|
elif channel == self.targets["discussion"]:
|
||||||
|
self.parse_fandom_discussion(' '.join(event.arguments))
|
||||||
|
|
||||||
def on_nicknameinuse(self, c, e):
|
def on_nicknameinuse(self, c, e):
|
||||||
c.nick(c.get_nickname() + "_")
|
c.nick(c.get_nickname() + "_")
|
||||||
|
|
||||||
async def parse_fandom_message(self, message):
|
async def parse_fandom_message(self, message):
|
||||||
raw_msg = message
|
|
||||||
message = message.split("\x035*\x03")
|
message = message.split("\x035*\x03")
|
||||||
try:
|
|
||||||
user = message[1][4:].strip().strip(chr(3))
|
|
||||||
except IndexError:
|
|
||||||
return
|
|
||||||
# print(asyncio.all_tasks())
|
# print(asyncio.all_tasks())
|
||||||
half = message[0].find("\x0302http")
|
half = message[0].find("\x0302http")
|
||||||
if half == -1:
|
if half == -1:
|
||||||
|
|
|
@ -24,6 +24,7 @@ class Wiki:
|
||||||
fail_times: int = 0 # corresponding to amount of times connection with wiki failed for client reasons (400-499)
|
fail_times: int = 0 # corresponding to amount of times connection with wiki failed for client reasons (400-499)
|
||||||
session: aiohttp.ClientSession = None
|
session: aiohttp.ClientSession = None
|
||||||
rc_active: int = 0
|
rc_active: int = 0
|
||||||
|
last_check: float = 0.0
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def fetch_wiki(extended, script_path, session: aiohttp.ClientSession, ratelimiter: RateLimiter, amount=20) -> aiohttp.ClientResponse:
|
async def fetch_wiki(extended, script_path, session: aiohttp.ClientSession, ratelimiter: RateLimiter, amount=20) -> aiohttp.ClientResponse:
|
||||||
|
|
Loading…
Reference in a new issue