diff --git a/modules/onlinebot/online/org_controller.py b/modules/onlinebot/online/org_controller.py index 757b5ad..7f732ee 100644 --- a/modules/onlinebot/online/org_controller.py +++ b/modules/onlinebot/online/org_controller.py @@ -199,6 +199,7 @@ class OrgController: output = [] data = [] accounts = [] + timestamp = 0 ours = self.db.query("SELECT o.org_id, a.org_name from orgs o " "left join all_orgs a on o.org_id = a.org_id order by lower(a.org_name)") for org in ours: @@ -207,6 +208,9 @@ class OrgController: self.cache.store('org_roster', f"{org.org_id}.5.json", json.dumps(result)) else: result = json.loads(self.cache.retrieve('org_roster', f"{org.org_id}.5.json").data) + d = datetime.datetime.strptime(result[2] + " +0000", '%Y/%m/%d %H:%M:%S %z').timestamp() + if d > timestamp: + timestamp = d for char_info in result[1]: data.append((char_info["CHAR_INSTANCE"], char_info["NAME"], char_info["FIRSTNAME"], @@ -288,6 +292,13 @@ class OrgController: self.logger.info( f"Successfully fetched {len(data)} players from {len(ours)} orgs " f"in {time.time() - start:.2f} seconds. - ") + while (timestamp + 24 * 60 * 60) < datetime.datetime.now().timestamp(): + timestamp += 24 * 60 * 60 + self.db.exec("UPDATE timer_event SET next_run=? WHERE handler=? AND event_sub_type=?", [ + int(timestamp +24*60*60 + 10*60), + "modules.onlinebot.online.org_controller.OrgController.fetch_orgs", + 86400 + ]) del self.threads['roster'] if "roster" not in self.threads.keys(): diff --git a/modules/orgbot/org/org_roster_controller.py b/modules/orgbot/org/org_roster_controller.py index d42f267..95a7da6 100644 --- a/modules/orgbot/org/org_roster_controller.py +++ b/modules/orgbot/org/org_roster_controller.py @@ -1,3 +1,4 @@ +import datetime import json import time import typing @@ -196,6 +197,14 @@ class OrgRosterController: [self.public_channel_service.org_id]) conn.commit() self.bot.send_org_message('Successfully updated the roster.') + d = datetime.datetime.strptime(result[2] + " +0000", '%Y/%m/%d %H:%M:%S %z').timestamp() + while (d + 24*60*60) < datetime.datetime.now().timestamp(): + d += 24*60*60 + self.db.exec("UPDATE timer_event SET next_run=? WHERE handler=? AND event_sub_type=?", [ + int(d+24*60*60 + 15*60), + "modules.orgbot.org.org_roster_controller.OrgRosterController.update_roster", + 86400 + ]) @event(PublicChannelService.ORG_MSG_EVENT, "Update org roster when characters join or leave", is_hidden=True) def org_msg_event(self, _, event_data):