mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
- Started cleanup of command handler
- Removed IUnloadableService - Started removing INService (removed it from services which implement behavior interfaces) - wip - Added scrutor for better service registration - wip
This commit is contained in:
@@ -142,8 +142,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> TryBlockLate(DiscordSocketClient client, ICommandContext context, string moduleName,
|
||||
CommandInfo command)
|
||||
public async Task<bool> TryBlockLate(ICommandContext context, string moduleName, CommandInfo command)
|
||||
{
|
||||
if (TryGetOverrides(context.Guild?.Id ?? 0, command.Name, out var perm) && perm is not null)
|
||||
{
|
||||
|
@@ -18,7 +18,7 @@ using Serilog;
|
||||
|
||||
namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
|
||||
public sealed class SelfService : ILateExecutor, IReadyExecutor
|
||||
{
|
||||
private readonly ConnectionMultiplexer _redis;
|
||||
private readonly CommandHandler _cmdHandler;
|
||||
@@ -54,6 +54,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
_httpFactory = factory;
|
||||
_bss = bss;
|
||||
|
||||
Log.Information("Self service created");
|
||||
var sub = _redis.GetSubscriber();
|
||||
if (_client.ShardId == 0)
|
||||
{
|
||||
@@ -226,7 +227,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
}
|
||||
|
||||
// forwards dms
|
||||
public async Task LateExecute(DiscordSocketClient client, IGuild guild, IUserMessage msg)
|
||||
public async Task LateExecute(IGuild guild, IUserMessage msg)
|
||||
{
|
||||
var bs = _bss.Data;
|
||||
if (msg.Channel is IDMChannel && _bss.Data.ForwardMessages && ownerChannels.Any())
|
||||
|
@@ -22,7 +22,7 @@ using YamlDotNet.Serialization;
|
||||
|
||||
namespace NadekoBot.Modules.CustomReactions.Services
|
||||
{
|
||||
public sealed class CustomReactionsService : IEarlyBehavior, INService, IReadyExecutor
|
||||
public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
|
||||
{
|
||||
public enum CrField
|
||||
{
|
||||
@@ -77,6 +77,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
_pubSub = pubSub;
|
||||
_rng = new NadekoRandom();
|
||||
|
||||
Log.Information("Custom reaction service created");
|
||||
_pubSub.Sub(_crsReloadedKey, OnCrsShouldReload);
|
||||
pubSub.Sub(_gcrAddedKey, OnGcrAdded);
|
||||
pubSub.Sub(_gcrDeletedkey, OnGcrDeleted);
|
||||
@@ -380,7 +381,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
return result[_rng.Next(0, result.Count)];
|
||||
}
|
||||
|
||||
public async Task<bool> RunBehavior(DiscordSocketClient client, IGuild guild, IUserMessage msg)
|
||||
public async Task<bool> RunBehavior(IGuild guild, IUserMessage msg)
|
||||
{
|
||||
// maybe this message is a custom reaction
|
||||
var cr = TryGetCustomReaction(msg);
|
||||
|
@@ -5,17 +5,8 @@ using NadekoBot.Modules.Gambling.Common.AnimalRacing;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Services
|
||||
{
|
||||
public class AnimalRaceService : INService, IUnloadableService
|
||||
public class AnimalRaceService : INService
|
||||
{
|
||||
public ConcurrentDictionary<ulong, AnimalRace> AnimalRaces { get; } = new ConcurrentDictionary<ulong, AnimalRace>();
|
||||
|
||||
public Task Unload()
|
||||
{
|
||||
foreach (var kvp in AnimalRaces)
|
||||
{
|
||||
try { kvp.Value.Dispose(); } catch { }
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ using Serilog;
|
||||
|
||||
namespace NadekoBot.Modules.Games.Services
|
||||
{
|
||||
public class ChatterBotService : IEarlyBehavior, INService
|
||||
public class ChatterBotService : IEarlyBehavior
|
||||
{
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly PermissionService _perms;
|
||||
@@ -103,7 +103,7 @@ namespace NadekoBot.Modules.Games.Services
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> RunBehavior(DiscordSocketClient client, IGuild guild, IUserMessage usrMsg)
|
||||
public async Task<bool> RunBehavior(IGuild guild, IUserMessage usrMsg)
|
||||
{
|
||||
if (!(guild is SocketGuild sg))
|
||||
return false;
|
||||
|
@@ -21,7 +21,7 @@ using Serilog;
|
||||
|
||||
namespace NadekoBot.Modules.Games.Services
|
||||
{
|
||||
public class GamesService : INService, IUnloadableService
|
||||
public class GamesService : INService
|
||||
{
|
||||
private readonly GamesConfigService _gamesConfig;
|
||||
|
||||
@@ -101,26 +101,6 @@ namespace NadekoBot.Modules.Games.Services
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Unload()
|
||||
{
|
||||
_t.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
|
||||
AcrophobiaGames.ForEach(x => x.Value.Dispose());
|
||||
AcrophobiaGames.Clear();
|
||||
HangmanGames.ForEach(x => x.Value.Dispose());
|
||||
HangmanGames.Clear();
|
||||
await Task.WhenAll(RunningTrivias.Select(x => x.Value.StopGame())).ConfigureAwait(false);
|
||||
RunningTrivias.Clear();
|
||||
|
||||
TicTacToeGames.Clear();
|
||||
|
||||
await Task.WhenAll(RunningContests.Select(x => x.Value.Stop()))
|
||||
.ConfigureAwait(false);
|
||||
RunningContests.Clear();
|
||||
NunchiGames.ForEach(x => x.Value.Dispose());
|
||||
NunchiGames.Clear();
|
||||
}
|
||||
|
||||
public void AddTypingArticle(IUser user, string text)
|
||||
{
|
||||
TypingArticles.Add(new TypingArticle
|
||||
|
@@ -3,7 +3,6 @@ using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Modules.Games.Common;
|
||||
using NadekoBot.Db.Models;
|
||||
@@ -16,7 +15,7 @@ using Serilog;
|
||||
|
||||
namespace NadekoBot.Modules.Games.Services
|
||||
{
|
||||
public class PollService : IEarlyBehavior, INService
|
||||
public class PollService : IEarlyBehavior
|
||||
{
|
||||
public ConcurrentDictionary<ulong, PollRunner> ActivePolls { get; } = new ConcurrentDictionary<ulong, PollRunner>();
|
||||
|
||||
@@ -106,7 +105,7 @@ namespace NadekoBot.Modules.Games.Services
|
||||
try { await msg.DeleteAsync().ConfigureAwait(false); } catch { }
|
||||
}
|
||||
|
||||
public async Task<bool> RunBehavior(DiscordSocketClient client, IGuild guild, IUserMessage msg)
|
||||
public async Task<bool> RunBehavior(IGuild guild, IUserMessage msg)
|
||||
{
|
||||
if (guild is null)
|
||||
return false;
|
||||
|
@@ -1,6 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using System;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
@@ -40,7 +39,7 @@ namespace NadekoBot.Modules.Help.Services
|
||||
.Build();
|
||||
}
|
||||
|
||||
public Task LateExecute(DiscordSocketClient client, IGuild guild, IUserMessage msg)
|
||||
public Task LateExecute(IGuild guild, IUserMessage msg)
|
||||
{
|
||||
var settings = _bss.Data;
|
||||
if (guild is null)
|
||||
|
@@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
@@ -12,7 +11,7 @@ using NadekoBot.Db;
|
||||
|
||||
namespace NadekoBot.Modules.Permissions.Services
|
||||
{
|
||||
public sealed class BlacklistService : IEarlyBehavior, INService
|
||||
public sealed class BlacklistService : IEarlyBehavior
|
||||
{
|
||||
private readonly DbService _db;
|
||||
private readonly IPubSub _pubSub;
|
||||
@@ -39,7 +38,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
return default;
|
||||
}
|
||||
|
||||
public Task<bool> RunBehavior(DiscordSocketClient _, IGuild guild, IUserMessage usrMsg)
|
||||
public Task<bool> RunBehavior(IGuild guild, IUserMessage usrMsg)
|
||||
{
|
||||
foreach (var bl in _blacklist)
|
||||
{
|
||||
|
@@ -63,7 +63,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
public Task<bool> TryBlockLate(DiscordSocketClient client, ICommandContext ctx, string moduleName, CommandInfo command)
|
||||
public Task<bool> TryBlockLate(ICommandContext ctx, string moduleName, CommandInfo command)
|
||||
{
|
||||
var guild = ctx.Guild;
|
||||
var user = ctx.User;
|
||||
|
@@ -17,7 +17,7 @@ using Serilog;
|
||||
|
||||
namespace NadekoBot.Modules.Permissions.Services
|
||||
{
|
||||
public class FilterService : IEarlyBehavior, INService
|
||||
public class FilterService : IEarlyBehavior
|
||||
{
|
||||
private readonly DbService _db;
|
||||
|
||||
@@ -117,13 +117,13 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
if (guild is null || usrMsg is null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
return RunBehavior(null, guild, usrMsg);
|
||||
return RunBehavior(guild, usrMsg);
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<bool> RunBehavior(DiscordSocketClient _, IGuild guild, IUserMessage msg)
|
||||
public async Task<bool> RunBehavior(IGuild guild, IUserMessage msg)
|
||||
{
|
||||
if (!(msg.Author is IGuildUser gu) || gu.GuildPermissions.Administrator)
|
||||
return false;
|
||||
|
@@ -21,7 +21,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
}
|
||||
|
||||
|
||||
public Task<bool> TryBlockLate(DiscordSocketClient client, ICommandContext ctx, string moduleName, CommandInfo command)
|
||||
public Task<bool> TryBlockLate(ICommandContext ctx, string moduleName, CommandInfo command)
|
||||
{
|
||||
var settings = _bss.Data;
|
||||
var commandName = command.Name.ToLowerInvariant();
|
||||
|
@@ -98,8 +98,7 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<bool> TryBlockLate(DiscordSocketClient client, ICommandContext ctx, string moduleName,
|
||||
CommandInfo command)
|
||||
public async Task<bool> TryBlockLate(ICommandContext ctx, string moduleName, CommandInfo command)
|
||||
{
|
||||
var guild = ctx.Guild;
|
||||
var msg = ctx.Message;
|
||||
|
@@ -31,7 +31,7 @@ using Image = SixLabors.ImageSharp.Image;
|
||||
|
||||
namespace NadekoBot.Modules.Searches.Services
|
||||
{
|
||||
public class SearchesService : INService, IUnloadableService
|
||||
public class SearchesService : INService
|
||||
{
|
||||
private readonly IHttpClientFactory _httpFactory;
|
||||
private readonly DiscordSocketClient _client;
|
||||
@@ -482,19 +482,6 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
}
|
||||
}
|
||||
|
||||
public Task Unload()
|
||||
{
|
||||
AutoBoobTimers.ForEach(x => x.Value.Change(Timeout.Infinite, Timeout.Infinite));
|
||||
AutoBoobTimers.Clear();
|
||||
AutoButtTimers.ForEach(x => x.Value.Change(Timeout.Infinite, Timeout.Infinite));
|
||||
AutoButtTimers.Clear();
|
||||
AutoHentaiTimers.ForEach(x => x.Value.Change(Timeout.Infinite, Timeout.Infinite));
|
||||
AutoHentaiTimers.Clear();
|
||||
|
||||
_imageCacher.Clear();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task<MtgData> GetMtgCardAsync(string search)
|
||||
{
|
||||
search = search.Trim().ToLowerInvariant();
|
||||
|
@@ -13,7 +13,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Utility.Services
|
||||
{
|
||||
public class ConverterService : INService, IUnloadableService
|
||||
public class ConverterService : INService
|
||||
{
|
||||
public ConvertUnit[] Units =>
|
||||
_cache.Redis.GetDatabase()
|
||||
@@ -87,12 +87,6 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
public Task Unload()
|
||||
{
|
||||
_currencyUpdater?.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
public class Rates
|
||||
|
@@ -16,7 +16,7 @@ using Serilog;
|
||||
|
||||
namespace NadekoBot.Modules.Utility.Services
|
||||
{
|
||||
public class PatreonRewardsService : INService, IUnloadableService
|
||||
public class PatreonRewardsService : INService
|
||||
{
|
||||
private readonly SemaphoreSlim getPledgesLocker = new SemaphoreSlim(1, 1);
|
||||
|
||||
@@ -218,11 +218,5 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
public Task Unload()
|
||||
{
|
||||
_updater?.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ using Serilog;
|
||||
|
||||
namespace NadekoBot.Modules.Utility.Services
|
||||
{
|
||||
public sealed class RepeaterService : IReadyExecutor, INService
|
||||
public sealed class RepeaterService : IReadyExecutor
|
||||
{
|
||||
public const int MAX_REPEATERS = 5;
|
||||
|
||||
|
@@ -17,7 +17,7 @@ using Serilog;
|
||||
|
||||
namespace NadekoBot.Modules.Utility.Services
|
||||
{
|
||||
public class StreamRoleService : INService, IUnloadableService
|
||||
public class StreamRoleService : INService
|
||||
{
|
||||
private readonly DbService _db;
|
||||
private readonly DiscordSocketClient _client;
|
||||
@@ -48,12 +48,6 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
});
|
||||
}
|
||||
|
||||
public Task Unload()
|
||||
{
|
||||
_client.GuildMemberUpdated -= Client_GuildMemberUpdated;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task Client_GuildMemberUpdated(SocketGuildUser before, SocketGuildUser after)
|
||||
{
|
||||
var _ = Task.Run(async () =>
|
||||
|
@@ -11,7 +11,7 @@ using NadekoBot.Modules.Administration;
|
||||
|
||||
namespace NadekoBot.Modules.Utility.Services
|
||||
{
|
||||
public class VerboseErrorsService : INService, IUnloadableService
|
||||
public class VerboseErrorsService : INService
|
||||
{
|
||||
private readonly ConcurrentHashSet<ulong> guildsEnabled;
|
||||
private readonly DbService _db;
|
||||
@@ -32,12 +32,6 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
.Select(x => x.GuildId));
|
||||
}
|
||||
|
||||
public Task Unload()
|
||||
{
|
||||
_ch.CommandErrored -= LogVerboseError;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task LogVerboseError(CommandInfo cmd, ITextChannel channel, string reason)
|
||||
{
|
||||
if (channel is null || !guildsEnabled.Contains(channel.GuildId))
|
||||
|
@@ -28,7 +28,7 @@ using Image = SixLabors.ImageSharp.Image;
|
||||
|
||||
namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
public class XpService : INService, IUnloadableService
|
||||
public class XpService : INService
|
||||
{
|
||||
private enum NotifOf
|
||||
{
|
||||
@@ -1182,14 +1182,6 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
}
|
||||
}
|
||||
|
||||
public Task Unload()
|
||||
{
|
||||
_cmd.OnMessageNoTrigger -= _cmd_OnMessageNoTrigger;
|
||||
_client.UserVoiceStateUpdated -= _client_OnUserVoiceStateUpdated;
|
||||
_client.GuildAvailable -= _client_OnGuildAvailable;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void XpReset(ulong guildId, ulong userId)
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
|
Reference in New Issue
Block a user