From eb4a3075eac706c7824a56a63ad726e6c726e799 Mon Sep 17 00:00:00 2001 From: Madpeter <57852827+Madpeterz@users.noreply.github.com> Date: Thu, 30 Sep 2021 16:38:19 +0100 Subject: [PATCH] adds localchat support for the bot and objects --- .../DiscordSupervisor/ChannelControl.cs | 24 +++++++++++++++++++ BetterSecondbot/DiscordSupervisor/relay.cs | 17 ++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/BetterSecondbot/DiscordSupervisor/ChannelControl.cs b/BetterSecondbot/DiscordSupervisor/ChannelControl.cs index 8424954..6894389 100644 --- a/BetterSecondbot/DiscordSupervisor/ChannelControl.cs +++ b/BetterSecondbot/DiscordSupervisor/ChannelControl.cs @@ -32,6 +32,30 @@ namespace BetterSecondBot.DiscordSupervisor return null; } + protected async Task SendEmbedToChannelAsync(string channelname, string sender, string message, Color color, string catmapid, UUID sender_id, string TopicType) + { + if (AllowNewOutbound() == true) + { + try + { + channelname = channelname.ToLowerInvariant(); + channelname = String.Concat(channelname.Where(char.IsLetterOrDigit)); + ITextChannel Channel = await FindTextChannel(channelname, catmap[catmapid], sender_id, TopicType, false).ConfigureAwait(true); + if (Channel != null) + { + var embed = new EmbedBuilder(); + embed.AddField(sender, message).WithColor(color); + return await Channel.SendMessageAsync(null, false, embed.Build()).ConfigureAwait(false); + } + } + catch + { + return null; + } + } + return null; + } + protected async Task FindTextChannel(string channelname, ICategoryChannel cat, UUID sender, string TopicType, bool CleanChannel) { return await FindTextChannel(DiscordServer, channelname, cat, sender, TopicType, true, CleanChannel); diff --git a/BetterSecondbot/DiscordSupervisor/relay.cs b/BetterSecondbot/DiscordSupervisor/relay.cs index 0b66039..0f05946 100644 --- a/BetterSecondbot/DiscordSupervisor/relay.cs +++ b/BetterSecondbot/DiscordSupervisor/relay.cs @@ -58,9 +58,9 @@ namespace BetterSecondBot.DiscordSupervisor { if (HasBot() == true) { - if (fromme == false) + if (DiscordClientConnected == true) { - if (DiscordClientConnected == true) + if (fromme == false) { if (avatar == true) { @@ -85,9 +85,20 @@ namespace BetterSecondBot.DiscordSupervisor } else { - controler.getBot().Debug("DiscordBotChatControler - Not from an avatar"); + if (sender_uuid != UUID.Zero) + { + await SendEmbedToChannelAsync("localchat", sender_name, message, Discord.Color.DarkMagenta, "bot", UUID.Zero, "bot").ConfigureAwait(false); + } + else + { + await SendEmbedToChannelAsync("localchat", sender_name, message, Discord.Color.DarkRed, "bot", UUID.Zero, "bot").ConfigureAwait(false); + } } } + else + { + await SendEmbedToChannelAsync("localchat", "{ME}", message, Discord.Color.LightGrey, "bot", UUID.Zero, "bot").ConfigureAwait(false); + } } } return Task.CompletedTask;