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();
NadekoBot.CommandHandler.CommandExecuted += DelMsgOnCmd_Handler;
}
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 NadekoBot.Extensions;
using System.Threading;
using System.Diagnostics;
using NLog;
namespace NadekoBot.Modules.ClashOfClans
{
@ -22,8 +24,12 @@ namespace NadekoBot.Modules.ClashOfClans
private static Timer checkWarTimer { get; }
private static new readonly Logger _log;
static ClashOfClans()
{
_log = LogManager.GetCurrentClassLogger();
var sw = Stopwatch.StartNew();
using (var uow = DbHandler.UnitOfWork())
{
ClashWars = new ConcurrentDictionary<ulong, List<ClashWar>>(
@ -50,6 +56,9 @@ namespace NadekoBot.Modules.ClashOfClans
}
}
}, 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)

View File

@ -7,6 +7,8 @@ using System.Collections.Concurrent;
using NadekoBot.Services.Database.Models;
using Discord;
using NadekoBot.Extensions;
using NLog;
using System.Diagnostics;
namespace NadekoBot.Modules.CustomReactions
{
@ -18,14 +20,20 @@ namespace NadekoBot.Modules.CustomReactions
public static ConcurrentDictionary<string, uint> ReactionStats { get; } = new ConcurrentDictionary<string, uint>();
private static new readonly Logger _log;
static CustomReactions()
{
_log = LogManager.GetCurrentClassLogger();
var sw = Stopwatch.StartNew();
using (var uow = DbHandler.UnitOfWork())
{
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)));
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()
{

View File

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

View File

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

View File

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

View File

@ -91,15 +91,17 @@ namespace NadekoBot
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."); }));
internal Task ConnectAsync() =>
Task.WhenAll(Clients.Select(async c =>
internal async Task ConnectAsync()
{
foreach (var c in Clients)
{
try
{
var sw = Stopwatch.StartNew();
await c.ConnectAsync().ConfigureAwait(false);
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
{
@ -111,7 +113,8 @@ namespace NadekoBot
_log.Error(ex2);
}
}
}));
}
}
internal Task DownloadAllUsersAsync() =>
Task.WhenAll(Clients.Select(async c =>
@ -119,7 +122,7 @@ namespace NadekoBot
var sw = Stopwatch.StartNew();
await c.DownloadAllUsersAsync().ConfigureAwait(false);
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)