From ef7e1e2392d680384ace6a2173c5ff39e47deb9e Mon Sep 17 00:00:00 2001 From: Madpeter Date: Mon, 11 May 2020 10:53:52 +0100 Subject: [PATCH] readds localchat support not being able see replys in local was dumb --- Core/bottypes/Discord/ChannelControl.cs | 7 ++++-- Core/bottypes/Discord/Inbound.cs | 29 ++++++++++++++++++------- Core/bottypes/Discord/relay.cs | 4 ++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Core/bottypes/Discord/ChannelControl.cs b/Core/bottypes/Discord/ChannelControl.cs index d92a136..97c23a4 100644 --- a/Core/bottypes/Discord/ChannelControl.cs +++ b/Core/bottypes/Discord/ChannelControl.cs @@ -103,6 +103,10 @@ namespace BSB.bottypes { display_topic = "Actions -> !clear"; } + else if (channelname == "localchat") + { + display_topic = "Actions -> !clear"; + } else if (sender_id == UUID.Zero.ToString()) { display_topic = "" + myconfig.userName + " #" + MyVersion + ""; @@ -115,7 +119,6 @@ namespace BSB.bottypes { display_topic = "" + channeltopictype + ":" + sender_id + ": Actions -> !clear, !close"; } - IGuildChannel channel = await DiscordServer.CreateTextChannelAsync(channelname, X => DiscordGetNewChannelProperies(X, channelname, display_topic, channeltopictype.ToLowerInvariant())); ITextChannel Txtchan = await DiscordServer.GetTextChannelAsync(channel.Id); return Txtchan; @@ -151,7 +154,7 @@ namespace BSB.bottypes ICategoryChannel newcat = await DiscordServer.CreateCategoryAsync(A).ConfigureAwait(true); catmap.Add(A, newcat); } - List required_channels = new List() { "status", "interface" }; + List required_channels = new List() { "status", "interface","localchat" }; IReadOnlyCollection found_chans = await DiscordServer.GetTextChannelsAsync(CacheMode.AllowDownload); List GroupChannels = new List(); foreach (ITextChannel chan in found_chans) diff --git a/Core/bottypes/Discord/Inbound.cs b/Core/bottypes/Discord/Inbound.cs index 6a8f799..2f89173 100644 --- a/Core/bottypes/Discord/Inbound.cs +++ b/Core/bottypes/Discord/Inbound.cs @@ -10,6 +10,11 @@ namespace BSB.bottypes { public abstract class DiscordBotInbound : DiscordBotRelay { + protected async Task InboundLocalchatMessage(SocketMessage message) + { + Client.Self.Chat("[" + message.Author.Username + "]->" + message.Content, 0, ChatType.Normal); + return await MarkMessage(message, "✅"); + } protected async Task InboundInterfaceMessage(SocketMessage message) { StringBuilder output = new StringBuilder(); @@ -97,13 +102,11 @@ namespace BSB.bottypes } if (process_status == true) { - var Tickmark = new Emoji("✅"); - await message.AddReactionAsync(Tickmark, RequestOptions.Default); + await MarkMessage(message, "✅"); } else { - var Failed = new Emoji("❌"); - await message.AddReactionAsync(Failed, RequestOptions.Default); + await MarkMessage(message, "❌"); } } else @@ -140,8 +143,7 @@ namespace BSB.bottypes else if (UUID.TryParse(bits[1], out UUID avatar) == true) { Client.Self.InstantMessage(avatar, "[" + message.Author.Username + "]->" + message.Content); - var Tickmark = new Emoji("✅"); - await message.AddReactionAsync(Tickmark,RequestOptions.Default); + await MarkMessage(message, "✅"); } } } @@ -181,13 +183,13 @@ namespace BSB.bottypes Noticetitle = Noticetitle.Replace("!notice ", ""); Noticetitle = Noticetitle.Trim(); CommandsInterface.Call("GroupNotice", "" + group.ToString() + "~#~" + Noticetitle + "~#~" + Noticemessage, UUID.Zero); + await MarkMessage(message, "✅"); } else { CommandsInterface.Call("Groupchat", "" + group.ToString() + "~#~" + "[" + message.Author.Username + "]->" + message.Content, UUID.Zero); + await MarkMessage(message, "✅"); } - var Tickmark = new Emoji("✅"); - await message.AddReactionAsync(Tickmark, RequestOptions.Default); } } } @@ -195,6 +197,13 @@ namespace BSB.bottypes return Task.CompletedTask; } + protected async Task MarkMessage(SocketMessage message,string emote) + { + var Tickmark = new Emoji(emote); + await message.AddReactionAsync(Tickmark, RequestOptions.Default); + return Task.CompletedTask; + } + protected async Task DiscordClientMessageReceived(SocketMessage message) { if (AllowNewOutbound() == true) @@ -218,6 +227,10 @@ namespace BSB.bottypes { await InboundInterfaceMessage(message); } + else if(Chan.Name == "localchat") + { + await InboundLocalchatMessage(message); + } } else if (Chan.CategoryId == catmap["im"].Id) { diff --git a/Core/bottypes/Discord/relay.cs b/Core/bottypes/Discord/relay.cs index a411862..d7e1ad8 100644 --- a/Core/bottypes/Discord/relay.cs +++ b/Core/bottypes/Discord/relay.cs @@ -90,6 +90,10 @@ namespace BSB.bottypes await DiscordIMMessage(sender_uuid, sender_name, message).ConfigureAwait(false); } } + else + { + _ = SendMessageToChannelAsync("localchat", ""+sender_name+":"+message, "bot", UUID.Zero, "bot"); + } } } }