diff --git a/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs b/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs index 7af6c403..da6fc766 100644 --- a/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs @@ -7,6 +7,7 @@ using NadekoBot.Services.Database.Models; using NLog; using System; using System.Collections.Concurrent; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; @@ -23,9 +24,11 @@ namespace NadekoBot.Modules.Administration static AutoAssignRoleCommands() { + _log = LogManager.GetCurrentClassLogger(); + var sw = Stopwatch.StartNew(); + AutoAssignedRoles = new ConcurrentDictionary(NadekoBot.AllGuildConfigs.Where(x => x.AutoAssignRoleId != 0) .ToDictionary(k => k.GuildId, v => v.AutoAssignRoleId)); - _log = LogManager.GetCurrentClassLogger(); NadekoBot.Client.UserJoined += async (user) => { try @@ -43,6 +46,9 @@ namespace NadekoBot.Modules.Administration } catch (Exception ex) { _log.Warn(ex); } }; + + sw.Stop(); + _log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s"); } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs b/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs index fac9949e..5b7e927f 100644 --- a/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/DMForwardCommands.cs @@ -3,7 +3,9 @@ using Discord.Commands; using NadekoBot.Attributes; using NadekoBot.Extensions; using NadekoBot.Services; +using NLog; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; @@ -16,9 +18,13 @@ namespace NadekoBot.Modules.Administration { private static bool ForwardDMs { get; set; } private static bool ForwardDMsToAllOwners { get; set; } + + private static readonly Logger _log; static DMForwardCommands() { + _log = LogManager.GetCurrentClassLogger(); + using (var uow = DbHandler.UnitOfWork()) { var config = uow.BotConfig.GetOrCreate(); diff --git a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs index ee1351f5..481f2f6e 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -11,6 +11,7 @@ using NLog; using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -37,6 +38,7 @@ namespace NadekoBot.Modules.Administration { _client = NadekoBot.Client; _log = LogManager.GetCurrentClassLogger(); + var sw = Stopwatch.StartNew(); using (var uow = DbHandler.UnitOfWork()) { @@ -62,6 +64,9 @@ namespace NadekoBot.Modules.Administration _log.Warn(ex); } }, null, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10)); + + sw.Stop(); + _log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s"); } public LogCommands() diff --git a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs index 1e051bcd..1bc8fdbe 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs @@ -8,6 +8,7 @@ using NadekoBot.Services.Database.Models; using NLog; using System; using System.Collections.Concurrent; +using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -79,10 +80,15 @@ namespace NadekoBot.Modules.Administration static RepeatCommands() { + var _log = LogManager.GetCurrentClassLogger(); + var sw = Stopwatch.StartNew(); using (var uow = DbHandler.UnitOfWork()) { repeaters = new ConcurrentDictionary(uow.Repeaters.GetAll().Select(r => new RepeatRunner(r)).Where(r => r != null).ToDictionary(r => r.Repeater.ChannelId)); } + + sw.Stop(); + _log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s"); } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs index d25ed363..e53934d6 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs @@ -6,9 +6,11 @@ using NadekoBot.Attributes; using NadekoBot.Extensions; using NadekoBot.Services; using NadekoBot.Services.Database.Models; +using NLog; using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -34,21 +36,25 @@ namespace NadekoBot.Modules.Administration All } - static MuteCommands() { - using (var uow = DbHandler.UnitOfWork()) - { - var configs = NadekoBot.AllGuildConfigs; - GuildMuteRoles = new ConcurrentDictionary(configs - .Where(c => !string.IsNullOrWhiteSpace(c.MuteRoleName)) - .ToDictionary(c => c.GuildId, c => c.MuteRoleName)); + static MuteCommands() + { + var _log = LogManager.GetCurrentClassLogger(); + var sw = Stopwatch.StartNew(); + + var configs = NadekoBot.AllGuildConfigs; + GuildMuteRoles = new ConcurrentDictionary(configs + .Where(c => !string.IsNullOrWhiteSpace(c.MuteRoleName)) + .ToDictionary(c => c.GuildId, c => c.MuteRoleName)); - MutedUsers = new ConcurrentDictionary>(configs.ToDictionary( - k => k.GuildId, - v => new ConcurrentHashSet(v.MutedUsers.Select(m => m.UserId)) - )); - } + MutedUsers = new ConcurrentDictionary>(configs.ToDictionary( + k => k.GuildId, + v => new ConcurrentHashSet(v.MutedUsers.Select(m => m.UserId)) + )); NadekoBot.Client.UserJoined += Client_UserJoined; + + sw.Stop(); + _log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s"); } private static async void Client_UserJoined(IGuildUser usr) diff --git a/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs b/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs index 2d8e7921..c0ea4ad6 100644 --- a/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs @@ -8,6 +8,7 @@ using NadekoBot.Services.Database.Models; using NLog; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; @@ -22,8 +23,11 @@ namespace NadekoBot.Modules.Administration public static List RotatingStatusMessages { get; } public static bool RotatingStatuses { get; private set; } = false; + //todo wtf is with this while(true) in constructor static PlayingRotateCommands() { + _log = LogManager.GetCurrentClassLogger(); + using (var uow = DbHandler.UnitOfWork()) { var conf = uow.BotConfig.GetOrCreate(); @@ -31,7 +35,6 @@ namespace NadekoBot.Modules.Administration RotatingStatuses = conf.RotatingStatuses; } - _log = LogManager.GetCurrentClassLogger(); var t = Task.Run(async () => { var index = 0; diff --git a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs index 7a8dc486..14dd4e30 100644 --- a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs @@ -4,8 +4,10 @@ using Discord.WebSocket; using NadekoBot.Attributes; using NadekoBot.Extensions; using NadekoBot.Services; +using NLog; using System; using System.Collections.Concurrent; +using System.Diagnostics; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -22,11 +24,16 @@ namespace NadekoBot.Modules.Administration private static ConcurrentHashSet voicePlusTextCache { get; } static VoicePlusTextCommands() { + var _log = LogManager.GetCurrentClassLogger(); + var sw = Stopwatch.StartNew(); using (var uow = DbHandler.UnitOfWork()) { voicePlusTextCache = new ConcurrentHashSet(NadekoBot.AllGuildConfigs.Where(g => g.VoicePlusTextEnabled).Select(g => g.GuildId)); } NadekoBot.Client.UserVoiceStateUpdated += UserUpdatedEventHandler; + + sw.Stop(); + _log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s"); } private static async void UserUpdatedEventHandler(IUser iuser, IVoiceState before, IVoiceState after) diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index f1ae8ad1..8c91ae77 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -10,6 +10,8 @@ using Discord.WebSocket; using NadekoBot.Services.Database.Models; using System.Collections.Generic; using NadekoBot.Services.Database; +using NLog; +using System.Diagnostics; namespace NadekoBot.Modules.Gambling { diff --git a/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs b/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs index 1cf7f92a..f0b99b3f 100644 --- a/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs @@ -7,6 +7,7 @@ using NLog; using Services.CleverBotApi; using System; using System.Collections.Concurrent; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; @@ -30,6 +31,7 @@ namespace NadekoBot.Modules.Games static CleverBotCommands() { _log = LogManager.GetCurrentClassLogger(); + var sw = Stopwatch.StartNew(); using (var uow = DbHandler.UnitOfWork()) { @@ -39,6 +41,9 @@ namespace NadekoBot.Modules.Games .Where(gc => gc.CleverbotEnabled) .ToDictionary(gc => gc.GuildId, gc => bot.CreateSession())); } + + sw.Stop(); + _log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s"); } public static async Task TryAsk(IUserMessage msg) { diff --git a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs index 1af1a4a7..31246d71 100644 --- a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs @@ -10,6 +10,7 @@ using NLog; using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Security.Cryptography; @@ -44,6 +45,8 @@ namespace NadekoBot.Modules.Games static PlantPickCommands() { _log = LogManager.GetCurrentClassLogger(); + var sw = Stopwatch.StartNew(); + NadekoBot.Client.MessageReceived += PotentialFlowerGeneration; using (var uow = DbHandler.UnitOfWork()) @@ -55,6 +58,9 @@ namespace NadekoBot.Modules.Games chance = conf.CurrencyGenerationChance; cooldown = conf.CurrencyGenerationCooldown; } + + sw.Stop(); + _log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s"); } private static async void PotentialFlowerGeneration(IMessage imsg) diff --git a/src/NadekoBot/Modules/NSFW/NSFW.cs b/src/NadekoBot/Modules/NSFW/NSFW.cs index 3cef9c13..2268393f 100644 --- a/src/NadekoBot/Modules/NSFW/NSFW.cs +++ b/src/NadekoBot/Modules/NSFW/NSFW.cs @@ -11,12 +11,17 @@ using System.Text.RegularExpressions; using System.Xml.Linq; using NadekoBot.Extensions; using System.Xml; +using System.Threading; +using System.Collections.Concurrent; namespace NadekoBot.Modules.NSFW { [NadekoModule("NSFW", "~")] public class NSFW : DiscordModule { + //ulong/cancel + private static ConcurrentDictionary AutoHentaiTimers { get; } = new ConcurrentDictionary(); + public NSFW() : base() { } @@ -54,7 +59,52 @@ namespace NadekoBot.Modules.NSFW if (string.IsNullOrWhiteSpace(link)) await channel.SendErrorAsync("No results found.").ConfigureAwait(false); else - await channel.SendMessageAsync(link).ConfigureAwait(false); + await channel.EmbedAsync(new EmbedBuilder().WithOkColor() + .WithImageUrl(link) + .WithDescription("Tag: " + tag) + .Build()).ConfigureAwait(false); + } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task AutoHentai(IUserMessage umsg, int interval = 0, string tags = null) + { + Timer t; + + if (interval == 0) + { + if (AutoHentaiTimers.TryRemove(umsg.Channel.Id, out t)) + { + t.Change(Timeout.Infinite, Timeout.Infinite); //proper way to disable the timer + await umsg.Channel.SendConfirmAsync("Autohentai stopped.").ConfigureAwait(false); + } + return; + } + + if (interval < 20) + return; + + var tagsArr = tags?.Split('|'); + + t = new Timer(async (state) => + { + try + { + if (tagsArr == null || tagsArr.Length == 0) + await Hentai(umsg, null).ConfigureAwait(false); + else + await Hentai(umsg, tagsArr[new NadekoRandom().Next(0, tagsArr.Length)]); + } + catch { } + }, null, interval * 1000, interval * 1000); + + AutoHentaiTimers.AddOrUpdate(umsg.Channel.Id, t, (key, old) => + { + old.Change(Timeout.Infinite, Timeout.Infinite); + return t; + }); + + await umsg.Channel.SendConfirmAsync($"Autohentai started. Reposting every {interval}s with one of the following tags:\n{string.Join(", ", tagsArr)}").ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Permissions/Permissions.cs b/src/NadekoBot/Modules/Permissions/Permissions.cs index d3de046c..d0db3176 100644 --- a/src/NadekoBot/Modules/Permissions/Permissions.cs +++ b/src/NadekoBot/Modules/Permissions/Permissions.cs @@ -8,6 +8,8 @@ using Discord; using NadekoBot.Services.Database.Models; using System.Collections.Concurrent; using NadekoBot.Extensions; +using NLog; +using System.Diagnostics; namespace NadekoBot.Modules.Permissions { @@ -26,6 +28,9 @@ namespace NadekoBot.Modules.Permissions static Permissions() { + var _log = LogManager.GetCurrentClassLogger(); + var sw = Stopwatch.StartNew(); + using (var uow = DbHandler.UnitOfWork()) { Cache = new ConcurrentDictionary(uow.GuildConfigs @@ -38,6 +43,9 @@ namespace NadekoBot.Modules.Permissions PermRole = v.PermissionRole })); } + + sw.Stop(); + _log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s"); } public Permissions() : base() diff --git a/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs b/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs index 3852786e..3ae4557c 100644 --- a/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs @@ -8,6 +8,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NLog; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Net.Http; @@ -27,6 +28,7 @@ namespace NadekoBot.Modules.Searches static JokeCommands() { _log = LogManager.GetCurrentClassLogger(); + if (File.Exists("data/wowjokes.json")) { wowJokes = JsonConvert.DeserializeObject>(File.ReadAllText("data/wowjokes.json")); diff --git a/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs b/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs index 3500ab83..4f50b9cf 100644 --- a/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs @@ -18,7 +18,7 @@ namespace NadekoBot.Modules.Searches [Group] public class OverwatchCommands { - private Logger _log; + private readonly Logger _log; public OverwatchCommands() { _log = LogManager.GetCurrentClassLogger(); diff --git a/src/NadekoBot/Modules/Searches/Commands/PokemonSearchCommands.cs b/src/NadekoBot/Modules/Searches/Commands/PokemonSearchCommands.cs index 36ead93d..578e96f1 100644 --- a/src/NadekoBot/Modules/Searches/Commands/PokemonSearchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/PokemonSearchCommands.cs @@ -6,6 +6,7 @@ using NadekoBot.Modules.Searches.Models; using Newtonsoft.Json; using NLog; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -28,6 +29,8 @@ namespace NadekoBot.Modules.Searches static PokemonSearchCommands() { _log = LogManager.GetCurrentClassLogger(); + var sw = Stopwatch.StartNew(); + if (File.Exists(PokemonListFile)) { pokemons = JsonConvert.DeserializeObject>(File.ReadAllText(PokemonListFile)); @@ -38,6 +41,9 @@ namespace NadekoBot.Modules.Searches pokemonAbilities = JsonConvert.DeserializeObject>(File.ReadAllText(PokemonAbilitiesFile)); else _log.Warn(PokemonAbilitiesFile + " is missing. Pokemon abilities not loaded."); + + sw.Stop(); + _log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s"); } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs index 8a09497e..8308e175 100644 --- a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs @@ -17,6 +17,7 @@ using Newtonsoft.Json; using NLog; using NadekoBot.Services.Database; using NadekoBot.Extensions; +using System.Diagnostics; namespace NadekoBot.Modules.Searches { @@ -78,8 +79,8 @@ namespace NadekoBot.Modules.Searches static StreamNotificationCommands() { + _log = LogManager.GetCurrentClassLogger(); - _log = NLog.LogManager.GetCurrentClassLogger(); checkTimer = new Timer(async (state) => { oldCachedStatuses = new ConcurrentDictionary(cachedStatuses); diff --git a/src/NadekoBot/Modules/Searches/Commands/Translator.cs b/src/NadekoBot/Modules/Searches/Commands/Translator.cs index fd6695df..f54bfb5d 100644 --- a/src/NadekoBot/Modules/Searches/Commands/Translator.cs +++ b/src/NadekoBot/Modules/Searches/Commands/Translator.cs @@ -20,14 +20,11 @@ namespace NadekoBot.Modules.Searches [Group] public class TranslateCommands { - private static ConcurrentDictionary TranslatedChannels { get; } - private static ConcurrentDictionary UserLanguages { get; } + private static ConcurrentDictionary TranslatedChannels { get; } = new ConcurrentDictionary(); + private static ConcurrentDictionary UserLanguages { get; } = new ConcurrentDictionary(); static TranslateCommands() { - TranslatedChannels = new ConcurrentDictionary(); - UserLanguages = new ConcurrentDictionary(); - NadekoBot.Client.MessageReceived += async (msg) => { try diff --git a/src/NadekoBot/Modules/Utility/Commands/UnitConversion.cs b/src/NadekoBot/Modules/Utility/Commands/UnitConversion.cs index 78874828..4ba6c05e 100644 --- a/src/NadekoBot/Modules/Utility/Commands/UnitConversion.cs +++ b/src/NadekoBot/Modules/Utility/Commands/UnitConversion.cs @@ -9,6 +9,7 @@ using Newtonsoft.Json; using NLog; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Net.Http; @@ -32,7 +33,6 @@ namespace NadekoBot.Modules.Utility static UnitConverterCommands() { _log = LogManager.GetCurrentClassLogger(); - try { var data = JsonConvert.DeserializeObject>(File.ReadAllText("data/units.json")).Select(u => new ConvertUnit() diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index f61b1b22..f935b872 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -599,6 +599,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to autohentai. + /// + public static string autohentai_cmd { + get { + return ResourceManager.GetString("autohentai_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Posts a hentai every X seconds with a random tag from the provided tags. Use `|` to separate tags. 20 seconds minimum. Provide no arguments to disable.. + /// + public static string autohentai_desc { + get { + return ResourceManager.GetString("autohentai_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}autohentai 30 yuri|tail|long_hair` or `{0}autohentai`. + /// + public static string autohentai_usage { + get { + return ResourceManager.GetString("autohentai_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to autoplay ap. /// diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 7ef0ff55..c799d127 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2844,4 +2844,13 @@ `{0}activity` + + autohentai + + + Posts a hentai every X seconds with a random tag from the provided tags. Use `|` to separate tags. 20 seconds minimum. Provide no arguments to disable. + + + `{0}autohentai 30 yuri|tail|long_hair` or `{0}autohentai` + \ No newline at end of file