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();

View File

@ -436,10 +436,19 @@
<value>listcustreact lcr</value>
</data>
<data name="listcustreact_desc" xml:space="preserve">
<value>Lists global or server custom reactions (15 commands per page). Running the command in DM will list global custom reactions, while running it in server will list that server's custom reactions.</value>
<value>Lists global or server custom reactions (20 commands per page). Running the command in DM will list global custom reactions, while running it in server will list that server's custom reactions. Specifying `all` argument instead of the number will DM you a text file with a list of all custom reactions.</value>
</data>
<data name="listcustreact_usage" xml:space="preserve">
<value>`{0}lcr 1`</value>
<value>`{0}lcr 1` or `{0}lcr all`</value>
</data>
<data name="listcustreactg_cmd" xml:space="preserve">
<value>listcustreactg lcrg</value>
</data>
<data name="listcustreactg_desc" xml:space="preserve">
<value>Lists global or server custom reactions (20 commands per page) grouped by trigger, and show a number of responses for each. Running the command in DM will list global custom reactions, while running it in server will list that server's custom reactions.</value>
</data>
<data name="listcustreactg_usage" xml:space="preserve">
<value>`{0}lcrg 1`</value>
</data>
<data name="showcustreact_cmd" xml:space="preserve">
<value>showcustreact scr</value>

View File

@ -1,6 +1,8 @@
using Discord;
using Discord.WebSocket;
using ImageProcessorCore;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
@ -287,6 +289,9 @@ namespace NadekoBot.Extensions
}
public static string ToJson<T>(this T any, Formatting formatting = Formatting.Indented) =>
JsonConvert.SerializeObject(any, formatting);
public static int KiB(this int value) => value * 1024;
public static int KB(this int value) => value * 1000;