forked from TeamInklings/Octobot
Force maximum Cognitive Complexity via InspectCode (#60)
This PR uses a new feature of the InspectCode action: extensions. By adding the `Cognitive Complexity` extension, InspectCode can provide warnings and force the contributors to follow standards regarding complex methods. This functionality was previously provided by CodeFactor, but it is no longer used. Here's the full changelog of this PR: - Allowed Actions to run on push for any branch, not just `master`; - Added `Cognitive Complexity` plugin for InspectCode; - Significantly reduced complexity of KickCommandGroup, MuteCommandGroup and GuildUpdateService --------- Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
8c72dc663e
commit
27b8f15e3b
11 changed files with 476 additions and 421 deletions
|
@ -76,15 +76,15 @@ public class ClearCommandGroup : CommandGroup {
|
|||
if (!currentUserResult.IsDefined(out var currentUser))
|
||||
return Result.FromError(currentUserResult);
|
||||
|
||||
return await ClearMessagesAsync(amount, guildId.Value, channelId.Value, messages, user, currentUser);
|
||||
var data = await _dataService.GetData(guildId.Value, CancellationToken);
|
||||
Messages.Culture = GuildSettings.Language.Get(data.Settings);
|
||||
|
||||
return await ClearMessagesAsync(amount, data, channelId.Value, messages, user, currentUser, CancellationToken);
|
||||
}
|
||||
|
||||
private async Task<Result> ClearMessagesAsync(
|
||||
int amount, Snowflake guildId, Snowflake channelId, IReadOnlyList<IMessage> messages,
|
||||
IUser user, IUser currentUser) {
|
||||
var cfg = await _dataService.GetSettings(guildId, CancellationToken);
|
||||
Messages.Culture = GuildSettings.Language.Get(cfg);
|
||||
|
||||
int amount, GuildData data, Snowflake channelId, IReadOnlyList<IMessage> messages,
|
||||
IUser user, IUser currentUser, CancellationToken ct = default) {
|
||||
var idList = new List<Snowflake>(messages.Count);
|
||||
var builder = new StringBuilder().AppendLine(Mention.Channel(channelId)).AppendLine();
|
||||
for (var i = messages.Count - 1; i >= 1; i--) { // '>= 1' to skip last message ('Boyfriend is thinking...')
|
||||
|
@ -98,18 +98,18 @@ public class ClearCommandGroup : CommandGroup {
|
|||
var description = builder.ToString();
|
||||
|
||||
var deleteResult = await _channelApi.BulkDeleteMessagesAsync(
|
||||
channelId, idList, user.GetTag().EncodeHeader(), CancellationToken);
|
||||
channelId, idList, user.GetTag().EncodeHeader(), ct);
|
||||
if (!deleteResult.IsSuccess)
|
||||
return Result.FromError(deleteResult.Error);
|
||||
|
||||
var logResult = _utility.LogActionAsync(
|
||||
cfg, channelId, user, title, description, currentUser, CancellationToken);
|
||||
data.Settings, channelId, user, title, description, currentUser, ct);
|
||||
if (!logResult.IsSuccess)
|
||||
return Result.FromError(logResult.Error);
|
||||
|
||||
var embed = new EmbedBuilder().WithSmallTitle(title, currentUser)
|
||||
.WithColour(ColorsList.Green).Build();
|
||||
|
||||
return await _feedbackService.SendContextualEmbedResultAsync(embed, CancellationToken);
|
||||
return await _feedbackService.SendContextualEmbedResultAsync(embed, ct);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue