fixed .antispamignore

Improved livechannel error handling
This commit is contained in:
Toastie 2025-03-19 14:38:14 +13:00
parent 134e5a8c92
commit d9d35420c9
Signed by: toastie_t0ast
GPG key ID: 0861BE54AD481DC7
8 changed files with 46 additions and 25 deletions

View file

@ -2,7 +2,21 @@
*a,c,f,r,o*
## [6.0.7] - 18.03.2025
## [6.0.8] - 19.03.2025
### Added
- Live channel commands
- `.lcha` adds a channel with a template message (supports placeholders, and works on category channels too!)
- Every 10 minutes, channel name will be updated
- example: `.lcha #my-channel --> Members: %server.members% <--` will display the number of members in the server as a channel name, updating once every 10 minutes
- `.lchl` lists all live channels (Up to 5)
- `.lchd <channel or channelId>` removed a live channel
### Fixed
- `.antispamignore` fixed
## [6.0.7] - 19.03.2025
### Added

View file

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

View file

@ -1,4 +1,5 @@
#nullable disable
using System.Net;
using LinqToDB;
using LinqToDB.EntityFrameworkCore;
using EllieBot.Common.ModuleBehaviors;
@ -248,23 +249,21 @@ public class MuteService : IEService, IReadyExecutor
{
ArgumentNullException.ThrowIfNull(guild);
const string defaultMuteRoleName = "nadeko-mute";
const string defaultMuteRoleName = "ellie-mute";
var muteRoleName = _guildMuteRoles.GetOrAdd(guild.Id, defaultMuteRoleName);
var muteRole = guild.Roles.FirstOrDefault(r => r.Name == muteRoleName);
if (muteRole is null)
//if it doesn't exist, create it
{
try
{
muteRole = await guild.CreateRoleAsync(muteRoleName, isMentionable: false);
}
catch
catch (Exception ex)
{
//if creations fails, maybe the name is not correct, find default one, if doesn't work, create default one
muteRole = guild.Roles.FirstOrDefault(r => r.Name == muteRoleName)
?? await guild.CreateRoleAsync(defaultMuteRoleName, isMentionable: false);
Log.Warning(ex, "Unable to create mute role for guild {GuildId}", guild.Id);
return null;
}
}
@ -280,9 +279,10 @@ public class MuteService : IEService, IReadyExecutor
await Task.Delay(200);
}
}
catch
catch (HttpException ex) when (ex.DiscordCode == DiscordErrorCode.MissingPermissions)
{
// ignored
Log.Error(ex, "Error in Initializing mute role in guild {GuildId}: {Message}", guild.Id, ex.Message);
break;
}
}

View file

@ -143,9 +143,9 @@ public partial class Administration
return;
await Response()
.Confirm(GetText(strs.prot_enable("Anti-Raid")),
$"{ctx.User.Mention} {GetAntiRaidString(stats)}")
.SendAsync();
.Confirm(GetText(strs.prot_enable("Anti-Raid")),
$"{ctx.User.Mention} {GetAntiRaidString(stats)}")
.SendAsync();
}
[Cmd]
@ -213,9 +213,9 @@ public partial class Administration
var stats = await _service.StartAntiSpamAsync(ctx.Guild.Id, messageCount, action, time, role?.Id);
await Response()
.Confirm(GetText(strs.prot_enable("Anti-Spam")),
$"{ctx.User.Mention} {GetAntiSpamString(stats)}")
.SendAsync();
.Confirm(GetText(strs.prot_enable("Anti-Spam")),
$"{ctx.User.Mention} {GetAntiSpamString(stats)}")
.SendAsync();
}
[Cmd]

View file

@ -10,7 +10,7 @@ namespace EllieBot.Modules.Administration.Services;
public class ProtectionService : IReadyExecutor, IEService
{
public event Func<PunishmentAction, ProtectionType, IGuildUser[], Task> OnAntiProtectionTriggered = delegate
public event Func<PunishmentAction, ProtectionType, IGuildUser[], Task> OnAntiProtectionTriggered = static delegate
{
return Task.CompletedTask;
};
@ -301,7 +301,7 @@ public class ProtectionService : IReadyExecutor, IEService
{
if (_antiRaidGuilds.TryRemove(guildId, out _))
{
using var uow = _db.GetDbContext();
await using var uow = _db.GetDbContext();
await uow.GetTable<AntiRaidSetting>()
.Where(x => x.GuildId == guildId)
.DeleteAsync();
@ -316,7 +316,7 @@ public class ProtectionService : IReadyExecutor, IEService
{
if (_antiSpamGuilds.TryRemove(guildId, out _))
{
using var uow = _db.GetDbContext();
await using var uow = _db.GetDbContext();
await uow.GetTable<AntiSpamSetting>()
.Where(x => x.GuildId == guildId)
.DeleteAsync();
@ -335,7 +335,9 @@ public class ProtectionService : IReadyExecutor, IEService
ulong? roleId)
{
var g = _client.GetGuild(guildId);
await _mute.GetMuteRole(g);
if (action == PunishmentAction.Mute)
await _mute.GetMuteRole(g);
if (!IsDurationAllowed(action))
punishDurationMinutes = 0;
@ -391,7 +393,7 @@ public class ProtectionService : IReadyExecutor, IEService
};
await using var uow = _db.GetDbContext();
var spam = await uow.GetTable<AntiSpamSetting>()
var spam = await uow.Set<AntiSpamSetting>()
.Include(x => x.IgnoredChannels)
.Where(x => x.GuildId == guildId)
.FirstOrDefaultAsyncEF();

View file

@ -22,15 +22,17 @@ public partial class Utility
var eb = CreateEmbed()
.WithOkColor()
.WithDescription(GetText(strs.livechannel_added(channel.Name)))
.AddField(GetText(strs.template), template)
.AddField(GetText(strs.template), template, true)
.AddField(GetText(strs.preview),
await repSvc.ReplaceAsync(template,
new(
client: ctx.Client as DiscordSocketClient,
guild: ctx.Guild
)));
)),
true)
.WithFooter(GetText(strs.livechannel_please_wait));
await Response()
.Confirm(strs.livechannel_added(channel.Name))
.Embed(eb)
.SendAsync();
return;
}

View file

@ -83,7 +83,9 @@ public class LiveChannelService(
if (channel.Name != text)
await channel.ModifyAsync(x => x.Name = text);
}
catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.Forbidden)
catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.Forbidden
|| ex.DiscordCode == DiscordErrorCode.MissingPermissions
|| ex.HttpCode == HttpStatusCode.NotFound)
{
await RemoveLiveChannelAsync(config.GuildId, config.ChannelId);
Log.Warning(

View file

@ -1230,6 +1230,7 @@
"livechannel_not_found": "Channel was not found in the live channels list.",
"livechannel_list_title": "Live Channels in {0}",
"livechannel_list_empty": "No live channels configured for this server.",
"livechannel_please_wait": "Please allow up to 10 minutes for the changes to take effect",
"template": "Template",
"preview": "Preview"
}