Merge remote-tracking branch 'upstream/1.0' into 1.0

This commit is contained in:
fkndean
2016-11-14 05:19:58 -05:00
6 changed files with 160 additions and 77 deletions

View File

@@ -11,6 +11,7 @@ using System.Collections.Concurrent;
using NadekoBot.Services.Database.Models;
using Discord;
using NadekoBot.Extensions;
using System.IO;
namespace NadekoBot.Modules.CustomReactions
{
@@ -114,7 +115,8 @@ namespace NadekoBot.Modules.CustomReactions
}
[NadekoCommand, Usage, Description, Aliases]
public async Task ListCustReact(IUserMessage imsg,int page = 1)
[Priority(0)]
public async Task ListCustReact(IUserMessage imsg, int page = 1)
{
var channel = imsg.Channel as ITextChannel;
@@ -129,7 +131,72 @@ namespace NadekoBot.Modules.CustomReactions
if (customReactions == null || !customReactions.Any())
await imsg.Channel.SendMessageAsync("`No custom reactions found`").ConfigureAwait(false);
else
await imsg.Channel.SendMessageAsync($"`Page {page} of custom reactions:`\n" + string.Join("\n", customReactions.OrderBy(cr => cr.Trigger).Skip((page - 1) * 15).Take(15).Select(cr => $"`#{cr.Id}` `Trigger:` {cr.Trigger}")))
await imsg.Channel.SendMessageAsync(
$"`Page {page} of custom reactions:`\n" +
string.Join("\n", customReactions
.OrderBy(cr => cr.Trigger)
.Skip((page - 1) * 20)
.Take(20)
.Select(cr => $"`#{cr.Id}` `Trigger:` {cr.Trigger}")))
.ConfigureAwait(false);
}
public enum All
{
All
}
[NadekoCommand, Usage, Description, Aliases]
[Priority(1)]
public async Task ListCustReact(IUserMessage imsg, All x)
{
var channel = imsg.Channel as ITextChannel;
ConcurrentHashSet<CustomReaction> customReactions;
if (channel == null)
customReactions = GlobalReactions;
else
customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>());
if (customReactions == null || !customReactions.Any())
await imsg.Channel.SendMessageAsync("`No custom reactions found`").ConfigureAwait(false);
else
{
var txtStream = await customReactions.GroupBy(cr => cr.Trigger)
.OrderBy(cr => cr.Key)
.Select(cr => new { Trigger = cr.Key, Responses = cr.Count() })
.ToJson()
.ToStream()
.ConfigureAwait(false);
if (channel == null) // its a private one, just send back
await imsg.Channel.SendFileAsync(txtStream, "customreactions.txt", "List of all custom reactions").ConfigureAwait(false);
else
await ((IGuildUser)imsg.Author).SendFileAsync(txtStream, "customreactions.txt", "List of all custom reactions").ConfigureAwait(false);
}
}
[NadekoCommand, Usage, Description, Aliases]
public async Task ListCustReactG(IUserMessage imsg, int page = 1)
{
var channel = (ITextChannel)imsg.Channel;
if (page < 1 || page > 10000)
return;
ConcurrentHashSet<CustomReaction> customReactions;
if (channel == null)
customReactions = GlobalReactions;
else
customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>());
if (customReactions == null || !customReactions.Any())
await imsg.Channel.SendMessageAsync("`No custom reactions found`").ConfigureAwait(false);
else
await imsg.Channel.SendMessageAsync($"{imsg.Author.Mention}\n`Page {page} of custom reactions (grouped):`\n" +
string.Join("\r\n", customReactions
.GroupBy(cr=>cr.Trigger)
.OrderBy(cr => cr.Key)
.Skip((page - 1) * 20)
.Take(20)
.Select(cr => $"**{cr.Key.Trim().ToLowerInvariant()}** `x{cr.Count()}`")))
.ConfigureAwait(false);
}

View File

@@ -41,7 +41,7 @@ namespace NadekoBot.Modules.Gambling
role = role ?? channel.Guild.EveryoneRole;
var members = role.Members().Where(u => u.Status == UserStatus.Online);
var members = role.Members().Where(u => u.Status != UserStatus.Offline && u.Status != UserStatus.Unknown);
var membersArray = members as IUser[] ?? members.ToArray();
var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)];
await channel.SendMessageAsync($"**Raffled user:** {usr.Username} (id: {usr.Id})").ConfigureAwait(false);

View File

@@ -337,7 +337,7 @@ namespace NadekoBot.Modules.Music.Classes
var allVideos = await Task.Run(async () => { try { return await YouTube.Default.GetAllVideosAsync(link).ConfigureAwait(false); } catch { return Enumerable.Empty<YouTubeVideo>(); } }).ConfigureAwait(false);
var videos = allVideos.Where(v => v.AdaptiveKind == AdaptiveKind.Audio);
var video = videos
.Where(v => v.AudioBitrate < 192)
.Where(v => v.AudioBitrate < 256)
.OrderByDescending(v => v.AudioBitrate)
.FirstOrDefault();