Merge pull request 'v6' () from EllieBotDevs/elliebot:v6 into v6

Reviewed-on: 
This commit is contained in:
Toastie 2025-03-20 21:42:26 +00:00
commit 4642607ccc
10 changed files with 199 additions and 144 deletions
CHANGELOG.md
src/EllieBot
EllieBot.csproj
Modules
Administration
Permissions/Filter
Searches
StreamNotification
_common/StreamNotifications
Utility

View file

@ -2,6 +2,34 @@
*a,c,f,r,o*
## [6.0.12] - 20.03.2025
### Fixed
- `.antispamignore` fixed for the last time hopefully
- protection commands are some of the oldest commands, and they might get overhauled in future updates
- please report if you find any other weird issue with them
## [6.0.11] - 20.03.2025
### Changed
- wordfilter, invitefilter and linkfilter will now properly detect forwarded messages, as forwards were used to circumvent filtering.
### Fixed
- `.dmc` fixed
- Fixed .streamremove - now showing proper youtube name when removing instead of channel id
## [6.0.10] - 20.03.2025
### Changed
- Live channels `.lcha` is limited to 1 for now. It will be reverted back to 5 in a couple of days at most as some things need to be implemented.
### Fixed
- `.antispam` won't break if you have thread channels in the server anymore
- `.ve` now works properly
- selfhosters: `.yml` parsing errors will now tell you which .yml file is causing the issue and why.
## [6.0.9] - 19.03.2025
### Changed

View file

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

View file

@ -107,12 +107,12 @@ public class AdministrationService : IEService, IReadyExecutor
.UpdateWithOutputAsync(x => new()
{
DeleteMessageOnCommand = !x.DeleteMessageOnCommand
});
}, (old, newVal) => newVal);
if (conf.Length == 0)
return false;
var val = conf[0].Inserted.DeleteMessageOnCommand;
var val = conf[0].DeleteMessageOnCommand;
if (val)
deleteMessagesOnCommand.Add(guildId);

View file

@ -27,6 +27,7 @@ public class ProtectionService : IReadyExecutor, IEService
private readonly UserPunishService _punishService;
private readonly INotifySubscriber _notifySub;
private readonly ShardData _shardData;
private readonly Channel<PunishQueueItem> _punishUserQueue =
Channel.CreateUnbounded<PunishQueueItem>(new()
{
@ -176,10 +177,7 @@ public class ProtectionService : IReadyExecutor, IEService
try
{
if (!_antiSpamGuilds.TryGetValue(channel.Guild.Id, out var spamSettings)
|| spamSettings.AntiSpamSettings.IgnoredChannels.Contains(new()
{
ChannelId = channel.Id
}))
|| spamSettings.AntiSpamSettings.IgnoredChannels.Any(x => x.ChannelId == channel.Id))
return;
var stats = spamSettings.UserStats.AddOrUpdate(msg.Author.Id,
@ -282,13 +280,15 @@ public class ProtectionService : IReadyExecutor, IEService
Seconds = seconds,
UserThreshold = userThreshold,
PunishDuration = minutesDuration
}, _ => new()
},
_ => new()
{
Action = action,
Seconds = seconds,
UserThreshold = userThreshold,
PunishDuration = minutesDuration
}, () => new()
},
() => new()
{
GuildId = guildId
});
@ -370,14 +370,16 @@ public class ProtectionService : IReadyExecutor, IEService
MessageThreshold = stats.AntiSpamSettings.MessageThreshold,
MuteTime = stats.AntiSpamSettings.MuteTime,
RoleId = stats.AntiSpamSettings.RoleId
}, (old) => new()
},
(old) => new()
{
GuildId = guildId,
Action = stats.AntiSpamSettings.Action,
MessageThreshold = stats.AntiSpamSettings.MessageThreshold,
MuteTime = stats.AntiSpamSettings.MuteTime,
RoleId = stats.AntiSpamSettings.RoleId
}, () => new()
},
() => new()
{
GuildId = guildId
});
@ -405,7 +407,7 @@ public class ProtectionService : IReadyExecutor, IEService
if (spam.IgnoredChannels.All(x => x.ChannelId != channelId))
{
if (_antiSpamGuilds.TryGetValue(guildId, out var temp))
temp.AntiSpamSettings.IgnoredChannels.Add(obj); // add to local cache
temp.AntiSpamSettings.IgnoredChannels.Add(obj);
spam.IgnoredChannels.Add(obj);
added = true;
@ -417,7 +419,7 @@ public class ProtectionService : IReadyExecutor, IEService
uow.Set<AntiSpamIgnore>().Remove(toRemove);
if (_antiSpamGuilds.TryGetValue(guildId, out var temp))
temp.AntiSpamSettings.IgnoredChannels.Remove(toRemove); // remove from local cache
temp.AntiSpamSettings.IgnoredChannels.RemoveAll(x => x.ChannelId == channelId);
added = false;
}
@ -468,13 +470,15 @@ public class ProtectionService : IReadyExecutor, IEService
ActionDurationMinutes = actionDurationMinutes,
MinAge = TimeSpan.FromMinutes(minAgeMinutes),
RoleId = roleId
}, _ => new()
},
_ => new()
{
Action = action,
ActionDurationMinutes = actionDurationMinutes,
MinAge = TimeSpan.FromMinutes(minAgeMinutes),
RoleId = roleId
}, () => new()
},
() => new()
{
GuildId = guildId
});

View file

@ -140,7 +140,8 @@ public sealed class FilterService : IExecOnMessage, IReadyExecutor
var filteredChannelWords =
FilteredWordsForChannel(usrMsg.Channel.Id, guild.Id) ?? new ConcurrentHashSet<string>();
var filteredServerWords = FilteredWordsForServer(guild.Id) ?? new ConcurrentHashSet<string>();
var wordsInMessage = usrMsg.Content.ToLowerInvariant().Split(' ');
var wordsInMessage = (usrMsg.Content + " " + usrMsg.ForwardedMessages.FirstOrDefault().Message?.Content)
.ToLowerInvariant().Split(' ');
if (filteredChannelWords.Count != 0 || filteredServerWords.Count != 0)
{
foreach (var word in wordsInMessage)
@ -183,7 +184,8 @@ public sealed class FilterService : IExecOnMessage, IReadyExecutor
return false;
if ((InviteFilteringChannels.Contains(usrMsg.Channel.Id) || InviteFilteringServers.Contains(guild.Id))
&& usrMsg.Content.IsDiscordInvite())
&& (usrMsg.Content.IsDiscordInvite() ||
usrMsg.ForwardedMessages.Any(x => x.Message?.Content.IsDiscordInvite() ?? false)))
{
Log.Information("User {UserName} [{UserId}] sent a filtered invite to {ChannelId} channel",
usrMsg.Author.ToString(),
@ -219,7 +221,8 @@ public sealed class FilterService : IExecOnMessage, IReadyExecutor
return false;
if ((LinkFilteringChannels.Contains(usrMsg.Channel.Id) || LinkFilteringServers.Contains(guild.Id))
&& usrMsg.Content.TryGetUrlPath(out _))
&& (usrMsg.Content.TryGetUrlPath(out _) ||
usrMsg.ForwardedMessages.Any(x => x.Message?.Content.TryGetUrlPath(out _) ?? false)))
{
Log.Information("User {UserName} [{UserId}] sent a filtered link to {ChannelId} channel",
usrMsg.Author.ToString(),

View file

@ -48,7 +48,10 @@ public partial class Searches
return;
}
await Response().Confirm(strs.stream_removed(Format.Bold(fs.Username), fs.Type)).SendAsync();
await Response()
.Confirm(strs.stream_removed(
Format.Bold(string.IsNullOrWhiteSpace(fs.PrettyName) ? fs.Username : fs.PrettyName),
fs.Type)).SendAsync();
}
[Cmd]

View file

@ -63,20 +63,19 @@ public class NotifChecker
.ToDictionary(x => x.Key.Name, x => x.Value));
var newStreamData = await oldStreamDataDict
.Select(x =>
.Select(async x =>
{
// get all stream data for the streams of this type
if (_streamProviders.TryGetValue(x.Key,
out var provider))
{
return provider.GetStreamDataAsync(x.Value
return await provider.GetStreamDataAsync(x.Value
.Select(entry => entry.Key)
.ToList());
}
// this means there's no provider for this stream data, (and there was before?)
return Task.FromResult<IReadOnlyCollection<StreamData>>(
new List<StreamData>());
return [];
})
.WhenAll();

View file

@ -1,12 +1,7 @@
using System.Net;
using EllieBot.Db.Models;
using EllieBot.Services;
using EllieBot.Db.Models;
using System.Text.RegularExpressions;
using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Xml.Linq;
using AngleSharp.Browser;
namespace EllieBot.Modules.Searches.Common.StreamNotifications.Providers;
@ -112,6 +107,8 @@ public sealed partial class YouTubeProvider : Provider
/// <param name="channelId">Channel ID or name</param>
/// <returns><see cref="StreamData"/> of the channel. Null if none found</returns>
public override async Task<StreamData?> GetStreamDataAsync(string channelId)
{
try
{
var instances = _scs.Data.InvidiousInstances;
@ -164,6 +161,13 @@ public sealed partial class YouTubeProvider : Provider
UniqueName = vid.AuthorId,
};
}
catch (Exception ex)
{
Log.Warning(ex, "Unable to get stream data for a youtube channel {ChannelId}", channelId);
_failingStreams.TryAdd(channelId, DateTime.UtcNow);
return null;
}
}
/// <summary>
/// Gets stream data of all specified YouTube channels

View file

@ -17,7 +17,7 @@ public class LiveChannelService(
IReplacementService repSvc,
ShardData shardData) : IReadyExecutor, IEService
{
public const int MAX_LIVECHANNELS = 5;
public const int MAX_LIVECHANNELS = 1;
private readonly ConcurrentDictionary<ulong, ConcurrentDictionary<ulong, LiveChannelConfig>> _liveChannels = new();

View file

@ -1,4 +1,5 @@
#nullable disable
using LinqToDB;
using LinqToDB.EntityFrameworkCore;
using EllieBot.Common.ModuleBehaviors;
using EllieBot.Db.Models;
@ -50,16 +51,29 @@ public class VerboseErrorsService : IReadyExecutor, IEService
}
}
/// <summary>
/// Toggles or sets verbose errors for the specified guild.
/// </summary>
/// <param name="guildId">The ID of the guild to toggle verbose errors for.</param>
/// <param name="maybeEnabled">If specified, sets to this value; otherwise toggles current value.</param>
/// <returns>Returns the new state of verbose errors (true = enabled, false = disabled).</returns>
public async Task<bool> ToggleVerboseErrors(ulong guildId, bool? maybeEnabled = null)
{
await using var ctx = _db.GetDbContext();
var isEnabled = ctx.GetTable<GuildConfig>()
var current = await ctx.GetTable<GuildConfig>()
.Where(x => x.GuildId == guildId)
.Select(x => x.VerboseErrors)
.FirstOrDefault();
.FirstOrDefaultAsync();
if (isEnabled) // This doesn't need to be duplicated inside the using block
var newState = maybeEnabled ?? !current;
await ctx.GetTable<GuildConfig>()
.Where(x => x.GuildId == guildId)
.Set(x => x.VerboseErrors, newState)
.UpdateAsync();
if (newState)
{
_guildsDisabled.TryRemove(guildId);
}
@ -68,7 +82,7 @@ public class VerboseErrorsService : IReadyExecutor, IEService
_guildsDisabled.Add(guildId);
}
return isEnabled;
return newState;
}
public async Task OnReadyAsync()