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
+4 -4
View File
@@ -85,11 +85,11 @@ class OrgBanController(BaseModule):
elif len(orgs) > 1:
blob = "Your search had multiple results; please pick an org:<br>"
for org in orgs:
blob += "[%s] <highlight>%s<end> (<highlight>%s<end>) <%s>%s<end> [<highlight>%s<end> " \
blob += "[%s] <highlight>%s</highlight> (<highlight>%s</highlight>) <%s>%s</%s> [<highlight>%s</highlight> " \
"members]<br><pagebreak>" \
% (self.text.make_chatcmd("Unban", "/tell <myname> orgban remove %s" % org.org_id),
# self.text.make_chatcmd("More", "/tell <myname> org info %s" % org.org_id),
org.org_name, org.org_id, org.faction.lower(), org.faction, org.member_count)
org.org_name, org.org_id, org.faction.lower(), org.faction, org.faction.lower(), org.member_count)
return ChatBlob("Pick an Org", blob)
@command(command="orgban", params=[Const("add", is_optional=True), Int("Organisation"),
@@ -119,10 +119,10 @@ class OrgBanController(BaseModule):
elif len(orgs) > 1:
blob = "Your search had multiple results; please pick an org:<br>"
for org in orgs:
blob += "[%s] <highlight>%s<end> (<highlight>%s<end>) <%s>%s<end> [<highlight>%s<end> " \
blob += "[%s] <highlight>%s</highlight> (<highlight>%s</highlight>) <%s>%s</%s> [<highlight>%s</highlight> " \
"members]<br><pagebreak>" \
% (self.text.make_chatcmd("Add Ban", "/tell <myname> orgban add %s" % org.org_id),
org.org_name, org.org_id, org.faction.lower(), org.faction, org.member_count)
org.org_name, org.org_id, org.faction.lower(), org.faction, org.faction.lower(), org.member_count)
return ChatBlob("Pick an Org", blob)
def fetch_single(self, org_id, sender: object):
@@ -44,7 +44,10 @@ class DiscordCommandHandler(BaseModule):
@event("discord_command", "should the bot take care of discord commands", False)
def discord_command_handler(self, _, event_data):
acc = event_data.account
ctx: Message = event_data.message
if not acc:
return
message = ctx.clean_content
if message.startswith(self.discord.setting_service.get("symbol").get_value()):
threading.Thread(target=self.command_service.process_command(
@@ -138,6 +141,7 @@ class DiscordCommandHandler(BaseModule):
('#(.+?)#', r'\1'),
('&lt;', '<'),
('&gt;', '>'),
(r"<font color=('*?).+?\1>", ''),
('</font>', '')]:
ctx = re.sub(pattern, sub, ctx)
cnt = 1
@@ -147,7 +151,7 @@ class DiscordCommandHandler(BaseModule):
ctx.rstrip()
ctx.rstrip(">")
return ctx
return self.discord.text.strip_html_tags(ctx)
@command(command="discord", params=[Const("invite")], access_level="member",
description="Get a personal Discord invite", sub_command="invite")
@@ -389,7 +393,7 @@ class DiscordCommandHandler(BaseModule):
@timerevent(budatime="5m", description="update activity")
def change_count(self, _, _1):
if hasattr(self, "loop"):
if hasattr(self.discord, "loop"):
count = self.db.query_single('SELECT count(*) as count from online '
'where char_id NOT IN (select char_id from org_bots) and bot=?',
[self.bot.get_char_id()]).count
+3 -3
View File
@@ -342,9 +342,9 @@ class DiscordController:
DictObject(acc), msg.content,
prefix + msg.content)
else:
prefix = f"[-UNK-] {msg.author.username}: " if self.alias_usage().get_value() else f"[DC] {msg.author.username}: "
prefix = f"[-UNK-] {msg.author.name}: " if self.alias_usage().get_value() else f"[DC] {msg.author.name}: "
self.relay_hub_service.send_message("Discord_(" + channel.name+")",
DictObject({'char_id': 0, 'name': msg.author.username, 'discord_handle': f'{msg.author.name}#{msg.author.discriminator}'}), msg.content,
DictObject({'char_id': 0, 'name': msg.author.name, 'discord_handle': f'{msg.author.name}#{msg.author.discriminator}'}), msg.content,
prefix + msg.content)
if str(channel.id) not in self.channel_blacklist().get_value().lstrip("[").rstrip("]").split(','):
self.bot.event_service.fire_event("discord_command", DictObject({'account': acc, 'message': msg}))
@@ -395,7 +395,7 @@ class DiscordController:
return True
def check(self, msg: Message):
if msg.pinned or (len(msg.embeds) > 0 and (msg.created_at.utcnow() < datetime.utcnow()-timedelta(hours=12))):
if msg.pinned or (len(msg.embeds) > 0) and (msg.created_at.utcnow() < datetime.utcnow() - timedelta(hours=12)):
return False
else:
return True
@@ -29,7 +29,7 @@
},
"join": {
"en_US": "{char} has joined the private channel. {logon}",
"de_DE": "<orange>Online<end>: {char}. {logon}"
"de_DE": "<orange>Online</orange>>: {char}. {logon}"
},
"leave": {
"en_US": "<highlight>{char}</highlight> has left the private channel. {logoff}",
@@ -59,8 +59,8 @@ class TopicController:
def format_topic_message(self, topic):
time_string = self.util.time_to_readable(int(time.time()) - topic["created_at"])
return f"Topic: <highlight>{topic['topic_message']}<end> " \
f"[set by <highlight>{topic['created_by']['name']}<end>][{time_string} ago]"
return f"Topic: <highlight>{topic['topic_message']}</highlight> " \
f"[set by <highlight>{topic['created_by']['name']}</highlight>][{time_string} ago]"
@event(PrivateChannelService.JOINED_PRIVATE_CHANNEL_EVENT, "Show topic to characters joining the private channel")
def show_topic(self, _, event_data):