Browse Source

Add 'discord' command

Stuart Johnson 5 months ago
parent
commit
1ac80d9585

+ 21 - 1
.vs/TFA-Bot/xs/UserPrefs.xml

@@ -11,11 +11,31 @@
       <File FileName="TFA-Bot/Program.cs" Line="162" Column="84" />
       <File FileName="TFA-Bot/DataClasses/clsNodeGroup.cs" Line="73" Column="30" />
       <File FileName="TFA-Bot/DataClasses/clsNode.cs" Line="97" Column="62" />
-      <File FileName="TFA-Bot/DiscordBot/clsBotClient.cs" Line="29" Column="30" />
+      <File FileName="TFA-Bot/DiscordBot/clsBotClient.cs" Line="169" Column="84" />
       <File FileName="TFA-Bot/clsEmail.cs" Line="96" Column="14" />
       <File FileName="TFA-Bot/clsAlarm.cs" Line="107" Column="34" />
+      <File FileName="TFA-Bot/DiscordBot/Commands/clsDiscord.cs" Line="32" Column="13" />
+      <File FileName="TFA-Bot/DiscordBot/Commands/clsGoodnight.cs" Line="31" Column="1" />
+      <File FileName="TFA-Bot/DiscordBot/Commands/clsEmail.cs" Line="26" Column="55" />
       <File FileName="TFA-Bot Status" />
     </Files>
+    <Pads>
+      <Pad Id="ProjectPad">
+        <State name="__root__">
+          <Node name="TFA-Bot" expanded="True">
+            <Node name="TFA-Bot" expanded="True" selected="True">
+              <Node name="DiscordBot" expanded="True">
+                <Node name="Commands" expanded="True" />
+              </Node>
+              <Node name="Spreadsheet" expanded="True" />
+            </Node>
+          </Node>
+        </State>
+      </Pad>
+      <Pad Id="MonoDevelop.Debugger.WatchPad">
+        <State />
+      </Pad>
+    </Pads>
   </MonoDevelop.Ide.Workbench>
   <MonoDevelop.Ide.DebuggingService.PinnedWatches />
   <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />

+ 58 - 0
TFA-Bot/DiscordBot/Commands/clsDiscord.cs

@@ -0,0 +1,58 @@
+using System;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using DSharpPlus.EventArgs;
+
+namespace TFABot.DiscordBot.Commands
+{
+    public class clsDiscord : IBotCommand
+    {
+    
+        public String[] MatchCommand {get; private set;}
+        public String[] MatchSubstring {get; private set;}
+        public Regex[] MatchRegex {get; private set;}
+        
+        public clsDiscord()
+        {
+            MatchCommand = new [] {"discord"};
+        }
+        
+        public void Run(MessageCreateEventArgs e)
+        {
+            var sb = new StringBuilder();
+            
+            String alertChannelString = null;
+            if (Program.SettingsList.TryGetValue("Discord-AlertsChannel",out alertChannelString))
+            alertChannelString = alertChannelString.ToLower().Replace("#","");
+            
+            sb.AppendLine($"Discord Gateway: {Program.Bot._client.GatewayUrl} Version: {Program.Bot._client.GatewayVersion}");
+            sb.AppendLine($"                 {Program.Bot._client.CurrentUser}   ");
+            sb.AppendLine($"                 Ping {Program.Bot._client.Ping}");
+            
+            
+            sb.AppendLine();
+            foreach (var discord in Program.Bot._client.Guilds.Values)
+            {
+                sb.AppendLine($"{discord.Name} {discord.Id} {discord.RegionId}");
+                sb.AppendLine($"   Channels:{discord.Channels.Count} Members:{discord.MemberCount} Owner:{discord.Owner.DisplayName}#{discord.Owner.Discriminator}");
+                sb.AppendLine($"   Joined:{discord.JoinedAt:yyyy-MM-dd}");
+                
+                if (discord.Id != 419201548372017163)
+                {
+                    sb.Append($"   Alert Channel: '{alertChannelString}' ");
+                    sb.AppendLine(discord.Channels.Any(x => x.Name == alertChannelString) ? "" : "NOT FOUND");
+                }
+                sb.AppendLine();
+            }
+
+
+            e.Channel.SendMessageAsync($"```{sb.ToString()}```");
+        }
+
+        public void HelpString (ref clsColumnDisplay columnDisplay)
+        {
+                columnDisplay.AppendCol("discord","","Display discord status");
+        }
+    }
+}

+ 7 - 4
TFA-Bot/DiscordBot/clsBotClient.cs

@@ -20,9 +20,9 @@ namespace DiscordBot
 {
     public class clsBotClient : IDisposable
     {
-        const ulong FactomServerID = 419201548372017163;
-        const ulong FactomOperatorAlertChannel = 443025488655417364;
-        const string FactomOperatorAlertChannelString =  "operators-alerts";
+        public const ulong FactomServerID = 419201548372017163;
+        public const ulong FactomOperatorAlertChannel = 443025488655417364;
+        public const string FactomOperatorAlertChannelString =  "operators-alerts";
         
         clsAlarm AlarmNoFactomChannel;
     
@@ -126,6 +126,9 @@ namespace DiscordBot
         //Discord Server connected
         private Task Client_GuildAvailable(GuildCreateEventArgs e)
         {
+
+            Console.WriteLine($"Discord Server: {e.Guild.Name} {e.Guild.Id}");
+        
             if (e.Guild.Id == FactomServerID)  //Factom's Discord server
             {
                 Factom_BotAlert = e.Guild.Channels.FirstOrDefault(x=>x.Id == FactomOperatorAlertChannel);
@@ -181,7 +184,7 @@ namespace DiscordBot
                     }
                     else
                     {
-                        Console.WriteLine($"ERROR: Cant find AlartChannel {alertChannelString}");
+                        Console.WriteLine($"ERROR: Can't find AlertChannel {alertChannelString}");
                     }
 #endif                                    
                 }

+ 1 - 0
TFA-Bot/TFA-Bot.csproj

@@ -141,6 +141,7 @@
     <Compile Include="DiscordBot\Commands\clsNetworks.cs" />
     <Compile Include="clsEmail.cs" />
     <Compile Include="DiscordBot\Commands\clsEmail.cs" />
+    <Compile Include="DiscordBot\Commands\clsDiscord.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="packages.config" />