RcGcDb/src/bot.py

36 lines
1.1 KiB
Python
Raw Normal View History

2020-07-09 22:24:23 +00:00
import logging.config
from src.config import settings
2020-07-09 23:58:25 +00:00
import sqlite3
from src.wiki import Wiki
2020-07-10 13:38:36 +00:00
import asyncio, aiohttp
2020-07-09 22:24:23 +00:00
logging.config.dictConfig(settings["logging"])
logger = logging.getLogger("rcgcdb.bot")
logger.debug("Current settings: {settings}".format(settings=settings))
2020-07-09 23:58:25 +00:00
conn = sqlite3.connect('rcgcdb.db')
c = conn.cursor()
2020-07-10 13:38:36 +00:00
# Log Fail states with structure wiki_id: number of fail states
2020-07-09 23:58:25 +00:00
all_wikis = {}
2020-07-10 13:38:36 +00:00
mw_msgs = {} # will have the type of id: tuple
2020-07-09 22:24:23 +00:00
2020-07-10 13:38:36 +00:00
# First populate the all_wikis list with every wiki
# Reasons for this: 1. we require amount of wikis to calculate the cooldown between requests
# 2. Easier to code
2020-07-09 22:24:23 +00:00
2020-07-10 13:38:36 +00:00
for wiki in c.execute('SELECT ROWID, * FROM wikis'):
all_wikis[wiki[0]] = Wiki()
2020-07-09 22:24:23 +00:00
# Start queueing logic
2020-07-10 13:38:36 +00:00
async def main_loop():
for db_wiki in c.execute('SELECT ROWID, * FROM wikis'):
extended = False
if wiki[0] not in all_wikis:
logger.debug("New wiki: {}".format(wiki[1]))
all_wikis[wiki[0]] = Wiki()
local_wiki = all_wikis[wiki[0]] # set a reference to a wiki object from memory
if all_wikis[wiki[0]].mw_messages is None:
extended = True
wiki_response = await all_wikis[wiki[0]].fetch_wiki(extended)