mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
Updated editorconfig to (mostly?) require braces around if/else statements, and applied the new formatting rules
This commit is contained in:
@@ -314,7 +314,9 @@ public partial class Administration : NadekoModule<AdministrationService>
|
||||
}
|
||||
|
||||
if (time is null)
|
||||
{
|
||||
await msg.DeleteAsync();
|
||||
}
|
||||
else if (time.Time <= TimeSpan.FromDays(7))
|
||||
{
|
||||
_ = Task.Run(async () =>
|
||||
|
@@ -41,7 +41,7 @@ public class AdministrationService : INService
|
||||
|
||||
private Task DelMsgOnCmd_Handler(IUserMessage msg, CommandInfo cmd)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
if (msg.Channel is not SocketTextChannel channel)
|
||||
return;
|
||||
@@ -97,7 +97,10 @@ public class AdministrationService : INService
|
||||
{
|
||||
if (old is null)
|
||||
{
|
||||
old = new() { ChannelId = chId };
|
||||
old = new()
|
||||
{
|
||||
ChannelId = chId
|
||||
};
|
||||
conf.DelMsgOnCmdChannels.Add(old);
|
||||
}
|
||||
|
||||
@@ -126,6 +129,7 @@ public class AdministrationService : INService
|
||||
if (!users.Any())
|
||||
return;
|
||||
foreach (var u in users)
|
||||
{
|
||||
try
|
||||
{
|
||||
await u.ModifyAsync(usr => usr.Deaf = value);
|
||||
@@ -134,6 +138,7 @@ public class AdministrationService : INService
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task EditMessage(
|
||||
|
@@ -19,7 +19,9 @@ public sealed class AutoAssignRoleService : INService
|
||||
private readonly Channel<SocketGuildUser> _assignQueue = Channel.CreateBounded<SocketGuildUser>(
|
||||
new BoundedChannelOptions(100)
|
||||
{
|
||||
FullMode = BoundedChannelFullMode.DropOldest, SingleReader = true, SingleWriter = false
|
||||
FullMode = BoundedChannelFullMode.DropOldest,
|
||||
SingleReader = true,
|
||||
SingleWriter = false
|
||||
});
|
||||
|
||||
public AutoAssignRoleService(DiscordSocketClient client, Bot bot, DbService db)
|
||||
@@ -118,7 +120,10 @@ public sealed class AutoAssignRoleService : INService
|
||||
|
||||
await uow.GuildConfigs.AsNoTracking()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.UpdateAsync(_ => new() { AutoAssignRoleIds = null });
|
||||
.UpdateAsync(_ => new()
|
||||
{
|
||||
AutoAssignRoleIds = null
|
||||
});
|
||||
|
||||
_autoAssignableRoles.TryRemove(guildId, out _);
|
||||
|
||||
|
@@ -97,7 +97,8 @@ namespace NadekoBot.Modules.Administration
|
||||
var embed = _eb.Create()
|
||||
.WithDescription(GetText(strs.purge_user_confirm(Format.Bold(userId.ToString()))));
|
||||
|
||||
if (!await PromptUserConfirmAsync(embed)) return;
|
||||
if (!await PromptUserConfirmAsync(embed))
|
||||
return;
|
||||
|
||||
await _service.PurgeUserAsync(userId);
|
||||
await ctx.OkAsync();
|
||||
|
@@ -52,7 +52,11 @@ DELETE FROM Clubs;";
|
||||
|
||||
public SelectResult SelectSql(string sql)
|
||||
{
|
||||
var result = new SelectResult { ColumnNames = new(), Results = new() };
|
||||
var result = new SelectResult
|
||||
{
|
||||
ColumnNames = new(),
|
||||
Results = new()
|
||||
};
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
var conn = uow.Database.GetDbConnection();
|
||||
@@ -61,7 +65,8 @@ DELETE FROM Clubs;";
|
||||
using var reader = cmd.ExecuteReader();
|
||||
if (reader.HasRows)
|
||||
{
|
||||
for (var i = 0; i < reader.FieldCount; i++) result.ColumnNames.Add(reader.GetName(i));
|
||||
for (var i = 0; i < reader.FieldCount; i++)
|
||||
result.ColumnNames.Add(reader.GetName(i));
|
||||
while (reader.Read())
|
||||
{
|
||||
var obj = new object[reader.FieldCount];
|
||||
@@ -93,13 +98,19 @@ DELETE FROM Clubs;";
|
||||
await uow.Set<WaifuInfo>()
|
||||
.AsQueryable()
|
||||
.Where(x => x.Claimer.UserId == userId)
|
||||
.UpdateAsync(x => new() { 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() { AffinityId = null });
|
||||
.UpdateAsync(x => new()
|
||||
{
|
||||
AffinityId = null
|
||||
});
|
||||
}
|
||||
|
||||
// delete guild xp
|
||||
|
@@ -26,7 +26,7 @@ public class GameVoiceChannelService : INService
|
||||
|
||||
private Task OnPresenceUpdate(SocketUser socketUser, SocketPresence before, SocketPresence after)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -34,20 +34,18 @@ public class GameVoiceChannelService : INService
|
||||
return;
|
||||
// if the user is in the voice channel and that voice channel is gvc
|
||||
|
||||
if (newUser.VoiceChannel is not { } vc
|
||||
if (newUser.VoiceChannel is not { } vc
|
||||
|| !GameVoiceChannels.Contains(vc.Id))
|
||||
return;
|
||||
|
||||
//if the activity has changed, and is a playi1ng activity
|
||||
foreach (var activity in after.Activities)
|
||||
{
|
||||
if (activity is { Type: ActivityType.Playing })
|
||||
{
|
||||
//trigger gvc
|
||||
if (await TriggerGvc(newUser, activity.Name))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//if the activity has changed, and is a playi1ng activity
|
||||
foreach (var activity in after.Activities)
|
||||
{
|
||||
if (activity is { Type: ActivityType.Playing })
|
||||
//trigger gvc
|
||||
if (await TriggerGvc(newUser, activity.Name))
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -82,7 +80,7 @@ public class GameVoiceChannelService : INService
|
||||
|
||||
private Task OnUserVoiceStateUpdated(SocketUser usr, SocketVoiceState oldState, SocketVoiceState newState)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -94,7 +92,7 @@ public class GameVoiceChannelService : INService
|
||||
|
||||
if (!GameVoiceChannels.Contains(newState.VoiceChannel.Id))
|
||||
return;
|
||||
|
||||
|
||||
foreach (var game in gUser.Activities.Select(x => x.Name))
|
||||
{
|
||||
if (await TriggerGvc(gUser, game))
|
||||
|
@@ -190,7 +190,8 @@ public partial class Administration
|
||||
|
||||
await _service.ByeTest((ITextChannel)ctx.Channel, user);
|
||||
var enabled = _service.GetByeEnabled(ctx.Guild.Id);
|
||||
if (!enabled) await ReplyPendingLocalizedAsync(strs.byemsg_enable($"`{prefix}bye`"));
|
||||
if (!enabled)
|
||||
await ReplyPendingLocalizedAsync(strs.byemsg_enable($"`{prefix}bye`"));
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -203,7 +204,8 @@ public partial class Administration
|
||||
|
||||
await _service.GreetTest((ITextChannel)ctx.Channel, user);
|
||||
var enabled = _service.GetGreetEnabled(ctx.Guild.Id);
|
||||
if (!enabled) await ReplyPendingLocalizedAsync(strs.greetmsg_enable($"`{prefix}greet`"));
|
||||
if (!enabled)
|
||||
await ReplyPendingLocalizedAsync(strs.greetmsg_enable($"`{prefix}greet`"));
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
|
@@ -50,7 +50,7 @@ public class GreetService : INService, IReadyExecutor
|
||||
await Task.Delay(2000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Task ClientOnGuildMemberUpdated(Cacheable<SocketGuildUser, ulong> optOldUser, SocketGuildUser newUser)
|
||||
{
|
||||
// if user is a new booster
|
||||
@@ -61,7 +61,8 @@ public class GreetService : INService, IReadyExecutor
|
||||
&& newDate > oldDate))
|
||||
{
|
||||
var conf = GetOrAddSettingsForGuild(newUser.Guild.Id);
|
||||
if (!conf.SendBoostMessage) return Task.CompletedTask;
|
||||
if (!conf.SendBoostMessage)
|
||||
return Task.CompletedTask;
|
||||
|
||||
_ = Task.Run(TriggerBoostMessage(conf, newUser));
|
||||
}
|
||||
@@ -85,7 +86,8 @@ public class GreetService : INService, IReadyExecutor
|
||||
try
|
||||
{
|
||||
var toDelete = await channel.SendAsync(rep.Replace(toSend));
|
||||
if (conf.BoostMessageDeleteAfter > 0) toDelete.DeleteAfter(conf.BoostMessageDeleteAfter);
|
||||
if (conf.BoostMessageDeleteAfter > 0)
|
||||
toDelete.DeleteAfter(conf.BoostMessageDeleteAfter);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -107,13 +109,14 @@ public class GreetService : INService, IReadyExecutor
|
||||
|
||||
private Task OnUserLeft(SocketGuild guild, SocketUser user)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var conf = GetOrAddSettingsForGuild(guild.Id);
|
||||
|
||||
if (!conf.SendChannelByeMessage) return;
|
||||
if (!conf.SendChannelByeMessage)
|
||||
return;
|
||||
var channel = guild.TextChannels.FirstOrDefault(c => c.Id == conf.ByeMessageChannelId);
|
||||
|
||||
if (channel is null) //maybe warn the server owner that the channel is missing
|
||||
@@ -187,7 +190,8 @@ public class GreetService : INService, IReadyExecutor
|
||||
try
|
||||
{
|
||||
var toDelete = await channel.SendAsync(text);
|
||||
if (conf.AutoDeleteByeMessagesTimer > 0) toDelete.DeleteAfter(conf.AutoDeleteByeMessagesTimer);
|
||||
if (conf.AutoDeleteByeMessagesTimer > 0)
|
||||
toDelete.DeleteAfter(conf.AutoDeleteByeMessagesTimer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -214,7 +218,8 @@ public class GreetService : INService, IReadyExecutor
|
||||
try
|
||||
{
|
||||
var toDelete = await channel.SendAsync(text);
|
||||
if (conf.AutoDeleteGreetMessagesTimer > 0) toDelete.DeleteAfter(conf.AutoDeleteGreetMessagesTimer);
|
||||
if (conf.AutoDeleteGreetMessagesTimer > 0)
|
||||
toDelete.DeleteAfter(conf.AutoDeleteGreetMessagesTimer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -229,14 +234,14 @@ public class GreetService : INService, IReadyExecutor
|
||||
// probably the best thing to do is to drop newest (raiding) users
|
||||
FullMode = BoundedChannelFullMode.DropNewest
|
||||
});
|
||||
|
||||
|
||||
private async Task<bool> GreetDmUser(GreetSettings conf, IGuildUser user)
|
||||
{
|
||||
var completionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
await _greetDmQueue.Writer.WriteAsync((conf, user, completionSource));
|
||||
return await completionSource.Task;
|
||||
}
|
||||
|
||||
|
||||
private async Task<bool> GreetDmUserInternal(GreetSettings conf, IGuildUser user)
|
||||
{
|
||||
try
|
||||
@@ -248,15 +253,17 @@ public class GreetService : INService, IReadyExecutor
|
||||
|
||||
var text = SmartText.CreateFrom(conf.DmGreetMessageText);
|
||||
text = rep.Replace(text);
|
||||
|
||||
|
||||
if (text is SmartPlainText pt)
|
||||
{
|
||||
text = new SmartEmbedText() { PlainText = pt.Text };
|
||||
}
|
||||
text = new SmartEmbedText()
|
||||
{
|
||||
PlainText = pt.Text
|
||||
};
|
||||
|
||||
((SmartEmbedText)text).Footer = new()
|
||||
{
|
||||
Text = $"This message was sent from {user.Guild} server.", IconUrl = user.Guild.IconUrl
|
||||
Text = $"This message was sent from {user.Guild} server.",
|
||||
IconUrl = user.Guild.IconUrl
|
||||
};
|
||||
|
||||
await user.SendAsync(text);
|
||||
@@ -271,7 +278,7 @@ public class GreetService : INService, IReadyExecutor
|
||||
|
||||
private Task OnUserJoined(IGuildUser user)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -308,9 +315,7 @@ public class GreetService : INService, IReadyExecutor
|
||||
}
|
||||
|
||||
if (conf.SendDmGreetMessage)
|
||||
{
|
||||
await GreetDmUser(conf, user);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@@ -18,7 +18,9 @@ public sealed class ImageOnlyChannelService : IEarlyBehavior
|
||||
private readonly Channel<IUserMessage> _deleteQueue = Channel.CreateBounded<IUserMessage>(
|
||||
new BoundedChannelOptions(100)
|
||||
{
|
||||
FullMode = BoundedChannelFullMode.DropOldest, SingleReader = true, SingleWriter = false
|
||||
FullMode = BoundedChannelFullMode.DropOldest,
|
||||
SingleReader = true,
|
||||
SingleWriter = false
|
||||
});
|
||||
|
||||
|
||||
@@ -78,7 +80,11 @@ public sealed class ImageOnlyChannelService : IEarlyBehavior
|
||||
}
|
||||
else
|
||||
{
|
||||
uow.ImageOnlyChannels.Add(new() { GuildId = guildId, ChannelId = channelId });
|
||||
uow.ImageOnlyChannels.Add(new()
|
||||
{
|
||||
GuildId = guildId,
|
||||
ChannelId = channelId
|
||||
});
|
||||
|
||||
channels = _enabledOn.GetOrAdd(guildId, new ConcurrentHashSet<ulong>());
|
||||
channels.Add(channelId);
|
||||
|
@@ -127,13 +127,13 @@ public class MuteService : INService
|
||||
if (string.IsNullOrWhiteSpace(reason))
|
||||
return;
|
||||
|
||||
_= Task.Run(() => user.SendMessageAsync(embed: _eb.Create()
|
||||
.WithDescription(
|
||||
$"You've been muted in {user.Guild} server")
|
||||
.AddField("Mute Type", type.ToString())
|
||||
.AddField("Moderator", mod.ToString())
|
||||
.AddField("Reason", reason)
|
||||
.Build()));
|
||||
_ = Task.Run(() => user.SendMessageAsync(embed: _eb.Create()
|
||||
.WithDescription(
|
||||
$"You've been muted in {user.Guild} server")
|
||||
.AddField("Mute Type", type.ToString())
|
||||
.AddField("Moderator", mod.ToString())
|
||||
.AddField("Reason", reason)
|
||||
.Build()));
|
||||
}
|
||||
|
||||
private void OnUserUnmuted(
|
||||
@@ -145,13 +145,13 @@ public class MuteService : INService
|
||||
if (string.IsNullOrWhiteSpace(reason))
|
||||
return;
|
||||
|
||||
_= Task.Run(() => user.SendMessageAsync(embed: _eb.Create()
|
||||
.WithDescription(
|
||||
$"You've been unmuted in {user.Guild} server")
|
||||
.AddField("Unmute Type", type.ToString())
|
||||
.AddField("Moderator", mod.ToString())
|
||||
.AddField("Reason", reason)
|
||||
.Build()));
|
||||
_ = Task.Run(() => user.SendMessageAsync(embed: _eb.Create()
|
||||
.WithDescription(
|
||||
$"You've been unmuted in {user.Guild} server")
|
||||
.AddField("Unmute Type", type.ToString())
|
||||
.AddField("Moderator", mod.ToString())
|
||||
.AddField("Reason", reason)
|
||||
.Build()));
|
||||
}
|
||||
|
||||
private Task Client_UserJoined(IGuildUser usr)
|
||||
@@ -162,7 +162,7 @@ public class MuteService : INService
|
||||
|
||||
if (muted is null || !muted.Contains(usr.Id))
|
||||
return Task.CompletedTask;
|
||||
_= Task.Run(() => MuteUser(usr, _client.CurrentUser, reason: "Sticky mute"));
|
||||
_ = Task.Run(() => MuteUser(usr, _client.CurrentUser, reason: "Sticky mute"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -200,7 +200,10 @@ 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() { UserId = usr.Id });
|
||||
config.MutedUsers.Add(new()
|
||||
{
|
||||
UserId = usr.Id
|
||||
});
|
||||
if (MutedUsers.TryGetValue(usr.Guild.Id, out var muted))
|
||||
muted.Add(usr.Id);
|
||||
|
||||
@@ -242,9 +245,13 @@ public class MuteService : INService
|
||||
{
|
||||
var config = uow.GuildConfigsForId(guildId,
|
||||
set => set.Include(gc => gc.MutedUsers).Include(gc => gc.UnmuteTimers));
|
||||
var match = new MutedUserId { UserId = usrId };
|
||||
var match = new MutedUserId
|
||||
{
|
||||
UserId = usrId
|
||||
};
|
||||
var toRemove = config.MutedUsers.FirstOrDefault(x => x.Equals(match));
|
||||
if (toRemove is not null) uow.Remove(toRemove);
|
||||
if (toRemove is not null)
|
||||
uow.Remove(toRemove);
|
||||
if (MutedUsers.TryGetValue(guildId, out var muted))
|
||||
muted.TryRemove(usrId);
|
||||
|
||||
@@ -308,6 +315,7 @@ public class MuteService : INService
|
||||
}
|
||||
|
||||
foreach (var toOverwrite in await guild.GetTextChannelsAsync())
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!toOverwrite.PermissionOverwrites.Any(x => x.TargetId == muteRole.Id
|
||||
@@ -322,6 +330,7 @@ public class MuteService : INService
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
return muteRole;
|
||||
}
|
||||
@@ -339,7 +348,8 @@ public class MuteService : INService
|
||||
var config = uow.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnmuteTimers));
|
||||
config.UnmuteTimers.Add(new()
|
||||
{
|
||||
UserId = user.Id, UnmuteAt = DateTime.UtcNow + after
|
||||
UserId = user.Id,
|
||||
UnmuteAt = DateTime.UtcNow + after
|
||||
}); // add teh unmute timer to the database
|
||||
uow.SaveChanges();
|
||||
}
|
||||
@@ -359,7 +369,8 @@ public class MuteService : INService
|
||||
var config = uow.GuildConfigsForId(guild.Id, set => set.Include(x => x.UnbanTimer));
|
||||
config.UnbanTimer.Add(new()
|
||||
{
|
||||
UserId = user.Id, UnbanAt = DateTime.UtcNow + after
|
||||
UserId = user.Id,
|
||||
UnbanAt = DateTime.UtcNow + after
|
||||
}); // add teh unmute timer to the database
|
||||
uow.SaveChanges();
|
||||
}
|
||||
@@ -379,7 +390,9 @@ public class MuteService : INService
|
||||
var config = uow.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnroleTimer));
|
||||
config.UnroleTimer.Add(new()
|
||||
{
|
||||
UserId = user.Id, UnbanAt = DateTime.UtcNow + after, RoleId = role.Id
|
||||
UserId = user.Id,
|
||||
UnbanAt = DateTime.UtcNow + after,
|
||||
RoleId = role.Id
|
||||
}); // add teh unmute timer to the database
|
||||
uow.SaveChanges();
|
||||
}
|
||||
@@ -401,26 +414,24 @@ public class MuteService : INService
|
||||
var toAdd = new Timer(async _ =>
|
||||
{
|
||||
if (type == TimerType.Ban)
|
||||
{
|
||||
try
|
||||
{
|
||||
RemoveTimerFromDb(guildId, userId, type);
|
||||
StopTimer(guildId, userId, type);
|
||||
var guild = _client.GetGuild(guildId); // load the guild
|
||||
if (guild is not null) await guild.RemoveBanAsync(userId);
|
||||
if (guild is not null)
|
||||
await guild.RemoveBanAsync(userId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Couldn't unban user {UserId} in guild {GuildId}", userId, guildId);
|
||||
}
|
||||
}
|
||||
else if (type == TimerType.AddRole)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (roleId is null)
|
||||
return;
|
||||
|
||||
|
||||
RemoveTimerFromDb(guildId, userId, type);
|
||||
StopTimer(guildId, userId, type);
|
||||
var guild = _client.GetGuild(guildId);
|
||||
@@ -433,9 +444,7 @@ public class MuteService : INService
|
||||
{
|
||||
Log.Warning(ex, "Couldn't remove role from user {UserId} in guild {GuildId}", userId, guildId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
// unmute the user, this will also remove the timer from the db
|
||||
@@ -446,7 +455,6 @@ public class MuteService : INService
|
||||
RemoveTimerFromDb(guildId, userId, type); // if unmute errored, just remove unmute from db
|
||||
Log.Warning(ex, "Couldn't unmute user {UserId} in guild {GuildId}", userId, guildId);
|
||||
}
|
||||
}
|
||||
},
|
||||
null,
|
||||
after,
|
||||
@@ -467,7 +475,8 @@ public class MuteService : INService
|
||||
if (!UnTimers.TryGetValue(guildId, out var userTimer))
|
||||
return;
|
||||
|
||||
if (userTimer.TryRemove((userId, type), out var removed)) removed.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
if (userTimer.TryRemove((userId, type), out var removed))
|
||||
removed.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
}
|
||||
|
||||
private void RemoveTimerFromDb(ulong guildId, ulong userId, TimerType type)
|
||||
@@ -485,7 +494,8 @@ public class MuteService : INService
|
||||
toDelete = config.UnbanTimer.FirstOrDefault(x => x.UserId == userId);
|
||||
}
|
||||
|
||||
if (toDelete is not null) uow.Remove(toDelete);
|
||||
if (toDelete is not null)
|
||||
uow.Remove(toDelete);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
}
|
@@ -41,7 +41,7 @@ public partial class Administration
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
|
||||
await _service.ClearAllOverrides(ctx.Guild.Id);
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.perm_override_all);
|
||||
|
@@ -56,7 +56,13 @@ public class DiscordPermOverrideService : INService, ILateBlocker
|
||||
.FirstOrDefaultAsync(x => x.GuildId == guildId && commandName == x.Command);
|
||||
|
||||
if (over is null)
|
||||
uow.Set<DiscordPermOverride>().Add(over = new() { Command = commandName, Perm = perm, GuildId = guildId });
|
||||
uow.Set<DiscordPermOverride>()
|
||||
.Add(over = new()
|
||||
{
|
||||
Command = commandName,
|
||||
Perm = perm,
|
||||
GuildId = guildId
|
||||
});
|
||||
else
|
||||
over.Perm = perm;
|
||||
|
||||
@@ -77,7 +83,8 @@ public class DiscordPermOverrideService : INService, ILateBlocker
|
||||
uow.RemoveRange(overrides);
|
||||
await uow.SaveChangesAsync();
|
||||
|
||||
foreach (var over in overrides) _overrides.TryRemove((guildId, over.Command), out _);
|
||||
foreach (var over in overrides)
|
||||
_overrides.TryRemove((guildId, over.Command), out _);
|
||||
}
|
||||
|
||||
public async Task RemoveOverride(ulong guildId, string commandName)
|
||||
|
@@ -24,9 +24,7 @@ public sealed class PlayingRotateService : INService, IReadyExecutor
|
||||
_selfService = selfService;
|
||||
|
||||
if (client.ShardId == 0)
|
||||
{
|
||||
_rep = new ReplacementBuilder().WithClient(client).WithProviders(phProviders).Build();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task OnReadyAsync()
|
||||
@@ -37,7 +35,7 @@ public sealed class PlayingRotateService : INService, IReadyExecutor
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_bss.Data.RotateStatuses)
|
||||
if (!_bss.Data.RotateStatuses)
|
||||
continue;
|
||||
|
||||
IReadOnlyList<RotatingPlayingStatus> rotatingStatuses;
|
||||
@@ -82,7 +80,11 @@ public sealed class PlayingRotateService : INService, IReadyExecutor
|
||||
public async Task AddPlaying(ActivityType t, string status)
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
var toAdd = new RotatingPlayingStatus { Status = status, Type = t };
|
||||
var toAdd = new RotatingPlayingStatus
|
||||
{
|
||||
Status = status,
|
||||
Type = t
|
||||
};
|
||||
uow.Add(toAdd);
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
|
@@ -27,7 +27,10 @@ public partial class Administration
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(GuildPerm.Administrator)]
|
||||
public async partial Task AntiAlt(StoopidTime minAge, PunishmentAction action, [Leftover] StoopidTime punishTime = null)
|
||||
public async partial Task AntiAlt(
|
||||
StoopidTime minAge,
|
||||
PunishmentAction action,
|
||||
[Leftover] StoopidTime punishTime = null)
|
||||
{
|
||||
var minAgeMinutes = (int)minAge.Time.TotalMinutes;
|
||||
var punishTimeMinutes = (int?)punishTime?.Time.TotalMinutes ?? 0;
|
||||
@@ -120,7 +123,8 @@ public partial class Administration
|
||||
|
||||
var stats = await _service.StartAntiRaidAsync(ctx.Guild.Id, userThreshold, seconds, action, time);
|
||||
|
||||
if (stats is null) return;
|
||||
if (stats is null)
|
||||
return;
|
||||
|
||||
await SendConfirmAsync(GetText(strs.prot_enable("Anti-Raid")),
|
||||
$"{ctx.User.Mention} {GetAntiRaidString(stats)}");
|
||||
@@ -244,7 +248,8 @@ public partial class Administration
|
||||
ignoredString = "none";
|
||||
|
||||
var add = string.Empty;
|
||||
if (settings.MuteTime > 0) add = $" ({TimeSpan.FromMinutes(settings.MuteTime):hh\\hmm\\m})";
|
||||
if (settings.MuteTime > 0)
|
||||
add = $" ({TimeSpan.FromMinutes(settings.MuteTime):hh\\hmm\\m})";
|
||||
|
||||
return GetText(strs.spam_stats(Format.Bold(settings.MessageThreshold.ToString()),
|
||||
Format.Bold(settings.Action + add),
|
||||
|
@@ -25,7 +25,11 @@ public class ProtectionService : INService
|
||||
private readonly UserPunishService _punishService;
|
||||
|
||||
private readonly Channel<PunishQueueItem> _punishUserQueue =
|
||||
Channel.CreateUnbounded<PunishQueueItem>(new() { SingleReader = true, SingleWriter = false });
|
||||
Channel.CreateUnbounded<PunishQueueItem>(new()
|
||||
{
|
||||
SingleReader = true,
|
||||
SingleWriter = false
|
||||
});
|
||||
|
||||
public ProtectionService(
|
||||
DiscordSocketClient client,
|
||||
@@ -51,7 +55,8 @@ public class ProtectionService : INService
|
||||
.Where(x => ids.Contains(x.GuildId))
|
||||
.ToList();
|
||||
|
||||
foreach (var gc in configs) Initialize(gc);
|
||||
foreach (var gc in configs)
|
||||
Initialize(gc);
|
||||
}
|
||||
|
||||
_client.MessageReceived += HandleAntiSpam;
|
||||
@@ -94,7 +99,7 @@ public class ProtectionService : INService
|
||||
|
||||
private Task _client_LeftGuild(SocketGuild guild)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
TryStopAntiRaid(guild.Id);
|
||||
TryStopAntiSpam(guild.Id);
|
||||
@@ -123,12 +128,18 @@ public class ProtectionService : INService
|
||||
|
||||
if (raid is not null)
|
||||
{
|
||||
var raidStats = new AntiRaidStats { AntiRaidSettings = raid };
|
||||
var raidStats = new AntiRaidStats
|
||||
{
|
||||
AntiRaidSettings = raid
|
||||
};
|
||||
_antiRaidGuilds[gc.GuildId] = raidStats;
|
||||
}
|
||||
|
||||
if (spam is not null)
|
||||
_antiSpamGuilds[gc.GuildId] = new() { AntiSpamSettings = spam };
|
||||
_antiSpamGuilds[gc.GuildId] = new()
|
||||
{
|
||||
AntiSpamSettings = spam
|
||||
};
|
||||
|
||||
var alt = gc.AntiAltSetting;
|
||||
if (alt is not null)
|
||||
@@ -202,12 +213,16 @@ public class ProtectionService : INService
|
||||
|
||||
if (msg.Channel is not ITextChannel channel)
|
||||
return Task.CompletedTask;
|
||||
_= Task.Run(async () =>
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_antiSpamGuilds.TryGetValue(channel.Guild.Id, out var spamSettings)
|
||||
|| spamSettings.AntiSpamSettings.IgnoredChannels.Contains(new() { ChannelId = channel.Id }))
|
||||
|| spamSettings.AntiSpamSettings.IgnoredChannels.Contains(new()
|
||||
{
|
||||
ChannelId = channel.Id
|
||||
}))
|
||||
return;
|
||||
|
||||
var stats = spamSettings.UserStats.AddOrUpdate(msg.Author.Id,
|
||||
@@ -251,6 +266,7 @@ public class ProtectionService : INService
|
||||
gus[0].Guild.Name);
|
||||
|
||||
foreach (var gu in gus)
|
||||
{
|
||||
await _punishUserQueue.Writer.WriteAsync(new()
|
||||
{
|
||||
Action = action,
|
||||
@@ -259,6 +275,7 @@ public class ProtectionService : INService
|
||||
MuteTime = muteTime,
|
||||
RoleId = roleId
|
||||
});
|
||||
}
|
||||
|
||||
_ = OnAntiProtectionTriggered(action, pt, gus);
|
||||
}
|
||||
@@ -385,18 +402,23 @@ public class ProtectionService : INService
|
||||
|
||||
public async Task<bool?> AntiSpamIgnoreAsync(ulong guildId, ulong channelId)
|
||||
{
|
||||
var obj = new AntiSpamIgnore { ChannelId = channelId };
|
||||
var obj = new AntiSpamIgnore
|
||||
{
|
||||
ChannelId = channelId
|
||||
};
|
||||
bool added;
|
||||
await using var uow = _db.GetDbContext();
|
||||
var gc = uow.GuildConfigsForId(guildId,
|
||||
set => set.Include(x => x.AntiSpamSetting).ThenInclude(x => x.IgnoredChannels));
|
||||
var spam = gc.AntiSpamSetting;
|
||||
if (spam is null) return null;
|
||||
if (spam is null)
|
||||
return null;
|
||||
|
||||
if (spam.IgnoredChannels.Add(obj)) // if adding to db is successful
|
||||
{
|
||||
if (_antiSpamGuilds.TryGetValue(guildId, out var temp))
|
||||
temp.AntiSpamSettings.IgnoredChannels.Add(obj); // add to local cache
|
||||
|
||||
added = true;
|
||||
}
|
||||
else
|
||||
@@ -405,6 +427,7 @@ public class ProtectionService : INService
|
||||
uow.Set<AntiSpamIgnore>().Remove(toRemove); // remove from db
|
||||
if (_antiSpamGuilds.TryGetValue(guildId, out var temp))
|
||||
temp.AntiSpamSettings.IgnoredChannels.Remove(toRemove); // remove from local cache
|
||||
|
||||
added = false;
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,7 @@ public sealed class UserSpamStats
|
||||
lock (_applyLock)
|
||||
{
|
||||
Cleanup();
|
||||
Log.Information("{Count}",_messageTracker.Count.ToString());
|
||||
Log.Information("{Count}", _messageTracker.Count.ToString());
|
||||
return _messageTracker.Count;
|
||||
}
|
||||
}
|
||||
|
@@ -40,13 +40,18 @@ public partial class Administration
|
||||
}
|
||||
|
||||
var role = (IRole)roleResult.BestMatch;
|
||||
if (role.Position > ((IGuildUser)ctx.User).GetRoles()
|
||||
.Select(r => r.Position)
|
||||
.Max()
|
||||
if (role.Position
|
||||
> ((IGuildUser)ctx.User).GetRoles()
|
||||
.Select(r => r.Position)
|
||||
.Max()
|
||||
&& ctx.User.Id != ctx.Guild.OwnerId)
|
||||
return null;
|
||||
var emote = x.Last().ToIEmote();
|
||||
return new { role, emote };
|
||||
return new
|
||||
{
|
||||
role,
|
||||
emote
|
||||
};
|
||||
})
|
||||
.Where(x => x is not null)
|
||||
.WhenAll();
|
||||
@@ -59,7 +64,10 @@ public partial class Administration
|
||||
try
|
||||
{
|
||||
await target.AddReactionAsync(x.emote,
|
||||
new() { RetryMode = RetryMode.Retry502 | RetryMode.RetryRatelimit });
|
||||
new()
|
||||
{
|
||||
RetryMode = RetryMode.Retry502 | RetryMode.RetryRatelimit
|
||||
});
|
||||
}
|
||||
catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.BadRequest)
|
||||
{
|
||||
@@ -79,9 +87,10 @@ public partial class Administration
|
||||
ReactionRoles = all.Select(x =>
|
||||
{
|
||||
return new ReactionRole
|
||||
{
|
||||
EmoteName = x.emote.ToString(), RoleId = x.role.Id
|
||||
};
|
||||
{
|
||||
EmoteName = x.emote.ToString(),
|
||||
RoleId = x.role.Id
|
||||
};
|
||||
})
|
||||
.ToList()
|
||||
}))
|
||||
@@ -144,7 +153,8 @@ public partial class Administration
|
||||
{
|
||||
var ch = g.GetTextChannel(rr.ChannelId);
|
||||
IUserMessage msg = null;
|
||||
if (ch is not null) msg = await ch.GetMessageAsync(rr.MessageId) as IUserMessage;
|
||||
if (ch is not null)
|
||||
msg = await ch.GetMessageAsync(rr.MessageId) as IUserMessage;
|
||||
var content = msg?.Content.TrimTo(30) ?? "DELETED!";
|
||||
embed.AddField($"**{rr.Index + 1}.** {ch?.Name ?? "DELETED!"}",
|
||||
GetText(strs.reaction_roles_message(rr.ReactionRoles?.Count ?? 0, content)));
|
||||
|
@@ -89,7 +89,10 @@ public class RoleCommandsService : INService
|
||||
var dl = await msg.GetOrDownloadAsync();
|
||||
await dl.RemoveReactionAsync(reaction.Emote,
|
||||
dl.Author,
|
||||
new() { RetryMode = RetryMode.RetryRatelimit | RetryMode.Retry502 });
|
||||
new()
|
||||
{
|
||||
RetryMode = RetryMode.RetryRatelimit | RetryMode.Retry502
|
||||
});
|
||||
Log.Warning("User {Author} is adding unrelated reactions to the reaction roles message", dl.Author);
|
||||
}
|
||||
});
|
||||
|
@@ -304,7 +304,7 @@ public partial class Administration
|
||||
var toLeave = _client.Guilds
|
||||
.Where(s => s.MemberCount == 1 && s.Users.Count == 1)
|
||||
.ToList();
|
||||
|
||||
|
||||
foreach (var server in toLeave)
|
||||
{
|
||||
try
|
||||
@@ -425,7 +425,8 @@ public partial class Administration
|
||||
{
|
||||
var success = await _service.SetAvatar(img);
|
||||
|
||||
if (success) await ReplyConfirmLocalizedAsync(strs.set_avatar);
|
||||
if (success)
|
||||
await ReplyConfirmLocalizedAsync(strs.set_avatar);
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
|
@@ -59,7 +59,8 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
|
||||
|
||||
HandleStatusChanges();
|
||||
|
||||
if (_client.ShardId == 0) _pubSub.Sub(_imagesReloadKey, async _ => await _imgs.Reload());
|
||||
if (_client.ShardId == 0)
|
||||
_pubSub.Sub(_imagesReloadKey, async _ => await _imgs.Reload());
|
||||
|
||||
_pubSub.Sub(_guildLeaveKey,
|
||||
async input =>
|
||||
@@ -70,7 +71,8 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
|
||||
|
||||
var server = _client.Guilds.FirstOrDefault(g => g.Id.ToString() == guildStr
|
||||
|| g.Name.Trim().ToUpperInvariant() == guildStr);
|
||||
if (server is null) return;
|
||||
if (server is null)
|
||||
return;
|
||||
|
||||
if (server.OwnerId != _client.CurrentUser.Id)
|
||||
{
|
||||
@@ -90,15 +92,16 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
|
||||
await using var uow = _db.GetDbContext();
|
||||
|
||||
autoCommands = uow.AutoCommands.AsNoTracking()
|
||||
.Where(x => x.Interval >= 5)
|
||||
.AsEnumerable()
|
||||
.GroupBy(x => x.GuildId)
|
||||
.ToDictionary(x => x.Key,
|
||||
y => y.ToDictionary(x => x.Id, TimerFromAutoCommand).ToConcurrent())
|
||||
.ToConcurrent();
|
||||
.Where(x => x.Interval >= 5)
|
||||
.AsEnumerable()
|
||||
.GroupBy(x => x.GuildId)
|
||||
.ToDictionary(x => x.Key,
|
||||
y => y.ToDictionary(x => x.Id, TimerFromAutoCommand).ToConcurrent())
|
||||
.ToConcurrent();
|
||||
|
||||
var startupCommands = uow.AutoCommands.AsNoTracking().Where(x => x.Interval == 0);
|
||||
foreach (var cmd in startupCommands)
|
||||
{
|
||||
try
|
||||
{
|
||||
await ExecuteCommand(cmd);
|
||||
@@ -106,8 +109,10 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (_client.ShardId == 0) await LoadOwnerChannels();
|
||||
if (_client.ShardId == 0)
|
||||
await LoadOwnerChannels();
|
||||
}
|
||||
|
||||
private Timer TimerFromAutoCommand(AutoCommand x)
|
||||
@@ -171,13 +176,14 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
|
||||
private async Task LoadOwnerChannels()
|
||||
{
|
||||
var channels = await _creds.OwnerIds.Select(id =>
|
||||
{
|
||||
var user = _client.GetUser(id);
|
||||
if (user is null)
|
||||
return Task.FromResult<IDMChannel>(null);
|
||||
{
|
||||
var user = _client.GetUser(id);
|
||||
if (user is null)
|
||||
return Task.FromResult<IDMChannel>(null);
|
||||
|
||||
return user.CreateDMChannelAsync();
|
||||
}).WhenAll();
|
||||
return user.CreateDMChannelAsync();
|
||||
})
|
||||
.WhenAll();
|
||||
|
||||
ownerChannels = channels.Where(x => x is not null)
|
||||
.ToDictionary(x => x.Recipient.Id, x => x)
|
||||
@@ -187,7 +193,9 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
|
||||
Log.Warning(
|
||||
"No owner channels created! Make sure you've specified the correct OwnerId in the creds.yml file and invited the bot to a Discord server");
|
||||
else
|
||||
Log.Information("Created {OwnerChannelCount} out of {TotalOwnerChannelCount} owner message channels", ownerChannels.Count, _creds.OwnerIds.Count);
|
||||
Log.Information("Created {OwnerChannelCount} out of {TotalOwnerChannelCount} owner message channels",
|
||||
ownerChannels.Count,
|
||||
_creds.OwnerIds.Count);
|
||||
}
|
||||
|
||||
public Task LeaveGuild(string guildStr)
|
||||
@@ -214,6 +222,7 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
|
||||
var allOwnerChannels = ownerChannels.Values;
|
||||
|
||||
foreach (var ownerCh in allOwnerChannels.Where(ch => ch.Recipient.Id != msg.Author.Id))
|
||||
{
|
||||
try
|
||||
{
|
||||
await ownerCh.SendConfirmAsync(_eb, title, toSend);
|
||||
@@ -222,6 +231,7 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
|
||||
{
|
||||
Log.Warning("Can't contact owner with id {OwnerId}", ownerCh.Recipient.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -337,10 +347,22 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
|
||||
});
|
||||
|
||||
public Task SetGameAsync(string game, ActivityType type)
|
||||
=> _pubSub.Pub(_activitySetKey, new() { Name = game, Link = null, Type = type });
|
||||
=> _pubSub.Pub(_activitySetKey,
|
||||
new()
|
||||
{
|
||||
Name = game,
|
||||
Link = null,
|
||||
Type = type
|
||||
});
|
||||
|
||||
public Task SetStreamAsync(string name, string link)
|
||||
=> _pubSub.Pub(_activitySetKey, new() { Name = name, Link = link, Type = ActivityType.Streaming });
|
||||
=> _pubSub.Pub(_activitySetKey,
|
||||
new()
|
||||
{
|
||||
Name = name,
|
||||
Link = link,
|
||||
Type = ActivityType.Streaming
|
||||
});
|
||||
|
||||
private sealed class ActivityPubData
|
||||
{
|
||||
|
@@ -112,6 +112,7 @@ public partial class Administration
|
||||
|
||||
rolesStr.AppendLine("\t\t\t\t ⟪" + groupNameText + "⟫");
|
||||
foreach (var (model, role) in kvp.AsEnumerable())
|
||||
{
|
||||
if (role is null)
|
||||
{
|
||||
}
|
||||
@@ -123,6 +124,7 @@ public partial class Administration
|
||||
else
|
||||
rolesStr.AppendLine(" " + role.Name + $" (lvl {model.LevelRequirement}+)");
|
||||
}
|
||||
}
|
||||
|
||||
rolesStr.AppendLine();
|
||||
}
|
||||
|
@@ -34,9 +34,15 @@ public class SelfAssignedRolesService : INService
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var roles = uow.SelfAssignableRoles.GetFromGuild(guildId);
|
||||
if (roles.Any(s => s.RoleId == role.Id && s.GuildId == role.Guild.Id)) return false;
|
||||
if (roles.Any(s => s.RoleId == role.Id && s.GuildId == role.Guild.Id))
|
||||
return false;
|
||||
|
||||
uow.SelfAssignableRoles.Add(new() { Group = group, RoleId = role.Id, GuildId = role.Guild.Id });
|
||||
uow.SelfAssignableRoles.Add(new()
|
||||
{
|
||||
Group = group,
|
||||
RoleId = role.Id,
|
||||
GuildId = role.Guild.Id
|
||||
});
|
||||
uow.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
@@ -67,7 +73,8 @@ public class SelfAssignedRolesService : INService
|
||||
return (AssignResult.ErrNotAssignable, autoDelete, null);
|
||||
if (theRoleYouWant.LevelRequirement > userLevelData.Level)
|
||||
return (AssignResult.ErrLvlReq, autoDelete, theRoleYouWant.LevelRequirement);
|
||||
if (guildUser.RoleIds.Contains(role.Id)) return (AssignResult.ErrAlreadyHave, autoDelete, null);
|
||||
if (guildUser.RoleIds.Contains(role.Id))
|
||||
return (AssignResult.ErrAlreadyHave, autoDelete, null);
|
||||
|
||||
var roleIds = roles.Where(x => x.Group == theRoleYouWant.Group).Select(x => x.RoleId).ToArray();
|
||||
if (exclusive)
|
||||
@@ -116,7 +123,11 @@ public class SelfAssignedRolesService : INService
|
||||
}
|
||||
else if (toUpdate is null)
|
||||
{
|
||||
gc.SelfAssignableRoleGroupNames.Add(new() { Name = name, Number = group });
|
||||
gc.SelfAssignableRoleGroupNames.Add(new()
|
||||
{
|
||||
Name = name,
|
||||
Number = group
|
||||
});
|
||||
set = true;
|
||||
}
|
||||
else
|
||||
@@ -136,7 +147,8 @@ public class SelfAssignedRolesService : INService
|
||||
|
||||
if (roles.FirstOrDefault(r => r.RoleId == role.Id) is null)
|
||||
return (RemoveResult.ErrNotAssignable, autoDelete);
|
||||
if (!guildUser.RoleIds.Contains(role.Id)) return (RemoveResult.ErrNotHave, autoDelete);
|
||||
if (!guildUser.RoleIds.Contains(role.Id))
|
||||
return (RemoveResult.ErrNotHave, autoDelete);
|
||||
try
|
||||
{
|
||||
await guildUser.RemoveRoleAsync(role);
|
||||
@@ -198,7 +210,8 @@ public class SelfAssignedRolesService : INService
|
||||
return areExclusive;
|
||||
}
|
||||
|
||||
public (bool Exclusive, IReadOnlyCollection<(SelfAssignedRole Model, IRole Role)> Roles, IDictionary<int, string> GroupNames
|
||||
public (bool Exclusive, IReadOnlyCollection<(SelfAssignedRole Model, IRole Role)> Roles, IDictionary<int, string>
|
||||
GroupNames
|
||||
) GetRoles(IGuild guild)
|
||||
{
|
||||
var exclusive = false;
|
||||
|
@@ -138,7 +138,11 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
if (removed == 0)
|
||||
{
|
||||
var toAdd = new IgnoredLogItem { LogItemId = itemId, ItemType = itemType };
|
||||
var toAdd = new IgnoredLogItem
|
||||
{
|
||||
LogItemId = itemId,
|
||||
ItemType = itemType
|
||||
};
|
||||
logSetting.LogIgnores.Add(toAdd);
|
||||
}
|
||||
|
||||
@@ -183,7 +187,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
private Task _client_UserUpdated(SocketUser before, SocketUser uAfter)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -306,7 +310,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
private Task _client_UserVoiceStateUpdated_TTS(SocketUser iusr, SocketVoiceState before, SocketVoiceState after)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -351,7 +355,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
IUser mod,
|
||||
MuteType muteType,
|
||||
string reason)
|
||||
=> _= Task.Run(async () =>
|
||||
=> _ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -396,7 +400,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
IUser mod,
|
||||
MuteType muteType,
|
||||
string reason)
|
||||
=> _= Task.Run(async () =>
|
||||
=> _ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -443,7 +447,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
public Task TriggeredAntiProtection(PunishmentAction action, ProtectionType protection, params IGuildUser[] users)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -453,7 +457,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
if (!GuildLogSettings.TryGetValue(users.First().Guild.Id, out var logSetting)
|
||||
|| logSetting.LogOtherId is null)
|
||||
return;
|
||||
|
||||
|
||||
ITextChannel? logChannel;
|
||||
if ((logChannel = await TryGetLogChannel(users.First().Guild, logSetting, LogType.Other)) is null)
|
||||
return;
|
||||
@@ -513,7 +517,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
private Task _client_GuildUserUpdated(Cacheable<SocketGuildUser, ulong> optBefore, SocketGuildUser after)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -575,7 +579,8 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
if (!before.IsBot
|
||||
&& logSetting.LogUserPresenceId is not null
|
||||
&& (logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.UserPresence)) is not null)
|
||||
&& (logChannel =
|
||||
await TryGetLogChannel(before.Guild, logSetting, LogType.UserPresence)) is not null)
|
||||
{
|
||||
if (before.Status != after.Status)
|
||||
{
|
||||
@@ -585,7 +590,10 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
strs.user_status_change("👤" + Format.Bold(after.Username),
|
||||
Format.Bold(after.Status.ToString())));
|
||||
PresenceUpdates.AddOrUpdate(logChannel,
|
||||
new List<string> { str },
|
||||
new List<string>
|
||||
{
|
||||
str
|
||||
},
|
||||
(_, list) =>
|
||||
{
|
||||
list.Add(str);
|
||||
@@ -597,7 +605,10 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
var str =
|
||||
$"👾`{PrettyCurrentTime(after.Guild)}`👤__**{after.Username}**__ is now playing **{after.Activities.FirstOrDefault()?.Name ?? "-"}**.";
|
||||
PresenceUpdates.AddOrUpdate(logChannel,
|
||||
new List<string> { str },
|
||||
new List<string>
|
||||
{
|
||||
str
|
||||
},
|
||||
(_, list) =>
|
||||
{
|
||||
list.Add(str);
|
||||
@@ -616,7 +627,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
private Task _client_ChannelUpdated(IChannel cbefore, IChannel cafter)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -664,7 +675,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
private Task _client_ChannelDestroyed(IChannel ich)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -702,7 +713,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
private Task _client_ChannelCreated(IChannel ich)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -738,7 +749,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
private Task _client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState before, SocketVoiceState after)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -784,7 +795,10 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(str))
|
||||
PresenceUpdates.AddOrUpdate(logChannel,
|
||||
new List<string> { str },
|
||||
new List<string>
|
||||
{
|
||||
str
|
||||
},
|
||||
(_, list) =>
|
||||
{
|
||||
list.Add(str);
|
||||
@@ -801,7 +815,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
private Task _client_UserLeft(SocketGuild guild, SocketUser usr)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -836,7 +850,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
private Task _client_UserJoined(IGuildUser usr)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -875,7 +889,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
private Task _client_UserUnbanned(IUser usr, IGuild guild)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -910,7 +924,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
private Task _client_UserBanned(IUser usr, IGuild guild)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -947,7 +961,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
|
||||
private Task _client_MessageDeleted(Cacheable<IMessage, ulong> optMsg, Cacheable<IMessageChannel, ulong> optCh)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -1001,7 +1015,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
SocketMessage imsg2,
|
||||
ISocketMessageChannel ch)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@@ -89,7 +89,8 @@ public partial class Administration
|
||||
Log.Warning(ex, "Exception occured while warning a user");
|
||||
var errorEmbed = _eb.Create().WithErrorColor().WithDescription(GetText(strs.cant_apply_punishment));
|
||||
|
||||
if (dmFailed) errorEmbed.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||
if (dmFailed)
|
||||
errorEmbed.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||
|
||||
await ctx.Channel.EmbedAsync(errorEmbed);
|
||||
return;
|
||||
@@ -102,7 +103,8 @@ public partial class Administration
|
||||
embed.WithDescription(GetText(strs.user_warned_and_punished(Format.Bold(user.ToString()),
|
||||
Format.Bold(punishment.Punishment.ToString()))));
|
||||
|
||||
if (dmFailed) embed.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||
if (dmFailed)
|
||||
embed.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||
|
||||
await ctx.Channel.EmbedAsync(embed);
|
||||
}
|
||||
@@ -359,7 +361,8 @@ public partial class Administration
|
||||
[UserPerm(GuildPerm.BanMembers)]
|
||||
public async partial Task WarnPunish(int number)
|
||||
{
|
||||
if (!_service.WarnPunishRemove(ctx.Guild.Id, number)) return;
|
||||
if (!_service.WarnPunishRemove(ctx.Guild.Id, number))
|
||||
return;
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.warn_punish_rem(Format.Bold(number.ToString())));
|
||||
}
|
||||
@@ -402,7 +405,8 @@ public partial class Administration
|
||||
{
|
||||
var defaultMessage = GetText(strs.bandm(Format.Bold(ctx.Guild.Name), msg));
|
||||
var embed = _service.GetBanUserDmEmbed(Context, guildUser, defaultMessage, msg, time.Time);
|
||||
if (embed is not null) await guildUser.SendAsync(embed);
|
||||
if (embed is not null)
|
||||
await guildUser.SendAsync(embed);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -419,7 +423,8 @@ public partial class Administration
|
||||
time.Time.Humanize(3, minUnit: TimeUnit.Minute, culture: Culture),
|
||||
true);
|
||||
|
||||
if (dmFailed) toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||
if (dmFailed)
|
||||
toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||
|
||||
await ctx.Channel.EmbedAsync(toSend);
|
||||
}
|
||||
@@ -463,7 +468,8 @@ public partial class Administration
|
||||
{
|
||||
var defaultMessage = GetText(strs.bandm(Format.Bold(ctx.Guild.Name), msg));
|
||||
var embed = _service.GetBanUserDmEmbed(Context, user, defaultMessage, msg, null);
|
||||
if (embed is not null) await ctx.User.SendAsync(embed);
|
||||
if (embed is not null)
|
||||
await ctx.User.SendAsync(embed);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -478,7 +484,8 @@ public partial class Administration
|
||||
.AddField(GetText(strs.username), user.ToString(), true)
|
||||
.AddField("ID", user.Id.ToString(), true);
|
||||
|
||||
if (dmFailed) toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||
if (dmFailed)
|
||||
toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||
|
||||
await ctx.Channel.EmbedAsync(toSend);
|
||||
}
|
||||
@@ -648,7 +655,8 @@ public partial class Administration
|
||||
.AddField(GetText(strs.username), user.ToString(), true)
|
||||
.AddField("ID", user.Id.ToString(), true);
|
||||
|
||||
if (dmFailed) toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||
if (dmFailed)
|
||||
toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||
|
||||
await ctx.Channel.EmbedAsync(toSend);
|
||||
}
|
||||
@@ -699,7 +707,8 @@ public partial class Administration
|
||||
.AddField(GetText(strs.username), user.ToString(), true)
|
||||
.AddField("ID", user.Id.ToString(), true);
|
||||
|
||||
if (dmFailed) toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||
if (dmFailed)
|
||||
toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||
|
||||
await ctx.Channel.EmbedAsync(toSend);
|
||||
}
|
||||
@@ -719,6 +728,7 @@ public partial class Administration
|
||||
|
||||
await ctx.Channel.TriggerTypingAsync();
|
||||
foreach (var userStr in userStrings)
|
||||
{
|
||||
if (ulong.TryParse(userStr, out var userId))
|
||||
{
|
||||
IUser user = await ctx.Guild.GetUserAsync(userId)
|
||||
@@ -739,7 +749,8 @@ public partial class Administration
|
||||
}
|
||||
|
||||
//Hierachy checks only if the user is in the guild
|
||||
if (user is IGuildUser gu && !await CheckRoleHierarchy(gu)) return;
|
||||
if (user is IGuildUser gu && !await CheckRoleHierarchy(gu))
|
||||
return;
|
||||
|
||||
banning.Add(user);
|
||||
}
|
||||
@@ -747,6 +758,7 @@ public partial class Administration
|
||||
{
|
||||
missing.Add(userStr);
|
||||
}
|
||||
}
|
||||
|
||||
var missStr = string.Join("\n", missing);
|
||||
if (string.IsNullOrWhiteSpace(missStr))
|
||||
@@ -760,6 +772,7 @@ public partial class Administration
|
||||
var banningMessage = await ctx.Channel.EmbedAsync(toSend);
|
||||
|
||||
foreach (var toBan in banning)
|
||||
{
|
||||
try
|
||||
{
|
||||
await ctx.Guild.AddBanAsync(toBan.Id, 7, $"{ctx.User} | Massban");
|
||||
@@ -768,6 +781,7 @@ public partial class Administration
|
||||
{
|
||||
Log.Warning(ex, "Error banning {User} user in {GuildId} server", toBan.Id, ctx.Guild.Id);
|
||||
}
|
||||
}
|
||||
|
||||
await banningMessage.ModifyAsync(x => x.Embed = _eb.Create()
|
||||
.WithDescription(
|
||||
@@ -805,7 +819,10 @@ public partial class Administration
|
||||
.Select(x => ctx.Guild.AddBanAsync(x.Id.Value,
|
||||
7,
|
||||
x.Reason,
|
||||
new() { RetryMode = RetryMode.AlwaysRetry })));
|
||||
new()
|
||||
{
|
||||
RetryMode = RetryMode.AlwaysRetry
|
||||
})));
|
||||
|
||||
//wait for the message and edit it
|
||||
var banningMessage = await banningMessageTask;
|
||||
|
@@ -30,12 +30,12 @@ public class UserPunishService : INService, IReadyExecutor
|
||||
_bcs = bcs;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
|
||||
public async Task OnReadyAsync()
|
||||
{
|
||||
if (_client.ShardId != 0)
|
||||
return;
|
||||
|
||||
|
||||
var expiryTimer = new PeriodicTimer(TimeSpan.FromHours(12));
|
||||
do
|
||||
{
|
||||
@@ -429,7 +429,11 @@ WHERE GuildId={guildId}
|
||||
}
|
||||
else if (template is null)
|
||||
{
|
||||
uow.BanTemplates.Add(new() { GuildId = guildId, Text = text });
|
||||
uow.BanTemplates.Add(new()
|
||||
{
|
||||
GuildId = guildId,
|
||||
Text = text
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -485,7 +489,8 @@ WHERE GuildId={guildId}
|
||||
if (string.IsNullOrWhiteSpace(template))
|
||||
template = JsonConvert.SerializeObject(new
|
||||
{
|
||||
color = _bcs.Data.Color.Error.PackedValue >> 8, description = defaultMessage
|
||||
color = _bcs.Data.Color.Error.PackedValue >> 8,
|
||||
description = defaultMessage
|
||||
});
|
||||
// if template is set to "-" do not dm the user
|
||||
else if (template == "-")
|
||||
@@ -495,7 +500,8 @@ WHERE GuildId={guildId}
|
||||
else if (!SmartText.CreateFrom(template).IsEmbed)
|
||||
template = JsonConvert.SerializeObject(new
|
||||
{
|
||||
color = _bcs.Data.Color.Error.PackedValue >> 8, description = template
|
||||
color = _bcs.Data.Color.Error.PackedValue >> 8,
|
||||
description = template
|
||||
});
|
||||
|
||||
var output = SmartText.CreateFrom(template);
|
||||
|
@@ -49,11 +49,13 @@ public class VcRoleService : INService
|
||||
{
|
||||
if (add)
|
||||
{
|
||||
if (!user.RoleIds.Contains(role.Id)) await user.AddRoleAsync(role);
|
||||
if (!user.RoleIds.Contains(role.Id))
|
||||
await user.AddRoleAsync(role);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (user.RoleIds.Contains(role.Id)) await user.RemoveRoleAsync(role);
|
||||
if (user.RoleIds.Contains(role.Id))
|
||||
await user.RemoveRoleAsync(role);
|
||||
}
|
||||
}
|
||||
catch
|
||||
@@ -80,7 +82,7 @@ public class VcRoleService : INService
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var configWithVcRole = uow.GuildConfigsForId(arg.GuildId, set => set.Include(x => x.VcRoleInfos));
|
||||
_= InitializeVcRole(configWithVcRole);
|
||||
_ = InitializeVcRole(configWithVcRole);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
@@ -137,8 +139,13 @@ public class VcRoleService : INService
|
||||
using var uow = _db.GetDbContext();
|
||||
var conf = uow.GuildConfigsForId(guildId, set => set.Include(x => x.VcRoleInfos));
|
||||
var toDelete = conf.VcRoleInfos.FirstOrDefault(x => x.VoiceChannelId == vcId); // remove old one
|
||||
if (toDelete is not null) uow.Remove(toDelete);
|
||||
conf.VcRoleInfos.Add(new() { VoiceChannelId = vcId, RoleId = role.Id }); // add new one
|
||||
if (toDelete is not null)
|
||||
uow.Remove(toDelete);
|
||||
conf.VcRoleInfos.Add(new()
|
||||
{
|
||||
VoiceChannelId = vcId,
|
||||
RoleId = role.Id
|
||||
}); // add new one
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
||||
@@ -166,7 +173,7 @@ public class VcRoleService : INService
|
||||
|
||||
var oldVc = oldState.VoiceChannel;
|
||||
var newVc = newState.VoiceChannel;
|
||||
_= Task.Run(() =>
|
||||
_ = Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -181,7 +188,8 @@ public class VcRoleService : INService
|
||||
if (oldVc is not null && guildVcRoles.TryGetValue(oldVc.Id, out var role))
|
||||
Assign(false, gusr, role);
|
||||
//add new
|
||||
if (newVc is not null && guildVcRoles.TryGetValue(newVc.Id, out role)) Assign(true, gusr, role);
|
||||
if (newVc is not null && guildVcRoles.TryGetValue(newVc.Id, out role))
|
||||
Assign(true, gusr, role);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user