From f8b37391cbdc3251486e819d5846d7dece6bf3b8 Mon Sep 17 00:00:00 2001 From: Daniel-I-Am Date: Sun, 30 Aug 2020 12:05:33 +0200 Subject: [PATCH] Fix some code style issues --- .editorconfig | 7 +++++ ChaosBot/Discord/Modules/User/Points.cs | 26 ++++++++----------- ChaosBot/Discord/Modules/User/RaffleCmd.cs | 18 ++++++------- .../Discord/PreConditions/CheckCommandPerm.cs | 10 +++---- .../PreConditions/CheckModuleEnabled.cs | 8 +++--- ChaosBot/Discord/Services/CommandHandler.cs | 7 ++--- .../Discord/Services/CustomCommandHandler.cs | 2 +- .../Discord/Services/ExperienceHandler.cs | 4 +-- ChaosBot/Discord/Services/TimerHandler.cs | 8 +++--- 9 files changed, 44 insertions(+), 46 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a882442 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 diff --git a/ChaosBot/Discord/Modules/User/Points.cs b/ChaosBot/Discord/Modules/User/Points.cs index 11aebef..63cb333 100644 --- a/ChaosBot/Discord/Modules/User/Points.cs +++ b/ChaosBot/Discord/Modules/User/Points.cs @@ -114,11 +114,11 @@ namespace ChaosBot.Discord.Modules.User $"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>."); } } - + public async Task TotalPoints() { ulong cur = 0; - + try { using (ChaosbotContext dbContext = new ChaosbotContext()) @@ -135,10 +135,8 @@ namespace ChaosBot.Discord.Modules.User _logger.Error( $"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>."); } - - - await ReplyAsync($"{Context.User.Mention}, you have {cur} points.", false); + await ReplyAsync($"{Context.User.Mention}, you have {cur} points.", false); } public async Task RemPoints(SocketUser user = null, ulong Amount = 0) @@ -149,11 +147,11 @@ namespace ChaosBot.Discord.Modules.User using (ChaosbotContext dbContext = new ChaosbotContext()) { IQueryable ctxPoints = dbContext.Points; - + IQueryable ctxusrPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(user.Id)); Point usrPoint; - + if(ctxusrPoint.Any()) { usrPoint = ctxusrPoint.First(); @@ -196,7 +194,7 @@ namespace ChaosBot.Discord.Modules.User using (ChaosbotContext dbContext = new ChaosbotContext()) { IQueryable ctxPoints = dbContext.Points; - + IQueryable ctxPointCheck = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(user.Id)); Point usrPoint; @@ -217,7 +215,6 @@ namespace ChaosBot.Discord.Modules.User await dbContext.Points.Upsert(usrPoint) .On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync(); - } await ReplyAsync( @@ -229,14 +226,14 @@ namespace ChaosBot.Discord.Modules.User using (ChaosbotContext dbContext = new ChaosbotContext()) { IQueryable ctxPoints = dbContext.Points; - + IQueryable ctxUserPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(Context.User.Id)); IQueryable ctxRctPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(user.Id)); if (ctxUserPoint.Any()) { Point usrPoint = ctxUserPoint.First(); - + if (usrPoint.Amount >= Amount) { usrPoint.Amount -= Amount; @@ -263,11 +260,10 @@ namespace ChaosBot.Discord.Modules.User await dbContext.Points.Upsert(rctPoint) .On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync(); - + await ReplyAsync( $"{Context.User.Mention} has given {user.Mention} {Amount} points for a total of {cur} points.", false); - } else { @@ -299,7 +295,7 @@ namespace ChaosBot.Discord.Modules.User using (ChaosbotContext dbContext = new ChaosbotContext()) { Point usrPoint = new Point(); - + usrPoint.Amount = 0; usrPoint.DiscordGuildId = Context.Guild.Id; usrPoint.DiscordUserId = user.Id; @@ -319,4 +315,4 @@ namespace ChaosBot.Discord.Modules.User false); } } -} \ No newline at end of file +} diff --git a/ChaosBot/Discord/Modules/User/RaffleCmd.cs b/ChaosBot/Discord/Modules/User/RaffleCmd.cs index 725429d..59e5b88 100644 --- a/ChaosBot/Discord/Modules/User/RaffleCmd.cs +++ b/ChaosBot/Discord/Modules/User/RaffleCmd.cs @@ -124,11 +124,11 @@ namespace ChaosBot.Discord.Modules.User $"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>."); } } - + public async Task TotalRaffle() { int cur = 0; - + try { using (ChaosbotContext dbContext = new ChaosbotContext()) @@ -145,13 +145,11 @@ namespace ChaosBot.Discord.Modules.User _logger.Error( $"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>."); } - - - await ReplyAsync($"{Context.User.Mention}, you have {cur} raffle tickets.", false); + await ReplyAsync($"{Context.User.Mention}, you have {cur} raffle tickets.", false); } - public async Task AddRaffle(SocketUser user = null, int Amount = 0, bool admin = false) + public async Task AddRaffle(SocketUser user = null, int amount = 0, bool admin = false) { int cur = 0; try @@ -162,7 +160,7 @@ namespace ChaosBot.Discord.Modules.User { IQueryable ctxRaffles = dbContext.Raffles; - for (int i = 0; i < Amount; i++) + for (int i = 0; i < amount; i++) { Raffle usrRaff = new Raffle(); @@ -181,7 +179,7 @@ namespace ChaosBot.Discord.Modules.User } await ReplyAsync( - $"{Context.User.Mention} has added {Amount} tickets to {user.Mention} for a total of {cur} tickets.", + $"{Context.User.Mention} has added {amount} tickets to {user.Mention} for a total of {cur} tickets.", false); } } @@ -206,7 +204,7 @@ namespace ChaosBot.Discord.Modules.User .Where(p => p.DiscordUserId.Equals(user.Id)); cur = ctxRaffleDetail.Count(); - + if (cur < Amount) Amount = cur; @@ -339,4 +337,4 @@ namespace ChaosBot.Discord.Modules.User } } } -} \ No newline at end of file +} diff --git a/ChaosBot/Discord/PreConditions/CheckCommandPerm.cs b/ChaosBot/Discord/PreConditions/CheckCommandPerm.cs index 82afcdd..0bd1ad3 100644 --- a/ChaosBot/Discord/PreConditions/CheckCommandPerm.cs +++ b/ChaosBot/Discord/PreConditions/CheckCommandPerm.cs @@ -21,10 +21,10 @@ namespace ChaosBot.Discord.PreConditions { // Debug information _logger.Trace($"CheckCommandPerm.CheckPermissionsAsync|Checking permissions for command: {command.Name}"); - + // If user is not SocketGuildUser, then return error if (!(context.User is SocketGuildUser gUser)) return Task.FromResult(PreconditionResult.FromError("You must be in a guild to run this command.")); - + // Get the possible permissions List commandPermissions; using (ChaosbotContext dbContext = new ChaosbotContext()) @@ -52,7 +52,7 @@ namespace ChaosBot.Discord.PreConditions { if(context.User.Id == perm.TargetId) return Task.FromResult(PreconditionResult.FromSuccess()); - + return Task.FromResult(PreconditionResult.FromError($"You do not have access to this command.")); } else @@ -60,7 +60,7 @@ namespace ChaosBot.Discord.PreConditions // Return the permission value requiredGroup = perm.TargetId; } - + // Check if any of the users roles are of the required group, if so, permission granted if (gUser.Roles.Any(r => r.Id == requiredGroup)) return Task.FromResult(PreconditionResult.FromSuccess()); @@ -86,4 +86,4 @@ namespace ChaosBot.Discord.PreConditions return Task.FromResult(PreconditionResult.FromError($"You do not have access to this command.")); } } -} \ No newline at end of file +} diff --git a/ChaosBot/Discord/PreConditions/CheckModuleEnabled.cs b/ChaosBot/Discord/PreConditions/CheckModuleEnabled.cs index 4eae395..b23b92e 100644 --- a/ChaosBot/Discord/PreConditions/CheckModuleEnabled.cs +++ b/ChaosBot/Discord/PreConditions/CheckModuleEnabled.cs @@ -22,13 +22,13 @@ namespace ChaosBot.Discord.PreConditions _logger.Trace($"CheckModuleEnabled.CheckPermissionsAsync|Checking module enabled for module: {_moduleName}"); if (context.Guild == null) return Task.FromResult(PreconditionResult.FromError("This must be run in a guild.")); - + // Check if module enabled in database bool isModuleEnabled = GetResult(context, _moduleName); if (isModuleEnabled) return Task.FromResult(PreconditionResult.FromSuccess()); - + // Permission denied return Task.FromResult(PreconditionResult.FromError($"You do not have access to this command.")); } @@ -36,10 +36,10 @@ namespace ChaosBot.Discord.PreConditions public static bool GetResult(ICommandContext context, string moduleName) { if (context.Guild == null) throw new Exception("This must be run in a guild"); - + // Check if module enabled in database return Convert.ToBoolean(ConfigurationRepository.GetValue($"Module:{moduleName}:Enabled", context.Guild.Id, "true")); } } -} \ No newline at end of file +} diff --git a/ChaosBot/Discord/Services/CommandHandler.cs b/ChaosBot/Discord/Services/CommandHandler.cs index 73841d7..f430c19 100644 --- a/ChaosBot/Discord/Services/CommandHandler.cs +++ b/ChaosBot/Discord/Services/CommandHandler.cs @@ -115,10 +115,7 @@ namespace ChaosBot.Discord.Services .On(x => new {x.DiscordGuildId, x.DiscordUserId}).RunAsync(); } - await user.Guild.SystemChannel.SendMessageAsync($"{user.Username} has joined the server."); - - - + await user.Guild.SystemChannel.SendMessageAsync($"{user.Username} has joined the server."); } catch (Exception ex) { @@ -213,4 +210,4 @@ namespace ChaosBot.Discord.Services } } } -} \ No newline at end of file +} diff --git a/ChaosBot/Discord/Services/CustomCommandHandler.cs b/ChaosBot/Discord/Services/CustomCommandHandler.cs index 536b8de..66c5e9c 100644 --- a/ChaosBot/Discord/Services/CustomCommandHandler.cs +++ b/ChaosBot/Discord/Services/CustomCommandHandler.cs @@ -44,4 +44,4 @@ namespace ChaosBot.Discord.Services return false; } } -} \ No newline at end of file +} diff --git a/ChaosBot/Discord/Services/ExperienceHandler.cs b/ChaosBot/Discord/Services/ExperienceHandler.cs index 18f2375..47be2eb 100644 --- a/ChaosBot/Discord/Services/ExperienceHandler.cs +++ b/ChaosBot/Discord/Services/ExperienceHandler.cs @@ -21,7 +21,7 @@ namespace ChaosBot.Discord.Services try { if (!CheckModuleEnabled.GetResult(context, "Experience")) return; - + using (ChaosbotContext dbContext = new ChaosbotContext()) { IQueryable ctxUser = dbContext.ExperiencePoints; @@ -116,4 +116,4 @@ namespace ChaosBot.Discord.Services return curLevel; } } -} \ No newline at end of file +} diff --git a/ChaosBot/Discord/Services/TimerHandler.cs b/ChaosBot/Discord/Services/TimerHandler.cs index 4ccb18f..0a0a06e 100644 --- a/ChaosBot/Discord/Services/TimerHandler.cs +++ b/ChaosBot/Discord/Services/TimerHandler.cs @@ -16,7 +16,7 @@ namespace ChaosBot.Discord.Services public static void Initialize(IServiceProvider services) { _client = services.GetRequiredService(); - + foreach (IConfigurationSection serverConfig in Program.AppSettingsHandler.GetSection("Servers").GetChildren()) { long? lodestoneChannelSloganDescriptionId = serverConfig.GetValue("Lodestone:SloganDescription:Channel", null); @@ -50,13 +50,13 @@ namespace ChaosBot.Discord.Services _logger.Warn($"Could not cast channel {socketChannel.Id} to ITextChannel"); return; } - + if (!guild.GetUser(_client.CurrentUser.Id).GetPermissions(channel).ManageChannel) return; string description = LodestoneManager .GetFreeCompanyById(serverConfig.GetValue("Lodestone:FreeCompanyId")).FreeCompany .Slogan; - + await channel.ModifyAsync(x => { x.Topic = description; }); } catch (Exception ex) @@ -69,4 +69,4 @@ namespace ChaosBot.Discord.Services } } } -} \ No newline at end of file +}