/// <summary> /// Bot meta reload admin command. /// </summary> public void CMD_Reload(string[] cmds, IUserMessage message) { // NOTE: This implies a one-guild bot. A multi-guild bot probably shouldn't have this "BotCommander" role-based verification. // But under current scale, a true-admin confirmation isn't worth the bother. if (!DenizenMetaBot.IsBotCommander(message.Author as SocketGuildUser)) { SendErrorMessageReply(message, "Authorization Failure", "Nope! That's not for you!"); return; } SendGenericPositiveMessageReply(message, "Reloading", "Yes, boss. Reloading meta documentation now..."); BuildNumberTracker.UpdateAll(); MetaDocs docs = new MetaDocs(); docs.DownloadAll(); MetaDocs.CurrentMeta = docs; EmbedBuilder embed = new EmbedBuilder().WithTitle("Reload Complete").WithDescription("Documentation reloaded successfully."); if (docs.LoadErrors.Count > 0) { List <string> errors = docs.LoadErrors.Count > 5 ? docs.LoadErrors.GetRange(0, 5) : docs.LoadErrors; SendErrorMessageReply(message, "Error(s) While Reloading", string.Join("\n", errors)); embed.AddField("Errors", docs.LoadErrors.Count, true); } embed.AddField("Commands", docs.Commands.Count, true); embed.AddField("Mechanisms", docs.Mechanisms.Count, true); embed.AddField("Tags", docs.Tags.Count, true); embed.AddField("Events", docs.Events.Count, true); embed.AddField("Actions", docs.Actions.Count, true); embed.AddField("Languages", docs.Languages.Count, true); embed.AddField("Guide Pages", docs.GuidePages.Count, true); SendReply(message, embed.Build()); }
/// <summary>Checks whether meta commands are denied in the relevant channel. If denied, will return 'true' and show a rejection message.</summary> /// <param name="message">The message being replied to.</param> /// <returns>True if they are denied.</returns> public static bool CheckMetaDenied(IUserMessage message) { if (!DenizenMetaBot.MetaCommandsAllowed(message.Channel)) { SendErrorMessageReply(message, "Command Not Allowed Here", "Meta documentation commands are not allowed in this channel. Please switch to a bot spam channel, or a Denizen channel."); return(true); } return(false); }
/// <summary>Bot meta reload admin command.</summary> public void CMD_Reload(CommandData command) { // NOTE: This implies a one-guild bot. A multi-guild bot probably shouldn't have this "BotCommander" role-based verification. // But under current scale, a true-admin confirmation isn't worth the bother. if (!DenizenMetaBot.IsBotCommander(command.Message.Author as SocketGuildUser)) { SendErrorMessageReply(command.Message, "Authorization Failure", "Nope! That's not for you!"); return; } SendGenericPositiveMessageReply(command.Message, "Reloading", "Yes, boss. Reloading meta documentation now..."); BuildNumberTracker.UpdateAll(); MetaDocs docs = MetaDocsLoader.DownloadAll(); MetaDocs.CurrentMeta = docs; EmbedBuilder embed = new EmbedBuilder().WithTitle("Reload Complete").WithDescription("Documentation reloaded successfully."); if (docs.LoadErrors.Count > 0) { List <string> errors = docs.LoadErrors.Count > 5 ? docs.LoadErrors.GetRange(0, 5) : docs.LoadErrors; SendErrorMessageReply(command.Message, "Error(s) While Reloading", string.Join("\n", errors)); embed.AddField("Errors", docs.LoadErrors.Count, true); } embed.AddField("Commands", docs.Commands.Count, true); embed.AddField("Mechanisms", docs.Mechanisms.Count, true); embed.AddField("Tags", docs.Tags.Count, true); embed.AddField("Object Types", docs.ObjectTypes.Count, true); embed.AddField("Events", docs.Events.Count, true); embed.AddField("Actions", docs.Actions.Count, true); embed.AddField("Languages", docs.Languages.Count, true); embed.AddField("Guide Pages", docs.GuidePages.Count, true); SendReply(command.Message, embed.Build()); foreach (string url in DenizenMetaBot.ReloadWebooks) { try { Program.ReusableWebClient.PostAsync(url, new ByteArrayContent(Array.Empty <byte>())).Wait(); } catch (Exception ex) { Console.Error.Write($"Failed to ping webhook URL '{url}': {ex}"); } } }
/// <summary>User command to get help (shows a list of valid bot commands).</summary> public void CMD_Help(CommandData command) { StringBuilder infoCmds = new(CmdsInfo); if (!DenizenMetaBot.ProjectToDetails.IsEmpty()) { infoCmds.Append("`update [project ...]` shows an update link for the named project(s)\n") .Append("`github [project ...]` shows a GitHub link for the named project(s)\n") .Append("`issues [project ...]` shows an issue posting link for the named project(s)\n"); } if (!DenizenMetaBot.InformationalData.IsEmpty()) { infoCmds.Append("`info <name ...>` shows a prewritten informational notice reply\n"); } if (!DenizenMetaBot.Rules.IsEmpty()) { infoCmds.Append("`rule [rule ...]` shows the identified rule\n"); } if (!DenizenMetaBot.Quotes.IsEmpty()) { infoCmds.Append("`quote [quote]` shows a random quote that matches the search (if any)"); } EmbedBuilder embed = new EmbedBuilder().WithTitle("Bot Command Help"); embed.AddField("**Available Informational Commands:**", infoCmds); embed.AddField("**Available Utility Commands:**", CmdsUtility); if (DenizenMetaBot.MetaCommandsAllowed(command.Message.Channel)) { embed.AddField("**Available Meta Docs Commands:**", CmdsMeta); } if (DenizenMetaBot.IsBotCommander(command.Message.Author as SocketGuildUser)) { embed.AddField("**Available Admin Commands:**", CmdsAdmin); } SendReply(command.Message, embed.Build()); }