Added some more unloads, upped version to 2.0

This commit is contained in:
Master Kwoth 2017-10-09 00:54:10 +02:00
parent 33ac43e1b5
commit 72f36270dc
6 changed files with 24 additions and 11 deletions

View File

@ -20,7 +20,7 @@ namespace NadekoBot.Services.Impl
private readonly IBotCredentials _creds; private readonly IBotCredentials _creds;
private readonly DateTime _started; 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 Author => "Kwoth#2560";
public string Library => "Discord.Net"; public string Library => "Discord.Net";

View File

@ -22,6 +22,7 @@ using NadekoBot.Common.TypeReaders.Models;
using NadekoBot.Services.Database; using NadekoBot.Services.Database;
using StackExchange.Redis; using StackExchange.Redis;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Runtime.Loader;
namespace NadekoBot namespace NadekoBot
{ {
@ -418,7 +419,7 @@ namespace NadekoBot
{ {
if (_packageModules.ContainsKey(name)) if (_packageModules.ContainsKey(name))
return false; return false;
var package = Assembly.LoadFile(Path.Combine(AppContext.BaseDirectory, var package = Assembly.LoadFile(Path.Combine(AppContext.BaseDirectory,
"modules", "modules",
$"NadekoBot.Modules.{name}", $"NadekoBot.Modules.{name}",

View File

@ -16,10 +16,11 @@ using Microsoft.EntityFrameworkCore;
using System.Net.Http; using System.Net.Http;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using AngleSharp; using AngleSharp;
using System.Threading;
namespace NadekoBot.Modules.Searches.Services namespace NadekoBot.Modules.Searches.Services
{ {
public class SearchesService : INService public class SearchesService : INService, IUnloadableService
{ {
public HttpClient Http { get; } public HttpClient Http { get; }
@ -41,6 +42,11 @@ namespace NadekoBot.Modules.Searches.Services
private readonly ConcurrentDictionary<ulong, SearchImageCacher> _imageCacher = new ConcurrentDictionary<ulong, SearchImageCacher>(); private readonly ConcurrentDictionary<ulong, SearchImageCacher> _imageCacher = new ConcurrentDictionary<ulong, SearchImageCacher>();
//todo clear when module unloaded
public ConcurrentDictionary<ulong, Timer> _autoHentaiTimers { get; } = new ConcurrentDictionary<ulong, Timer>();
public ConcurrentDictionary<ulong, Timer> _autoBoobTimers { get; } = new ConcurrentDictionary<ulong, Timer>();
public ConcurrentDictionary<ulong, Timer> _autoButtTimers { get; } = new ConcurrentDictionary<ulong, Timer>();
private readonly ConcurrentDictionary<ulong, HashSet<string>> _blacklistedTags = new ConcurrentDictionary<ulong, HashSet<string>>(); private readonly ConcurrentDictionary<ulong, HashSet<string>> _blacklistedTags = new ConcurrentDictionary<ulong, HashSet<string>>();
public SearchesService(DiscordSocketClient client, IGoogleApiService google, DbService db, IEnumerable<GuildConfig> gcs) public SearchesService(DiscordSocketClient client, IGoogleApiService google, DbService db, IEnumerable<GuildConfig> gcs)
@ -222,6 +228,19 @@ namespace NadekoBot.Modules.Searches.Services
var response = await Http.GetStringAsync("http://api.icndb.com/jokes/random/").ConfigureAwait(false); var response = await Http.GetStringAsync("http://api.icndb.com/jokes/random/").ConfigureAwait(false);
return JObject.Parse(response)["value"]["joke"].ToString() + " 😆"; 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 public struct UserChannelPair

View File

@ -12,7 +12,6 @@ namespace NadekoBot.Modules.Games
{ {
public partial class Games public partial class Games
{ {
//todo move games to service, unload
[Group] [Group]
public class TriviaCommands : NadekoSubmodule<GamesService> public class TriviaCommands : NadekoSubmodule<GamesService>
{ {

View File

@ -41,7 +41,7 @@ namespace NadekoBot.Modules.Music
_db = db; _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) //private Task Client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState oldState, SocketVoiceState newState)
//{ //{
// var t = Task.Run(() => // var t = Task.Run(() =>

View File

@ -6,7 +6,6 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System.Threading; using System.Threading;
using System.Collections.Concurrent;
using NadekoBot.Common; using NadekoBot.Common;
using NadekoBot.Common.Attributes; using NadekoBot.Common.Attributes;
using NadekoBot.Common.Collections; using NadekoBot.Common.Collections;
@ -19,11 +18,6 @@ namespace NadekoBot.Modules.NSFW
// thanks to halitalf for adding autoboob and autobutt features :D // thanks to halitalf for adding autoboob and autobutt features :D
public class NSFW : NadekoTopLevelModule<SearchesService> public class NSFW : NadekoTopLevelModule<SearchesService>
{ {
//todo clear when module unloaded
private static readonly ConcurrentDictionary<ulong, Timer> _autoHentaiTimers = new ConcurrentDictionary<ulong, Timer>();
private static readonly ConcurrentDictionary<ulong, Timer> _autoBoobTimers = new ConcurrentDictionary<ulong, Timer>();
private static readonly ConcurrentDictionary<ulong, Timer> _autoButtTimers = new ConcurrentDictionary<ulong, Timer>();
private static readonly ConcurrentHashSet<ulong> _hentaiBombBlacklist = new ConcurrentHashSet<ulong>(); private static readonly ConcurrentHashSet<ulong> _hentaiBombBlacklist = new ConcurrentHashSet<ulong>();
private async Task InternalHentai(IMessageChannel channel, string tag, bool noError) private async Task InternalHentai(IMessageChannel channel, string tag, bool noError)