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:
+1
-1
@@ -100,7 +100,7 @@ try:
|
|||||||
else:
|
else:
|
||||||
db.shared = db
|
db.shared = db
|
||||||
else:
|
else:
|
||||||
raise Exception("Unknown database type '%s'" % config.database.type)
|
raise Exception(f"Unknown database type '{config.database.type}'")
|
||||||
|
|
||||||
# run db upgrade scripts
|
# run db upgrade scripts
|
||||||
run_upgrades()
|
run_upgrades()
|
||||||
|
|||||||
@@ -18,8 +18,13 @@ name = "bot"
|
|||||||
# So we're saving the logs into ./logs/##bot_name##/
|
# So we're saving the logs into ./logs/##bot_name##/
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
name = sys.argv[1]
|
name = sys.argv[1]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.mkdir(f"./logs/{name}")
|
os.mkdir(f"./logs", mode=4600)
|
||||||
|
except FileExistsError as error:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
os.mkdir(f"./logs/{name}", mode=4600)
|
||||||
except FileExistsError as error:
|
except FileExistsError as error:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -22,12 +22,12 @@ class Logger:
|
|||||||
|
|
||||||
def log_chat(self, conn_id, channel, sender, msg):
|
def log_chat(self, conn_id, channel, sender, msg):
|
||||||
if sender:
|
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:
|
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):
|
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):
|
def format_chat_message(self, msg):
|
||||||
msg = re.sub(r"<a\s+href=\".+?[^\\]\">", "[link]", msg, flags=re.UNICODE | re.DOTALL)
|
msg = re.sub(r"<a\s+href=\".+?[^\\]\">", "[link]", msg, flags=re.UNICODE | re.DOTALL)
|
||||||
|
|||||||
@@ -47,16 +47,15 @@ class MessageHubService:
|
|||||||
invalid_sources = []
|
invalid_sources = []
|
||||||
if len(inspect.signature(callback).parameters) != 1:
|
if len(inspect.signature(callback).parameters) != 1:
|
||||||
raise Exception(
|
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:
|
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:
|
for source in default_sources:
|
||||||
if source not in self.sources:
|
if source not in self.sources:
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
"Could not subscribe destination '%s' to source '%s' because source does not exist" % (
|
f"Could not subscribe destination '{destination}' to source '{source}' because source does not exist")
|
||||||
destination, source))
|
|
||||||
|
|
||||||
self.hub[destination] = (DictObject({"name": destination,
|
self.hub[destination] = (DictObject({"name": destination,
|
||||||
"callback": callback,
|
"callback": callback,
|
||||||
@@ -85,11 +84,11 @@ class MessageHubService:
|
|||||||
|
|
||||||
def subscribe_to_source(self, destination, source):
|
def subscribe_to_source(self, destination, source):
|
||||||
if source not in self.sources:
|
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)
|
obj = self.hub.get(destination, None)
|
||||||
if not obj:
|
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:
|
if source not in obj.sources:
|
||||||
self.db.exec("DELETE FROM message_hub_subscriptions WHERE destination = ?", [destination])
|
self.db.exec("DELETE FROM message_hub_subscriptions WHERE destination = ?", [destination])
|
||||||
@@ -105,7 +104,7 @@ class MessageHubService:
|
|||||||
|
|
||||||
obj = self.hub.get(destination, None)
|
obj = self.hub.get(destination, None)
|
||||||
if not obj:
|
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:
|
if source in obj.sources:
|
||||||
self.db.exec("DELETE FROM message_hub_subscriptions WHERE destination = ?", [destination])
|
self.db.exec("DELETE FROM message_hub_subscriptions WHERE destination = ?", [destination])
|
||||||
|
|||||||
@@ -71,8 +71,8 @@ class PublicChannelService(BaseModule):
|
|||||||
else:
|
else:
|
||||||
data = self.event_service.db.query_single('SELECT org_name from all_orgs where org_id=?', [self.org_id])
|
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.org_name = data.org_name if data else 'Unknown Org'
|
||||||
self.logger.info("Org Id: %d" % self.org_id)
|
self.logger.info(f"Org Id: {self.org_id:d}")
|
||||||
self.logger.info("Org Name: %s" % self.org_name)
|
self.logger.info(f"Org Name: {self.org_name}")
|
||||||
|
|
||||||
def remove(self, conn: Conn, packet: server_packets.PublicChannelLeft):
|
def remove(self, conn: Conn, packet: server_packets.PublicChannelLeft):
|
||||||
if conn.id != "main":
|
if conn.id != "main":
|
||||||
|
|||||||
@@ -52,15 +52,14 @@ class SettingService:
|
|||||||
row = self.db.query_single("SELECT name, value, description FROM setting WHERE name = ?", [name])
|
row = self.db.query_single("SELECT name, value, description FROM setting WHERE name = ?", [name])
|
||||||
|
|
||||||
if row is None:
|
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 (?, ?, ?, ?, ?)",
|
self.db.exec("INSERT INTO setting (name, value, description, module, verified) VALUES (?, ?, ?, ?, ?)",
|
||||||
[name, "", description, module, 1])
|
[name, "", description, module, 1])
|
||||||
print(2, name)
|
|
||||||
|
|
||||||
# verify default value is a valid value, and is formatted appropriately
|
# verify default value is a valid value, and is formatted appropriately
|
||||||
setting.set_value(value)
|
setting.set_value(value)
|
||||||
else:
|
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 = ?",
|
self.db.exec("UPDATE setting SET description = ?, verified = ?, module = ? WHERE name = ?",
|
||||||
[description, 1, module, name])
|
[description, 1, module, name])
|
||||||
self.settings[name] = setting
|
self.settings[name] = setting
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class DictionarySettingType(SettingType):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
def get_display_value(self):
|
def get_display_value(self):
|
||||||
return "<highlight>%s</highlight>" % (self.get_value() or "<empty>")
|
return f"<highlight>{self.get_value() or '<empty>'}</highlight>"
|
||||||
|
|
||||||
def get_display(self):
|
def get_display(self):
|
||||||
return """This setting is controlled by the bot and cannot be set manually."""
|
return """This setting is controlled by the bot and cannot be set manually."""
|
||||||
@@ -121,6 +121,7 @@ class HiddenSettingType(TextSettingType):
|
|||||||
else:
|
else:
|
||||||
return "<highlight><empty></highlight>"
|
return "<highlight><empty></highlight>"
|
||||||
|
|
||||||
|
@property
|
||||||
def get_display(self):
|
def get_display(self):
|
||||||
text = Registry.get_instance("text")
|
text = Registry.get_instance("text")
|
||||||
|
|
||||||
|
|||||||
+8
-8
@@ -60,19 +60,19 @@ class Text:
|
|||||||
def make_chatcmd(self, name, msg, style=""):
|
def make_chatcmd(self, name, msg, style=""):
|
||||||
msg = msg.strip()
|
msg = msg.strip()
|
||||||
msg = msg.replace("'", "'")
|
msg = msg.replace("'", "'")
|
||||||
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>"):
|
def make_tellcmd(self, name, msg, style="", char="<myname>"):
|
||||||
return self.make_chatcmd(name, f"/tell {char} {msg}", style)
|
return self.make_chatcmd(name, f"/tell {char} {msg}", style)
|
||||||
|
|
||||||
def make_charlink(self, char, 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):
|
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"):
|
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):
|
def format_item(self, item, ql=None, with_icon=True):
|
||||||
if not item:
|
if not item:
|
||||||
@@ -89,8 +89,8 @@ class Text:
|
|||||||
|
|
||||||
def generate_item(self, item, ql, synonym=None):
|
def generate_item(self, item, ql, synonym=None):
|
||||||
if synonym:
|
if synonym:
|
||||||
return {"icon_%s" % synonym: self.make_item(item.lowid, item.highid, ql, self.make_image(item.icon)),
|
return {f"icon_{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)}
|
f"text_{synonym}": self.make_item(item.lowid, item.highid, ql, item.name)}
|
||||||
else:
|
else:
|
||||||
return {"icon": self.make_item(item.lowid, item.highid, ql, self.make_image(item.icon)),
|
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)}
|
"text": self.make_item(item.lowid, item.highid, ql, item.name)}
|
||||||
@@ -120,10 +120,10 @@ class Text:
|
|||||||
count = len(selected)
|
count = len(selected)
|
||||||
pages = ""
|
pages = ""
|
||||||
if page > 1:
|
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):
|
if offset + page_size < len(data):
|
||||||
pages += f" Page {page}/{math.ceil(len(data) / page_size)}"
|
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"
|
pages += "\n"
|
||||||
if count == 0:
|
if count == 0:
|
||||||
return no_data_msg
|
return no_data_msg
|
||||||
|
|||||||
+3
-3
@@ -232,12 +232,12 @@ class Tyrbot:
|
|||||||
if not self.iterate(1):
|
if not self.iterate(1):
|
||||||
time_waited += 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()
|
start = time.time()
|
||||||
self.event_service.fire_event("connect", None)
|
self.event_service.fire_event("connect", None)
|
||||||
self.event_service.run_timer_events_at_startup()
|
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.ready = True
|
||||||
self.command_service.ignore = []
|
self.command_service.ignore = []
|
||||||
timestamp = int(time.time())
|
timestamp = int(time.time())
|
||||||
@@ -275,7 +275,7 @@ class Tyrbot:
|
|||||||
|
|
||||||
if len(inspect.signature(handler).parameters) != 2:
|
if len(inspect.signature(handler).parameters) != 2:
|
||||||
raise Exception(
|
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 = self.packet_handlers.get(packet_id, [])
|
||||||
handlers.append(DictObject({"priority": priority, "handler": handler}))
|
handlers.append(DictObject({"priority": priority, "handler": handler}))
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class AccountController:
|
|||||||
msg = sorted(entries, key=lambda k: k[0])
|
msg = sorted(entries, key=lambda k: k[0])
|
||||||
for _, mess in msg:
|
for _, mess in msg:
|
||||||
out += mess
|
out += mess
|
||||||
self.bot.send_mass_message(request.sender.char_id, ChatBlob("All accounts", out))
|
self.bot.send_mass_message(request.sender.char_id, ChatBlob(f"All accounts ({len(entries)})", out))
|
||||||
|
|
||||||
@command(command="points", params=[], access_level="member",
|
@command(command="points", params=[], access_level="member",
|
||||||
description="View your points")
|
description="View your points")
|
||||||
|
|||||||
@@ -179,8 +179,9 @@ class AltsController:
|
|||||||
blob += f"{self.util.get_prof_icon(alt.profession)} " \
|
blob += f"{self.util.get_prof_icon(alt.profession)} " \
|
||||||
f"<yellow>{self.text.zfill(alt.level, 220)}</yellow>:" \
|
f"<yellow>{self.text.zfill(alt.level, 220)}</yellow>:" \
|
||||||
f"<green>{self.text.zfill(alt.ai_level, 30)}</green> " \
|
f"<green>{self.text.zfill(alt.ai_level, 30)}</green> " \
|
||||||
f":: <{alt.faction.lower()}>{name}</{alt.faction.lower()}> " \
|
f":: <{alt.faction.lower()}>{name}</{alt.faction.lower()}>"
|
||||||
f"[<{alt.faction.lower()}>{alt.org_name}</{alt.faction.lower()}> - " \
|
if alt.org_name != "":
|
||||||
|
blob += f" [<{alt.faction.lower()}>{alt.org_name}</{alt.faction.lower()}> - " \
|
||||||
f"<highlight>{alt.org_rank_id + 1}</highlight>]"
|
f"<highlight>{alt.org_rank_id + 1}</highlight>]"
|
||||||
if self.buddy_service.is_online(alt.char_id):
|
if self.buddy_service.is_online(alt.char_id):
|
||||||
blob += " [<green>Online</green>]"
|
blob += " [<green>Online</green>]"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from core.logger import Logger
|
|||||||
from core.lookup.pork_service import PorkService
|
from core.lookup.pork_service import PorkService
|
||||||
from core.setting_service import SettingService
|
from core.setting_service import SettingService
|
||||||
from core.text import Text
|
from core.text import Text
|
||||||
|
from core.translation_service import TranslationService
|
||||||
from core.tyrbot import Tyrbot
|
from core.tyrbot import Tyrbot
|
||||||
from core.util import Util
|
from core.util import Util
|
||||||
from modules.core.accounting.services.account_service import AccountService
|
from modules.core.accounting.services.account_service import AccountService
|
||||||
@@ -31,6 +32,8 @@ class PreferenceController:
|
|||||||
self.setting_service: SettingService = registry.get_instance("setting_service")
|
self.setting_service: SettingService = registry.get_instance("setting_service")
|
||||||
self.discord: DiscordController = registry.get_instance("discord_controller")
|
self.discord: DiscordController = registry.get_instance("discord_controller")
|
||||||
self.job_scheduler = registry.get_instance("job_scheduler")
|
self.job_scheduler = registry.get_instance("job_scheduler")
|
||||||
|
self.ts: TranslationService = registry.get_instance("translation_service")
|
||||||
|
self.getresp = self.ts.get_response
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.command_alias_service.add_alias("prefs", "preferences")
|
self.command_alias_service.add_alias("prefs", "preferences")
|
||||||
@@ -68,6 +71,15 @@ class PreferenceController:
|
|||||||
return f"<highlight>{main.name}</highlight>'s <highlight>{pref.capitalize()}</highlight> " \
|
return f"<highlight>{main.name}</highlight>'s <highlight>{pref.capitalize()}</highlight> " \
|
||||||
f"preference has been set to {value}."
|
f"preference has been set to {value}."
|
||||||
|
|
||||||
|
@command(command="prefadmin", params=[Character('character')], description="View the preferences of a player", access_level="moderator")
|
||||||
|
def show_prefadmin(self, request, char):
|
||||||
|
if not char.char_id:
|
||||||
|
return self.getresp("global", "char_not_found", {"char": char.name})
|
||||||
|
account = self.account_service.get_account(char.char_id)
|
||||||
|
if not account:
|
||||||
|
return f"{char.name} has no preferences you could manage...."
|
||||||
|
return ChatBlob(f"{account.name}'s Preferences", self.get_pref_view_full(account, account))
|
||||||
|
|
||||||
def get_prefs(self, char_id):
|
def get_prefs(self, char_id):
|
||||||
return self.account_service.get_account(char_id)
|
return self.account_service.get_account(char_id)
|
||||||
|
|
||||||
@@ -82,25 +94,31 @@ class PreferenceController:
|
|||||||
self.db.exec(f"UPDATE account set {pref}={value} where char_id=(SELECT main from account where char_id=?)",
|
self.db.exec(f"UPDATE account set {pref}={value} where char_id=(SELECT main from account where char_id=?)",
|
||||||
[char_id])
|
[char_id])
|
||||||
|
|
||||||
def get_pref_view_small(self, prefs):
|
def get_pref_view_small(self, prefs, owner=None):
|
||||||
return f"\n" \
|
return f"\n" \
|
||||||
f" └ [{self._make_cmd('news', prefs.news_spam)}] News - " \
|
f" └ [{self._make_cmd('news', prefs.news_spam, owner)}] News - " \
|
||||||
f"Autoinvite [{self._make_cmd('autoinvite', prefs.auto_invite)}], \n" \
|
f"Autoinvite [{self._make_cmd('autoinvite', prefs.auto_invite, owner)}], \n" \
|
||||||
f" └ [{self._make_cmd('raidinvite', prefs.raid_invite)}] Raidinvite - " \
|
f" └ [{self._make_cmd('raidinvite', prefs.raid_invite, owner)}] Raidinvite - " \
|
||||||
f"Massmessage [{self._make_cmd('raidspam', prefs.raid_invite)}], \n" \
|
f"Massmessage [{self._make_cmd('raidspam', prefs.raid_invite, owner)}], \n" \
|
||||||
f" └ [{self._make_cmd('subtilespam', prefs.subtile_spam)}] Subtilespam"
|
f" └ [{self._make_cmd('subtilespam', prefs.subtile_spam, owner)}] Subtilespam"
|
||||||
|
|
||||||
def get_pref_view_full(self, prefs):
|
def get_pref_view_full(self, prefs, owner=None):
|
||||||
return f"\n" \
|
return f"\n" \
|
||||||
f"<tab>└ [ {self._make_cmd('news', prefs.news_spam)} ] Do you want your News on Logon? \n" \
|
f"<tab>└ [ {self._make_cmd('news', prefs.news_spam, owner)} ] Do you want your News on Logon? \n" \
|
||||||
f"<tab>└ [ {self._make_cmd('autoinvite', prefs.auto_invite)} ] Do you want to receive autoinvites? \n" \
|
f"<tab>└ [ {self._make_cmd('autoinvite', prefs.auto_invite, owner)} ] Do you want to receive autoinvites? \n" \
|
||||||
f"<tab>└ [ {self._make_cmd('raidinvite', prefs.raid_invite)} ] Do you want to receive raidinvites? \n" \
|
f"<tab>└ [ {self._make_cmd('raidinvite', prefs.raid_invite, owner)} ] Do you want to receive raidinvites? \n" \
|
||||||
f"<tab>└ [ {self._make_cmd('raidspam', prefs.raid_invite)} ] Do you want to receive massmessages? \n" \
|
f"<tab>└ [ {self._make_cmd('raidspam', prefs.raid_invite, owner)} ] Do you want to receive massmessages? \n" \
|
||||||
f"<tab>└ [ {self._make_cmd('subtilespam', prefs.subtile_spam)} ] Do you want a subtile invite spam? \n"
|
f"<tab>└ [ {self._make_cmd('subtilespam', prefs.subtile_spam, owner)} ] Do you want a subtile invite spam? \n"
|
||||||
|
|
||||||
def _make_cmd(self, pref, value):
|
def _make_cmd(self, pref, value, owner=None):
|
||||||
# ---
|
# ---
|
||||||
# [ ON | OFF ]
|
# [ YES | NO ]
|
||||||
|
if owner:
|
||||||
|
if value == 1:
|
||||||
|
return f"<green>YES</green> | {self.text.make_chatcmd('NO', f'/tell <myname> prefadmin set {owner.name} {pref} off')}"
|
||||||
|
else:
|
||||||
|
return f"{self.text.make_chatcmd('YES', f'/tell <myname> prefadmin set {owner.name} {pref} on')} | <red>NO</red>"
|
||||||
|
|
||||||
if value == 1:
|
if value == 1:
|
||||||
return f"<green>YES</green> | {self.text.make_chatcmd('NO', f'/tell <myname> preferences set {pref} off')}"
|
return f"<green>YES</green> | {self.text.make_chatcmd('NO', f'/tell <myname> preferences set {pref} off')}"
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ class AccessService:
|
|||||||
|
|
||||||
def get_access_level(self, char_id) -> dict:
|
def get_access_level(self, char_id) -> dict:
|
||||||
account = self.account_service.get_main(char_id)
|
account = self.account_service.get_main(char_id)
|
||||||
|
# For performance's sake, we'll assume that the main has the highest rank;
|
||||||
|
# if it only has the rank "all" (no rank), we'll also check the toon using the command.
|
||||||
if account:
|
if account:
|
||||||
al = self.get_single_access_level(account.char_id)
|
al = self.get_single_access_level(account.char_id)
|
||||||
if al["label"] == "all":
|
if al["label"] == "all":
|
||||||
@@ -48,21 +50,6 @@ class AccessService:
|
|||||||
return al
|
return al
|
||||||
else:
|
else:
|
||||||
return self.get_single_access_level(char_id)
|
return self.get_single_access_level(char_id)
|
||||||
# access_level1 = self.get_single_access_level(char_id)
|
|
||||||
#
|
|
||||||
# alts = self.account_service.get_alts(char_id)
|
|
||||||
# if not alts:
|
|
||||||
# return access_level1
|
|
||||||
#
|
|
||||||
# main = alts[0]
|
|
||||||
# if main.char_id == char_id:
|
|
||||||
# return access_level1
|
|
||||||
# else:
|
|
||||||
# access_level2 = self.get_single_access_level(main.char_id)
|
|
||||||
# if access_level1["level"] < access_level2["level"]:
|
|
||||||
# return access_level1
|
|
||||||
# else:
|
|
||||||
# return access_level2
|
|
||||||
|
|
||||||
def compare_access_levels(self, access_level1, access_level2) -> int:
|
def compare_access_levels(self, access_level1, access_level2) -> int:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -147,13 +147,18 @@ class AccountService:
|
|||||||
acc_cache = {}
|
acc_cache = {}
|
||||||
|
|
||||||
def get_account(self, char_id) -> DictObject:
|
def get_account(self, char_id) -> DictObject:
|
||||||
|
# The way the caching is handled does not come without side effects:
|
||||||
|
# For example, after purging an account,
|
||||||
|
# you could still update it (i.e. add points, alts, ...)
|
||||||
|
# which would result in log entries,
|
||||||
|
# without an associated account
|
||||||
if char_id not in self.acc_cache.keys():
|
if char_id not in self.acc_cache.keys():
|
||||||
out = self.db.query_single(
|
out = self.db.query_single(
|
||||||
"SELECT a.*, p.* from account a left join player p on a.char_id = p.char_id where "
|
"SELECT a.*, p.* from account a left join player p on a.char_id = p.char_id where "
|
||||||
"a.char_id=(SELECT main from account where char_id=?) "
|
"a.char_id=(SELECT main from account where char_id=?) "
|
||||||
"and a.char_id not in (SELECT char_id from org_bots)",
|
"and a.char_id not in (SELECT char_id from org_bots)",
|
||||||
[char_id]) or DictObject({})
|
[char_id]) or DictObject({})
|
||||||
|
|
||||||
self.acc_cache[char_id] = out
|
self.acc_cache[char_id] = out
|
||||||
self.bot.job_scheduler.delayed_job(lambda x: self.acc_cache.pop(char_id), 5)
|
self.bot.job_scheduler.delayed_job(lambda x: self.acc_cache.pop(char_id), 5)
|
||||||
else:
|
else:
|
||||||
@@ -419,7 +424,7 @@ class AccountService:
|
|||||||
f"LEFT JOIN (SELECT * FROM online WHERE bot=?) o ON a.char_id=o.char_id "
|
f"LEFT JOIN (SELECT * FROM online WHERE bot=?) o ON a.char_id=o.char_id "
|
||||||
f"WHERE a.char_id NOT IN (SELECT char_id from org_bots) "
|
f"WHERE a.char_id NOT IN (SELECT char_id from org_bots) "
|
||||||
f"and a.disabled = 0 {'and o.char_id is not null' if online_only else ''} "
|
f"and a.disabled = 0 {'and o.char_id is not null' if online_only else ''} "
|
||||||
f"order by a.main, a.main=a.char_id desc, p.level desc, p.ai_level desc",
|
f"group by o.char_id order by a.main, a.main=a.char_id desc, p.level desc, p.ai_level desc",
|
||||||
[self.bot.get_char_id()])
|
[self.bot.get_char_id()])
|
||||||
|
|
||||||
def get_by_group(self, group) -> List[DictObject]:
|
def get_by_group(self, group) -> List[DictObject]:
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ class PrivateChannelController:
|
|||||||
description="Relay commands from the private channel to the relay hub", is_hidden=True)
|
description="Relay commands from the private channel to the relay hub", is_hidden=True)
|
||||||
def outgoing_private_channel_message_event(self, _, event_data):
|
def outgoing_private_channel_message_event(self, _, event_data):
|
||||||
if isinstance(event_data.message, ChatBlob):
|
if isinstance(event_data.message, ChatBlob):
|
||||||
pages = self.text.paginate(ChatBlob(event_data.message.title, event_data.message.msg),
|
pages = self.text.paginate(event_data.message,
|
||||||
self.setting_service.get("org_channel_max_page_length").get_value())
|
self.setting_service.get("org_channel_max_page_length").get_value())
|
||||||
if len(pages) < 4:
|
if len(pages) < 4:
|
||||||
for page in pages:
|
for page in pages:
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ class OrgChannelController:
|
|||||||
is_hidden=True)
|
is_hidden=True)
|
||||||
def outgoing_org_message_event(self, _, event_data):
|
def outgoing_org_message_event(self, _, event_data):
|
||||||
if isinstance(event_data.message, ChatBlob):
|
if isinstance(event_data.message, ChatBlob):
|
||||||
pages = self.text.paginate(ChatBlob(event_data.message.title, event_data.message.msg),
|
pages = self.text.paginate(event_data.message,
|
||||||
self.setting_service.get("org_channel_max_page_length").get_value())
|
self.setting_service.get("org_channel_max_page_length").get_value())
|
||||||
if len(pages) < 4:
|
if len(pages) < 4:
|
||||||
for page in pages:
|
for page in pages:
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ from modules.standard.helpbot.playfield_controller import PlayfieldController
|
|||||||
|
|
||||||
@instance()
|
@instance()
|
||||||
class TowerService(BaseModule):
|
class TowerService(BaseModule):
|
||||||
# [{'org_name': "Dragons", 'hot': time.time() + 60 * 60}, {'org_name': "Most Wanted", 'hot': time.time() + 60 * 60}]
|
# For this Module to work properly you might need to
|
||||||
|
# contact the API host of your choice to whitelist your IP addresses.
|
||||||
attack_hot = []
|
attack_hot = []
|
||||||
plant = []
|
plant = []
|
||||||
|
|
||||||
@@ -112,6 +113,10 @@ class TowerService(BaseModule):
|
|||||||
# ?limit is a parameter not documented anywhere, but allows pulling the whole list
|
# ?limit is a parameter not documented anywhere, but allows pulling the whole list
|
||||||
# On other API implementations this parameter has no effect,
|
# On other API implementations this parameter has no effect,
|
||||||
# as the server always responds with the full list.
|
# as the server always responds with the full list.
|
||||||
|
|
||||||
|
# In the Future, this Event will get moved to an external process,
|
||||||
|
# which maintains the tower Cache for all connected bots,
|
||||||
|
# like it has been done with the Worldboss timers.
|
||||||
from torpy.http.requests import TorRequests
|
from torpy.http.requests import TorRequests
|
||||||
with TorRequests() as tor_request:
|
with TorRequests() as tor_request:
|
||||||
with tor_request.get_session(1) as session:
|
with tor_request.get_session(1) as session:
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import sys
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from conf.config import BotConfig
|
|
||||||
from core.command_alias_service import CommandAliasService
|
from core.command_alias_service import CommandAliasService
|
||||||
from core.decorators import instance, command, event
|
from core.decorators import instance, command, event
|
||||||
from core.dict_object import DictObject
|
from core.dict_object import DictObject
|
||||||
@@ -17,18 +15,18 @@ from modules.standard.datanet.ws_controller import WebsocketRelayController
|
|||||||
|
|
||||||
@instance()
|
@instance()
|
||||||
class WorldBossController:
|
class WorldBossController:
|
||||||
|
# Timers are provided through an local websocket relay, which gets fed by an external API;
|
||||||
|
# If you intend to take advantage of this module,
|
||||||
|
# you **will** need to contact the API host of your choice to whitelist
|
||||||
|
# The IP Addresses with which you intend to access the API.
|
||||||
|
# example timer data:
|
||||||
|
# [{"name":"Tarasque","time": <mortal time>},
|
||||||
|
# {"name":"Vizaresh","time": <mortal time>}]
|
||||||
|
timer_data = []
|
||||||
|
|
||||||
alerts = [480 * 60, 360 * 60, 240 * 60, 120 * 60, 60 * 60, 60 * 15,
|
alerts = [480 * 60, 360 * 60, 240 * 60, 120 * 60, 60 * 60, 60 * 15,
|
||||||
60 * 5, 60 * 3, 60 * 2, 60, 30, 15, 10, 5, 4, 3, 2, 1, 0]
|
60 * 5, 60 * 3, 60 * 2, 60, 30, 15, 10, 5, 4, 3, 2, 1, 0]
|
||||||
jobs = []
|
jobs = []
|
||||||
timer_data = []
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
mod = __import__(f'conf.{sys.argv[1]}', fromlist=['BotConfig'])
|
|
||||||
config: BotConfig = getattr(mod, 'BotConfig')
|
|
||||||
if hasattr(config, "timer_url"):
|
|
||||||
self.timer_api = config.timer_url
|
|
||||||
else:
|
|
||||||
self.timer_api = None
|
|
||||||
|
|
||||||
def inject(self, registry):
|
def inject(self, registry):
|
||||||
self.logger = Logger(__name__)
|
self.logger = Logger(__name__)
|
||||||
|
|||||||
@@ -57,6 +57,6 @@ class PerksController:
|
|||||||
if row.perk_name != current_perk:
|
if row.perk_name != current_perk:
|
||||||
blob += f"\n<header2>{row.perk_name} {row.max_perk_level}</header2>\n"
|
blob += f"\n<header2>{row.perk_name} {row.max_perk_level}</header2>\n"
|
||||||
current_perk = row.perk_name
|
current_perk = row.perk_name
|
||||||
blob += f"{row.skill} <highlight>{row.buff_amount:d}</highlight>\n"
|
blob += f"{row.skill} <highlight>{row.buff_amount}</highlight>\n"
|
||||||
|
|
||||||
return ChatBlob(f"Buff Perks for {level:d} {prof}", blob)
|
return ChatBlob(f"Buff Perks for {level} {prof}", blob)
|
||||||
|
|||||||
Reference in New Issue
Block a user