Moved org finder to the core

Allowed viewing the most recent account logs by using !account log recent
Allowed removing of chatbots
Moved the so far hardcoded org prefixing into the DB, which allows dynamically changing them.
Fix for orgrosters; org leaves are being detected now.
This commit is contained in:
2022-02-11 15:43:48 +01:00
parent 6d6bfbc678
commit d3461ef462
10 changed files with 165 additions and 77 deletions
+20 -15
View File
@@ -1,6 +1,3 @@
from threading import Thread
from core import command_request, sender_obj
from core.aochat.BaseModule import BaseModule
from core.buddy_service import BuddyService
from core.chat_blob import ChatBlob
@@ -31,6 +28,7 @@ class BotController(BaseModule):
self.org_pork: PorkService = registry.get_instance("org_pork_service")
self.command_alias_service: CommandAliasService = registry.get_instance("command_alias_service")
self.buddy_service: BuddyService = registry.get_instance("buddy_service")
self.online = registry.get_instance("buddy_service")
def pre_start(self):
self.db.exec("CREATE TABLE IF NOT EXISTS org_bots(char_id int primary key not null, org_id int not null)")
@@ -38,24 +36,31 @@ class BotController(BaseModule):
def start(self):
pass
@command(command="bots", params=[Const("add"), Character("botname")], access_level="admin",
description="Add an bot to the bot list")
def bots_add_any(self, sender, _, bot):
Thread(target=self.bots_add, args=(bot, sender)).start()
def bots_add(self, bot: sender_obj, request: command_request):
@command(command="orgs", params=[Const("bots"), Const("add"), Character("botname")], access_level="admin",
description="Add an bot to the bot list", sub_command="bots_mng")
def cmd_orgs_bots_add(self, request, _, _1, bot):
player = self.pork.request_char_info(bot.name, 5)
if self.db.exec("INSERT IGNORE INTO org_bots(char_id, org_id) VALUES(?, ?)", [bot.char_id, player.org_id]) == 0:
request.reply("The bot <highlight>%s<end> is already marked as an chatbot." % bot.name)
request.reply(f"The bot <highlight>{bot.name}<end> is already marked as a chatbot.")
else:
request.reply("Successfully marked <highlight>%s<end> as an chatbot." % bot.name)
self.db.exec("DELETE FROM online where char_id=?", [bot.char_id])
request.reply(f"Successfully marked <highlight>{bot.name}<end> as a chatbot.")
@command(command="bots",
params=[],
@command(command="orgs", params=[Const("bots"), Const("rem"), Character("botname")], access_level="admin",
description="Add an bot to the bot list", sub_command="bots_mng")
def cmd_orgs_bots_rem(self, request, _, _1, bot):
if self.db.exec("DELETE FROM org_bots WHERE char_id=?", [bot.char_id]) == 0:
request.reply(f"<highlight>{bot.name}<end> is not a chatbot.")
else:
request.reply(f"Successfully removed <highlight>{bot.name}<end> as a chatbot. The character will show up in !online again after its next login.")
@command(command="orgs",
params=[Const("bots")],
access_level="moderator",
description="show all orgbots",
sub_command="show")
def bots_show_all(self, _):
sub_command="bots_show")
def cmd_orgs_bots_show(self, _, _1):
def format_row(query):
bud = self.buddy_service.is_online(query["char_id"])
buddy = "<green>O<end>" if bud == 1 else "<red>O<end>" if bud == 0 else "<grey>U<end>"