mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
More target-typed new and redundant paranthesis cleanup
This commit is contained in:
@@ -26,11 +26,11 @@ public class AdministrationService : INService
|
||||
_db = db;
|
||||
_logService = logService;
|
||||
|
||||
DeleteMessagesOnCommand = new ConcurrentHashSet<ulong>(bot.AllGuildConfigs
|
||||
DeleteMessagesOnCommand = new(bot.AllGuildConfigs
|
||||
.Where(g => g.DeleteMessageOnCommand)
|
||||
.Select(g => g.GuildId));
|
||||
|
||||
DeleteMessagesOnCommandChannels = new ConcurrentDictionary<ulong, bool>(bot.AllGuildConfigs
|
||||
DeleteMessagesOnCommandChannels = new(bot.AllGuildConfigs
|
||||
.SelectMany(x => x.DelMsgOnCmdChannels)
|
||||
.ToDictionary(x => x.ChannelId, x => x.State)
|
||||
.ToConcurrent());
|
||||
@@ -108,7 +108,7 @@ public class AdministrationService : INService
|
||||
{
|
||||
if (old is null)
|
||||
{
|
||||
old = new DelMsgOnCmdChannel { ChannelId = chId };
|
||||
old = new() { ChannelId = chId };
|
||||
conf.DelMsgOnCmdChannels.Add(old);
|
||||
}
|
||||
|
||||
|
@@ -128,7 +128,7 @@ public sealed class AutoAssignRoleService : INService
|
||||
.GuildConfigs
|
||||
.AsNoTracking()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.UpdateAsync(_ => new GuildConfig(){ AutoAssignRoleIds = null});
|
||||
.UpdateAsync(_ => new(){ AutoAssignRoleIds = null});
|
||||
|
||||
_autoAssignableRoles.TryRemove(guildId, out _);
|
||||
|
||||
@@ -154,7 +154,7 @@ public static class GuildConfigExtensions
|
||||
public static List<ulong> GetAutoAssignableRoles(this GuildConfig gc)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(gc.AutoAssignRoleIds))
|
||||
return new List<ulong>();
|
||||
return new();
|
||||
|
||||
return gc.AutoAssignRoleIds.Split(',').Select(ulong.Parse).ToList();
|
||||
}
|
||||
|
@@ -59,8 +59,8 @@ DELETE FROM Clubs;";
|
||||
{
|
||||
var result = new SelectResult()
|
||||
{
|
||||
ColumnNames = new List<string>(),
|
||||
Results = new List<string[]>(),
|
||||
ColumnNames = new(),
|
||||
Results = new(),
|
||||
};
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
@@ -116,14 +116,14 @@ DELETE FROM Clubs;";
|
||||
.Set<WaifuInfo>()
|
||||
.AsQueryable()
|
||||
.Where(x => x.Claimer.UserId == userId)
|
||||
.UpdateAsync(x => new WaifuInfo() {ClaimerId = null});
|
||||
.UpdateAsync(x => new() {ClaimerId = null});
|
||||
|
||||
// all affinities set to this waifu are reset
|
||||
await uow
|
||||
.Set<WaifuInfo>()
|
||||
.AsQueryable()
|
||||
.Where(x => x.Affinity.UserId == userId)
|
||||
.UpdateAsync(x => new WaifuInfo() {AffinityId = null});
|
||||
.UpdateAsync(x => new() {AffinityId = null});
|
||||
}
|
||||
|
||||
// delete guild xp
|
||||
|
@@ -64,7 +64,7 @@ public class DiscordPermOverrideService : INService, ILateBlocker
|
||||
if (over is null)
|
||||
{
|
||||
uow.Set<DiscordPermOverride>()
|
||||
.Add(over = new DiscordPermOverride()
|
||||
.Add(over = new()
|
||||
{
|
||||
Command = commandName,
|
||||
Perm = perm,
|
||||
|
@@ -19,7 +19,7 @@ public class GameVoiceChannelService : INService
|
||||
_db = db;
|
||||
_client = client;
|
||||
|
||||
GameVoiceChannels = new ConcurrentHashSet<ulong>(
|
||||
GameVoiceChannels = new(
|
||||
bot.AllGuildConfigs.Where(gc => gc.GameVoiceChannel != null)
|
||||
.Select(gc => gc.GameVoiceChannel.Value));
|
||||
|
||||
@@ -40,8 +40,7 @@ public class GameVoiceChannelService : INService
|
||||
|
||||
//if the activity has changed, and is a playing activity
|
||||
if (before.Activity != after.Activity
|
||||
&& after.Activity != null
|
||||
&& after.Activity.Type == Discord.ActivityType.Playing)
|
||||
&& after.Activity is { Type: Discord.ActivityType.Playing })
|
||||
{
|
||||
//trigger gvc
|
||||
await TriggerGvc(after, after.Activity.Name);
|
||||
|
@@ -102,7 +102,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
.ToConcurrent();
|
||||
}
|
||||
|
||||
_timerReference = new Timer(async (state) =>
|
||||
_timerReference = new(async state =>
|
||||
{
|
||||
var keys = PresenceUpdates.Keys.ToList();
|
||||
|
||||
@@ -143,7 +143,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
|
||||
_prot.OnAntiProtectionTriggered += TriggeredAntiProtection;
|
||||
|
||||
_clearTimer = new Timer(_ =>
|
||||
_clearTimer = new(_ =>
|
||||
{
|
||||
_ignoreMessageIds.Clear();
|
||||
}, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1));
|
||||
@@ -228,7 +228,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
(value ? channelId : (ulong?) null);
|
||||
;
|
||||
await uow.SaveChangesAsync();
|
||||
GuildLogSettings.AddOrUpdate(guildId, (id) => logSetting, (id, old) => logSetting);
|
||||
GuildLogSettings.AddOrUpdate(guildId, id => logSetting, (id, old) => logSetting);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var logSetting = uow.LogSettingsFor(gid);
|
||||
GuildLogSettings.AddOrUpdate(gid, (id) => logSetting, (id, old) => logSetting);
|
||||
GuildLogSettings.AddOrUpdate(gid, id => logSetting, (id, old) => logSetting);
|
||||
switch (type)
|
||||
{
|
||||
case LogType.Other:
|
||||
|
@@ -60,7 +60,7 @@ public class MuteService : INService
|
||||
.ToDictionary(c => c.GuildId, c => c.MuteRoleName)
|
||||
.ToConcurrent();
|
||||
|
||||
MutedUsers = new ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>>(configs
|
||||
MutedUsers = new(configs
|
||||
.ToDictionary(
|
||||
k => k.GuildId,
|
||||
v => new ConcurrentHashSet<ulong>(v.MutedUsers.Select(m => m.UserId))
|
||||
@@ -194,7 +194,7 @@ public class MuteService : INService
|
||||
var config = uow.GuildConfigsForId(usr.Guild.Id,
|
||||
set => set.Include(gc => gc.MutedUsers)
|
||||
.Include(gc => gc.UnmuteTimers));
|
||||
config.MutedUsers.Add(new MutedUserId()
|
||||
config.MutedUsers.Add(new()
|
||||
{
|
||||
UserId = usr.Id
|
||||
});
|
||||
@@ -327,7 +327,7 @@ public class MuteService : INService
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnmuteTimers));
|
||||
config.UnmuteTimers.Add(new UnmuteTimer()
|
||||
config.UnmuteTimers.Add(new()
|
||||
{
|
||||
UserId = user.Id,
|
||||
UnmuteAt = DateTime.UtcNow + after,
|
||||
@@ -344,7 +344,7 @@ public class MuteService : INService
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow.GuildConfigsForId(guild.Id, set => set.Include(x => x.UnbanTimer));
|
||||
config.UnbanTimer.Add(new UnbanTimer()
|
||||
config.UnbanTimer.Add(new()
|
||||
{
|
||||
UserId = user.Id,
|
||||
UnbanAt = DateTime.UtcNow + after,
|
||||
@@ -361,7 +361,7 @@ public class MuteService : INService
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnroleTimer));
|
||||
config.UnroleTimer.Add(new UnroleTimer()
|
||||
config.UnroleTimer.Add(new()
|
||||
{
|
||||
UserId = user.Id,
|
||||
UnbanAt = DateTime.UtcNow + after,
|
||||
@@ -433,7 +433,7 @@ public class MuteService : INService
|
||||
}, null, after, Timeout.InfiniteTimeSpan);
|
||||
|
||||
//add it, or stop the old one and add this one
|
||||
userUnTimers.AddOrUpdate((userId, type), (key) => toAdd, (key, old) =>
|
||||
userUnTimers.AddOrUpdate((userId, type), key => toAdd, (key, old) =>
|
||||
{
|
||||
old.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
return toAdd;
|
||||
|
@@ -39,7 +39,7 @@ public sealed class PlayingRotateService : INService
|
||||
.WithProviders(phProviders)
|
||||
.Build();
|
||||
|
||||
_t = new Timer(RotatingStatuses, new TimerState(), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
|
||||
_t = new(RotatingStatuses, new TimerState(), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -32,7 +32,7 @@ public class ProtectionService : INService
|
||||
private readonly UserPunishService _punishService;
|
||||
|
||||
private readonly Channel<PunishQueueItem> PunishUserQueue =
|
||||
System.Threading.Channels.Channel.CreateUnbounded<PunishQueueItem>(new UnboundedChannelOptions()
|
||||
System.Threading.Channels.Channel.CreateUnbounded<PunishQueueItem>(new()
|
||||
{
|
||||
SingleReader = true,
|
||||
SingleWriter = false
|
||||
@@ -134,11 +134,11 @@ public class ProtectionService : INService
|
||||
}
|
||||
|
||||
if (spam != null)
|
||||
_antiSpamGuilds[gc.GuildId] = new AntiSpamStats() { AntiSpamSettings = spam };
|
||||
_antiSpamGuilds[gc.GuildId] = new() { AntiSpamSettings = spam };
|
||||
|
||||
var alt = gc.AntiAltSetting;
|
||||
if (alt is not null)
|
||||
_antiAltGuilds[gc.GuildId] = new AntiAltStats(alt);
|
||||
_antiAltGuilds[gc.GuildId] = new(alt);
|
||||
}
|
||||
|
||||
private Task HandleUserJoined(SocketGuildUser user)
|
||||
@@ -154,7 +154,7 @@ public class ProtectionService : INService
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
if (maybeAlts is AntiAltStats alts)
|
||||
if (maybeAlts is { } alts)
|
||||
{
|
||||
if (user.CreatedAt != default)
|
||||
{
|
||||
@@ -177,7 +177,7 @@ public class ProtectionService : INService
|
||||
|
||||
try
|
||||
{
|
||||
if (!(maybeStats is AntiRaidStats stats) || !stats.RaidUsers.Add(user))
|
||||
if (!(maybeStats is { } stats) || !stats.RaidUsers.Add(user))
|
||||
return;
|
||||
|
||||
++stats.UsersCount;
|
||||
@@ -217,13 +217,13 @@ public class ProtectionService : INService
|
||||
try
|
||||
{
|
||||
if (!_antiSpamGuilds.TryGetValue(channel.Guild.Id, out var spamSettings) ||
|
||||
spamSettings.AntiSpamSettings.IgnoredChannels.Contains(new AntiSpamIgnore()
|
||||
spamSettings.AntiSpamSettings.IgnoredChannels.Contains(new()
|
||||
{
|
||||
ChannelId = channel.Id
|
||||
}))
|
||||
return;
|
||||
|
||||
var stats = spamSettings.UserStats.AddOrUpdate(msg.Author.Id, (id) => new UserSpamStats(msg),
|
||||
var stats = spamSettings.UserStats.AddOrUpdate(msg.Author.Id, id => new(msg),
|
||||
(id, old) =>
|
||||
{
|
||||
old.ApplyNextMessage(msg); return old;
|
||||
@@ -261,7 +261,7 @@ public class ProtectionService : INService
|
||||
|
||||
foreach (var gu in gus)
|
||||
{
|
||||
await PunishUserQueue.Writer.WriteAsync(new PunishQueueItem()
|
||||
await PunishUserQueue.Writer.WriteAsync(new()
|
||||
{
|
||||
Action = action,
|
||||
Type = pt,
|
||||
@@ -288,7 +288,7 @@ public class ProtectionService : INService
|
||||
|
||||
var stats = new AntiRaidStats()
|
||||
{
|
||||
AntiRaidSettings = new AntiRaidSetting()
|
||||
AntiRaidSettings = new()
|
||||
{
|
||||
Action = action,
|
||||
Seconds = seconds,
|
||||
@@ -355,7 +355,7 @@ public class ProtectionService : INService
|
||||
|
||||
var stats = new AntiSpamStats
|
||||
{
|
||||
AntiSpamSettings = new AntiSpamSetting()
|
||||
AntiSpamSettings = new()
|
||||
{
|
||||
Action = action,
|
||||
MessageThreshold = messageCount,
|
||||
@@ -457,7 +457,7 @@ public class ProtectionService : INService
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiAltSetting));
|
||||
gc.AntiAltSetting = new AntiAltSetting()
|
||||
gc.AntiAltSetting = new()
|
||||
{
|
||||
Action = action,
|
||||
ActionDurationMinutes = actionDurationMinutes,
|
||||
@@ -466,7 +466,7 @@ public class ProtectionService : INService
|
||||
};
|
||||
|
||||
await uow.SaveChangesAsync();
|
||||
_antiAltGuilds[guildId] = new AntiAltStats(gc.AntiAltSetting);
|
||||
_antiAltGuilds[guildId] = new(gc.AntiAltSetting);
|
||||
}
|
||||
|
||||
public async Task<bool> TryStopAntiAlt(ulong guildId)
|
||||
|
@@ -88,7 +88,7 @@ public class RoleCommandsService : INService
|
||||
{
|
||||
var dl = await msg.GetOrDownloadAsync().ConfigureAwait(false);
|
||||
await dl.RemoveReactionAsync(reaction.Emote, dl.Author,
|
||||
new RequestOptions()
|
||||
new()
|
||||
{
|
||||
RetryMode = RetryMode.RetryRatelimit | RetryMode.Retry502
|
||||
}).ConfigureAwait(false);
|
||||
|
@@ -44,7 +44,7 @@ public class SelfAssignedRolesService : INService
|
||||
return false;
|
||||
}
|
||||
|
||||
uow.SelfAssignableRoles.Add(new SelfAssignedRole
|
||||
uow.SelfAssignableRoles.Add(new()
|
||||
{
|
||||
Group = group,
|
||||
RoleId = role.Id,
|
||||
@@ -73,7 +73,7 @@ public class SelfAssignedRolesService : INService
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var stats = uow.GetOrCreateUserXpStats(guildUser.Guild.Id, guildUser.Id);
|
||||
userLevelData = new LevelStats(stats.Xp + stats.AwardedXp);
|
||||
userLevelData = new(stats.Xp + stats.AwardedXp);
|
||||
}
|
||||
|
||||
var (autoDelete, exclusive, roles) = GetAdAndRoles(guildUser.Guild.Id);
|
||||
@@ -144,7 +144,7 @@ public class SelfAssignedRolesService : INService
|
||||
}
|
||||
else if (toUpdate is null)
|
||||
{
|
||||
gc.SelfAssignableRoleGroupNames.Add(new GroupName
|
||||
gc.SelfAssignableRoleGroupNames.Add(new()
|
||||
{
|
||||
Name = name,
|
||||
Number = group,
|
||||
|
@@ -134,7 +134,7 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
|
||||
|
||||
private Timer TimerFromAutoCommand(AutoCommand x)
|
||||
{
|
||||
return new Timer(async (obj) => await ExecuteCommand((AutoCommand) obj).ConfigureAwait(false),
|
||||
return new(async obj => await ExecuteCommand((AutoCommand) obj).ConfigureAwait(false),
|
||||
x,
|
||||
x.Interval * 1000,
|
||||
x.Interval * 1000);
|
||||
|
@@ -30,7 +30,7 @@ public class UserPunishService : INService
|
||||
_blacklistService = blacklistService;
|
||||
_bcs = bcs;
|
||||
|
||||
_warnExpiryTimer = new Timer(async _ =>
|
||||
_warnExpiryTimer = new(async _ =>
|
||||
{
|
||||
await CheckAllWarnExpiresAsync();
|
||||
}, null, TimeSpan.FromSeconds(0), TimeSpan.FromHours(12));
|
||||
@@ -330,7 +330,7 @@ WHERE GuildId={guildId}
|
||||
|
||||
uow.RemoveRange(toDelete);
|
||||
|
||||
ps.Add(new WarningPunishment()
|
||||
ps.Add(new()
|
||||
{
|
||||
Count = number,
|
||||
Punishment = punish,
|
||||
@@ -437,7 +437,7 @@ WHERE GuildId={guildId}
|
||||
}
|
||||
else if (template is null)
|
||||
{
|
||||
uow.BanTemplates.Add(new BanTemplate()
|
||||
uow.BanTemplates.Add(new()
|
||||
{
|
||||
GuildId = guildId,
|
||||
Text = text,
|
||||
|
@@ -23,8 +23,8 @@ public class VcRoleService : INService
|
||||
_client = client;
|
||||
|
||||
_client.UserVoiceStateUpdated += ClientOnUserVoiceStateUpdated;
|
||||
VcRoles = new ConcurrentDictionary<ulong, ConcurrentDictionary<ulong, IRole>>();
|
||||
ToAssign = new ConcurrentDictionary<ulong, ConcurrentQueue<(bool, IGuildUser, IRole)>>();
|
||||
VcRoles = new();
|
||||
ToAssign = new();
|
||||
var missingRoles = new ConcurrentBag<VcRoleInfo>();
|
||||
|
||||
using (var uow = db.GetDbContext())
|
||||
@@ -147,7 +147,7 @@ public class VcRoleService : INService
|
||||
{
|
||||
uow.Remove(toDelete);
|
||||
}
|
||||
conf.VcRoleInfos.Add(new VcRoleInfo()
|
||||
conf.VcRoleInfos.Add(new()
|
||||
{
|
||||
VoiceChannelId = vcId,
|
||||
RoleId = role.Id,
|
||||
|
Reference in New Issue
Block a user