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
@@ -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