.lcr all and .lcrg added
This commit is contained in:
parent
25735a679f
commit
6b32a0321a
@ -11,6 +11,7 @@ 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 System.IO;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.CustomReactions
|
namespace NadekoBot.Modules.CustomReactions
|
||||||
{
|
{
|
||||||
@ -114,7 +115,8 @@ namespace NadekoBot.Modules.CustomReactions
|
|||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[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;
|
var channel = imsg.Channel as ITextChannel;
|
||||||
|
|
||||||
@ -129,7 +131,72 @@ namespace NadekoBot.Modules.CustomReactions
|
|||||||
if (customReactions == null || !customReactions.Any())
|
if (customReactions == null || !customReactions.Any())
|
||||||
await imsg.Channel.SendMessageAsync("`No custom reactions found`").ConfigureAwait(false);
|
await imsg.Channel.SendMessageAsync("`No custom reactions found`").ConfigureAwait(false);
|
||||||
else
|
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);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,10 +436,19 @@
|
|||||||
<value>listcustreact lcr</value>
|
<value>listcustreact lcr</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="listcustreact_desc" xml:space="preserve">
|
<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>
|
||||||
<data name="listcustreact_usage" xml:space="preserve">
|
<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>
|
||||||
<data name="showcustreact_cmd" xml:space="preserve">
|
<data name="showcustreact_cmd" xml:space="preserve">
|
||||||
<value>showcustreact scr</value>
|
<value>showcustreact scr</value>
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using ImageProcessorCore;
|
using ImageProcessorCore;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
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 KiB(this int value) => value * 1024;
|
||||||
public static int KB(this int value) => value * 1000;
|
public static int KB(this int value) => value * 1000;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user