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
@@ -62,7 +62,7 @@ class AccountController:
msg = sorted(entries, key=lambda k: k[0])
for _, mess in msg:
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",
description="View your points")
+4 -3
View File
@@ -179,9 +179,10 @@ class AltsController:
blob += f"{self.util.get_prof_icon(alt.profession)} " \
f"<yellow>{self.text.zfill(alt.level, 220)}</yellow>:" \
f"<green>{self.text.zfill(alt.ai_level, 30)}</green> " \
f":: <{alt.faction.lower()}>{name}</{alt.faction.lower()}> " \
f"[<{alt.faction.lower()}>{alt.org_name}</{alt.faction.lower()}> - " \
f"<highlight>{alt.org_rank_id + 1}</highlight>]"
f":: <{alt.faction.lower()}>{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>]"
if self.buddy_service.is_online(alt.char_id):
blob += " [<green>Online</green>]"
blob += "\n"
@@ -8,6 +8,7 @@ from core.logger import Logger
from core.lookup.pork_service import PorkService
from core.setting_service import SettingService
from core.text import Text
from core.translation_service import TranslationService
from core.tyrbot import Tyrbot
from core.util import Util
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.discord: DiscordController = registry.get_instance("discord_controller")
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):
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> " \
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):
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=?)",
[char_id])
def get_pref_view_small(self, prefs):
def get_pref_view_small(self, prefs, owner=None):
return f"\n" \
f" └ [{self._make_cmd('news', prefs.news_spam)}] News - " \
f"Autoinvite [{self._make_cmd('autoinvite', prefs.auto_invite)}], \n" \
f" └ [{self._make_cmd('raidinvite', prefs.raid_invite)}] Raidinvite - " \
f"Massmessage [{self._make_cmd('raidspam', prefs.raid_invite)}], \n" \
f" └ [{self._make_cmd('subtilespam', prefs.subtile_spam)}] Subtilespam"
f" └ [{self._make_cmd('news', prefs.news_spam, owner)}] News - " \
f"Autoinvite [{self._make_cmd('autoinvite', prefs.auto_invite, owner)}], \n" \
f" └ [{self._make_cmd('raidinvite', prefs.raid_invite, owner)}] Raidinvite - " \
f"Massmessage [{self._make_cmd('raidspam', prefs.raid_invite, owner)}], \n" \
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" \
f"<tab>└ [ {self._make_cmd('news', prefs.news_spam)} ] 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('raidinvite', prefs.raid_invite)} ] 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('subtilespam', prefs.subtile_spam)} ] Do you want a subtile invite spam? \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, owner)} ] Do you want to receive autoinvites? \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, owner)} ] Do you want to receive massmessages? \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:
return f"<green>YES</green> | {self.text.make_chatcmd('NO', f'/tell <myname> preferences set {pref} off')}"
else:
@@ -41,6 +41,8 @@ class AccessService:
def get_access_level(self, char_id) -> dict:
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:
al = self.get_single_access_level(account.char_id)
if al["label"] == "all":
@@ -48,21 +50,6 @@ class AccessService:
return al
else:
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:
"""
@@ -147,13 +147,18 @@ class AccountService:
acc_cache = {}
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():
out = self.db.query_single(
"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=?) "
"and a.char_id not in (SELECT char_id from org_bots)",
[char_id]) or DictObject({})
self.acc_cache[char_id] = out
self.bot.job_scheduler.delayed_job(lambda x: self.acc_cache.pop(char_id), 5)
else:
@@ -419,7 +424,7 @@ class AccountService:
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"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()])
def get_by_group(self, group) -> List[DictObject]: