Changed the string formatter from % to f"",

Fixed a bug related to logging [log dir does not exist on master, and needs to get created on first startup]
Added !prefadmin <user> to view preferences of players, and change them
Orgrank & name will be hidden in !alts, if the character is not in an org
Page prefix & suffix are now being relayed [for example, it affects !online
Fixed !perks
Added comments regarding external API's.
This commit is contained in:
2021-08-14 02:36:20 +02:00
parent 80b5a4b577
commit 46d0ba3634
19 changed files with 104 additions and 86 deletions
+3 -3
View File
@@ -22,12 +22,12 @@ class Logger:
def log_chat(self, conn_id, channel, sender, msg):
if sender:
self.info("(%s) [%s] %s: %s" % (conn_id, channel, sender, self.format_chat_message(msg)))
self.info(f"({conn_id}) [{channel}] {sender}: {self.format_chat_message(msg)}")
else:
self.info("(%s) [%s] %s" % (conn_id, channel, self.format_chat_message(msg)))
self.info(f"({conn_id}) [{channel}] {self.format_chat_message(msg)}")
def log_tell(self, conn_id, direction, sender, msg):
self.info("(%s) %s %s: %s" % (conn_id, direction.capitalize(), sender, self.format_chat_message(msg)))
self.info(f"({conn_id}) {direction.capitalize()} {sender}: {self.format_chat_message(msg)}")
def format_chat_message(self, msg):
msg = re.sub(r"<a\s+href=\".+?[^\\]\">", "[link]", msg, flags=re.UNICODE | re.DOTALL)
+6 -7
View File
@@ -47,16 +47,15 @@ class MessageHubService:
invalid_sources = []
if len(inspect.signature(callback).parameters) != 1:
raise Exception(
"Incorrect number of arguments for handler '%s.%s()'" % (callback.__module__, callback.__name__))
f"Incorrect number of arguments for handler '{callback.__module__}.{callback.__name__}()'")
if destination in self.hub:
raise Exception("Message hub destination '%s' already subscribed" % destination)
raise Exception(f"Message hub destination '{destination}' already subscribed")
for source in default_sources:
if source not in self.sources:
self.logger.warning(
"Could not subscribe destination '%s' to source '%s' because source does not exist" % (
destination, source))
f"Could not subscribe destination '{destination}' to source '{source}' because source does not exist")
self.hub[destination] = (DictObject({"name": destination,
"callback": callback,
@@ -85,11 +84,11 @@ class MessageHubService:
def subscribe_to_source(self, destination, source):
if source not in self.sources:
raise Exception("Message hub source '%s' doeselecs not exist" % source)
raise Exception(f"Message hub source '{source}' does not exist")
obj = self.hub.get(destination, None)
if not obj:
raise Exception("Message hub destination '%s' does not exist" % destination)
raise Exception(f"Message hub destination '{destination}' does not exist")
if source not in obj.sources:
self.db.exec("DELETE FROM message_hub_subscriptions WHERE destination = ?", [destination])
@@ -105,7 +104,7 @@ class MessageHubService:
obj = self.hub.get(destination, None)
if not obj:
raise Exception("Message hub destination '%s' does not exist" % destination)
raise Exception(f"Message hub destination '{destination}' does not exist")
if source in obj.sources:
self.db.exec("DELETE FROM message_hub_subscriptions WHERE destination = ?", [destination])
+2 -2
View File
@@ -71,8 +71,8 @@ class PublicChannelService(BaseModule):
else:
data = self.event_service.db.query_single('SELECT org_name from all_orgs where org_id=?', [self.org_id])
self.org_name = data.org_name if data else 'Unknown Org'
self.logger.info("Org Id: %d" % self.org_id)
self.logger.info("Org Name: %s" % self.org_name)
self.logger.info(f"Org Id: {self.org_id:d}")
self.logger.info(f"Org Name: {self.org_name}")
def remove(self, conn: Conn, packet: server_packets.PublicChannelLeft):
if conn.id != "main":
+2 -3
View File
@@ -52,15 +52,14 @@ class SettingService:
row = self.db.query_single("SELECT name, value, description FROM setting WHERE name = ?", [name])
if row is None:
self.logger.debug("Adding setting '%s'" % name)
self.logger.debug(f"Adding setting '{name}'")
self.db.exec("INSERT INTO setting (name, value, description, module, verified) VALUES (?, ?, ?, ?, ?)",
[name, "", description, module, 1])
print(2, name)
# verify default value is a valid value, and is formatted appropriately
setting.set_value(value)
else:
self.logger.debug("Updating setting '%s'" % name)
self.logger.debug(f"Updating setting '{name}'")
self.db.exec("UPDATE setting SET description = ?, verified = ?, module = ? WHERE name = ?",
[description, 1, module, name])
self.settings[name] = setting
+2 -1
View File
@@ -105,7 +105,7 @@ class DictionarySettingType(SettingType):
return value
def get_display_value(self):
return "<highlight>%s</highlight>" % (self.get_value() or "&lt;empty&gt;")
return f"<highlight>{self.get_value() or '&lt;empty&gt;'}</highlight>"
def get_display(self):
return """This setting is controlled by the bot and cannot be set manually."""
@@ -121,6 +121,7 @@ class HiddenSettingType(TextSettingType):
else:
return "<highlight>&lt;empty&gt;</highlight>"
@property
def get_display(self):
text = Registry.get_instance("text")
+8 -8
View File
@@ -60,19 +60,19 @@ class Text:
def make_chatcmd(self, name, msg, style=""):
msg = msg.strip()
msg = msg.replace("'", "&#39;")
return "<a %s href='chatcmd://%s'>%s</a>" % (style, msg, name)
return f"<a {style} href='chatcmd://{msg}'>{name}</a>"
def make_tellcmd(self, name, msg, style="", char="<myname>"):
return self.make_chatcmd(name, f"/tell {char} {msg}", style)
def make_charlink(self, char, style=""):
return "<a %s href='user://%s'>%s</a>" % (style, char, char)
return f"<a {style} href='user://{char}'>{char}</a>"
def make_item(self, low_id, high_id, ql, name):
return "<a href='itemref://%d/%d/%d'>%s</a>" % (low_id, high_id, ql, name)
return f"<a href='itemref://{low_id:d}/{high_id:d}/{ql:d}'>{name}</a>"
def make_image(self, image_id, image_db="rdb"):
return "<img src='%s://%s'>" % (image_db, image_id)
return f"<img src='{image_db}://{image_id}'>"
def format_item(self, item, ql=None, with_icon=True):
if not item:
@@ -89,8 +89,8 @@ class Text:
def generate_item(self, item, ql, synonym=None):
if synonym:
return {"icon_%s" % synonym: self.make_item(item.lowid, item.highid, ql, self.make_image(item.icon)),
"text_%s" % synonym: self.make_item(item.lowid, item.highid, ql, item.name)}
return {f"icon_{synonym}": self.make_item(item.lowid, item.highid, ql, self.make_image(item.icon)),
f"text_{synonym}": self.make_item(item.lowid, item.highid, ql, item.name)}
else:
return {"icon": self.make_item(item.lowid, item.highid, ql, self.make_image(item.icon)),
"text": self.make_item(item.lowid, item.highid, ql, item.name)}
@@ -120,10 +120,10 @@ class Text:
count = len(selected)
pages = ""
if page > 1:
pages += "Pages: " + self.make_tellcmd("«« Page %d" % (page - 1), f'{cmd} --page={page - 1}')
pages += "Pages: " + self.make_tellcmd(f"«« Page {page - 1:d}", f'{cmd} --page={page - 1}')
if offset + page_size < len(data):
pages += f" Page {page}/{math.ceil(len(data) / page_size)}"
pages += " " + self.make_tellcmd("Page %d »»" % (page + 1), f'{cmd} --page={page + 1}')
pages += " " + self.make_tellcmd(f"Page {page + 1:d} »»", f'{cmd} --page={page + 1}')
pages += "\n"
if count == 0:
return no_data_msg
+3 -3
View File
@@ -232,12 +232,12 @@ class Tyrbot:
if not self.iterate(1):
time_waited += 1
self.logger.info("Login complete (%fs)" % (time.time() - start))
self.logger.info(f"Login complete ({time.time() - start:.2f}s)")
start = time.time()
self.event_service.fire_event("connect", None)
self.event_service.run_timer_events_at_startup()
self.logger.info("Connect events finished (%fs)" % (time.time() - start))
self.logger.info(f"Connect events finished ({time.time() - start:.2f}s)")
self.ready = True
self.command_service.ignore = []
timestamp = int(time.time())
@@ -275,7 +275,7 @@ class Tyrbot:
if len(inspect.signature(handler).parameters) != 2:
raise Exception(
"Incorrect number of arguments for handler '%s.%s()'" % (handler.__module__, handler.__name__))
f"Incorrect number of arguments for handler '{handler.__module__}.{handler.__name__}()'")
handlers = self.packet_handlers.get(packet_id, [])
handlers.append(DictObject({"priority": priority, "handler": handler}))