Medusa System Added

Read about the medusa system [here](https://nadekobot.readthedocs.io/en/latest/medusa/creating-a-medusa/)
This commit is contained in:
Kwoth
2022-04-16 12:44:46 +00:00
parent 3a516ab32a
commit 7cb15f5278
103 changed files with 3363 additions and 203 deletions

View File

@@ -7,7 +7,7 @@ using System.Threading.Channels;
namespace NadekoBot.Modules.Administration.Services;
public sealed class ImageOnlyChannelService : IEarlyBehavior
public sealed class ImageOnlyChannelService : IExecOnMessage
{
public int Priority { get; } = 0;
private readonly IMemoryCache _ticketCache;
@@ -93,7 +93,7 @@ public sealed class ImageOnlyChannelService : IEarlyBehavior
return newState;
}
public async Task<bool> RunBehavior(IGuild guild, IUserMessage msg)
public async Task<bool> ExecOnMessageAsync(IGuild guild, IUserMessage msg)
{
if (msg.Channel is not ITextChannel tch)
return false;

View File

@@ -5,7 +5,7 @@ using NadekoBot.Services.Database.Models;
namespace NadekoBot.Modules.Administration.Services;
public class DiscordPermOverrideService : INService, ILateBlocker
public class DiscordPermOverrideService : INService, IExecPreCommand
{
public int Priority { get; } = int.MaxValue;
private readonly DbService _db;
@@ -118,7 +118,7 @@ public class DiscordPermOverrideService : INService, ILateBlocker
.ToListAsync();
}
public async Task<bool> TryBlockLate(ICommandContext context, string moduleName, CommandInfo command)
public async Task<bool> ExecPreCommandAsync(ICommandContext context, string moduleName, CommandInfo command)
{
if (TryGetOverrides(context.Guild?.Id ?? 0, command.Name, out var perm) && perm is not null)
{

View File

@@ -1,4 +1,5 @@
#nullable disable
using Nadeko.Medusa;
using NadekoBot.Modules.Administration.Services;
using NadekoBot.Services.Database.Models;
@@ -19,13 +20,19 @@ public partial class Administration
private readonly DiscordSocketClient _client;
private readonly IBotStrings _strings;
private readonly IMedusaLoaderService _medusaLoader;
private readonly ICoordinator _coord;
public SelfCommands(DiscordSocketClient client, IBotStrings strings, ICoordinator coord)
public SelfCommands(
DiscordSocketClient client,
IBotStrings strings,
ICoordinator coord,
IMedusaLoaderService medusaLoader)
{
_client = client;
_strings = strings;
_coord = coord;
_medusaLoader = medusaLoader;
}
[Cmd]
@@ -506,6 +513,7 @@ public partial class Administration
public async partial Task StringsReload()
{
_strings.Reload();
await _medusaLoader.ReloadStrings();
await ReplyConfirmLocalizedAsync(strs.bot_strings_reloaded);
}

View File

@@ -6,7 +6,7 @@ using System.Collections.Immutable;
namespace NadekoBot.Modules.Administration.Services;
public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
public sealed class SelfService : IExecNoCommand, IReadyExecutor, INService
{
private readonly CommandHandler _cmdHandler;
private readonly DbService _db;
@@ -206,7 +206,7 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
=> _pubSub.Pub(_guildLeaveKey, guildStr);
// forwards dms
public async Task LateExecute(IGuild guild, IUserMessage msg)
public async Task ExecOnNoCommandAsync(IGuild guild, IUserMessage msg)
{
var bs = _bss.Data;
if (msg.Channel is IDMChannel && bs.ForwardMessages && ownerChannels.Any())

View File

@@ -913,7 +913,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
var embed = _eb.Create()
.WithOkColor()
.WithTitle("♻️ " + GetText(logChannel.Guild, strs.user_unbanned))
.WithDescription(usr.ToString())
.WithDescription(usr.ToString()!)
.AddField("Id", usr.Id.ToString())
.WithFooter(CurrentTime(guild));
@@ -948,7 +948,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
var embed = _eb.Create()
.WithOkColor()
.WithTitle("🚫 " + GetText(logChannel.Guild, strs.user_banned))
.WithDescription(usr.ToString())
.WithDescription(usr.ToString()!)
.AddField("Id", usr.Id.ToString())
.WithFooter(CurrentTime(guild));
@@ -999,7 +999,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
.WithOkColor()
.WithTitle("🗑 "
+ GetText(logChannel.Guild, strs.msg_del(((ITextChannel)msg.Channel).Name)))
.WithDescription(msg.Author.ToString())
.WithDescription(msg.Author.ToString()!)
.AddField(GetText(logChannel.Guild, strs.content),
string.IsNullOrWhiteSpace(resolvedMessage) ? "-" : resolvedMessage)
.AddField("Id", msg.Id.ToString())
@@ -1060,7 +1060,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
.WithTitle("📝 "
+ GetText(logChannel.Guild,
strs.msg_update(((ITextChannel)after.Channel).Name)))
.WithDescription(after.Author.ToString())
.WithDescription(after.Author.ToString()!)
.AddField(GetText(logChannel.Guild, strs.old_msg),
string.IsNullOrWhiteSpace(before.Content)
? "-"

View File

@@ -577,7 +577,7 @@ public partial class Administration
[BotPerm(GuildPerm.BanMembers)]
public async partial Task Unban([Leftover] string user)
{
var bans = await ctx.Guild.GetBansAsync();
var bans = await ctx.Guild.GetBansAsync().FlattenAsync();
var bun = bans.FirstOrDefault(x => x.User.ToString()!.ToLowerInvariant() == user.ToLowerInvariant());
@@ -596,9 +596,7 @@ public partial class Administration
[BotPerm(GuildPerm.BanMembers)]
public async partial Task Unban(ulong userId)
{
var bans = await ctx.Guild.GetBansAsync();
var bun = bans.FirstOrDefault(x => x.User.Id == userId);
var bun = await ctx.Guild.GetBanAsync(userId);
if (bun is null)
{