Bump version and change table name for RcGcDb

This commit is contained in:
Frisk 2023-08-13 15:57:05 +02:00
parent dcad29a3a3
commit 62c8880275
4 changed files with 9 additions and 9 deletions

View file

@ -4,7 +4,7 @@ try: # load settings
with open("settings.json", encoding="utf8") as sfile: with open("settings.json", encoding="utf8") as sfile:
settings = json.load(sfile) settings = json.load(sfile)
if "user-agent" in settings["header"]: if "user-agent" in settings["header"]:
settings["header"]["user-agent"] = settings["header"]["user-agent"].format(version="1.1") # set the version in the useragent settings["header"]["user-agent"] = settings["header"]["user-agent"].format(version="1.9 Beta") # set the version in the useragent
except FileNotFoundError: except FileNotFoundError:
logging.critical("No config file could be found. Please make sure settings.json is in the directory.") logging.critical("No config file could be found. Please make sure settings.json is in the directory.")
sys.exit(1) sys.exit(1)

View file

@ -66,7 +66,7 @@ class Discussions:
if "error" in discussion_feed_resp: if "error" in discussion_feed_resp:
error = discussion_feed_resp["error"] error = discussion_feed_resp["error"]
if error == "NotFoundException": # Discussions disabled if error == "NotFoundException": # Discussions disabled
await dbmanager.add("UPDATE rcgcdw SET postid = $1 WHERE wiki = $2", "-1", wiki.script_url) await dbmanager.add("UPDATE rcgcdb SET postid = $1 WHERE wiki = $2", "-1", wiki.script_url)
await dbmanager.update_db() await dbmanager.update_db()
await wiki.update_targets() await wiki.update_targets()
raise WikiError raise WikiError
@ -80,7 +80,7 @@ class Discussions:
return return
if wiki.discussion_id is None: # new wiki, just get the last post to not spam the channel if wiki.discussion_id is None: # new wiki, just get the last post to not spam the channel
if len(discussion_feed) > 0: if len(discussion_feed) > 0:
dbmanager.add(("UPDATE rcgcdw SET postid = $1 WHERE wiki = $2 AND ( postid != '-1' OR postid IS NULL )", ( dbmanager.add(("UPDATE rcgcdb SET postid = $1 WHERE wiki = $2 AND ( postid != '-1' OR postid IS NULL )", (
str(discussion_feed[-1]["id"]), str(discussion_feed[-1]["id"]),
wiki.script_url))) wiki.script_url)))
wiki.statistics.update(last_post=discussion_feed[-1]["id"]) wiki.statistics.update(last_post=discussion_feed[-1]["id"])
@ -129,7 +129,7 @@ class Discussions:
messagequeue.add_messages(message_list) messagequeue.add_messages(message_list)
if discussion_feed: if discussion_feed:
wiki.statistics.update(last_post=discussion_feed[-1]["id"]) wiki.statistics.update(last_post=discussion_feed[-1]["id"])
dbmanager.add(("UPDATE rcgcdw SET postid = $1 WHERE wiki = $2 AND ( postid != '-1' OR postid IS NULL )", (str(discussion_feed[-1]["id"]), dbmanager.add(("UPDATE rcgcdb SET postid = $1 WHERE wiki = $2 AND ( postid != '-1' OR postid IS NULL )", (str(discussion_feed[-1]["id"]),
wiki.script_url))) # If this is not enough for the future, save rcid in message sending function to make sure we always send all of the changes wiki.script_url))) # If this is not enough for the future, save rcid in message sending function to make sure we always send all of the changes

View file

@ -34,7 +34,7 @@ class DomainManager:
await self.new_wiki(Wiki(split_payload[1], safe_type_for_id(split_payload[2], int), safe_type_for_id(split_payload[3], str))) await self.new_wiki(Wiki(split_payload[1], safe_type_for_id(split_payload[2], int), safe_type_for_id(split_payload[3], str)))
elif split_payload[0] == "REMOVE": elif split_payload[0] == "REMOVE":
try: try:
results = await connection.fetch("SELECT * FROM rcgcdw WHERE wiki = $1;", split_payload[1]) results = await connection.fetch("SELECT * FROM rcgcdb WHERE wiki = $1;", split_payload[1])
if len(results) > 0: # If there are still webhooks for this wiki - just update its targets if len(results) > 0: # If there are still webhooks for this wiki - just update its targets
await self.return_domain(self.get_domain(split_payload[1])).get_wiki(split_payload[1]).update_targets() await self.return_domain(self.get_domain(split_payload[1])).get_wiki(split_payload[1]).update_targets()
except asyncpg.IdleSessionTimeoutError: except asyncpg.IdleSessionTimeoutError:

View file

@ -159,7 +159,7 @@ class Wiki:
Settings = namedtuple("Settings", ["lang", "display"]) Settings = namedtuple("Settings", ["lang", "display"])
target_settings: defaultdict[Settings, list[str]] = defaultdict(list) target_settings: defaultdict[Settings, list[str]] = defaultdict(list)
discussion_targets: defaultdict[Settings, list[str]] = defaultdict(list) discussion_targets: defaultdict[Settings, list[str]] = defaultdict(list)
async for webhook in dbmanager.fetch_rows("SELECT webhook, lang, display, rcid, postid FROM rcgcdw WHERE wiki = $1", self.script_url): async for webhook in dbmanager.fetch_rows("SELECT webhook, lang, display, rcid, postid FROM rcgcdb WHERE wiki = $1", self.script_url):
if webhook['rcid'] == -1 and webhook['postid'] == '-1': if webhook['rcid'] == -1 and webhook['postid'] == '-1':
await self.remove_wiki_from_db(4) await self.remove_wiki_from_db(4)
if webhook['rcid'] != -1: if webhook['rcid'] != -1:
@ -336,11 +336,11 @@ class Wiki:
if self.rc_id in (0, None, -1): if self.rc_id in (0, None, -1):
if len(recent_changes) > 0: if len(recent_changes) > 0:
self.statistics.update(last_action=recent_changes[-1]["rcid"]) self.statistics.update(last_action=recent_changes[-1]["rcid"])
dbmanager.add(("UPDATE rcgcdw SET rcid = $1 WHERE wiki = $2 AND ( rcid != -1 OR rcid IS NULL )", dbmanager.add(("UPDATE rcgcdb SET rcid = $1 WHERE wiki = $2 AND ( rcid != -1 OR rcid IS NULL )",
(recent_changes[-1]["rcid"], self.script_url))) (recent_changes[-1]["rcid"], self.script_url)))
else: else:
self.statistics.update(last_action=0) self.statistics.update(last_action=0)
dbmanager.add(("UPDATE rcgcdw SET rcid = 0 WHERE wiki = $1 AND ( rcid != -1 OR rcid IS NULL )", (self.script_url))) dbmanager.add(("UPDATE rcgcdb SET rcid = 0 WHERE wiki = $1 AND ( rcid != -1 OR rcid IS NULL )", (self.script_url)))
return # TODO Add a log entry? return # TODO Add a log entry?
categorize_events = {} categorize_events = {}
new_events = 0 new_events = 0
@ -369,7 +369,7 @@ class Wiki:
message_list.append(QueueEntry(message, webhooks, self)) message_list.append(QueueEntry(message, webhooks, self))
messagequeue.add_messages(message_list) messagequeue.add_messages(message_list)
self.statistics.update(last_action=highest_id) self.statistics.update(last_action=highest_id)
dbmanager.add(("UPDATE rcgcdw SET rcid = $1 WHERE wiki = $2 AND ( rcid != -1 OR rcid IS NULL )", (highest_id, self.script_url))) # If this is not enough for the future, save rcid in message sending function to make sure we always send all of the changes dbmanager.add(("UPDATE rcgcdb SET rcid = $1 WHERE wiki = $2 AND ( rcid != -1 OR rcid IS NULL )", (highest_id, self.script_url))) # If this is not enough for the future, save rcid in message sending function to make sure we always send all of the changes
return return
async def remove_webhook_from_db(self, reason: str): async def remove_webhook_from_db(self, reason: str):