Merge pull request #40 from Kwoth/dev

Ups
This commit is contained in:
samvaio 2016-12-16 05:20:52 +05:30 committed by GitHub
commit 9642a24fc9
6 changed files with 33 additions and 14 deletions

View File

@ -221,7 +221,7 @@ namespace NadekoBot.Modules.Gambling
{ {
var channel = (ITextChannel)umsg.Channel; var channel = (ITextChannel)umsg.Channel;
IEnumerable<Currency> richest; IEnumerable<Currency> richest = new List<Currency>();
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
richest = uow.Currency.GetTopRichest(10); richest = uow.Currency.GetTopRichest(10);
@ -235,7 +235,7 @@ $@"```xl
Id $$$ Id $$$
"), "),
(cur, cs) => cur.AppendLine($@"┣━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━┫ (cur, cs) => cur.AppendLine($@"┣━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━┫
{(channel.Guild.GetUser(cs.UserId)?.Username.TrimTo(18, true) ?? cs.UserId.ToString()),-20} {cs.Amount,6} ") {(channel.Guild.GetUser(cs.UserId)?.Username?.TrimTo(18, true) ?? cs.UserId.ToString()),-20} {cs.Amount,6} ")
).ToString() + "┗━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━┛```").ConfigureAwait(false); ).ToString() + "┗━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━┛```").ConfigureAwait(false);
} }
} }

View File

@ -112,16 +112,16 @@ namespace NadekoBot.Modules.Music
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Pause(IUserMessage umsg) public Task Pause(IUserMessage umsg)
{ {
var channel = (ITextChannel)umsg.Channel; var channel = (ITextChannel)umsg.Channel;
MusicPlayer musicPlayer; MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return; if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return Task.CompletedTask;
if (((IGuildUser)umsg.Author).VoiceChannel != musicPlayer.PlaybackVoiceChannel) if (((IGuildUser)umsg.Author).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
return; return Task.CompletedTask;
musicPlayer.TogglePause(); musicPlayer.TogglePause();
return Task.CompletedTask;
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -27,7 +27,7 @@ namespace NadekoBot.Modules.Utility
IEnumerable<Quote> quotes; IEnumerable<Quote> quotes;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
quotes = uow.Quotes.GetGroup(page * 16, 16); quotes = uow.Quotes.GetGroup(channel.Guild.Id, page * 16, 16);
} }
if (quotes.Any()) if (quotes.Any())

View File

@ -8,6 +8,6 @@ namespace NadekoBot.Services.Database.Repositories
{ {
IEnumerable<Quote> GetAllQuotesByKeyword(ulong guildId, string keyword); IEnumerable<Quote> GetAllQuotesByKeyword(ulong guildId, string keyword);
Task<Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string keyword); Task<Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string keyword);
IEnumerable<Quote> GetGroup(int skip, int take); IEnumerable<Quote> GetGroup(ulong guildId, int skip, int take);
} }
} }

View File

@ -15,8 +15,8 @@ namespace NadekoBot.Services.Database.Repositories.Impl
public IEnumerable<Quote> GetAllQuotesByKeyword(ulong guildId, string keyword) => public IEnumerable<Quote> GetAllQuotesByKeyword(ulong guildId, string keyword) =>
_set.Where(q => q.GuildId == guildId && q.Keyword == keyword); _set.Where(q => q.GuildId == guildId && q.Keyword == keyword);
public IEnumerable<Quote> GetGroup(int skip, int take) => public IEnumerable<Quote> GetGroup(ulong guildId, int skip, int take) =>
_set.OrderBy(q => q.Keyword).Skip(skip).Take(take).ToList(); _set.Where(q=>q.GuildId == guildId).OrderBy(q => q.Keyword).Skip(skip).Take(take).ToList();
public Task<Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string keyword) public Task<Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string keyword)
{ {

View File

@ -79,13 +79,32 @@ namespace NadekoBot
Clients[0].GetDMChannelAsync(channelId); Clients[0].GetDMChannelAsync(channelId);
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); _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 => { await c.ConnectAsync(); _log.Info($"Shard #{c.ShardId} connected."); })); {
foreach (var c in Clients)
{
try
{
await c.ConnectAsync().ConfigureAwait(false);
_log.Info($"Shard #{c.ShardId} connected.");
}
catch
{
_log.Error($"Shard #{c.ShardId} FAILED CONNECTING.");
try { await c.ConnectAsync().ConfigureAwait(false); }
catch (Exception ex2)
{
_log.Error($"Shard #{c.ShardId} FAILED CONNECTING TWICE.");
_log.Error(ex2);
}
}
}
}
internal Task DownloadAllUsersAsync() => internal Task DownloadAllUsersAsync() =>
Task.WhenAll(Clients.Select(async c => { await c.DownloadAllUsersAsync(); _log.Info($"Shard #{c.ShardId} downloaded {c.GetGuilds().Sum(g => g.GetUsers().Count)} users."); })); Task.WhenAll(Clients.Select(async c => { await c.DownloadAllUsersAsync().ConfigureAwait(false); _log.Info($"Shard #{c.ShardId} downloaded {c.GetGuilds().Sum(g => g.GetUsers().Count)} users."); }));
public async Task SetGame(string game) public async Task SetGame(string game)
{ {