From 5bb1b43e81fc418289da714124e7fd65a45abe5c Mon Sep 17 00:00:00 2001 From: Christopher Darnell Date: Thu, 6 May 2021 20:07:03 -0700 Subject: [PATCH] Removed extra spaces. Removed double \r\n across all code files. --- StarsiegeBot/BotSettings.cs | 11 --- StarsiegeBot/EventTriggers.cs | 33 ++------- StarsiegeBot/ExperiemntalCommands.cs | 3 - StarsiegeBot/GameCommands.cs | 31 +-------- StarsiegeBot/Phoenix/GroupManagement.cs | 12 +--- StarsiegeBot/Phoenix/GroupRoleManagement.cs | 17 +---- StarsiegeBot/Phoenix/LevelManagement.cs | 10 --- StarsiegeBot/Phoenix/LevelRoleManagement.cs | 9 --- StarsiegeBot/Phoenix/RoleManagement.cs | 10 --- StarsiegeBot/PrefixManagement.cs | 13 ---- StarsiegeBot/Program.cs | 77 ++++++++++----------- StarsiegeBot/Raven/NotFacts.cs | 14 ---- StarsiegeBot/Raven/SnappleFacts.cs | 15 +--- StarsiegeBot/Raven/TriviaHandler.cs | 14 ---- StarsiegeBot/Starsiege/DeathMessages.cs | 59 ++++------------ StarsiegeBot/Starsiege/Functions.cs | 24 +------ StarsiegeBot/Starsiege/GameInfo.cs | 10 --- StarsiegeBot/Starsiege/QuickchatHandler.cs | 47 +------------ StarsiegeBot/WelcomeMessage.cs | 48 ++----------- 19 files changed, 68 insertions(+), 389 deletions(-) diff --git a/StarsiegeBot/BotSettings.cs b/StarsiegeBot/BotSettings.cs index 30b13db..a274cc4 100644 --- a/StarsiegeBot/BotSettings.cs +++ b/StarsiegeBot/BotSettings.cs @@ -9,7 +9,6 @@ using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; - namespace StarsiegeBot { [Group("bot")] @@ -23,7 +22,6 @@ namespace StarsiegeBot public BotSettings() { Console.WriteLine("Bot Setting Commands Loaded"); - if (!(GuildSettings is null)) { // guild settings have already been set... stop resetting it. @@ -49,12 +47,10 @@ namespace StarsiegeBot item.SelfRoles = new Dictionary>(); item.Prefixes.Add(">"); // this line... is a test line. - GuildSettings = new Dictionary { { "default", item } }; - // Now that we have the initial stuff in memory, write it to file. string output = JsonConvert.SerializeObject(GuildSettings); File.WriteAllTextAsync(s_fileName, output); @@ -77,7 +73,6 @@ namespace StarsiegeBot [Description("Reports simplified data about the server settings.")] public async Task BaseItem(CommandContext ctx) { - await ctx.TriggerTypingAsync(); GuildSettings guild = GuildSettings[ctx.Guild.Id.ToString()]; DiscordEmbedBuilder embed = StartEmbed(ctx.Guild.Name + " Server settings."); embed.AddField("On/Off Items", "_ _"); @@ -93,12 +88,10 @@ namespace StarsiegeBot embed.AddField("Levels", guild.LevelRoles.Count.ToString(), true); await ctx.RespondAsync(embed); } - [Command("status"), RequireOwner] [Description("Sets the bot's nickname on this server.")] public async Task SetStatus(CommandContext ctx, string type, [RemainingText] string newStatus = null) { - await ctx.TriggerTypingAsync(); ActivityType aType = type.ToLower() switch { "competing" => ActivityType.Competing, @@ -112,15 +105,12 @@ namespace StarsiegeBot await ctx.Client.UpdateStatusAsync(act); await ctx.RespondAsync("Test."); } - [Command("username"), RequireOwner] public async Task SetUsername(CommandContext ctx, [RemainingText] string newName) { - await ctx.TriggerTypingAsync(); await ctx.Client.UpdateCurrentUserAsync(newName); await ctx.RespondAsync("How's my name name?"); } - private async Task StartTimer(CancellationToken cancellationToken) { await Task.Run(async () => @@ -148,7 +138,6 @@ namespace StarsiegeBot return embed; } } - public class GuildSettings { public bool UseGlobalPrefix { get; set; } diff --git a/StarsiegeBot/EventTriggers.cs b/StarsiegeBot/EventTriggers.cs index d92f926..aa4037e 100644 --- a/StarsiegeBot/EventTriggers.cs +++ b/StarsiegeBot/EventTriggers.cs @@ -10,7 +10,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; - namespace StarsiegeBot { class Triggers @@ -19,14 +18,12 @@ namespace StarsiegeBot public static DiscordMember notify; // protected string BotName { get; set; } private readonly BotSettings _guilds = new BotSettings(); - public Triggers(EventId botEventId) => BotEventId = botEventId; public Task CommandExecuted(CommandsNextExtension ext, CommandExecutionEventArgs e) { // e.Context.Client.Logger.LogCritical(BotEventId, $"Client is in {e.Context.Client.Guilds.Count}"); // let's log the name of the command and user // e.Context.Client.Logger.LogInformation(BotEventId, $"{e.Context.User.Username} successfully executed '{e.Command.QualifiedName}'"); - // since this method is not async, let's return // a completed task, so that no additional work // is done @@ -34,22 +31,18 @@ namespace StarsiegeBot } public Task MessageCreated(DiscordClient d, MessageCreateEventArgs e) { - // d.Logger.LogDebug(BotEventId, "MessageCreated."); - // Ignore all bots. We don't care. if (e.Author.IsBot) { return Task.CompletedTask; } - + // d.Logger.LogDebug(BotEventId, "MessageCreated."); CommandsNextExtension cnext = d.GetCommandsNext(); DiscordMessage msg = e.Message; - // Check if message has valid prefix. - // json file loaded... - int cmdStart = msg.GetStringPrefixLength("!"); + int cmdStart = msg.GetStringPrefixLength(d.CurrentUser.Mention.Insert(2, "!")); List prefixes = BotSettings.GuildSettings["default"].Prefixes; - prefixes.Add(d.CurrentUser.Mention); + // if Guild is not null, we're on a guild. Check for Guild Prefixes. if (!(e.Guild is null)) { string gId = e.Guild.Id.ToString(); @@ -69,6 +62,8 @@ namespace StarsiegeBot } } } + // hard code the bot's mention as a possible prefix. + prefixes.Add(d.CurrentUser.Mention.Insert(2, "!")); foreach (string item in prefixes) { cmdStart = msg.GetStringPrefixLength(item); @@ -76,21 +71,16 @@ namespace StarsiegeBot } // we didn't find a command prefix... Break. if (cmdStart == -1) return Task.CompletedTask; - // Retrieve prefix. string prefix = msg.Content.Substring(0, cmdStart); - string cmdString = msg.Content[cmdStart..]; - + string cmdString = msg.Content.Substring(cmdStart); // Retrieve full command string. Command command = cnext.FindCommand(cmdString, out string args); if (command == null) return Task.CompletedTask; - CommandContext ctx = cnext.CreateContext(msg, prefix, command, args); Task.Run(async () => await cnext.ExecuteCommandAsync(ctx)); - return Task.CompletedTask; } - public Task CommandErrored(CommandsNextExtension ext, CommandErrorEventArgs e) { e.Context.Client.Logger.LogError(BotEventId, $"{e.Context.User.Username} tried executing '{e.Command?.QualifiedName ?? ""}' but it errored: {e.Exception.GetType()}: {e.Exception.Message ?? ""}", DateTime.Now); @@ -101,12 +91,10 @@ namespace StarsiegeBot { output += item.ToString() + "\r\n"; } - Console.WriteLine(output); } return Task.CompletedTask; } - public Task InteractionCreated(DiscordClient d, InteractionCreateEventArgs e) { // d.Logger.LogDebug(BotEventId, $"{e.Interaction.User.Username} started an interaction. {e.Interaction.Data.Name}"); @@ -149,10 +137,9 @@ namespace StarsiegeBot } public Task ClientErrored(DiscordClient d, ClientErrorEventArgs e) { - // let's log the details of the error that just + // let's log the details of the error that just // occured in our client d.Logger.LogError(BotEventId, e.Exception, "Exception occured"); - // since this method is not async, let's return // a completed task, so that no additional work // is done @@ -193,7 +180,6 @@ namespace StarsiegeBot BotSettings.GuildSettings.Add(gId, item); } } - // let's log the name of the guild that was just // sent to our client d.Logger.LogInformation(BotEventId, $"Guild available: {e.Guild.Name}"); @@ -201,7 +187,6 @@ namespace StarsiegeBot // notify the *primary bot owner if the Guild count is above 75. So we can start bot verification process. if (d.Guilds.Count > 75 && !(notify is null)) notify.SendMessageAsync("**__WARNING__: BOT IS IN OVER 75 SERVERS."); - // since this method is not async, let's return // a completed task, so that no additional work // is done @@ -246,7 +231,6 @@ namespace StarsiegeBot // notify the *primary bot owner if the Guild count is above 75. So we can start bot verification process. if (e.Guilds.Count > 75) notify.SendMessageAsync("**__WARNING__: BOT IS IN OVER 75 SERVERS."); - return Task.CompletedTask; } public Task GuildEmojisUpdated(DiscordClient d, GuildEmojisUpdateEventArgs e) @@ -266,7 +250,6 @@ namespace StarsiegeBot { return Task.CompletedTask; } - string gId = e.Guild.Id.ToString(); if (BotSettings.GuildSettings[gId].UseWelcome && !(BotSettings.GuildSettings[gId].WelcomeChannel is null) && @@ -275,7 +258,6 @@ namespace StarsiegeBot string msg = WelcomeMessage.WelcomeMessageProcessing(BotSettings.GuildSettings[gId].WelcomeMessage, e.Member, e.Guild); BotSettings.GuildSettings[gId].WelcomeChannel.SendMessageAsync(msg); } - return Task.CompletedTask; } public Task GuildMemberRemoved(DiscordClient d, GuildMemberRemoveEventArgs e) @@ -382,7 +364,6 @@ namespace StarsiegeBot { // let's log the fact that this event occured d.Logger.LogInformation(BotEventId, $"Client is ready to process events. Client is in: {d.Guilds.Count} Guilds."); - // since this method is not async, let's return // a completed task, so that no additional work // is done diff --git a/StarsiegeBot/ExperiemntalCommands.cs b/StarsiegeBot/ExperiemntalCommands.cs index ab6b903..c1686e5 100644 --- a/StarsiegeBot/ExperiemntalCommands.cs +++ b/StarsiegeBot/ExperiemntalCommands.cs @@ -10,12 +10,10 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; - namespace StarsiegeBot { [Group("ex")] [Hidden] - [Description("Experimental commands. May break the bot.")] class ExperiemntalCommands : BaseCommandModule { @@ -25,7 +23,6 @@ namespace StarsiegeBot await ctx.RespondAsync("Attempting a shutdown..."); System.Environment.Exit(0); } - [Command("Report")] public async Task Report(CommandContext ctx) { diff --git a/StarsiegeBot/GameCommands.cs b/StarsiegeBot/GameCommands.cs index 1c45380..ec4f340 100644 --- a/StarsiegeBot/GameCommands.cs +++ b/StarsiegeBot/GameCommands.cs @@ -7,7 +7,6 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; - namespace StarsiegeBot { class GameCommands : BaseCommandModule @@ -21,19 +20,16 @@ namespace StarsiegeBot "{0} slaps {1} around a bit with a rubber chicken." }; private List _insultCopy; - public GameCommands() { // Let the console know we've loaded basic commands. Console.WriteLine("Basic Commands Loaded"); _insultCopy = _insultMaster.ToList(); } - [Command("8ball"), Aliases(new string[] { "ball", "8" })] [Description("The Magic 8-Ball is a fortune-telling or seeking advice")] public async Task Eightball(CommandContext ctx, [RemainingText, Description("Your question to the 8 ball")] string remainingText = "") { - await ctx.TriggerTypingAsync(); // Load all the traditional 8-Ball answers into an array. string[] results = new string[] { "It is certain.", "It is decidedly so.", "Without a doubt.", "Yes - definitely.", "You may rely on it.", "As I see it, yes.", "Most likely.", "Outlook good.", "Yes.", "Signs point to yes.", "Reply hazy, try again", "Ask again later.", "Better not tell you now.", "Cannot predict now.", "Concentrate and ask again.", "Don't count on it.", "My reply is no.", "My sources say no", "Outlook not so good.", "Very doubtful." }; // give the end user the randomly choosen result. @@ -43,7 +39,6 @@ namespace StarsiegeBot [Description("Gives some basic info about the bot")] public async Task About(CommandContext ctx) { - await ctx.TriggerTypingAsync(); // delcare an embed builder. DiscordEmbedBuilder embed = new DiscordEmbedBuilder(); // Title the ebemd with the bot's name and discrim. @@ -65,7 +60,6 @@ namespace StarsiegeBot { owners += owner.Username + "#" + owner.Discriminator + "\r\n"; } - embed.AddField("Owner(s)", owners, false); // send the data to the end user. await ctx.RespondAsync(embed); @@ -75,7 +69,6 @@ namespace StarsiegeBot public async Task Coinflip(CommandContext ctx) { // We're going to randomly select heads or tails and then give it to the user. - await ctx.TriggerTypingAsync(); string[] choices = { "heads", "tails" }; await ctx.RespondAsync(StartEmbed($"The coin landed on... {choices[Program.rnd.Next(0, choices.Length)]}")); } @@ -83,7 +76,6 @@ namespace StarsiegeBot [Description("Shows all those that have helped with my bot(s) over the years!")] public async Task Credits(CommandContext ctx) { - await ctx.TriggerTypingAsync(); // just some people that have helped me build the bot. string credits = "```asciidoc\r\n= CREDITS (Outdated) =\r\n" + "• UndeadShadow :: Flood Protection. Keepign teh bot from killing itself, and others.\r\n" + @@ -102,7 +94,6 @@ namespace StarsiegeBot public async Task Dice(CommandContext ctx, [RemainingText, Description("XdY")] string throwing = "d") { // let the end user know the bot is doing something... - await ctx.TriggerTypingAsync(); // in case the end user used caps, lower them. throwing = throwing.ToLower(); // set some int items. @@ -120,19 +111,17 @@ namespace StarsiegeBot // if we have a match, do some stuff! if (m.Success) { - // set an empty string, set a counter. + // set an empty string, set a counter. string dieResults = string.Empty; int dieResult = 0; // attempt to get the number of dice being "thrown" and the number of sides those die have. bool volTest = int.TryParse(m.Groups[1].ToString(), out int volume); bool sideTest = int.TryParse(m.Groups[3].ToString(), out int sides); - // They failed? Make some stuff up... We default to a 1d6 throw. if (!volTest) volume = 1; if (!sideTest) sides = 6; - // for each die we roll, get a result. for (int i = 0; i < volume; i++) { @@ -151,7 +140,7 @@ namespace StarsiegeBot totalResult += roll; dieResult += roll; } - // If the end user is rolling more than 10 of any kind of die, dont show the results of the rolls. Just + // If the end user is rolling more than 10 of any kind of die, dont show the results of the rolls. Just if (volume < 11) dieResults = $"{volume}d{sides}: Total: " + dieResult + " Avg: " + Math.Round(dieResult * 1.0 / volume, 2) + " Results: " + dieResults; else @@ -175,13 +164,10 @@ namespace StarsiegeBot } await ctx.RespondAsync(output); } - - [Command("random")] [Description("Random number generator.")] public async Task Random(CommandContext ctx, [Description("Lowest number choice. (Inclusive)")] int min, [Description("Highest Number Choice. (Inclusive)")] int max) { - await ctx.TriggerTypingAsync(); // Find which number given is lower, which is higher. // since rnd.Nex is inclusive, exclusive, increase the max by one. int i = Math.Min(min, max); @@ -192,7 +178,6 @@ namespace StarsiegeBot [Command("random")] public async Task Random(CommandContext ctx) { - await ctx.TriggerTypingAsync(); // some one didn't read the HELP file on Random. Explain it to them. await ctx.RespondAsync(StartEmbed($"Gives you a random number between