chore: code cleanup (mostly whitespace / remove unused imports)

This commit is contained in:
spiral 2022-03-30 04:36:22 -04:00
parent 56155782c3
commit 7afba4ea95
No known key found for this signature in database
GPG Key ID: 244A11E4B0BCF40E
29 changed files with 84 additions and 105 deletions

View File

@ -11,5 +11,4 @@ public record MessageRequest
public Embed[]? Embeds { get; set; }
public MessageComponent[]? Components { get; set; }
public Message.Reference? MessageReference { get; set; }
}

View File

@ -19,6 +19,7 @@ namespace PluralKit.API;
public class PrivateController: PKControllerBase
{
private readonly RedisService _redis;
public PrivateController(IServiceProvider svc) : base(svc)
{
_redis = svc.GetRequiredService<RedisService>();

View File

@ -2,12 +2,9 @@ using System.Reflection;
using Autofac;
using App.Metrics.AspNetCore;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
@ -100,7 +97,9 @@ public class Startup
.As<IConfiguration>();
builder.RegisterModule(new ConfigModule<ApiConfig>("API"));
builder.RegisterModule(new LoggingModule("api",
cfg: new LoggerConfiguration().Filter.ByExcluding(exc => exc.Exception is PKError || exc.Exception.IsUserError())));
cfg: new LoggerConfiguration().Filter.ByExcluding(
exc => exc.Exception is PKError || exc.Exception.IsUserError()
)));
// builder.RegisterModule(new MetricsModule("API"));
builder.RegisterModule<DataStoreModule>();
builder.RegisterModule<APIModule>();

View File

@ -1,5 +1,3 @@
using System.Net.WebSockets;
using App.Metrics;
using Autofac;
@ -123,7 +121,11 @@ public class Bot
{
Activities = new[]
{
new Activity {Name = "Restarting... (please wait)", Type = ActivityType.Game}
new Activity
{
Name = "Restarting... (please wait)",
Type = ActivityType.Game
}
},
Status = GatewayStatusUpdate.UserStatus.Idle
})));

View File

@ -1,5 +1,4 @@
using App.Metrics;
using App.Metrics.Gauge;
using App.Metrics.Meter;
using App.Metrics.Timer;

View File

@ -12,6 +12,7 @@ public partial class CommandTree
await ctx.Reply(
$"{Emojis.Error} Unknown command `pk;{ctx.FullCommand().Truncate(100)}`. Perhaps you meant to use one of the following commands?\n{commandListStr}\n\nFor a full list of possible commands, see <https://pluralkit.me/commands>.");
}
private async Task PrintCommandExpectedError(Context ctx, params Command[] potentialCommands)
{
var commandListStr = CreatePotentialCommandList(potentialCommands);

View File

@ -1,10 +1,6 @@
using Humanizer;
using Myriad.Builders;
using Myriad.Types;
using NodaTime;
using PluralKit.Core;
namespace PluralKit.Bot;

View File

@ -1,15 +1,11 @@
using System.Text;
using System.Text.RegularExpressions;
using Humanizer;
using Myriad.Builders;
using Myriad.Types;
using Newtonsoft.Json.Linq;
using NodaTime;
using PluralKit.Core;
namespace PluralKit.Bot;

View File

@ -1,6 +1,5 @@
using System.Text;
using Myriad.Extensions;
using Myriad.Rest.Exceptions;
using Myriad.Rest.Types;
using Myriad.Rest.Types.Requests;

View File

@ -5,8 +5,6 @@ using Humanizer;
using Myriad.Builders;
using Myriad.Types;
using NodaTime;
using PluralKit.Core;
namespace PluralKit.Bot;

View File

@ -323,6 +323,7 @@ public class MemberEdit
}
private string boldIf(string str, bool condition) => condition ? $"**{str}**" : str;
private async Task<EmbedBuilder> CreateMemberNameInfoEmbed(Context ctx, PKMember target)
{
var lcx = ctx.LookupContextFor(target.System);

View File

@ -20,6 +20,7 @@ namespace PluralKit.Bot;
public class ProxiedMessage
{
private static readonly Duration EditTimeout = Duration.FromMinutes(10);
// private readonly IDiscordCache _cache;
private readonly IClock _clock;

View File

@ -3,10 +3,6 @@ using System.Text.RegularExpressions;
using Myriad.Builders;
using Myriad.Types;
using NodaTime;
using NodaTime.Text;
using NodaTime.TimeZones;
using PluralKit.Core;
namespace PluralKit.Bot;
@ -479,9 +475,10 @@ public class SystemEdit
}
else
{
throw new PKSyntaxError(
"This system does not have a banner image set." + (isOwnSystem ? "Set one by attaching an image to this command, or by passing an image URL or @mention." : ""));
throw new PKSyntaxError("This system does not have a banner image set."
+ (isOwnSystem ? "Set one by attaching an image to this command, or by passing an image URL or @mention." : ""));
}
return;
}
@ -514,7 +511,6 @@ public class SystemEdit
? ctx.Reply(msg, new EmbedBuilder().Image(new Embed.EmbedImage(img.Url)).Build())
: ctx.Reply(msg));
}
}
public async Task Delete(Context ctx, PKSystem target)

View File

@ -52,12 +52,7 @@ public class MessageCreated: IEventHandler<MessageCreateEvent>
_dmCache = dmCache;
}
// for now, only return error messages for explicit commands
public ulong? ErrorChannelFor(MessageCreateEvent evt, ulong userId)
{
return evt.ChannelId;
}
public ulong? ErrorChannelFor(MessageCreateEvent evt, ulong userId) => evt.ChannelId;
private bool IsDuplicateMessage(Message msg) =>
// We consider a message duplicate if it has the same ID as the previous message that hit the gateway
_lastMessageCache.GetLastMessage(msg.ChannelId)?.Current.Id == msg.Id;

View File

@ -63,7 +63,8 @@ public class ProxyService
if (autoproxySettings.AutoproxyMode == AutoproxyMode.Latch && IsUnlatch(message))
{
// "unlatch"
await _repo.UpdateAutoproxy(ctx.SystemId.Value, guild.Id, null, new() {
await _repo.UpdateAutoproxy(ctx.SystemId.Value, guild.Id, null, new()
{
AutoproxyMember = null
});
return false;

View File

@ -18,8 +18,8 @@ public class ErrorMessageService
// globally rate limit errors for now, don't want to spam users when something breaks
private static readonly Duration MinErrorInterval = Duration.FromSeconds(10);
private static readonly Duration IntervalFromStartup = Duration.FromMinutes(2);
private readonly ILogger _logger;
private readonly ILogger _logger;
private readonly BotConfig _botConfig;
private readonly IMetrics _metrics;
private readonly DiscordApiClient _rest;

View File

@ -1,6 +1,5 @@
using Serilog;
using Myriad.Cache;
using Myriad.Gateway;
using Myriad.Rest;
@ -10,11 +9,11 @@ namespace PluralKit.Bot;
public class PrivateChannelService
{
private static readonly Dictionary<ulong, ulong> _channelsCache = new();
private readonly ILogger _logger;
private readonly ModelRepository _repo;
private readonly DiscordApiClient _rest;
private static Dictionary<ulong, ulong> _channelsCache = new();
public PrivateChannelService(ILogger logger, ModelRepository repo, DiscordApiClient rest)
{
_logger = logger;

View File

@ -169,7 +169,8 @@ public static class ContextUtils
if (currentPage < 0) currentPage += pageCount;
// If we can, remove the user's reaction (so they can press again quickly)
if ((await ctx.BotPermissions).HasFlag(PermissionSet.ManageMessages)) try
if ((await ctx.BotPermissions).HasFlag(PermissionSet.ManageMessages))
try
{
await ctx.Rest.DeleteUserReaction(msg.ChannelId, msg.Id, reaction.Emoji, reaction.UserId);
}

View File

@ -5,8 +5,6 @@ using App.Metrics;
using Dapper;
using Npgsql;
using SqlKata;
namespace PluralKit.Core;
@ -82,9 +80,11 @@ internal partial class Database: IDatabase
var query = _compiler.Compile(q);
using var conn = await Obtain();
using (_metrics.Measure.Timer.Time(CoreMetrics.DatabaseQuery, new MetricTags("Query", queryName)))
{
await foreach (var val in conn.QueryStreamAsync<T>(query.Sql, query.NamedBindings))
yield return val;
}
}
// the procedures (message_context and proxy_members, as of writing) have their own metrics tracking elsewhere
// still, including them here for consistency

View File

@ -30,8 +30,8 @@ as $$
system.id as system_id,
system.is_deleting,
guild.log_channel,
(channel_id = any(guild.blacklist)) as in_blacklist,
(channel_id = any(guild.log_blacklist)) as in_log_blacklist,
(channel_id = any (guild.blacklist)) as in_blacklist,
(channel_id = any (guild.log_blacklist)) as in_log_blacklist,
coalesce(guild.log_cleanup_enabled, false),
coalesce(system_guild.proxy_enabled, true) as proxy_enabled,
system_last_switch.switch as last_switch,

View File

@ -1,8 +1,6 @@
#nullable enable
using System.Collections;
using Dapper;
using Newtonsoft.Json;
namespace PluralKit.Core;

View File

@ -1,6 +1,5 @@
using Dapper.Contrib.Extensions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NodaTime;
@ -90,7 +89,8 @@ public static class PKSystemExt
ctx == LookupContext.ByOwner ? system.DescriptionPrivacy.ToJsonString() : null);
o.Add("member_list_privacy",
ctx == LookupContext.ByOwner ? system.MemberListPrivacy.ToJsonString() : null);
o.Add("group_list_privacy", ctx == LookupContext.ByOwner ? system.GroupListPrivacy.ToJsonString() : null);
o.Add("group_list_privacy",
ctx == LookupContext.ByOwner ? system.GroupListPrivacy.ToJsonString() : null);
o.Add("front_privacy", ctx == LookupContext.ByOwner ? system.FrontPrivacy.ToJsonString() : null);
o.Add("front_history_privacy",
ctx == LookupContext.ByOwner ? system.FrontHistoryPrivacy.ToJsonString() : null);

View File

@ -1,5 +1,3 @@
using Newtonsoft.Json.Linq;
using NodaTime;
using SqlKata;

View File

@ -1,8 +1,6 @@
#nullable enable
using Newtonsoft.Json.Linq;
using NodaTime;
using SqlKata;
namespace PluralKit.Core;

View File

@ -24,6 +24,7 @@ public class LoggingModule: Module
public LoggingModule(string component, Action<LoggerConfiguration> fn = null, LoggerConfiguration cfg = null)
{
_component = component;
// todo: this is messy and not really used anywhere...?
_fn = fn ?? (_ => { });
_cfg = cfg ?? new LoggerConfiguration();
}

View File

@ -9,6 +9,7 @@ public static class Limits
public static readonly int MaxMemberCount = 1000;
public static readonly int MaxGroupCount = 250;
public static int WarnThreshold(int limit) => limit - 50;
public static readonly int MaxDescriptionLength = 1000;
public static readonly int MaxProxyTagLength = 100;
public static readonly int MaxSwitchMemberCount = 150;

View File

@ -4,7 +4,7 @@ namespace PluralKit.Core;
public static class Proto
{
private static Dictionary<string, MessageParser> _parser = new();
private static readonly Dictionary<string, MessageParser> _parser = new();
public static byte[] Marshal(this IMessage message) => message.ToByteArray();
@ -12,11 +12,11 @@ public static class Proto
{
var type = typeof(T).ToString();
if (_parser.ContainsKey(type))
return (T)_parser[type].ParseFrom(message);
else
{
return (T)_parser[type].ParseFrom(message);
}
_parser.Add(type, new MessageParser<T>(() => new T()));
return Unmarshal<T>(message);
}
}
}

View File

@ -22,5 +22,4 @@ public static class Metrics
Context = "Bot",
MeasurementUnit = Unit.Items
};
}