mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
Kotz's editorconfig styles slightly modified. Target typed new usage. Brackets in expressions used for clarity.
This commit is contained in:
@@ -14,14 +14,13 @@ public class AntiRaidStats
|
||||
{
|
||||
public AntiRaidSetting AntiRaidSettings { get; set; }
|
||||
public int UsersCount { get; set; }
|
||||
public ConcurrentHashSet<IGuildUser> RaidUsers { get; set; } = new ConcurrentHashSet<IGuildUser>();
|
||||
public ConcurrentHashSet<IGuildUser> RaidUsers { get; set; } = new();
|
||||
}
|
||||
|
||||
public class AntiSpamStats
|
||||
{
|
||||
public AntiSpamSetting AntiSpamSettings { get; set; }
|
||||
public ConcurrentDictionary<ulong, UserSpamStats> UserStats { get; set; }
|
||||
= new ConcurrentDictionary<ulong, UserSpamStats>();
|
||||
public ConcurrentDictionary<ulong, UserSpamStats> UserStats { get; set; } = new();
|
||||
}
|
||||
|
||||
public class AntiAltStats
|
||||
|
@@ -15,13 +15,13 @@ public sealed class UserSpamStats : IDisposable
|
||||
ApplyNextMessage(msg);
|
||||
}
|
||||
|
||||
private readonly object applyLock = new object();
|
||||
private readonly object applyLock = new();
|
||||
public void ApplyNextMessage(IUserMessage message)
|
||||
{
|
||||
lock (applyLock)
|
||||
{
|
||||
var upperMsg = message.Content.ToUpperInvariant();
|
||||
if (upperMsg != LastMessage || string.IsNullOrWhiteSpace(upperMsg) && message.Attachments.Any())
|
||||
if (upperMsg != LastMessage || (string.IsNullOrWhiteSpace(upperMsg) && message.Attachments.Any()))
|
||||
{
|
||||
LastMessage = upperMsg;
|
||||
while (timers.TryDequeue(out var old))
|
||||
|
@@ -263,7 +263,7 @@ public partial class Administration
|
||||
.Where(x => !x.IsManaged && x != x.Guild.EveryoneRole)
|
||||
.ToList();
|
||||
|
||||
if (user.Id == ctx.Guild.OwnerId || ctx.User.Id != ctx.Guild.OwnerId && guser.GetRoles().Max(x => x.Position) <= userRoles.Max(x => x.Position))
|
||||
if (user.Id == ctx.Guild.OwnerId || (ctx.User.Id != ctx.Guild.OwnerId && guser.GetRoles().Max(x => x.Position) <= userRoles.Max(x => x.Position)))
|
||||
return;
|
||||
try
|
||||
{
|
||||
|
@@ -101,7 +101,7 @@ public partial class Administration
|
||||
await SendConfirmAsync(
|
||||
text: string.Join("\n", scmds
|
||||
.Select(x => $@"```css
|
||||
#{++i + page * 5}
|
||||
#{++i + (page * 5)}
|
||||
[{GetText(strs.server)}]: {(x.GuildId.HasValue ? $"{x.GuildName} #{x.GuildId}" : "-")}
|
||||
[{GetText(strs.channel)}]: {x.ChannelName} #{x.ChannelId}
|
||||
[{GetText(strs.command_text)}]: {x.CommandText}```")),
|
||||
@@ -133,7 +133,7 @@ public partial class Administration
|
||||
await SendConfirmAsync(
|
||||
text: string.Join("\n", scmds
|
||||
.Select(x => $@"```css
|
||||
#{++i + page * 5}
|
||||
#{++i + (page * 5)}
|
||||
[{GetText(strs.server)}]: {(x.GuildId.HasValue ? $"{x.GuildName} #{x.GuildId}" : "-")}
|
||||
[{GetText(strs.channel)}]: {x.ChannelName} #{x.ChannelId}
|
||||
{GetIntervalText(x.Interval)}
|
||||
|
@@ -45,7 +45,7 @@ public class AdministrationService : INService
|
||||
{
|
||||
var _ = Task.Run(async () =>
|
||||
{
|
||||
if (!(msg.Channel is SocketTextChannel channel))
|
||||
if (msg.Channel is not SocketTextChannel channel)
|
||||
return;
|
||||
|
||||
//wat ?!
|
||||
@@ -145,7 +145,7 @@ public class AdministrationService : INService
|
||||
{
|
||||
var msg = await chanl.GetMessageAsync(messageId);
|
||||
|
||||
if (!(msg is IUserMessage umsg) || msg.Author.Id != context.Client.CurrentUser.Id)
|
||||
if (msg is not IUserMessage umsg || msg.Author.Id != context.Client.CurrentUser.Id)
|
||||
return;
|
||||
|
||||
var rep = new ReplacementBuilder()
|
||||
|
@@ -14,7 +14,7 @@ public sealed class AutoAssignRoleService : INService
|
||||
//guildid/roleid
|
||||
private readonly ConcurrentDictionary<ulong, IReadOnlyList<ulong>> _autoAssignableRoles;
|
||||
|
||||
private Channel<SocketGuildUser> _assignQueue = Channel.CreateBounded<SocketGuildUser>(
|
||||
private readonly Channel<SocketGuildUser> _assignQueue = Channel.CreateBounded<SocketGuildUser>(
|
||||
new BoundedChannelOptions(100)
|
||||
{
|
||||
FullMode = BoundedChannelFullMode.DropOldest,
|
||||
|
@@ -41,7 +41,7 @@ public class DiscordPermOverrideService : INService, ILateBlocker
|
||||
public Task<PreconditionResult> ExecuteOverrides(ICommandContext ctx, CommandInfo command,
|
||||
GuildPerm perms, IServiceProvider services)
|
||||
{
|
||||
var rupa = new RequireUserPermissionAttribute((GuildPermission) perms);
|
||||
var rupa = new RequireUserPermissionAttribute(perms);
|
||||
return rupa.CheckPermissionsAsync(ctx, command, services);
|
||||
}
|
||||
|
||||
|
@@ -6,7 +6,7 @@ namespace NadekoBot.Modules.Administration.Services;
|
||||
// todo if any activity...
|
||||
public class GameVoiceChannelService : INService
|
||||
{
|
||||
public ConcurrentHashSet<ulong> GameVoiceChannels { get; } = new ConcurrentHashSet<ulong>();
|
||||
public ConcurrentHashSet<ulong> GameVoiceChannels { get; } = new();
|
||||
|
||||
private readonly DbService _db;
|
||||
private readonly DiscordSocketClient _client;
|
||||
@@ -84,7 +84,7 @@ public class GameVoiceChannelService : INService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!(usr is SocketGuildUser gUser))
|
||||
if (usr is not SocketGuildUser gUser)
|
||||
return;
|
||||
|
||||
var game = gUser.Activities.FirstOrDefault()?.Name;
|
||||
|
@@ -5,7 +5,7 @@ namespace NadekoBot.Modules.Administration.Services;
|
||||
|
||||
public class GuildTimezoneService : INService
|
||||
{
|
||||
public static ConcurrentDictionary<ulong, GuildTimezoneService> AllServices { get; } = new ConcurrentDictionary<ulong, GuildTimezoneService>();
|
||||
public static ConcurrentDictionary<ulong, GuildTimezoneService> AllServices { get; } = new();
|
||||
private readonly ConcurrentDictionary<ulong, TimeZoneInfo> _timezones;
|
||||
private readonly DbService _db;
|
||||
|
||||
|
@@ -14,7 +14,7 @@ public sealed class ImageOnlyChannelService : IEarlyBehavior
|
||||
private readonly DbService _db;
|
||||
private readonly ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>> _enabledOn;
|
||||
|
||||
private Channel<IUserMessage> _deleteQueue = Channel.CreateBounded<IUserMessage>(new BoundedChannelOptions(100)
|
||||
private readonly Channel<IUserMessage> _deleteQueue = Channel.CreateBounded<IUserMessage>(new BoundedChannelOptions(100)
|
||||
{
|
||||
FullMode = BoundedChannelFullMode.DropOldest,
|
||||
SingleReader = true,
|
||||
@@ -74,8 +74,8 @@ public sealed class ImageOnlyChannelService : IEarlyBehavior
|
||||
var newState = false;
|
||||
using var uow = _db.GetDbContext();
|
||||
if (forceDisable
|
||||
|| _enabledOn.TryGetValue(guildId, out var channels)
|
||||
&& channels.TryRemove(channelId))
|
||||
|| (_enabledOn.TryGetValue(guildId, out var channels)
|
||||
&& channels.TryRemove(channelId)))
|
||||
{
|
||||
uow.ImageOnlyChannels.Delete(x => x.ChannelId == channelId);
|
||||
}
|
||||
|
@@ -49,8 +49,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
|
||||
public ConcurrentDictionary<ulong, LogSetting> GuildLogSettings { get; }
|
||||
|
||||
private ConcurrentDictionary<ITextChannel, List<string>> PresenceUpdates { get; } =
|
||||
new ConcurrentDictionary<ITextChannel, List<string>>();
|
||||
private ConcurrentDictionary<ITextChannel, List<string>> PresenceUpdates { get; } = new();
|
||||
|
||||
private readonly Timer _timerReference;
|
||||
private readonly IBotStrings _strings;
|
||||
@@ -62,7 +61,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
|
||||
private readonly Timer _clearTimer;
|
||||
private readonly ConcurrentHashSet<ulong> _ignoreMessageIds = new ConcurrentHashSet<ulong>();
|
||||
private readonly ConcurrentHashSet<ulong> _ignoreMessageIds = new();
|
||||
|
||||
public LogCommandService(DiscordSocketClient client, IBotStrings strings,
|
||||
DbService db, MuteService mute, ProtectionService prot, GuildTimezoneService tz,
|
||||
@@ -218,7 +217,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
logSetting.LogVoicePresenceId =
|
||||
logSetting.UserMutedId =
|
||||
logSetting.LogVoicePresenceTTSId =
|
||||
value ? channelId : (ulong?) null;
|
||||
value ? channelId : null;
|
||||
;
|
||||
await uow.SaveChangesAsync();
|
||||
GuildLogSettings.AddOrUpdate(guildId, id => logSetting, (id, old) => logSetting);
|
||||
@@ -231,7 +230,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!(uAfter is SocketGuildUser after))
|
||||
if (uAfter is not SocketGuildUser after)
|
||||
return;
|
||||
|
||||
var g = after.Guild;
|
||||
@@ -359,7 +358,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!(iusr is IGuildUser usr))
|
||||
if (iusr is not IGuildUser usr)
|
||||
return;
|
||||
|
||||
var beforeVch = before.VoiceChannel;
|
||||
@@ -673,7 +672,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!(cbefore is IGuildChannel before))
|
||||
if (cbefore is not IGuildChannel before)
|
||||
return;
|
||||
|
||||
var after = (IGuildChannel) cafter;
|
||||
@@ -726,7 +725,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!(ich is IGuildChannel ch))
|
||||
if (ich is not IGuildChannel ch)
|
||||
return;
|
||||
|
||||
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out var logSetting)
|
||||
@@ -766,7 +765,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!(ich is IGuildChannel ch))
|
||||
if (ich is not IGuildChannel ch)
|
||||
return;
|
||||
|
||||
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out var logSetting)
|
||||
@@ -805,7 +804,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!(iusr is IGuildUser usr) || usr.IsBot)
|
||||
if (iusr is not IGuildUser usr || usr.IsBot)
|
||||
return;
|
||||
|
||||
var beforeVch = before.VoiceChannel;
|
||||
@@ -1024,7 +1023,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
return;
|
||||
|
||||
var ch = optCh.Value;
|
||||
if (!(ch is ITextChannel channel))
|
||||
if (ch is not ITextChannel channel)
|
||||
return;
|
||||
|
||||
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out var logSetting)
|
||||
@@ -1069,14 +1068,14 @@ public sealed class LogCommandService : ILogCommandService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!(imsg2 is IUserMessage after) || after.IsAuthor(_client))
|
||||
if (imsg2 is not IUserMessage after || after.IsAuthor(_client))
|
||||
return;
|
||||
|
||||
var before = (optmsg.HasValue ? optmsg.Value : null) as IUserMessage;
|
||||
if (before is null)
|
||||
return;
|
||||
|
||||
if (!(ch is ITextChannel channel))
|
||||
if (ch is not ITextChannel channel)
|
||||
return;
|
||||
|
||||
if (before.Content == after.Content)
|
||||
|
@@ -17,14 +17,13 @@ public class MuteService : INService
|
||||
public ConcurrentDictionary<ulong, string> GuildMuteRoles { get; }
|
||||
public ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>> MutedUsers { get; }
|
||||
|
||||
public ConcurrentDictionary<ulong, ConcurrentDictionary<(ulong, TimerType), Timer>> Un_Timers { get; }
|
||||
= new ConcurrentDictionary<ulong, ConcurrentDictionary<(ulong, TimerType), Timer>>();
|
||||
public ConcurrentDictionary<ulong, ConcurrentDictionary<(ulong, TimerType), Timer>> Un_Timers { get; } = new();
|
||||
|
||||
public event Action<IGuildUser, IUser, MuteType, string> UserMuted = delegate { };
|
||||
public event Action<IGuildUser, IUser, MuteType, string> UserUnmuted = delegate { };
|
||||
|
||||
private static readonly OverwritePermissions denyOverwrite =
|
||||
new OverwritePermissions(addReactions: PermValue.Deny, sendMessages: PermValue.Deny,
|
||||
new(addReactions: PermValue.Deny, sendMessages: PermValue.Deny,
|
||||
attachFiles: PermValue.Deny);
|
||||
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
@@ -8,14 +8,11 @@ namespace NadekoBot.Modules.Administration.Services;
|
||||
|
||||
public class ProtectionService : INService
|
||||
{
|
||||
private readonly ConcurrentDictionary<ulong, AntiRaidStats> _antiRaidGuilds
|
||||
= new ConcurrentDictionary<ulong, AntiRaidStats>();
|
||||
private readonly ConcurrentDictionary<ulong, AntiRaidStats> _antiRaidGuilds = new();
|
||||
|
||||
private readonly ConcurrentDictionary<ulong, AntiSpamStats> _antiSpamGuilds
|
||||
= new ConcurrentDictionary<ulong, AntiSpamStats>();
|
||||
private readonly ConcurrentDictionary<ulong, AntiSpamStats> _antiSpamGuilds = new();
|
||||
|
||||
private readonly ConcurrentDictionary<ulong, AntiAltStats> _antiAltGuilds
|
||||
= new ConcurrentDictionary<ulong, AntiAltStats>();
|
||||
private readonly ConcurrentDictionary<ulong, AntiAltStats> _antiAltGuilds = new();
|
||||
|
||||
public event Func<PunishmentAction, ProtectionType, IGuildUser[], Task> OnAntiProtectionTriggered
|
||||
= delegate { return Task.CompletedTask; };
|
||||
@@ -171,7 +168,7 @@ public class ProtectionService : INService
|
||||
|
||||
try
|
||||
{
|
||||
if (!(maybeStats is { } stats) || !stats.RaidUsers.Add(user))
|
||||
if (maybeStats is not { } stats || !stats.RaidUsers.Add(user))
|
||||
return;
|
||||
|
||||
++stats.UsersCount;
|
||||
@@ -201,10 +198,10 @@ public class ProtectionService : INService
|
||||
|
||||
private Task HandleAntiSpam(SocketMessage arg)
|
||||
{
|
||||
if (!(arg is SocketUserMessage msg) || msg.Author.IsBot)
|
||||
if (arg is not SocketUserMessage msg || msg.Author.IsBot)
|
||||
return Task.CompletedTask;
|
||||
|
||||
if (!(msg.Channel is ITextChannel channel))
|
||||
if (msg.Channel is not ITextChannel channel)
|
||||
return Task.CompletedTask;
|
||||
var _ = Task.Run(async () =>
|
||||
{
|
||||
|
@@ -5,7 +5,7 @@ namespace NadekoBot.Modules.Administration.Services;
|
||||
public class PruneService : INService
|
||||
{
|
||||
//channelids where prunes are currently occuring
|
||||
private ConcurrentHashSet<ulong> _pruningGuilds = new ConcurrentHashSet<ulong>();
|
||||
private readonly ConcurrentHashSet<ulong> _pruningGuilds = new();
|
||||
private readonly TimeSpan twoWeeks = TimeSpan.FromDays(14);
|
||||
private readonly ILogCommandService _logService;
|
||||
|
||||
|
@@ -17,8 +17,7 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
|
||||
private ImmutableDictionary<ulong, IDMChannel> ownerChannels =
|
||||
new Dictionary<ulong, IDMChannel>().ToImmutableDictionary();
|
||||
|
||||
private ConcurrentDictionary<ulong?, ConcurrentDictionary<int, Timer>> _autoCommands =
|
||||
new ConcurrentDictionary<ulong?, ConcurrentDictionary<int, Timer>>();
|
||||
private ConcurrentDictionary<ulong?, ConcurrentDictionary<int, Timer>> _autoCommands = new();
|
||||
|
||||
private readonly IImageCache _imgs;
|
||||
private readonly IHttpClientFactory _httpFactory;
|
||||
|
@@ -312,7 +312,7 @@ WHERE GuildId={guildId}
|
||||
// these 3 don't make sense with time
|
||||
if ((punish == PunishmentAction.Softban || punish == PunishmentAction.Kick || punish == PunishmentAction.RemoveRoles) && time != null)
|
||||
return false;
|
||||
if (number <= 0 || time != null && time.Time > TimeSpan.FromDays(49))
|
||||
if (number <= 0 || (time != null && time.Time > TimeSpan.FromDays(49)))
|
||||
return false;
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
|
@@ -31,7 +31,7 @@ public partial class Administration
|
||||
// bot can't punish a user who is higher in the hierarchy. Discord will return 403
|
||||
// moderator can be owner, in which case role hierarchy doesn't matter
|
||||
// otherwise, moderator has to have a higher role
|
||||
if (botMaxRole <= targetMaxRole || ctx.User.Id != ownerId && targetMaxRole >= modMaxRole || target.Id == ownerId)
|
||||
if (botMaxRole <= targetMaxRole || (ctx.User.Id != ownerId && targetMaxRole >= modMaxRole) || target.Id == ownerId)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.hierarchy);
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user