rmsoft1

CoreModule.cs

Apr 29th, 2018
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 27.46 KB | None | 0 0
  1. using Discord;
  2. using Discord.Commands;
  3. using Discord.WebSocket;
  4. using RMSoftware.IO;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Net;
  12. using System.IO;
  13. using System.Net.Http;
  14. namespace RMSoftware.ModularBot
  15. {
  16.    
  17.     public class CoreModule : ModuleBase
  18.     {
  19.  
  20.          DiscordSocketClient Client { get; set; }
  21.  
  22.          CommandService cmdsvr { get; set; }
  23.         public CoreModule(DiscordSocketClient client, CommandService cmdservice)
  24.         {
  25.             Client = client;
  26.             cmdsvr = cmdservice;
  27.         }
  28.         [Command("about"), Summary("Display information about the bot")]
  29.         public async Task ShowAbout()
  30.         {
  31.             EmbedBuilder builder = new EmbedBuilder();
  32.             builder.Title = "About";
  33.             builder.WithAuthor(Context.Client.CurrentUser);
  34.             builder.Color = Color.Blue;
  35.             builder.Description = "A Multi-purpose, multi-module bot designed for discord. Tailor it for your specific server, create your own modules and plug-ins. Includes a core module for custom text-based commands & EXEC functionality";
  36.             builder.AddField("Copyright", "Copyright © 2017 RMSoftware Development");
  37.             builder.AddField("Version", Assembly.GetExecutingAssembly().GetName().Version.ToString(3));
  38.             builder.WithFooter("RMSoftware.ModularBot, created by rmsoft1");
  39.             await Retry.Do(async () => await Context.Channel.SendMessageAsync("", false, builder.Build()), TimeSpan.FromMilliseconds(140));
  40.         }
  41.  
  42.         [Command("uptime"),Summary("Displays how long the bot has been connected")]
  43.         public async Task ShowUptime([Remainder]string args=null)
  44.         {
  45.             var delta = DateTime.Now - Program.StartTime;
  46.  
  47.             string format = string.Format("I've been alive and well for **{0}** hours, **{1}** minutes, and **{2}** seconds!", Math.Floor(delta.TotalHours).ToString("n0"), delta.Minutes, delta.Seconds);
  48.             await Retry.Do(async () => await Context.Channel.SendMessageAsync(format + " " + args), TimeSpan.FromMilliseconds(140));
  49.  
  50.         }
  51.  
  52.         [Command("status"), Summary("Set the bot's 'Playing' status"), Remarks("[CMDMgmt]")]
  53.         public async Task setStatus([Remainder]string args = null)
  54.         {
  55.            await Client.SetGameAsync(args);
  56.         }
  57.  
  58.         [Command("streamstatus"), Summary("Set the bot's status to streaming on twitch, with twitch url and custom text."), Remarks("[CMDMgmt]")]
  59.         public async Task setStatus(string streamurl, [Remainder]string args)
  60.         {
  61.            
  62.             await Client.SetGameAsync(args, streamurl, StreamType.Twitch);
  63.         }
  64.  
  65.         [Command("STOPBOT",RunMode=RunMode.Async), Summary("Shutdown the bot"), RequireOwner, Remarks("[CMDMgmt]")]
  66.         public async Task StopBot()
  67.         {
  68.             if (Program.LOG_ONLY_MODE)
  69.             {
  70.                 await Context.Channel.SendMessageAsync("Unable to run command. Origin instance started with `-log_only` parameter. Stop it from console or UI Host instead.");
  71.                 return;
  72.             }
  73.             await Context.Channel.SendMessageAsync("**[BotMaster]** called ***StopBot***... *Ending Session*");
  74.                 DiscordSocketClient c = (DiscordSocketClient)Context.Client;
  75.                 Program.BCMDStarted = false;
  76.                 await c.SetGameAsync("");
  77.                 await Task.Delay(1000);
  78.                 await c.SetStatusAsync(UserStatus.Invisible);
  79.                 await Task.Delay(1000);
  80.                 Program.BCMDStarted = false;
  81.                 await c.StopAsync();
  82.                 await Task.Delay(3000);//Allow the bot to shut down fully before telling Main() to scream at user to finger the keyboard to close the console.
  83.                 Program.discon = true;
  84.         }
  85.  
  86. #if DEBUG
  87.         [Command("Session", RunMode = RunMode.Async), Summary("Shutdown the bot with a session error."), RequireOwner, Remarks("[CMDMgmt]")]
  88.         public async Task InvalidateSession()
  89.         {
  90.             if (Program.LOG_ONLY_MODE)
  91.             {
  92.                 await Context.Channel.SendMessageAsync("Unable to run command. Origin instance started with `-log_only` parameter. Stop it from console or UI Host instead.");
  93.                 return;
  94.             }
  95.             await Context.Channel.SendMessageAsync("`CRITICAL: Instance owner triggered a session invalidation. Immediately terminating session and calling for restart.`");
  96.             await Task.Delay(200);
  97.             await Context.Channel.SendMessageAsync("`CRITICAL: If restart fails, please verify the install & ensure you can properly contact discord API.`");
  98.             await Task.Delay(400);
  99.             await Context.Channel.SendMessageAsync("`CRITICAL: This command is for DEBUG builds only!`");
  100.             DiscordSocketClient c = (DiscordSocketClient)Context.Client;
  101.             Program.BCMDStarted = false;
  102.             await c.SetGameAsync("");
  103.             await Task.Delay(1000);
  104.             await c.SetStatusAsync(UserStatus.Invisible);
  105.             await Task.Delay(1000);
  106.             Program.BCMDStarted = false;
  107.             await c.StopAsync();
  108.             await Task.Delay(3000);//Allow the bot to shut down fully before telling Main() to scream at user to finger the keyboard to close the console.
  109.             Program.discon = true;
  110.             Program.CriticalError = true;
  111.             Program.crashException = new Discord.Net.WebSocketClosedException(4007, "Forced invalidate session.");
  112.         }
  113.  
  114.         [Command("Throw", RunMode = RunMode.Async), Summary("Shutdown the bot with a session error."), RequireOwner, Remarks("[CMDMgmt]")]
  115.         public async Task crash()
  116.         {
  117.             if (Program.LOG_ONLY_MODE)
  118.             {
  119.                 await Context.Channel.SendMessageAsync("Unable to run command. Origin instance started with `-log_only` parameter. Stop it from console or UI Host instead.");
  120.                 return;
  121.             }
  122.             await Context.Channel.SendMessageAsync("`CRITICAL: Instance owner triggered a manual crash!`");
  123.             await Task.Delay(200);
  124.             await Context.Channel.SendMessageAsync("`CRITICAL: If restart fails, please verify the install & ensure you can properly contact discord API.`");
  125.             await Task.Delay(400);
  126.             await Context.Channel.SendMessageAsync("`CRITICAL: This command is for DEBUG builds only!`");
  127.             DiscordSocketClient c = (DiscordSocketClient)Context.Client;
  128.             Program.BCMDStarted = false;
  129.             await c.SetGameAsync("");
  130.             await Task.Delay(1000);
  131.             await c.SetStatusAsync(UserStatus.Invisible);
  132.             await Task.Delay(1000);
  133.             Program.BCMDStarted = false;
  134.             await c.StopAsync();
  135.             await Task.Delay(3000);//Allow the bot to shut down fully before telling Main() to scream at user to finger the keyboard to close the console.
  136.             Program.discon = true;
  137.             Program.CriticalError = true;
  138.             Program.crashException = new Exception("THIS IS A MANUAL DEBUG CRASH!");
  139.             throw (Program.crashException);
  140.         }
  141. #endif
  142.         [Command("RESTARTBOT", RunMode = RunMode.Async), Summary("Restart the bot"), RequireOwner, Remarks("[CMDMgmt]")]
  143.         public async Task RestartBot()
  144.         {
  145.             if(Program.LOG_ONLY_MODE)
  146.             {
  147.                 await Context.Channel.SendMessageAsync("Unable to run command. Origin instance started with `-log_only` parameter. Restart it from console or UI Host instead.");
  148.                 return;
  149.             }
  150.                 await Context.Channel.SendMessageAsync("**[BotMaster]** called ***RestartBot***... *Ending Session, then restarting the program...*");
  151.                 DiscordSocketClient c = (DiscordSocketClient)Context.Client;
  152.                 Program.BCMDStarted = false;
  153.                 await c.SetGameAsync("");
  154.                 await Task.Delay(1000);
  155.                 await c.SetStatusAsync(UserStatus.Invisible);
  156.                 await Task.Delay(1000);
  157.                 Program.BCMDStarted = false;
  158.                 await c.StopAsync();
  159.                 await Task.Delay(3000);//Allow the bot to shut down fully before telling Main() to scream at user to finger the keyboard to close the console.
  160.                 Program.RestartRequested = true;
  161.                 Program.discon = true;
  162.            
  163.  
  164.         }
  165.  
  166.         [Command("addcmd"), Summary("Add a custom command to the bot"),RequireContext(ContextType.Guild), Remarks("[CMDMgmt]")]
  167.         public async Task AddCmd(string cmdTag, bool DevCmdOnly, bool lockToGuild, [Remainder]string action)
  168.         {
  169.             SocketGuildUser user = ((SocketGuildUser)Context.Message.Author);
  170.             SocketMessage arg = Context.Message as SocketMessage;
  171.  
  172.             if (Program.rolemgt.CheckUserRole(user))//If user has a role that is in the database, it is good.
  173.             {
  174.                 try
  175.                 {
  176.                     Program.LogToConsole(new LogMessage(LogSeverity.Info,"CmdMgmt","User has a role in cmdMgrDB"));
  177.  
  178.                     string tosend = "";
  179.                     if (action.StartsWith(Program.CommandPrefix.ToString()))
  180.                     {
  181.                         tosend = "Haha, you're funny. This bot will not run commands with nested commands. *That's dumb*.";
  182.  
  183.                         await Retry.Do(async () => await Context.Channel.SendMessageAsync(tosend), TimeSpan.FromMilliseconds(140));
  184.                         return;
  185.                     }
  186.                     if (!lockToGuild)
  187.                     {
  188.                         tosend = Program.ccmg.AddCommand(cmdTag, action, DevCmdOnly);
  189.                     }
  190.                     if (lockToGuild)
  191.                     {
  192.                         tosend = Program.ccmg.AddCommand(cmdTag, action, DevCmdOnly, Context.Guild.Id);
  193.                     }
  194.  
  195.                     IUserMessage a = await Retry.Do(async () => await Context.Channel.SendMessageAsync(tosend), TimeSpan.FromMilliseconds(140));//This is something to try, if it works, then boom!
  196.                     return;
  197.                 }
  198.                 catch (System.Net.Http.HttpRequestException ex)
  199.                 {
  200.  
  201.                     await arg.Channel.SendMessageAsync("The request failed due to an API related http error that I can't sort out right now... please forgive me... (The command was most likely added anyway~)");
  202.  
  203.                     Program.LogToConsole(new LogMessage(LogSeverity.Error,"CritERR",ex.Message,ex));
  204.                 }
  205.                 catch (Exception ex)
  206.                 {
  207.                     Program.LogToConsole(new LogMessage(LogSeverity.Error, "CritERR", ex.Message, ex));
  208.                     ConsoleColor Last = Console.ForegroundColor;
  209.                     Console.ForegroundColor = ConsoleColor.Gray;
  210.                    
  211.                     Console.ForegroundColor = Last;
  212.                 }
  213.                 return;
  214.             }
  215.             await Retry.Do(async () => await Context.Channel.SendMessageAsync("HEY! You don't have permission to do that!"), TimeSpan.FromMilliseconds(140));
  216.             return;
  217.         }
  218.  
  219.         [Command("addcmds"), Summary("Add a series of commands from attached file."), RequireContext(ContextType.Guild), Remarks("[CMDMgmt]")]
  220.         public async Task AddCmds()
  221.         {
  222.             SocketGuildUser user = ((SocketGuildUser)Context.Message.Author);
  223.             SocketMessage arg = Context.Message as SocketMessage;
  224.            
  225.             if (Program.rolemgt.CheckUserRole(user))//If user has a role that is in the database, it is good.
  226.             {
  227.                 if (Context.Message.Attachments.Count < 1)
  228.                 {
  229.                     await Retry.Do(async () => await Context.Channel.SendMessageAsync("You must attach a file."), TimeSpan.FromMilliseconds(140));
  230.                     return;
  231.                 }
  232.  
  233.                 var a = Context.Message.Attachments.First();
  234.                 //TODO: Download, process and merge into command database.
  235.                 return;
  236.             }
  237.             await Retry.Do(async () => await Context.Channel.SendMessageAsync("HEY! You don't have permission to do that!"), TimeSpan.FromMilliseconds(140));
  238.             return;
  239.         }
  240.  
  241.         [Command("editcmd"), Summary("edit an existing custom command"), RequireContext(ContextType.Guild), Remarks("[CMDMgmt]")]
  242.         public async Task editcmd(string cmdTag, bool newDevCmdOnly, [Remainder]string newaction)
  243.         {
  244.             SocketGuildUser user = ((SocketGuildUser)Context.Message.Author);
  245.             SocketMessage arg = Context.Message as SocketMessage;
  246.  
  247.             if (Program.rolemgt.CheckUserRole(user))
  248.             {
  249.                 try
  250.                 {
  251.                     Program.LogToConsole(new LogMessage(LogSeverity.Info,"CmdMgmt","User has required permission."));
  252.  
  253.                     string tosend = "";
  254.  
  255.                     if (newaction.StartsWith(Program.CommandPrefix.ToString()))
  256.                     {
  257.                         tosend = "Haha, you're funny. This bot will not run commands with nested commands. *That's dumb*.";
  258.  
  259.                         await Retry.Do(async () => await Context.Channel.SendMessageAsync(tosend), TimeSpan.FromMilliseconds(140));
  260.                         return;
  261.                     }
  262.                     tosend = Program.ccmg.EditCommand(cmdTag, newaction, newDevCmdOnly);
  263.  
  264.                     RequestOptions op = new RequestOptions();
  265.                     op.Timeout = 256;
  266.                     op.RetryMode = RetryMode.AlwaysRetry;
  267.                     IUserMessage a = await Retry.Do(async () => await Context.Channel.SendMessageAsync(tosend), TimeSpan.FromMilliseconds(140));
  268.                     return;
  269.                 }
  270.                 catch (AggregateException ex)
  271.                 {
  272.  
  273.                     await arg.Channel.SendMessageAsync("The request failed (MANY TIMES) due to an API related http error that I can't sort out right now... please forgive me... (The command was most likely changed anyway~)");
  274.  
  275.                     Program.LogToConsole(new LogMessage(LogSeverity.Error,"CritERR",ex.Message,ex));
  276.                     ConsoleColor Last = Console.ForegroundColor;
  277.                     Console.ForegroundColor = ConsoleColor.Gray;
  278.                     Console.ForegroundColor = Last;
  279.                 }
  280.                 catch (Exception ex)
  281.                 {
  282.                     Program.LogToConsole(new LogMessage(LogSeverity.Error, "CritERR", ex.Message, ex));
  283.                     ConsoleColor Last = Console.ForegroundColor;
  284.                     Console.ForegroundColor = ConsoleColor.Gray;
  285.                     Console.ForegroundColor = Last;
  286.                 }
  287.                 return;
  288.             }
  289.             await Retry.Do(async () => await Context.Channel.SendMessageAsync("Hey " + arg.Author.Mention + ", You don't have permission to use this command!"), TimeSpan.FromMilliseconds(140));
  290.            
  291.             return;
  292.         }
  293.  
  294.         [Command("delcmd"), Summary("Remove specified custom command."), RequireContext(ContextType.Guild), Remarks("[CMDMgmt]")]
  295.         public async Task delcmd(string cmdTag)
  296.         {
  297.             SocketGuildUser user = ((SocketGuildUser)Context.Message.Author);
  298.             SocketMessage arg = Context.Message as SocketMessage;
  299.  
  300.             if (Program.rolemgt.CheckUserRole(user))
  301.             {
  302.                 try
  303.                 {
  304.  
  305.                     Program.ccmg.DeleteCommand(cmdTag);
  306.                     RequestOptions op = new RequestOptions();
  307.                     op.Timeout = 256;
  308.                     op.RetryMode = RetryMode.AlwaysRetry;
  309.                     await Retry.Do(async () => await Context.Channel.SendMessageAsync("Command removed!make sure to save."), TimeSpan.FromMilliseconds(140));
  310.                 }
  311.                 catch (AggregateException ex)
  312.                 {
  313.  
  314.                     await arg.Channel.SendMessageAsync("The request failed (MANY TIMES) due to an API related http error that I can't sort out right now... please forgive me... (The command probably still got removed though)");
  315.  
  316.                     Program.LogToConsole(new LogMessage(LogSeverity.Error, "CritERR", ex.Message, ex));
  317.                     ConsoleColor Last = Console.ForegroundColor;
  318.                     Console.ForegroundColor = ConsoleColor.Gray;
  319.                     Console.ForegroundColor = Last;
  320.                 }
  321.                 catch (Exception ex)
  322.                 {
  323.                     await arg.Channel.SendMessageAsync("Command is probably removed, but I threw some kind of error... My master will look into it...");
  324.                     Program.LogToConsole(new LogMessage(LogSeverity.Error, "CritERR", ex.Message, ex));
  325.                     ConsoleColor Last = Console.ForegroundColor;
  326.                     Console.ForegroundColor = ConsoleColor.Gray;
  327.                     Console.ForegroundColor = Last;
  328.                 }
  329.             }
  330.  
  331.             return;
  332.         }
  333.  
  334.         //TODO: remove the attachment property! -- STREAM IT
  335.         [Command("listcmd"), Summary("Shows a list of available commands."), RequireContext(ContextType.Guild)]
  336.         public async Task listCmds()
  337.         {
  338.             CommandList commandList = new CommandList(Client.CurrentUser.Username);
  339.             INICategory[] cmdcats = Program.ccmg.GetAllCommand();
  340.            
  341. #region CORE
  342.             foreach (CommandInfo item in cmdsvr.Commands)
  343.             {
  344.                 string group = item.Module.Aliases[0] + " ";
  345.                 string sum = item.Summary;
  346.                 if (string.IsNullOrWhiteSpace(group))
  347.                 {
  348.                     group = "";//Command's groupAttribute?
  349.                 }
  350.  
  351.                 if (item.Module.Name == "CoreModule")
  352.                 {
  353.                    
  354.                     if (string.IsNullOrEmpty(sum))
  355.                     {
  356.                         sum = "No summary was provided.";
  357.                     }
  358.                    
  359.                 }
  360.                 string usage = Program.CommandPrefix + group + item.Name + " ";
  361.                 foreach (var param in item.Parameters)
  362.                 {
  363.                     if (param.IsOptional)
  364.                     {
  365.                         usage += $"[{param.Type.Name} {param.Name}] ";
  366.                     }
  367.                     if (!param.IsOptional)
  368.                     {
  369.                         usage += $"<{param.Type.Name} {param.Name}> ";
  370.                     }
  371.                 }
  372.                 commandList.AddCommand(Program.CommandPrefix + group + item.Name, item.Remarks == "[CMDMgmt]", item.Module.Name == "CoreModule", sum, usage);
  373.             }
  374. #endregion
  375.  
  376. #region Custom Commands
  377.             foreach (INICategory item in cmdcats)
  378.             {
  379.                 if (item.CheckForEntry("guildID"))
  380.                 {
  381.                     if (item.GetEntryByName("guildID").GetAsUlong() != Context.Guild.Id)
  382.                     {
  383.                         continue;//if the entry exists, and it doesn't match the guild listcmd was called in, don't add it to the list.
  384.                     }
  385.  
  386.                 }
  387.                 string commandSummary = "";
  388.                 string usage = "";
  389.                 if (item.CheckForEntry("summary"))
  390.                 {
  391.                     commandSummary = item.GetEntryByName("summary").GetAsString();
  392.  
  393.                 }
  394.                 if (item.CheckForEntry("usage"))
  395.                 {
  396.                     usage = item.GetEntryByName("usage").GetAsString();
  397.  
  398.                 }
  399.                 commandList.AddCommand(Program.CommandPrefix + item.Name, item.GetEntryByName("restricted").GetAsBool(), false, commandSummary, usage);
  400.  
  401.             }
  402. #endregion
  403.  
  404.             try
  405.             {
  406.  
  407.                 using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
  408.                 {
  409.                     using (System.IO.StreamWriter sw = new System.IO.StreamWriter(ms))
  410.                     {
  411.  
  412.                         sw.WriteLine(commandList.GetFullHTML());
  413.                         sw.Flush();
  414.                         ms.Position = 0;
  415.                         await Context.Channel.SendMessageAsync("**See the attached web document for a full list of commands.**", false);
  416.                        
  417.                         await Context.Channel.SendFileAsync(ms, $"{Context.Guild.Name}_{Context.Client.CurrentUser.Username}_AllCommands.html");
  418.  
  419.                     }
  420.                 }
  421.  
  422.  
  423.  
  424.  
  425.             }
  426.             catch (AggregateException ex)
  427.             {
  428.  
  429.                 await Context.Channel.SendMessageAsync("Tried to do this THREE different times, and Quite honestly, I just could not do it... I'm sorry...");
  430.                 Program.LogToConsole(new LogMessage(LogSeverity.Error, "CritERR", ex.Message, ex));
  431.             }
  432.             return;
  433.  
  434.         }
  435.  
  436.         [Command("save"), Summary("Save the command database."), RequireContext(ContextType.Guild), Remarks("[CMDMgmt]")]
  437.         public async Task SaveCmd()
  438.         {
  439.  
  440.  
  441.             SocketMessage arg = Context.Message as SocketMessage;
  442.             SocketGuildUser user = ((SocketGuildUser)arg.Author);
  443.  
  444.             if (Program.rolemgt.CheckUserRole(user))
  445.             {
  446.  
  447.                 Program.LogToConsole(new LogMessage(LogSeverity.Info, "CmdEXEC","User has required permission"));
  448.                 await arg.Channel.SendMessageAsync("Command DB saved.");
  449.                 Program.ccmg.Save();
  450.                
  451.             }
  452.  
  453.             return;
  454.         }
  455.  
  456.         [Command("changes"), Summary("Shows what changed in this version")]
  457.         public async Task ShowChanges()
  458.         {
  459.             EmbedBuilder eb = new EmbedBuilder();
  460.  
  461.             eb.WithAuthor("What's New", Client.CurrentUser.GetAvatarUrl(), "");
  462.             eb.AddField($"v{Assembly.GetExecutingAssembly().GetName().Version.ToString(3)} (Beta release)", "• Adjusting logging feature... Making logging a globally-accessible system.\r\n• Fixed ERRORS.LOG. It will actually be created again.\r\n Re-worded save prompts.");
  463.             eb.WithFooter("RMSoftware.ModularBOT");
  464.             eb.Color = Color.DarkBlue;
  465.             RequestOptions op = new RequestOptions();
  466.             op.RetryMode = RetryMode.AlwaysRetry;
  467.             await Context.Channel.SendMessageAsync("**Full version history/change log: http://rms0.org?a=mbChanges**", false, eb.Build(), op);
  468.         }
  469.  
  470.         [Command("shadowban"), RequireContext(ContextType.Guild), RequireOwner, Remarks("[CMDMgmt]")]
  471.         public async Task IgnoreUser(params IUser[] users)
  472.         {
  473.             int count = 0;
  474.             foreach (var item in users)
  475.             {
  476.                 if (Program.rolemgt.AddUserToBlacklist(item as SocketUser))
  477.                 {
  478.                     count++;
  479.                 }
  480.             }
  481.             await Context.Channel.SendMessageAsync($"Added `{count}` user(s) to the blacklist. they can no longer access my commands.");
  482.         }
  483.  
  484.         [Command("shadowunban"), RequireContext(ContextType.Guild), RequireOwner, Remarks("[CMDMgmt]")]
  485.         public async Task UnIgnoreUser(params IUser[] users)
  486.         {
  487.             int count = 0;
  488.             foreach (var item in users)
  489.             {
  490.                 if (Program.rolemgt.DeleteUserFromBlacklist(item as SocketUser))
  491.                 {
  492.                     count++;
  493.                 }
  494.             }
  495.             await Context.Channel.SendMessageAsync($"Removed `{count}` user(s) from the blacklist. they can now access my commands.");
  496.         }
  497.  
  498.         [Command("addmgrole"), Summary("add a role to CommandMGMT database"), RequireContext(ContextType.Guild),RequireOwner, Remarks("[CMDMgmt]")]
  499.         public async Task AddRoletoDB(params IRole[] roles)
  500.         {
  501.             foreach (var item in roles)
  502.             {
  503.                 Program.rolemgt.AddCommandManagerRole(item as SocketRole);
  504.             }
  505.             await Context.Channel.SendMessageAsync($"Successfully added `{roles.Length}` role(s) to the CommandMGMT database for guild: `{Context.Guild.Name}`.");
  506.         }
  507.         [Command("delmgrole"), Summary("Delete a role from CommandMGMT database"), RequireContext(ContextType.Guild), RequireOwner, Remarks("[CMDMgmt]")]
  508.         public async Task DelRoleFromDB(params IRole[] roles)
  509.         {
  510.             foreach (var item in roles)
  511.             {
  512.                 Program.rolemgt.DeleteCommandManager(item as SocketRole);
  513.             }
  514.             await Context.Channel.SendMessageAsync($"Successfully removed `{roles.Length}` role(s) from the CommandMGMT database for guild: `{Context.Guild.Name}`.");
  515.         }
  516.         [Command("listmgrole",RunMode=RunMode.Async), Summary("lists the authorized management roles for the guild where the command was called."), RequireContext(ContextType.Guild), RequireOwner, Remarks("[CMDMgmt]")]
  517.         public async Task listmgroledbguild()
  518.         {
  519.             await Context.Channel.SendMessageAsync($"This could take a while...");
  520.             await Task.Delay(500);
  521.             using (Context.Channel.EnterTypingState())
  522.             {
  523.                 SocketRole[] items = Program.rolemgt.GetRolesForGuild(Context.Guild as SocketGuild);
  524.                 string roles = "";
  525.                 foreach (var item in items)
  526.                 {
  527.                     roles += $"{item.Id} - {item.Name}{Environment.NewLine}";
  528.                 }
  529.                 await Context.Channel.SendMessageAsync($"All authorized management roles for `{Context.Guild.Name}`:\r\n```\r\n{roles}\r\n```");
  530.             }
  531.                
  532.         }
  533.  
  534.         [Command("listallmgroles", RunMode = RunMode.Async), Summary("lists the authorized management roles for all guilds"), RequireContext(ContextType.Guild), RequireOwner, Remarks("[CMDMgmt]")]
  535.         public async Task listmgroledball()
  536.         {
  537.             int zint = 0;
  538.             await Context.Channel.SendMessageAsync($"This could take a while...");
  539.             await Task.Delay(500);
  540.             using (Context.Channel.EnterTypingState())
  541.             {
  542.                
  543.                 SocketRole[] items = Program.rolemgt.GetAllRoles();
  544.                 List<string> book = new List<string>();
  545.                 string roles = "";
  546.                 foreach (var item in items)
  547.                 {
  548.                     string toAddTo = $"{item.Id} - {item.Name}{Environment.NewLine}";
  549.                     int len = roles.Length + toAddTo.Length;
  550.  
  551.                     if(len >600)
  552.                     {
  553.                         len = 0;
  554.                         book.Add(new String(roles.ToCharArray()));//This is probably super dumb, but I want to add the string to the list and change the roles string without affecting the entry in the list. Im doing this to be safe.
  555.                         roles = "";
  556.  
  557.                     }
  558.                     roles += $"{item.Guild.Name} - {item.Id} - {item.Name}{Environment.NewLine}";
  559.                 }
  560.                 book.Add(roles);
  561.                 foreach (string item in book)
  562.                 {
  563.                     if(zint <1)
  564.                     {
  565.                         await Context.Channel.SendMessageAsync($"All authorized management roles in the database:\r\n```\r\n{item}\r\n```");
  566.                     }
  567.                     if (zint >= 1)
  568.                     {
  569.                         await Context.Channel.SendMessageAsync($"```\r\n{item}\r\n```");
  570.                     }
  571.                     zint++;
  572.  
  573.                     SocketGuildUser r = Context.User as SocketGuildUser;
  574.  
  575.                     string display = r.Nickname ?? r.Username;
  576.                 }
  577.             }
  578.  
  579.         }
  580.  
  581.     }
  582.  
  583.  
  584. }
Advertisement
Add Comment
Please, Sign In to add comment