Do not load settings which are not active (module not loaded)

Restart the bot, on heavy DB errors, with an 30 seconds delay (like: all connections terminated by DB, table_definition_cache exhausted)
Fix for channel prefixing (org <-> priv)
This commit is contained in:
2021-11-30 16:57:31 +01:00
parent c100b0ea76
commit bf6c1842d2
17 changed files with 57 additions and 29 deletions
@@ -159,7 +159,7 @@ class AccountController:
self.db.exec("DELETE FROM pending_accounts where main=? or alt=?", [account[0].main, account[0].main])
self.db.exec("DELETE FROM mail where recipient=? or sender=?", [account[0].main, account[0].main])
self.account_service.add_log(request.sender.char_id, "system",
f"Disabled Account of <highlight>{user.name}</highlight>.",
f"Purged the account of <highlight>{user.name}</highlight>.",
request.sender.char_id)
return f"Character <highlight>{user.name}'s</highlight> Account has been purged!"
else:
+2 -1
View File
@@ -6,6 +6,7 @@ from core.chat_blob import ChatBlob
from core.command_param_types import Const, Options, Character, Multiple, Any
from core.decorators import instance, command
from core.dict_object import DictObject
from core.sender_obj import SenderObj
from core.setting_service import SettingService
from core.text import Text
from core.translation_service import TranslationService
@@ -135,7 +136,7 @@ class AltsController:
for alt in alts:
char_id = self.character_service.resolve_char_to_id(alt)
if not char_id:
notfound.append(alt)
notfound.append(alt.name if type(alt) == SenderObj else alt)
continue
alt = DictObject({"char_id": char_id, "name": alt})
if main.char_id == alt.char_id:
@@ -78,7 +78,7 @@ class PrivateChannelController:
return hjson.load(f)
def handle_incoming_relay_message(self, ctx):
if not self.display_main().get_value() == "1" and ctx.source == "org_channel" and ctx.sender:
if self.display_main().get_value() and ctx.source == "private_channel" and ctx.sender:
name = f"{OrgChannelController.ORG_CHANNEL_PREFIX} <yellow>{ctx.sender.name}</yellow>"
if account := self.account_service.get_account(ctx.sender.char_id):
if account.main != ctx.sender.char_id:
@@ -92,9 +92,9 @@ class PrivateChannelController:
if not self.bot.is_ready():
if data.packet.char_id not in self.reinvite:
account = data.account
if account.disabled == 1:
if not self.account_service.simple_checks(account):
return
if self.pork.get_character_info(data.packet.char_id).org_id == self.bot.public_channel_service.org_id:
if self.account_service.get_entry(data.packet.char_id).get("member", self.bot.public_channel_service.org_id) == self.bot.public_channel_service.org_id:
return
if account.auto_invite == 1:
self.reinvite.append(data.packet.char_id)
@@ -102,12 +102,12 @@ class PrivateChannelController:
if self.private_channel_service.in_private_channel(data.packet.char_id):
return
account = data.account
if account.disabled == 1:
if not self.account_service.simple_checks(account):
return
if self.db.query_single("SELECT * from org_bots where char_id=?", [data.packet.char_id]):
return
if account.auto_invite == 1:
if self.pork.get_character_info(data.packet.char_id).org_id != self.bot.public_channel_service.org_id:
if self.account_service.get_entry(data.packet.char_id).get("member", self.bot.public_channel_service.org_id) != self.bot.public_channel_service.org_id:
self.private_channel_service.invite(data.packet.char_id)
self.bot.send_mass_message(data.packet.char_id, "You have been "
"<highlight>auto invited</highlight> "
+2 -2
View File
@@ -86,8 +86,8 @@ class CloakController:
timer_name = "Lower City Cloak"
else:
raise Exception(f"Unknown cloak action '{event_data.action}'")
self.timer_controller.add_timer(timer_name, event_data.sender.char_id, "org", int(time.time()), 3600)
if self.timer_controller:
self.timer_controller.add_timer(timer_name, event_data.sender.char_id, "org", int(time.time()), 3600)
def get_cloak_status(self, row):
one_hour = 3600
+5 -5
View File
@@ -40,14 +40,14 @@ class OrgChannelController:
def start(self):
self.message_hub_service.register_message_destination(
self.MESSAGE_SOURCE, self.handle_incoming_relay_message,
["private_channel", "websocket_relay", "cloak_reminder", "wave_counter", "shutdown_notice"],
[self.MESSAGE_SOURCE])
self.MESSAGE_SOURCE, self.handle_incoming_relay_message,
["private_channel", "websocket_relay", "cloak_reminder", "wave_counter", "shutdown_notice"],
[self.MESSAGE_SOURCE])
def handle_incoming_relay_message(self, ctx):
# {'source': 'org_channel', 'sender': {'char_id': 384018, 'name': 'Risianna'}, 'message': 'Sooo', 'formatted_message': "[<cyan>Org</cyan>] <a href='user://Risianna'>Risianna</a>: Sooo"}
if not self.display_main().get_value() == "1" and ctx.source == "private_channel" and ctx.sender:
name = f"{OrgChannelController.ORG_CHANNEL_PREFIX} <yellow>{ctx.sender.name}</yellow>"
if self.display_main().get_value() and ctx.source == "private_channel" and ctx.sender:
name = f"[<cyan>Priv</cyan>] <yellow>{ctx.sender.name}</yellow>"
if account := self.account_service.get_account(ctx.sender.char_id):
if account.main != ctx.sender.char_id:
name += f" (<yellow>{account.name}</yellow>)"
@@ -217,6 +217,8 @@ class OrgRosterController:
self.db.exec("INSERT INTO org_activity (message, time) VALUES(?, ?)", [ext_msg.get_message(), time.time()])
def process_org_msg(self, char_name, new_mode, actee=None):
# TODO: errors out on newly created chars, which do not show up on PoRK yet.
# self.pork.get_character_info(char_name)
char_id = self.character_service.resolve_char_to_id(char_name)
org_member = self.get_org_member(char_id)
self.process_update(char_id, org_member.member if org_member else None, new_mode, actee)
+2 -2
View File
@@ -356,9 +356,9 @@ class LootController:
if int(time.time()) - self.last_modify > 3600 and self.loot_list:
self.last_modify = None
self.loot_list = OrderedDict()
self.bot.send_org_message("Loot was last modified more than 1 hour ago, list has been cleared.")
self.bot.send_org_message("Loot was last modified more than 1 hour ago, list has been cleared.", fire_outgoing_event=False)
self.bot.send_private_channel_message(
"Loot was last modified more than 1 hour ago, list has been cleared.")
"Loot was last modified more than 1 hour ago, list has been cleared.", fire_outgoing_event=False)
def is_already_added(self, name: str):
for i, loot_item in self.loot_list.items():
+10
View File
@@ -1,6 +1,7 @@
from core.command_param_types import Any
from core.decorators import instance, command
from core.igncore import IgnCore
from core.text import Text
@instance()
@@ -8,6 +9,7 @@ class ChatController:
def inject(self, registry):
self.command_alias_service = registry.get_instance("command_alias_service")
self.bot: IgnCore = registry.get_instance("bot")
self.text: Text = registry.get_instance("text")
def start(self):
self.command_alias_service.add_alias("cmd", "shout")
@@ -20,3 +22,11 @@ class ChatController:
f"<yellow>────────────────</yellow>\n"
f"<highlight>{message}</highlight>\n"
f"<yellow>────────────────</yellow>")
@command(command="lft", params=[Any("message", is_optional=True)], access_level="member",
description="Show a highly visible message")
def shout_command(self, _, message):
lft = f"<a href='chatcmd:///lft <font color=#FFFF00>» {message or '<myname>'}<end>'>/lft {message or '<myname>'}</a>"
return self.text.format_page("Use this command for going LFT", "<yellow>────────────────</yellow>\n"
f"<highlight>{lft}</highlight>\n"
f"<yellow>────────────────</yellow>")
@@ -390,9 +390,9 @@ class SpecialsController:
inits_recharge = ((((init_result - 87.5) * 0.02) + 1 - weapon_attack + 4) * -900) + 1200
if inits_attack < inits_recharge:
return inits_recharge
return int(inits_recharge)
else:
return inits_attack
return int(inits_attack)
def get_aimed_shot_info(self, weapon_attack, weapon_recharge, aimed_shot_skill):
result = DictObject()