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:
@@ -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")
|
||||
|
||||
@@ -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]:
|
||||
|
||||
@@ -183,7 +183,7 @@ class PrivateChannelController:
|
||||
char_name = self.character_service.resolve_char_to_name(event_data.char_id)
|
||||
sender = DictObject({"char_id": event_data.char_id, "name": char_name})
|
||||
char = self.text.make_charlink(char_name)
|
||||
formatted_message = f"{self.PRIVATE_CHANNEL_PREFIX} {char}: {event_data.message}"
|
||||
formatted_message = f"{self.PRIVATE_CHANNEL_PREFIX}{char}: {event_data.message}"
|
||||
self.message_hub_service.send_message(self.MESSAGE_SOURCE, sender, event_data.message, formatted_message)
|
||||
|
||||
@event(event_type=PrivateChannelService.JOINED_PRIVATE_CHANNEL_EVENT,
|
||||
@@ -193,8 +193,8 @@ class PrivateChannelController:
|
||||
if main:
|
||||
info = "" if self.account_service.check_superadmin(main.char_id) else \
|
||||
":: <red>Admin</red> " if self.account_service.check_admin(main.char_id) else \
|
||||
":: <red>Moderator</red> " if self.account_service.check_moderator(main.char_id) else \
|
||||
":: <orange>Raidleader</orange> " if self.account_service.check_leader(main.char_id) else ""
|
||||
":: <red>Moderator</red> " if self.account_service.check_moderator(main.char_id) else \
|
||||
":: <orange>Raidleader</orange> " if self.account_service.check_leader(main.char_id) else ""
|
||||
if main.char_id != event_data.char_id:
|
||||
info += f":: Alt of <{main.faction.lower()}>{main.name}</{main.faction.lower()}>"
|
||||
else:
|
||||
@@ -223,23 +223,23 @@ class PrivateChannelController:
|
||||
description="Relay commands from the private channel to the relay hub", is_hidden=True)
|
||||
def outgoing_private_channel_message_event(self, _, event_data):
|
||||
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())
|
||||
if len(pages) < 4:
|
||||
for page in pages:
|
||||
message = "{priv} {message}".format(priv=self.PRIVATE_CHANNEL_PREFIX, message=page)
|
||||
message = "{priv}{message}".format(priv=self.PRIVATE_CHANNEL_PREFIX, message=page)
|
||||
self.message_hub_service.send_message(self.MESSAGE_SOURCE,
|
||||
None,
|
||||
page,
|
||||
message)
|
||||
else:
|
||||
message = "{priv} {message}".format(priv=self.PRIVATE_CHANNEL_PREFIX, message=event_data.message.title)
|
||||
message = "{priv}{message}".format(priv=self.PRIVATE_CHANNEL_PREFIX, message=event_data.message.title)
|
||||
self.message_hub_service.send_message(self.MESSAGE_SOURCE,
|
||||
None,
|
||||
event_data.message.title,
|
||||
message)
|
||||
else:
|
||||
message = "{priv} {message}".format(priv=self.PRIVATE_CHANNEL_PREFIX, message=event_data.message)
|
||||
message = "{priv}{message}".format(priv=self.PRIVATE_CHANNEL_PREFIX, message=event_data.message)
|
||||
self.message_hub_service.send_message(self.MESSAGE_SOURCE,
|
||||
None,
|
||||
message,
|
||||
|
||||
@@ -109,7 +109,7 @@ class OrgChannelController:
|
||||
is_hidden=True)
|
||||
def outgoing_org_message_event(self, _, event_data):
|
||||
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())
|
||||
if len(pages) < 4:
|
||||
for page in pages:
|
||||
|
||||
@@ -18,7 +18,8 @@ from modules.standard.helpbot.playfield_controller import PlayfieldController
|
||||
|
||||
@instance()
|
||||
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 = []
|
||||
plant = []
|
||||
|
||||
@@ -112,6 +113,10 @@ class TowerService(BaseModule):
|
||||
# ?limit is a parameter not documented anywhere, but allows pulling the whole list
|
||||
# On other API implementations this parameter has no effect,
|
||||
# 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
|
||||
with TorRequests() as tor_request:
|
||||
with tor_request.get_session(1) as session:
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import sys
|
||||
import time
|
||||
|
||||
from conf.config import BotConfig
|
||||
from core.command_alias_service import CommandAliasService
|
||||
from core.decorators import instance, command, event
|
||||
from core.dict_object import DictObject
|
||||
@@ -17,18 +15,18 @@ from modules.standard.datanet.ws_controller import WebsocketRelayController
|
||||
|
||||
@instance()
|
||||
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,
|
||||
60 * 5, 60 * 3, 60 * 2, 60, 30, 15, 10, 5, 4, 3, 2, 1, 0]
|
||||
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):
|
||||
self.logger = Logger(__name__)
|
||||
|
||||
@@ -57,6 +57,6 @@ class PerksController:
|
||||
if row.perk_name != current_perk:
|
||||
blob += f"\n<header2>{row.perk_name} {row.max_perk_level}</header2>\n"
|
||||
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