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*
## [6.0.3] - 12.03.2025
## [6.0.4] - 14.03.2025
### Added

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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