Moved the coloring from <color>[text]<end> to <color>[test]</color>, which allows the discord module to reparse the messages more accurately

This commit is contained in:
2022-04-29 20:12:15 +02:00
parent fcea02e1c9
commit 3cade228fe
22 changed files with 177 additions and 421 deletions
@@ -1,112 +0,0 @@
# from core.aochat import server_packets, client_packets
# from core.conn import Conn
# from core.decorators import instance
# from core.igncore import IgnCore
# from core.logger import Logger
# from core.lookup.character_service import CharacterService
# from core.setting_service import SettingService
# from core.setting_types import TextSettingType, BooleanSettingType, ColorSettingType
# from core.text import Text
# from modules.onlinebot.online.org_alias_controller import OrgAliasController
#
#
# @instance("AllianceRelayController")
# class AllianceRelayController:
# relay_channel_id = None
# MESSAGE_SOURCE = "alliance"
#
# def __init__(self):
# self.logger = Logger(__name__)
#
# # noinspection DuplicatedCode
# def inject(self, registry):
# self.bot: IgnCore = registry.get_instance("bot")
# self.setting_service: SettingService = registry.get_instance("setting_service")
# self.character_service: CharacterService = registry.get_instance("character_service")
# self.message_hub_service = registry.get_instance("message_hub_service")
# self.public_channel_service = registry.get_instance("public_channel_service")
# self.text: Text = registry.get_instance("text")
# self.alias_controller: OrgAliasController = registry.get_instance("org_alias_controller")
#
# def pre_start(self):
# self.message_hub_service.register_message_source(self.MESSAGE_SOURCE)
#
# def start(self):
# self.setting_service.register(self.module_name, "arelaybot", "",
# TextSettingType(allow_empty=True), "Bot for alliance relay")
#
# self.setting_service.register(self.module_name, "arelay_enabled", False,
# BooleanSettingType(), "Enable the alliance relay")
#
# self.setting_service.register(self.module_name, "arelay_color", "#C3C3C3",
# ColorSettingType(),
# "Color of messages from relay")
#
# # self.message_hub_service.register_message_destination(self.MESSAGE_SOURCE, self.handle_relay_hub_message, [],
# # [self.MESSAGE_SOURCE])
#
# self.bot.register_packet_handler(server_packets.PrivateChannelInvited.id, self.handle_private_channel_invite,
# 100)
# self.bot.register_packet_handler(server_packets.PrivateChannelMessage.id, self.handle_private_channel_message)
#
# # noinspection DuplicatedCode
# def handle_private_channel_invite(self, conn: Conn, packet: server_packets.PrivateChannelInvited):
# if conn.id != "main":
# return
#
# if not self.setting_service.get("arelay_enabled").get_value():
# return
#
# channel_name = self.character_service.get_char_name(packet.private_channel_id)
# if self.setting_service.get_value("arelaybot").lower() == channel_name.lower():
# self.bot.send_packet(client_packets.PrivateChannelJoin(packet.private_channel_id))
# self.logger.info("Joined private channel {channel}".format(channel=channel_name))
# self.relay_channel_id = packet.private_channel_id
#
# # noinspection DuplicatedCode
# def handle_private_channel_message(self, conn: Conn, packet: server_packets.PrivateChannelMessage):
# if conn.id != "main":
# return
#
# if not self.setting_service.get("arelay_enabled").get_value():
# return
#
# # ignore packets from the bot's own private channel and from the bot itself
# if packet.private_channel_id == self.bot.get_char_id() or packet.char_id == self.bot.get_char_id():
# return
#
# message = packet.message.lstrip()
# if message[:6] != "!agcr ":
# return
#
# message = message[6:]
# formatted_message = self.setting_service.get("arelay_color").format_text(message)
#
# sender = None
# self.message_hub_service.send_message(self.MESSAGE_SOURCE, sender, message, formatted_message)
#
# def handle_relay_hub_message(self, ctx):
# if not self.setting_service.get("arelay_enabled").get_value():
# return
#
# plain_msg = ctx.message or ctx.formatted_message
# invite = self.text.make_chatcmd("click here", "/tell <myname> discord invite",
# style="style='text-decoration:none'")
# name = f"[{self.alias_controller.get_alias(ctx.sender.org_id)}] {ctx.sender.name}"
# blob = self.text.format_page('Info',
# f"<header>::: Information :::</header><br><br>"
# f"This message has been sent to you by:<br><br>"
# f"<header2>Igncom</header2><br>"
# f"<notice>{ctx.sender.discord_handle}</notice><br>"
# f"<highlight>{name}</highlight> on Alliance Discord.<br><br>"
# f"To reply, either respond in the relay or "
# f"contact them directly at the provided handles.<br><br>"
# f"<header2>Have you joined The Alliance Discord yet? "
# f"If not <highlight>{invite}</highlight> to receive an invite.</header2>")
# self.send_message_to_alliance(f"{name}: {plain_msg}" + f" <yellow>[{blob}]</yellow>")
#
# def send_message_to_alliance(self, msg):
# if self.relay_channel_id:
# packet = client_packets.PrivateChannelMessage(self.relay_channel_id,
# "!agcr " + self.text.format_message(msg, False), "\0")
# self.bot.conns["main"].send_packet(packet)
+6 -6
View File
@@ -41,19 +41,19 @@ class BotController(BaseModule):
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(f"The bot <highlight>{bot.name}<end> is already marked as a chatbot.")
request.reply(f"The bot <highlight>{bot.name}</highlight> is already marked as a chatbot.")
else:
self.db.exec("DELETE FROM online where char_id=?", [bot.char_id])
request.reply(f"Successfully marked <highlight>{bot.name}<end> as a chatbot.")
request.reply(f"Successfully marked <highlight>{bot.name}</highlight> as a chatbot.")
@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.")
request.reply(f"<highlight>{bot.name}</highlight> 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.")
request.reply(f"Successfully removed <highlight>{bot.name}</highlight> as a chatbot. The character will show up in !online again after its next login.")
@command(command="orgs",
params=[Const("bots")],
@@ -63,8 +63,8 @@ class BotController(BaseModule):
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>"
return "- [{status}] <highlight>{name}<end> (<notice>{org_name}<end>)\n".format(**query, status=buddy)
buddy = "<green>O</green>" if bud == 1 else "<red>O</red>" if bud == 0 else "<grey>U</grey>"
return "- [{status}] <highlight>{name}</highlight> (<notice>{org_name}</notice>)\n".format(**query, status=buddy)
data = self.db.query("SELECT * FROM org_bots o LEFT JOIN player p on o.char_id = p.char_id order by p.org_name")
blob = ""
@@ -64,19 +64,19 @@ class OrgAliasController:
orgs = orgs[0]
if self.db.exec("REPLACE INTO org_alias(org_id, org_alias) VALUES (?, ?)", [orgs.org_id, alias]):
self.prefix_cache[orgs.org_id] = alias
return f"Alias for <highlight>{orgs.org_name}<end> has been set to [<highlight>{alias}</highlight>]."
return f"Alias for <highlight>{orgs.org_name}</highlight> has been set to [<highlight>{alias}</highlight>]."
else:
return f"There's already an alias for <highlight>{orgs.org_name}<end>.. its [<highlight>{self.get_alias(orgs.org_id)}</highlight>]"
return f"There's already an alias for <highlight>{orgs.org_name}</highlight>.. its [<highlight>{self.get_alias(orgs.org_id)}</highlight>]"
elif len(orgs) == 0:
return f"No org with the name <highlight>{search}<end> was found on PoRK."
return f"No org with the name <highlight>{search}</highlight> was found on PoRK."
else:
blob = "Your search had multiple results; please pick an org:<br>"
for org in orgs:
blob += f'[{self.text.make_chatcmd("Set Alias", f"/tell <myname> orgs alias set {alias} {org.org_id}")}]' \
f'[{self.text.make_chatcmd("More", f"/tell <myname> orgs info {org.org_id}")}]' \
f' <highlight>{org.org_name}<end> (<highlight>{org.org_id}<end>) ' \
f'<{org.faction.lower()}>{org.faction}<end> [<highlight>{org.member_count}<end> members]' \
f' <highlight>{org.org_name}</highlight> (<highlight>{org.org_id}</highlight>) ' \
f'<{org.faction.lower()}>{org.faction}</{org.faction.lower()}> [<highlight>{org.member_count}</highlight> members]' \
f'<br><pagebreak>'
return ChatBlob("Pick an Org", blob)
@@ -89,17 +89,17 @@ class OrgAliasController:
orgs = orgs[0]
if self.db.exec("DELETE FROM org_alias where org_id=?", [orgs.org_id]) == 1:
self.prefix_cache.pop(orgs.org_id)
return f"Alias for <highlight>{orgs.org_name}<end> has been removed."
return f"Alias for <highlight>{orgs.org_name}</highlight> has been removed."
else:
return f"There's no alias for <highlight>{orgs.org_name}<end>.."
return f"There's no alias for <highlight>{orgs.org_name}</highlight>.."
elif len(orgs) == 0:
return f"No org with the name <highlight>{search}<end> was found on PoRK."
return f"No org with the name <highlight>{search}</highlight> was found on PoRK."
else:
blob = "Your search had multiple results; please pick an org:<br>"
for org in orgs:
blob += f'[{self.text.make_chatcmd("Set Alias", f"/tell <myname> orgs alias rem {org.org_id}")}]' \
f'[{self.text.make_chatcmd("More", f"/tell <myname> orgs info {org.org_id}")}]' \
f' <highlight>{org.org_name}<end> (<highlight>{org.org_id}<end>) ' \
f'<{org.faction.lower()}>{org.faction}<end> [<highlight>{org.member_count}<end> members]' \
f' <highlight>{org.org_name}</highlight> (<highlight>{org.org_id}</highlight>) ' \
f'<{org.faction.lower()}>{org.faction}</{org.faction.lower()}> [<highlight>{org.member_count}</highlight> members]' \
f'<br><pagebreak>'
return ChatBlob("Pick an Org", blob)
+14 -14
View File
@@ -77,22 +77,22 @@ class OrgController:
orgs = orgs[0]
if self.db.exec("REPLACE INTO orgs(org_id) VALUES(?)",
[orgs.org_id]) == 1:
sender.reply(f"Adding the organisation <highlight>{orgs.org_name}<end> to the roster...")
sender.reply(f"Adding the organisation <highlight>{orgs.org_name}</highlight> to the roster...")
org_adder = Thread(name=orgs.org_id, target=self.fetch_single,
args=(orgs.org_id, orgs.org_name, sender))
self.threads[orgs.org_id] = org_adder
org_adder.start()
else:
return f"The organisation <highlight>{orgs.org_name}<end> is in the roster already."
return f"The organisation <highlight>{orgs.org_name}</highlight> is in the roster already."
elif len(orgs) == 0:
return f"No org with the name <highlight>{search}<end> was found on PoRK."
return f"No org with the name <highlight>{search}</highlight> was found on PoRK."
else:
blob = "Your search had multiple results; please pick an org:<br>"
for org in orgs:
blob += f'[{self.text.make_chatcmd("Add", f"/tell <myname> orgs add {org.org_id}")}]' \
f'[{self.text.make_chatcmd("More", f"/tell <myname> org info {org.org_id}")}]' \
f' <highlight>{org.org_name}<end> (<highlight>{org.org_id}<end>) ' \
f'<{org.faction.lower()}>{org.faction}<end> [<highlight>{org.member_count}<end> members]' \
f' <highlight>{org.org_name}</highlight> (<highlight>{org.org_id}</highlight>) ' \
f'<{org.faction.lower()}>{org.faction}</{org.faction.lower()}> [<highlight>{org.member_count}</highlight> members]' \
f'<br><pagebreak>'
return ChatBlob("Pick an Org", blob)
@@ -110,34 +110,34 @@ class OrgController:
org_remover = Thread(name=orgs.org_id, target=self.remove_single, args=(orgs.org_id, orgs.org_name))
self.threads[orgs.org_id] = org_remover
org_remover.start()
return f"Removed the organisation <highlight>{orgs.org_name}<end> from the roster."
return f"Removed the organisation <highlight>{orgs.org_name}</highlight> from the roster."
else:
return f"The organisation <highlight>{orgs.org_name}<end> is not on the roster list."
return f"The organisation <highlight>{orgs.org_name}</highlight> is not on the roster list."
elif len(orgs) == 0:
return f"The organisation <highlight>{search}<end> is not on the roster list."
return f"The organisation <highlight>{search}</highlight> is not on the roster list."
else:
blob = "Your search had multiple results; please pick an org:<br>"
for org in orgs:
blob += f'[{self.text.make_chatcmd("Remove", f"/tell <myname> orgs remove {org.org_id}")}]' \
f'[{self.text.make_chatcmd("More", f"/tell <myname> org info {org.org_id}")}]' \
f' <highlight>{org.org_name}<end> (<highlight>{org.org_id}<end>) ' \
f'<{org.faction.lower()}>{org.faction}<end> [<highlight>{org.member_count}<end> members]' \
f' <highlight>{org.org_name}</highlight> (<highlight>{org.org_id}</highlight>) ' \
f'<{org.faction.lower()}>{org.faction}</{org.faction.lower()}> [<highlight>{org.member_count}</highlight> members]' \
f'<br><pagebreak>'
return ChatBlob("Pick an Org", blob)
@command(command="orgs", params=[Const("list", is_optional=True)], access_level="member",
description="View all orgs on the online list", sub_command="online_info")
def orgs_list(self, sender: CommandRequest, _):
head = "<header>Organisations registered as Members<end>"
head = "<header>Organisations registered as Members</header>"
blob = ""
for org in self.db.query("SELECT o.*, a.*, oa.org_alias from orgs o "
"left join all_orgs a on o.org_id = a.org_id "
"left join org_alias oa on o.org_id = oa.org_id order by a.org_name"):
org = DictObject(org)
blob += "- %s%s%s<highlight>%s<end> (%d) with <highlight>%d<end> members\n" % (
"[<highlight>" + self.text.make_chatcmd("Info", "/tell <myname> orgs info %d" % org.org_id,
blob += "- %s%s%s<highlight>%s</highlight> (%d) with <highlight>%d</highlight> members\n" % (
"[<highlight>" + self.text.make_chatcmd("Info", f"/tell <myname> orgs info {org.org_id}",
style="style='text-decoration:none'") + "</highlight>] ",
"[<red>" + self.text.make_chatcmd("Remove", "/tell <myname> orgs rem %d" % org.org_id,
"[<red>" + self.text.make_chatcmd("Remove", f"/tell <myname> orgs rem {org.org_id}",
style="style='text-decoration:none'") + "</red>] " if
sender.sender.access_level["level"] <= 10 else "",
f"[<highlight>{self.org_alias.get_alias(org.org_id)}</highlight>] ",
+1 -1
View File
@@ -203,7 +203,7 @@ class RaidController:
continue
if prof != i.profession:
info += "\n\n<img src=tdb://id:GFX_GUI_FRIENDLIST_SPLITTER>"
info += "\n" + f"<img src=rdb://{self.profs.get(i.profession)}><tab><green>{i.profession}<end>\n"
info += "\n" + f"<img src=rdb://{self.profs.get(i.profession)}><tab><green>{i.profession}</green>\n"
info += "<img src=tdb://id:GFX_GUI_FRIENDLIST_SPLITTER>"
prof = i.profession