2021-05-28 17:16:14 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
2021-05-30 13:31:51 +00:00
|
|
|
from collections import OrderedDict
|
2021-05-28 17:16:14 +00:00
|
|
|
from typing import TYPE_CHECKING, Optional
|
|
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
import src.wiki
|
|
|
|
import src.wiki_ratelimiter
|
2021-05-30 13:31:51 +00:00
|
|
|
import irc.client_aio
|
2021-05-28 17:16:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Domain:
|
2021-05-30 13:31:51 +00:00
|
|
|
def __init__(self, name: str):
|
2021-05-30 11:23:48 +00:00
|
|
|
self.name = name # This should be always in format of topname.extension for example fandom.com
|
|
|
|
self.task: asyncio.Task = self.create_task()
|
2021-05-30 13:31:51 +00:00
|
|
|
self.wikis: OrderedDict[str, src.wiki.Wiki] = OrderedDict()
|
2021-05-28 17:16:14 +00:00
|
|
|
self.rate_limiter: src.wiki_ratelimiter = src.wiki_ratelimiter.RateLimiter()
|
2021-05-30 13:31:51 +00:00
|
|
|
self.irc = None
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return iter(self.wikis)
|
|
|
|
|
|
|
|
def __getitem__(self, item):
|
|
|
|
return
|
|
|
|
|
|
|
|
def set_irc(self, irc_client: irc.client_aio.AioSimpleIRCClient):
|
2021-05-28 17:16:14 +00:00
|
|
|
self.irc = irc_client
|
|
|
|
|
2021-05-30 13:31:51 +00:00
|
|
|
def add_wiki(self, wiki: src.wiki.Wiki, first=False):
|
2021-05-30 11:23:48 +00:00
|
|
|
"""Adds a wiki to domain list.
|
|
|
|
|
|
|
|
:parameter wiki - Wiki object
|
2021-05-30 13:31:51 +00:00
|
|
|
:parameter first (optional) - bool indicating if wikis should be added as first or last in the ordered dict"""
|
|
|
|
self.wikis[wiki.script_url] = wiki
|
|
|
|
if first:
|
|
|
|
self.wikis.move_to_end(wiki.script_url, last=False)
|
2021-05-30 11:23:48 +00:00
|
|
|
|
|
|
|
def create_task(self) -> asyncio.Task:
|
|
|
|
return asyncio.create_task(self.run_wiki_check())
|
|
|
|
|
|
|
|
async def run_wiki_check(self):
|
|
|
|
raise NotImplementedError
|