Compare commits

...

2 commits

Author SHA1 Message Date
082cf79736
Fixed localization init
xp card name is now a little lower
Updated CHANGELOG.md
2025-03-14 20:10:47 +13:00
612c230b7b
fixed unban/unmute timers wrongly trying to unban users on all servers at once 2025-03-14 18:04:58 +13:00
8 changed files with 157 additions and 136 deletions

View file

@ -2,7 +2,7 @@
*a,c,f,r,o* *a,c,f,r,o*
## [6.0.3] - 12.03.2025 ## [6.0.4] - 14.03.2025
### Added ### Added

View file

@ -4,7 +4,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>true</ImplicitUsings> <ImplicitUsings>true</ImplicitUsings>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages> <SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<Version>6.0.3</Version> <Version>6.0.4</Version>
<!-- Output/build --> <!-- Output/build -->
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory> <RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>

View file

@ -15,7 +15,12 @@ public enum MuteType
public class MuteService : IEService, IReadyExecutor public class MuteService : IEService, IReadyExecutor
{ {
public enum TimerType { Mute, Ban, AddRole } public enum TimerType
{
Mute,
Ban,
AddRole
}
private static readonly OverwritePermissions _denyOverwrite = new(addReactions: PermValue.Deny, private static readonly OverwritePermissions _denyOverwrite = new(addReactions: PermValue.Deny,
sendMessages: PermValue.Deny, sendMessages: PermValue.Deny,
@ -57,12 +62,12 @@ public class MuteService : IEService, IReadyExecutor
return; return;
_ = Task.Run(() => _sender.Response(user) _ = Task.Run(() => _sender.Response(user)
.Embed(_sender.CreateEmbed(user?.GuildId) .Embed(_sender.CreateEmbed(user?.GuildId)
.WithDescription($"You've been muted in {user.Guild} server") .WithDescription($"You've been muted in {user.Guild} server")
.AddField("Mute Type", type.ToString()) .AddField("Mute Type", type.ToString())
.AddField("Moderator", mod.ToString()) .AddField("Moderator", mod.ToString())
.AddField("Reason", reason)) .AddField("Reason", reason))
.SendAsync()); .SendAsync());
} }
private void OnUserUnmuted( private void OnUserUnmuted(
@ -75,12 +80,12 @@ public class MuteService : IEService, IReadyExecutor
return; return;
_ = Task.Run(() => _sender.Response(user) _ = Task.Run(() => _sender.Response(user)
.Embed(_sender.CreateEmbed(user.GuildId) .Embed(_sender.CreateEmbed(user.GuildId)
.WithDescription($"You've been unmuted in {user.Guild} server") .WithDescription($"You've been unmuted in {user.Guild} server")
.AddField("Unmute Type", type.ToString()) .AddField("Unmute Type", type.ToString())
.AddField("Moderator", mod.ToString()) .AddField("Moderator", mod.ToString())
.AddField("Reason", reason)) .AddField("Reason", reason))
.SendAsync()); .SendAsync());
} }
private Task Client_UserJoined(IGuildUser usr) private Task Client_UserJoined(IGuildUser usr)
@ -105,8 +110,8 @@ public class MuteService : IEService, IReadyExecutor
{ {
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var config = uow.GetTable<GuildConfig>() var config = uow.GetTable<GuildConfig>()
.Where(x => x.GuildId == guildId) .Where(x => x.GuildId == guildId)
.FirstOrDefault(); .FirstOrDefault();
config.MuteRoleName = name; config.MuteRoleName = name;
_guildMuteRoles.AddOrUpdate(guildId, name, (_, _) => name); _guildMuteRoles.AddOrUpdate(guildId, name, (_, _) => name);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
@ -121,8 +126,12 @@ public class MuteService : IEService, IReadyExecutor
if (type == MuteType.All) if (type == MuteType.All)
{ {
try try
{ await usr.ModifyAsync(x => x.Mute = true); } {
catch { } await usr.ModifyAsync(x => x.Mute = true);
}
catch
{
}
var muteRole = await GetMuteRole(usr.Guild); var muteRole = await GetMuteRole(usr.Guild);
if (!usr.RoleIds.Contains(muteRole.Id)) if (!usr.RoleIds.Contains(muteRole.Id))
@ -131,19 +140,19 @@ public class MuteService : IEService, IReadyExecutor
await using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
await uow.GetTable<MutedUserId>() await uow.GetTable<MutedUserId>()
.InsertOrUpdateAsync(() => new() .InsertOrUpdateAsync(() => new()
{ {
GuildId = usr.GuildId, GuildId = usr.GuildId,
UserId = usr.Id UserId = usr.Id
}, },
(_) => new() (_) => new()
{ {
}, },
() => new() () => new()
{ {
GuildId = usr.GuildId, GuildId = usr.GuildId,
UserId = usr.Id UserId = usr.Id
}); });
if (_mutedUsers.TryGetValue(usr.Guild.Id, out var muted)) if (_mutedUsers.TryGetValue(usr.Guild.Id, out var muted))
muted.Add(usr.Id); muted.Add(usr.Id);
@ -160,7 +169,9 @@ public class MuteService : IEService, IReadyExecutor
await usr.ModifyAsync(x => x.Mute = true); await usr.ModifyAsync(x => x.Mute = true);
UserMuted(usr, mod, MuteType.Voice, reason); UserMuted(usr, mod, MuteType.Voice, reason);
} }
catch { } catch
{
}
} }
else if (type == MuteType.Chat) else if (type == MuteType.Chat)
{ {
@ -183,12 +194,12 @@ public class MuteService : IEService, IReadyExecutor
await using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
await uow.GetTable<MutedUserId>() await uow.GetTable<MutedUserId>()
.Where(x => x.GuildId == guildId && x.UserId == usrId) .Where(x => x.GuildId == guildId && x.UserId == usrId)
.DeleteAsync(); .DeleteAsync();
await uow.GetTable<UnmuteTimer>() await uow.GetTable<UnmuteTimer>()
.Where(x => x.GuildId == guildId && x.UserId == usrId) .Where(x => x.GuildId == guildId && x.UserId == usrId)
.DeleteAsync(); .DeleteAsync();
if (_mutedUsers.TryGetValue(guildId, out var muted)) if (_mutedUsers.TryGetValue(guildId, out var muted))
muted.TryRemove(usrId); muted.TryRemove(usrId);
@ -197,11 +208,17 @@ public class MuteService : IEService, IReadyExecutor
if (usr is not null) if (usr is not null)
{ {
try try
{ await usr.ModifyAsync(x => x.Mute = false); } {
catch { } await usr.ModifyAsync(x => x.Mute = false);
}
catch
{
}
try try
{ await usr.RemoveRoleAsync(await GetMuteRole(usr.Guild)); } {
await usr.RemoveRoleAsync(await GetMuteRole(usr.Guild));
}
catch catch
{ {
/*ignore*/ /*ignore*/
@ -240,7 +257,9 @@ public class MuteService : IEService, IReadyExecutor
//if it doesn't exist, create it //if it doesn't exist, create it
{ {
try try
{ muteRole = await guild.CreateRoleAsync(muteRoleName, isMentionable: false); } {
muteRole = await guild.CreateRoleAsync(muteRoleName, isMentionable: false);
}
catch catch
{ {
//if creations fails, maybe the name is not correct, find default one, if doesn't work, create default one //if creations fails, maybe the name is not correct, find default one, if doesn't work, create default one
@ -282,12 +301,12 @@ public class MuteService : IEService, IReadyExecutor
{ {
var unmuteAt = DateTime.UtcNow + after; var unmuteAt = DateTime.UtcNow + after;
await uow.GetTable<UnmuteTimer>() await uow.GetTable<UnmuteTimer>()
.InsertAsync(() => new() .InsertAsync(() => new()
{ {
GuildId = user.GuildId, GuildId = user.GuildId,
UserId = user.Id, UserId = user.Id,
UnmuteAt = unmuteAt UnmuteAt = unmuteAt
}); });
} }
StartUn_Timer(user.GuildId, user.Id, after, TimerType.Mute); // start the timer StartUn_Timer(user.GuildId, user.Id, after, TimerType.Mute); // start the timer
@ -305,12 +324,12 @@ public class MuteService : IEService, IReadyExecutor
{ {
var unbanAt = DateTime.UtcNow + after; var unbanAt = DateTime.UtcNow + after;
await uow.GetTable<UnbanTimer>() await uow.GetTable<UnbanTimer>()
.InsertAsync(() => new() .InsertAsync(() => new()
{ {
GuildId = guild.Id, GuildId = guild.Id,
UserId = userId, UserId = userId,
UnbanAt = unbanAt UnbanAt = unbanAt
}); });
} }
StartUn_Timer(guild.Id, userId, after, TimerType.Ban); // start the timer StartUn_Timer(guild.Id, userId, after, TimerType.Ban); // start the timer
@ -415,83 +434,80 @@ public class MuteService : IEService, IReadyExecutor
{ {
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var configs = await uow.Set<GuildConfig>() var configs = await uow.Set<GuildConfig>()
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId)) .Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId))
.ToListAsyncLinqToDB(); .ToListAsyncLinqToDB();
_guildMuteRoles = configs.Where(c => !string.IsNullOrWhiteSpace(c.MuteRoleName)) _guildMuteRoles = configs.Where(c => !string.IsNullOrWhiteSpace(c.MuteRoleName))
.ToDictionary(c => c.GuildId, c => c.MuteRoleName) .ToDictionary(c => c.GuildId, c => c.MuteRoleName)
.ToConcurrent(); .ToConcurrent();
_mutedUsers = await uow.GetTable<MutedUserId>() _mutedUsers = await uow.GetTable<MutedUserId>()
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId)) .Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId))
.ToListAsyncLinqToDB() .ToListAsyncLinqToDB()
.Fmap(x => x.GroupBy(x => x.GuildId) .Fmap(x => x.GroupBy(x => x.GuildId)
.ToDictionary(g => g.Key, g => new ConcurrentHashSet<ulong>(g.Select(x => x.UserId))) .ToDictionary(g => g.Key, g => new ConcurrentHashSet<ulong>(g.Select(x => x.UserId)))
.ToConcurrent()); .ToConcurrent());
var max = TimeSpan.FromDays(49); var max = TimeSpan.FromDays(49);
var unmuteTimers = await uow.GetTable<UnmuteTimer>() var unmuteTimers = await uow.GetTable<UnmuteTimer>()
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId)) .Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId))
.ToListAsyncLinqToDB(); .ToListAsyncLinqToDB();
var unbanTimers = await uow.GetTable<UnbanTimer>() var unbanTimers = await uow.GetTable<UnbanTimer>()
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId)) .Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId))
.ToListAsyncLinqToDB(); .ToListAsyncLinqToDB();
var unroleTimers = await uow.GetTable<UnroleTimer>() var unroleTimers = await uow.GetTable<UnroleTimer>()
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId)) .Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId))
.ToListAsyncLinqToDB(); .ToListAsyncLinqToDB();
foreach (var conf in configs) foreach (var x in unmuteTimers)
{ {
foreach (var x in unmuteTimers) TimeSpan after;
if (x.UnmuteAt - TimeSpan.FromMinutes(2) <= DateTime.UtcNow)
{ {
TimeSpan after; after = TimeSpan.FromMinutes(2);
if (x.UnmuteAt - TimeSpan.FromMinutes(2) <= DateTime.UtcNow) }
{ else
after = TimeSpan.FromMinutes(2); {
} var unmute = x.UnmuteAt - DateTime.UtcNow;
else after = unmute > max ? max : unmute;
{
var unmute = x.UnmuteAt - DateTime.UtcNow;
after = unmute > max ? max : unmute;
}
StartUn_Timer(conf.GuildId, x.UserId, after, TimerType.Mute);
} }
foreach (var x in unbanTimers) StartUn_Timer(x.GuildId, x.UserId, after, TimerType.Mute);
{ }
TimeSpan after;
if (x.UnbanAt - TimeSpan.FromMinutes(2) <= DateTime.UtcNow)
{
after = TimeSpan.FromMinutes(2);
}
else
{
var unban = x.UnbanAt - DateTime.UtcNow;
after = unban > max ? max : unban;
}
StartUn_Timer(conf.GuildId, x.UserId, after, TimerType.Ban); foreach (var x in unbanTimers)
{
TimeSpan after;
if (x.UnbanAt - TimeSpan.FromMinutes(2) <= DateTime.UtcNow)
{
after = TimeSpan.FromMinutes(2);
}
else
{
var unban = x.UnbanAt - DateTime.UtcNow;
after = unban > max ? max : unban;
} }
foreach (var x in unroleTimers) StartUn_Timer(x.GuildId, x.UserId, after, TimerType.Ban);
{ }
TimeSpan after;
if (x.UnbanAt - TimeSpan.FromMinutes(2) <= DateTime.UtcNow)
{
after = TimeSpan.FromMinutes(2);
}
else
{
var unban = x.UnbanAt - DateTime.UtcNow;
after = unban > max ? max : unban;
}
StartUn_Timer(conf.GuildId, x.UserId, after, TimerType.AddRole, x.RoleId); foreach (var x in unroleTimers)
{
TimeSpan after;
if (x.UnbanAt - TimeSpan.FromMinutes(2) <= DateTime.UtcNow)
{
after = TimeSpan.FromMinutes(2);
} }
else
{
var unban = x.UnbanAt - DateTime.UtcNow;
after = unban > max ? max : unban;
}
StartUn_Timer(x.GuildId, x.UserId, after, TimerType.AddRole, x.RoleId);
} }
_client.UserJoined += Client_UserJoined; _client.UserJoined += Client_UserJoined;

View file

@ -716,8 +716,13 @@ public partial class Administration
var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7; var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7;
await ctx.Guild.AddBanAsync(user, banPrune, ("Softban | " + ctx.User + " | " + msg).TrimTo(512)); await ctx.Guild.AddBanAsync(user, banPrune, ("Softban | " + ctx.User + " | " + msg).TrimTo(512));
try try
{ await ctx.Guild.RemoveBanAsync(user); } {
catch { await ctx.Guild.RemoveBanAsync(user); } await ctx.Guild.RemoveBanAsync(user);
}
catch
{
}
var toSend = CreateEmbed() var toSend = CreateEmbed()
.WithOkColor() .WithOkColor()

View file

@ -119,7 +119,7 @@ public class XpTemplate
Pos = new() Pos = new()
{ {
X = 394, X = 394,
Y = 35 Y = 40
}, },
Show = true Show = true
} }

View file

@ -12,7 +12,7 @@ public class Localization : ILocalization, IReadyExecutor, IEService
JsonConvert.DeserializeObject<Dictionary<string, CommandData>>( JsonConvert.DeserializeObject<Dictionary<string, CommandData>>(
File.ReadAllText("./strings/commands/commands.en-US.json")); File.ReadAllText("./strings/commands/commands.en-US.json"));
private ConcurrentDictionary<ulong, CultureInfo> _guildCultureInfos; private ConcurrentDictionary<ulong, CultureInfo> _guildCultureInfos = [];
public IDictionary<ulong, CultureInfo> GuildCultureInfos public IDictionary<ulong, CultureInfo> GuildCultureInfos
=> _guildCultureInfos; => _guildCultureInfos;

View file

@ -21,7 +21,7 @@ dice:
- https://cdn.nadeko.bot/other/dice/8.png - https://cdn.nadeko.bot/other/dice/8.png
- https://cdn.nadeko.bot/other/dice/9.png - https://cdn.nadeko.bot/other/dice/9.png
xp: xp:
bg: https://cdn.nadeko.bot/xp/bgs/v6.png bg: https://cdn.nadeko.bot/other/xp/bg6_mini.png
slots: slots:
emojis: emojis:
- https://cdn.nadeko.bot/slots/10.png - https://cdn.nadeko.bot/slots/10.png

View file

@ -8,21 +8,21 @@
"Name": { "Name": {
"Color": "ffffffff", "Color": "ffffffff",
"Show": true, "Show": true,
"FontSize": 50, "FontSize": 25,
"Pos": { "Pos": {
"X": 105, "X": 65,
"Y": 25 "Y": 8
} }
}, },
"Icon": { "Icon": {
"Show": true, "Show": true,
"Pos": { "Pos": {
"X": 14, "X": 11,
"Y": 14 "Y": 11
}, },
"Size": { "Size": {
"X": 72, "X": 38,
"Y": 71 "Y": 38
} }
}, },
"Level": { "Level": {
@ -47,26 +47,26 @@
"Bar": { "Bar": {
"Show": true, "Show": true,
"Guild": { "Guild": {
"Color": "00000095", "Color": "00000066",
"PointA": { "PointA": {
"X": 282, "X": 202,
"Y": 248 "Y": 66
}, },
"PointB": { "PointB": {
"X": 247, "X": 180,
"Y": 379 "Y": 145
}, },
"Length": 450, "Length": 225,
"Direction": 3 "Direction": 3
} }
}, },
"Guild": { "Guild": {
"Color": "ffffffff", "Color": "ffffffff",
"Show": true, "Show": true,
"FontSize": 50, "FontSize": 25,
"Pos": { "Pos": {
"X": 490, "X": 330,
"Y": 313 "Y": 104
} }
} }
} }
@ -75,21 +75,21 @@
"Icon": { "Icon": {
"Show": true, "Show": true,
"Pos": { "Pos": {
"X": 722, "X": 451,
"Y": 25 "Y": 15
}, },
"Size": { "Size": {
"X": 45, "X": 29,
"Y": 45 "Y": 29
} }
}, },
"Name": { "Name": {
"Color": "ffffffff", "Color": "ffffffff",
"Show": true, "Show": true,
"FontSize": 35, "FontSize": 20,
"Pos": { "Pos": {
"X": 650, "X": 394,
"Y": 55 "Y": 40
} }
} }
} }