Merge pull request #55 from Kwoth/dev

Added some logging, slight changes and fixed music thumbnail
This commit is contained in:
samvaio 2016-12-29 19:19:24 +05:30 committed by GitHub
commit 2e6f42d7c5
7 changed files with 29 additions and 11 deletions

View File

@ -37,8 +37,6 @@ namespace NadekoBot.Modules.Administration
{ {
_log = LogManager.GetCurrentClassLogger(); _log = LogManager.GetCurrentClassLogger();
NadekoBot.CommandHandler.CommandExecuted += DelMsgOnCmd_Handler; NadekoBot.CommandHandler.CommandExecuted += DelMsgOnCmd_Handler;
} }
private static async Task DelMsgOnCmd_Handler(IUserMessage msg, Command cmd) private static async Task DelMsgOnCmd_Handler(IUserMessage msg, Command cmd)

View File

@ -12,6 +12,8 @@ using NadekoBot.Services.Database.Models;
using System.Linq; using System.Linq;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System.Threading; using System.Threading;
using System.Diagnostics;
using NLog;
namespace NadekoBot.Modules.ClashOfClans namespace NadekoBot.Modules.ClashOfClans
{ {
@ -22,8 +24,12 @@ namespace NadekoBot.Modules.ClashOfClans
private static Timer checkWarTimer { get; } private static Timer checkWarTimer { get; }
private static new readonly Logger _log;
static ClashOfClans() static ClashOfClans()
{ {
_log = LogManager.GetCurrentClassLogger();
var sw = Stopwatch.StartNew();
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
ClashWars = new ConcurrentDictionary<ulong, List<ClashWar>>( ClashWars = new ConcurrentDictionary<ulong, List<ClashWar>>(
@ -50,6 +56,9 @@ namespace NadekoBot.Modules.ClashOfClans
} }
} }
}, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1)); }, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
sw.Stop();
_log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s");
} }
private static async Task CheckWar(TimeSpan callExpire, ClashWar war) private static async Task CheckWar(TimeSpan callExpire, ClashWar war)

View File

@ -7,6 +7,8 @@ using System.Collections.Concurrent;
using NadekoBot.Services.Database.Models; using NadekoBot.Services.Database.Models;
using Discord; using Discord;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NLog;
using System.Diagnostics;
namespace NadekoBot.Modules.CustomReactions namespace NadekoBot.Modules.CustomReactions
{ {
@ -18,14 +20,20 @@ namespace NadekoBot.Modules.CustomReactions
public static ConcurrentDictionary<string, uint> ReactionStats { get; } = new ConcurrentDictionary<string, uint>(); public static ConcurrentDictionary<string, uint> ReactionStats { get; } = new ConcurrentDictionary<string, uint>();
private static new readonly Logger _log;
static CustomReactions() static CustomReactions()
{ {
_log = LogManager.GetCurrentClassLogger();
var sw = Stopwatch.StartNew();
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
var items = uow.CustomReactions.GetAll(); var items = uow.CustomReactions.GetAll();
GuildReactions = new ConcurrentDictionary<ulong, ConcurrentHashSet<CustomReaction>>(items.Where(g => g.GuildId != null && g.GuildId != 0).GroupBy(k => k.GuildId.Value).ToDictionary(g => g.Key, g => new ConcurrentHashSet<CustomReaction>(g))); GuildReactions = new ConcurrentDictionary<ulong, ConcurrentHashSet<CustomReaction>>(items.Where(g => g.GuildId != null && g.GuildId != 0).GroupBy(k => k.GuildId.Value).ToDictionary(g => g.Key, g => new ConcurrentHashSet<CustomReaction>(g)));
GlobalReactions = new ConcurrentHashSet<CustomReaction>(items.Where(g => g.GuildId == null || g.GuildId == 0)); GlobalReactions = new ConcurrentHashSet<CustomReaction>(items.Where(g => g.GuildId == null || g.GuildId == 0));
} }
sw.Stop();
_log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s");
} }
public CustomReactions() : base() public CustomReactions() : base()
{ {

View File

@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Gambling
public static string CurrencyPluralName { get; set; } public static string CurrencyPluralName { get; set; }
public static string CurrencySign { get; set; } public static string CurrencySign { get; set; }
public Gambling() : base() static Gambling()
{ {
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {

View File

@ -21,9 +21,7 @@ namespace NadekoBot.Modules.Games
} }
} }
} }
public Games() : base()
{
}
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]

View File

@ -22,6 +22,8 @@ namespace NadekoBot.Modules.Help
static Help() static Help()
{ {
//todo don't cache this, just query db when someone wants -h
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
var config = uow.BotConfig.GetOrCreate(); var config = uow.BotConfig.GetOrCreate();

View File

@ -91,15 +91,17 @@ namespace NadekoBot
internal Task LoginAsync(TokenType tokenType, string token) => internal Task LoginAsync(TokenType tokenType, string token) =>
Task.WhenAll(Clients.Select(async c => { await c.LoginAsync(tokenType, token).ConfigureAwait(false); _log.Info($"Shard #{c.ShardId} logged in."); })); Task.WhenAll(Clients.Select(async c => { await c.LoginAsync(tokenType, token).ConfigureAwait(false); _log.Info($"Shard #{c.ShardId} logged in."); }));
internal Task ConnectAsync() => internal async Task ConnectAsync()
Task.WhenAll(Clients.Select(async c => {
foreach (var c in Clients)
{ {
try try
{ {
var sw = Stopwatch.StartNew(); var sw = Stopwatch.StartNew();
await c.ConnectAsync().ConfigureAwait(false); await c.ConnectAsync().ConfigureAwait(false);
sw.Stop(); sw.Stop();
_log.Info($"Shard #{c.ShardId} connected after {sw.Elapsed.TotalSeconds}s ({++_connectedCount}/{Clients.Count})"); _log.Info($"Shard #{c.ShardId} connected after {sw.Elapsed.TotalSeconds:F2}s ({++_connectedCount}/{Clients.Count})");
} }
catch catch
{ {
@ -111,7 +113,8 @@ namespace NadekoBot
_log.Error(ex2); _log.Error(ex2);
} }
} }
})); }
}
internal Task DownloadAllUsersAsync() => internal Task DownloadAllUsersAsync() =>
Task.WhenAll(Clients.Select(async c => Task.WhenAll(Clients.Select(async c =>
@ -119,7 +122,7 @@ namespace NadekoBot
var sw = Stopwatch.StartNew(); var sw = Stopwatch.StartNew();
await c.DownloadAllUsersAsync().ConfigureAwait(false); await c.DownloadAllUsersAsync().ConfigureAwait(false);
sw.Stop(); sw.Stop();
_log.Info($"Shard #{c.ShardId} downloaded {c.GetGuilds().Sum(g => g.GetUsers().Count)} users after {sw.Elapsed.TotalSeconds}s ({++_downloadedCount}/{Clients.Count})."); _log.Info($"Shard #{c.ShardId} downloaded {c.GetGuilds().Sum(g => g.GetUsers().Count)} users after {sw.Elapsed.TotalSeconds:F2}s ({++_downloadedCount}/{Clients.Count}).");
})); }));
public async Task SetGame(string game) public async Task SetGame(string game)