Added the option to !opt-in/opt-out [onlinebot only]
Fixed command & event threading Events are now threaded by event_type (i.e. all buddy_logon events get ran in the same one) Added default preferences Fixed recipe loading for multiple installs (i.e. on different machines)
This commit is contained in:
@@ -76,23 +76,23 @@ class OrgController:
|
||||
orgs = orgs[0]
|
||||
if self.db.exec("REPLACE INTO orgs(org_id) VALUES(?)",
|
||||
[orgs.org_id]) == 1:
|
||||
sender.reply("Adding the organisation <highlight>%s<end> to the roster..." % orgs.org_name)
|
||||
sender.reply(f"Adding the organisation <highlight>{orgs.org_name}<end> to the roster...")
|
||||
org_adder = Thread(name=orgs.org_id, target=self.fetch_single,
|
||||
args=(orgs.org_id, orgs.org_name, sender))
|
||||
self.threads[orgs.org_id] = org_adder
|
||||
org_adder.start()
|
||||
else:
|
||||
return "The organisation <highlight>%s<end> is in the roster already." % orgs.org_name
|
||||
return f"The organisation <highlight>{orgs.org_name}<end> is in the roster already."
|
||||
elif len(orgs) == 0:
|
||||
return "No org with the name <highlight>%s<end> was found on PoRK." % search
|
||||
return f"No org with the name <highlight>{search}<end> was found on PoRK."
|
||||
else:
|
||||
blob = "Your search had multiple results; please pick an org:<br>"
|
||||
for org in orgs:
|
||||
blob += "[%s][%s] <highlight>%s<end> (<highlight>%s<end>) <%s>%s<end> [<highlight>%s<end> " \
|
||||
"members]<br><pagebreak>" \
|
||||
% (self.text.make_chatcmd("Add", "/tell <myname> orgs add %s" % org.org_id),
|
||||
self.text.make_chatcmd("More", "/tell <myname> org info %s" % org.org_id),
|
||||
org.org_name, org.org_id, org.faction.lower(), org.faction, org.member_count)
|
||||
blob += f'[{self.text.make_chatcmd("Add", f"/tell <myname> orgs add {org.org_id}")}]' \
|
||||
f'[{self.text.make_chatcmd("More", f"/tell <myname> org info {org.org_id}")}]' \
|
||||
f' <highlight>{org.org_name}<end> (<highlight>{org.org_id}<end>) ' \
|
||||
f'<{org.faction.lower()}>{org.faction}<end> [<highlight>{org.member_count}<end> members]' \
|
||||
f'<br><pagebreak>'
|
||||
return ChatBlob("Pick an Org", blob)
|
||||
|
||||
@command(command="orgs", params=[Const("rem"), Any("Organisation")], access_level="admin",
|
||||
@@ -109,19 +109,19 @@ class OrgController:
|
||||
org_remover = Thread(name=orgs.org_id, target=self.remove_single, args=(orgs.org_id, orgs.org_name))
|
||||
self.threads[orgs.org_id] = org_remover
|
||||
org_remover.start()
|
||||
return "Removed the organisation <highlight>%s<end> from the roster." % orgs.org_name
|
||||
return f"Removed the organisation <highlight>{orgs.org_name}<end> from the roster."
|
||||
else:
|
||||
return "The organisation <highlight>%s<end> is not on the roster list." % orgs.org_name
|
||||
return f"The organisation <highlight>{orgs.org_name}<end> is not on the roster list."
|
||||
elif len(orgs) == 0:
|
||||
return "The organisation <highlight>%s<end> is not on the roster list." % search
|
||||
return f"The organisation <highlight>{search}<end> is not on the roster list."
|
||||
else:
|
||||
blob = "Your search had multiple results; please pick an org:<br>"
|
||||
for org in orgs:
|
||||
blob += "[%s][%s] <highlight>%s<end> (<highlight>%s<end>) <%s>%s<end> [<highlight>%s<end> " \
|
||||
"members]<br><pagebreak>" \
|
||||
% (self.text.make_chatcmd("Remove", "/tell <myname> orgs remove %s" % org.org_id),
|
||||
self.text.make_chatcmd("More", "/tell <myname> org info %s" % org.org_id),
|
||||
org.org_name, org.org_id, org.faction.lower(), org.faction, org.member_count)
|
||||
blob += f'[{self.text.make_chatcmd("Remove", f"/tell <myname> orgs remove {org.org_id}")}]' \
|
||||
f'[{self.text.make_chatcmd("More", f"/tell <myname> org info {org.org_id}")}]' \
|
||||
f' <highlight>{org.org_name}<end> (<highlight>{org.org_id}<end>) ' \
|
||||
f'<{org.faction.lower()}>{org.faction}<end> [<highlight>{org.member_count}<end> members]' \
|
||||
f'<br><pagebreak>'
|
||||
return ChatBlob("Pick an Org", blob)
|
||||
|
||||
@command(command="orgs", params=[Const("list", is_optional=True)], access_level="member",
|
||||
@@ -169,7 +169,7 @@ class OrgController:
|
||||
continue
|
||||
data.append((int(match[0]), match[1], int(match[2]), match[4], start))
|
||||
count += 1
|
||||
self.logger.info("Batch %s done!" % letter)
|
||||
self.logger.info(f"Batch {letter} done!")
|
||||
|
||||
with self.db.pool.get_connection() as conn:
|
||||
with conn.cursor() as cur:
|
||||
@@ -183,7 +183,7 @@ class OrgController:
|
||||
"last_seen=VALUE(last_seen)",
|
||||
data)
|
||||
self.db.exec("DELETE FROM all_orgs where last_seen < ?", [time.time() - 2 * 24 * 60 * 60])
|
||||
self.logger.info("Successfully fetched %d orgs in %d seconds." % (count, time.time() - start))
|
||||
self.logger.info(f"Successfully fetched {count} orgs in {time.time() - start:.2f} seconds.")
|
||||
self.threads.pop('orgdiscover', None)
|
||||
|
||||
if "orgdiscover" not in self.threads.keys():
|
||||
@@ -229,7 +229,7 @@ class OrgController:
|
||||
"level": char_info["LEVELX"],
|
||||
"ai_level": char_info["ALIENLEVEL"],
|
||||
"ranks": 0}))
|
||||
self.logger.info("Organisation %s has been updated." % org.org_name)
|
||||
self.logger.info(f"Organisation {org.org_name} has been updated.")
|
||||
self.account_service.create_users(accounts)
|
||||
if len(data) > 1:
|
||||
with self.db.lock:
|
||||
@@ -286,8 +286,9 @@ class OrgController:
|
||||
"ranks": count}))
|
||||
self.account_service.remove_members(accounts)
|
||||
self.log(output, time.time() - start)
|
||||
self.logger.info("Successfully fetched %d players from %d orgs in %d seconds. - " % (
|
||||
len(data), len(ours), time.time() - start))
|
||||
self.logger.info(
|
||||
f"Successfully fetched {len(data)} players from {len(ours)} orgs "
|
||||
f"in {time.time() - start:.2f} seconds. - ")
|
||||
del self.threads['roster']
|
||||
|
||||
if "roster" not in self.threads.keys():
|
||||
@@ -330,11 +331,11 @@ class OrgController:
|
||||
"pvp_rating, pvp_title, source, last_updated) VALUES "
|
||||
"(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", data)
|
||||
self.account_service.create_users(accounts)
|
||||
self.logger.info("Organisation %s added!" % org_name)
|
||||
self.logger.info(f"Organisation {org_name} added!")
|
||||
sender.reply(f"<highlight>{org_name}</highlight> has been added to the roster. "
|
||||
f"Runtime: {time.time() - start:.2f} seconds.")
|
||||
|
||||
self.logger.info("Successfully fetched %d players in %d seconds." % (count, time.time() - start))
|
||||
self.logger.info(f"Successfully fetched {count} players in {time.time() - start} seconds.")
|
||||
del self.threads[org_id]
|
||||
|
||||
def remove_single(self, org_id, org_name):
|
||||
@@ -344,7 +345,7 @@ class OrgController:
|
||||
self.db.exec("UPDATE account set member=-1 where char_id in"
|
||||
" (SELECT char_id from player where org_id=?)", [org_id])
|
||||
self.db.exec("DELETE FROM online where char_id in (SELECT char_id from player where org_id=?)", [org_id])
|
||||
self.logger.info("Organisation %s removed!" % org_name)
|
||||
self.logger.info(f"Organisation {org_name} removed!")
|
||||
del self.threads[org_id]
|
||||
|
||||
def log(self, blob, duration):
|
||||
|
||||
Reference in New Issue
Block a user