From 72f36270dcbcde65b2008a40902b29d2230fb410 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Mon, 9 Oct 2017 00:54:10 +0200 Subject: [PATCH] Added some more unloads, upped version to 2.0 --- NadekoBot.Core/Services/Impl/StatsService.cs | 2 +- NadekoBot.Core/Services/NadekoBot.cs | 3 ++- .../Services/SearchesService.cs | 21 ++++++++++++++++++- NadekoBot.Modules.Games/TriviaCommands.cs | 1 - NadekoBot.Modules.Music/Music.cs | 2 +- NadekoBot.Modules.Nsfw/NSFW.cs | 6 ------ 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/NadekoBot.Core/Services/Impl/StatsService.cs b/NadekoBot.Core/Services/Impl/StatsService.cs index 6c8611e0..36d26e1c 100644 --- a/NadekoBot.Core/Services/Impl/StatsService.cs +++ b/NadekoBot.Core/Services/Impl/StatsService.cs @@ -20,7 +20,7 @@ namespace NadekoBot.Services.Impl private readonly IBotCredentials _creds; private readonly DateTime _started; - public const string BotVersion = "1.10.2"; + public const string BotVersion = "2.0.0-alpha"; public string Author => "Kwoth#2560"; public string Library => "Discord.Net"; diff --git a/NadekoBot.Core/Services/NadekoBot.cs b/NadekoBot.Core/Services/NadekoBot.cs index 52fc2926..171a654b 100644 --- a/NadekoBot.Core/Services/NadekoBot.cs +++ b/NadekoBot.Core/Services/NadekoBot.cs @@ -22,6 +22,7 @@ using NadekoBot.Common.TypeReaders.Models; using NadekoBot.Services.Database; using StackExchange.Redis; using Newtonsoft.Json; +using System.Runtime.Loader; namespace NadekoBot { @@ -418,7 +419,7 @@ namespace NadekoBot { if (_packageModules.ContainsKey(name)) return false; - + var package = Assembly.LoadFile(Path.Combine(AppContext.BaseDirectory, "modules", $"NadekoBot.Modules.{name}", diff --git a/NadekoBot.Module.Searches/Services/SearchesService.cs b/NadekoBot.Module.Searches/Services/SearchesService.cs index 0ae3253a..ba9e14cc 100644 --- a/NadekoBot.Module.Searches/Services/SearchesService.cs +++ b/NadekoBot.Module.Searches/Services/SearchesService.cs @@ -16,10 +16,11 @@ using Microsoft.EntityFrameworkCore; using System.Net.Http; using Newtonsoft.Json.Linq; using AngleSharp; +using System.Threading; namespace NadekoBot.Modules.Searches.Services { - public class SearchesService : INService + public class SearchesService : INService, IUnloadableService { public HttpClient Http { get; } @@ -41,6 +42,11 @@ namespace NadekoBot.Modules.Searches.Services private readonly ConcurrentDictionary _imageCacher = new ConcurrentDictionary(); + //todo clear when module unloaded + public ConcurrentDictionary _autoHentaiTimers { get; } = new ConcurrentDictionary(); + public ConcurrentDictionary _autoBoobTimers { get; } = new ConcurrentDictionary(); + public ConcurrentDictionary _autoButtTimers { get; } = new ConcurrentDictionary(); + private readonly ConcurrentDictionary> _blacklistedTags = new ConcurrentDictionary>(); public SearchesService(DiscordSocketClient client, IGoogleApiService google, DbService db, IEnumerable gcs) @@ -222,6 +228,19 @@ namespace NadekoBot.Modules.Searches.Services var response = await Http.GetStringAsync("http://api.icndb.com/jokes/random/").ConfigureAwait(false); return JObject.Parse(response)["value"]["joke"].ToString() + " 😆"; } + + 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 struct UserChannelPair diff --git a/NadekoBot.Modules.Games/TriviaCommands.cs b/NadekoBot.Modules.Games/TriviaCommands.cs index 75810ba9..4b8e4129 100644 --- a/NadekoBot.Modules.Games/TriviaCommands.cs +++ b/NadekoBot.Modules.Games/TriviaCommands.cs @@ -12,7 +12,6 @@ namespace NadekoBot.Modules.Games { public partial class Games { - //todo move games to service, unload [Group] public class TriviaCommands : NadekoSubmodule { diff --git a/NadekoBot.Modules.Music/Music.cs b/NadekoBot.Modules.Music/Music.cs index 3aac503c..9c15a01a 100644 --- a/NadekoBot.Modules.Music/Music.cs +++ b/NadekoBot.Modules.Music/Music.cs @@ -41,7 +41,7 @@ namespace NadekoBot.Modules.Music _db = db; } - //todo changing server region is bugged again + //todo 50 changing server region is bugged again //private Task Client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState oldState, SocketVoiceState newState) //{ // var t = Task.Run(() => diff --git a/NadekoBot.Modules.Nsfw/NSFW.cs b/NadekoBot.Modules.Nsfw/NSFW.cs index e9ad919b..7cc4f4fc 100644 --- a/NadekoBot.Modules.Nsfw/NSFW.cs +++ b/NadekoBot.Modules.Nsfw/NSFW.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Threading.Tasks; using NadekoBot.Extensions; using System.Threading; -using System.Collections.Concurrent; using NadekoBot.Common; using NadekoBot.Common.Attributes; using NadekoBot.Common.Collections; @@ -19,11 +18,6 @@ namespace NadekoBot.Modules.NSFW // thanks to halitalf for adding autoboob and autobutt features :D public class NSFW : NadekoTopLevelModule { - //todo clear when module unloaded - private static readonly ConcurrentDictionary _autoHentaiTimers = new ConcurrentDictionary(); - private static readonly ConcurrentDictionary _autoBoobTimers = new ConcurrentDictionary(); - private static readonly ConcurrentDictionary _autoButtTimers = new ConcurrentDictionary(); - private static readonly ConcurrentHashSet _hentaiBombBlacklist = new ConcurrentHashSet(); private async Task InternalHentai(IMessageChannel channel, string tag, bool noError)