parent
b41a78f674
commit
59eef96009
@ -2,6 +2,7 @@
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Classes;
|
||||
using NadekoBot.Modules.Permissions.Classes;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -45,14 +46,88 @@ namespace NadekoBot.Modules.Administration.Commands
|
||||
|
||||
cgb.CreateCommand(Prefix + "listcustreact")
|
||||
.Alias(Prefix + "lcr")
|
||||
.Description($"Lists all current custom reactions (paginated with 5 commands per page).\n**Usage**:{Prefix}lcr 1")
|
||||
.Description($"Lists all current custom reactions (paginated with 30 commands per page).\n**Usage**:{Prefix}lcr 1")
|
||||
.Parameter("num", ParameterType.Required)
|
||||
.Do(async e =>
|
||||
{
|
||||
int num;
|
||||
if (!int.TryParse(e.GetArg("num"), out num) || num <= 0) return;
|
||||
string result = GetCustomsOnPage(num - 1); //People prefer starting with 1
|
||||
await e.Channel.SendMessage(result).ConfigureAwait(false);
|
||||
if (!int.TryParse(e.GetArg("num"), out num) || num <= 0) num = 1;
|
||||
var cmds = GetCustomsOnPage(num - 1);
|
||||
if (!cmds.Any())
|
||||
{
|
||||
await e.Channel.SendMessage("");
|
||||
}
|
||||
else
|
||||
{
|
||||
string result = SearchHelper.ShowInPrettyCode<string>(cmds, s => $"{s,-25}"); //People prefer starting with 1
|
||||
await e.Channel.SendMessage($"`Showing page {num}:`\n" + result).ConfigureAwait(false);
|
||||
}
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "showcustreact")
|
||||
.Alias(Prefix + "scr")
|
||||
.Description($"Shows all possible responses from a single custom reaction.\n**Usage**:{Prefix}scr %mention% bb")
|
||||
.Parameter("name", ParameterType.Unparsed)
|
||||
.Do(async e =>
|
||||
{
|
||||
var name = e.GetArg("name")?.Trim();
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return;
|
||||
if (!NadekoBot.Config.CustomReactions.ContainsKey(name))
|
||||
{
|
||||
await e.Channel.SendMessage("`Can't find that custom reaction.`").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
var items = NadekoBot.Config.CustomReactions[name];
|
||||
var message = new StringBuilder($"Responses for {Format.Bold(name)}:\n");
|
||||
var last = items.Last();
|
||||
|
||||
int i = 1;
|
||||
foreach (var reaction in items)
|
||||
{
|
||||
message.AppendLine($"[{i++}] " + Format.Code(reaction));
|
||||
}
|
||||
await e.Channel.SendMessage(message.ToString());
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "editcustreact")
|
||||
.Alias(Prefix + "ecr")
|
||||
.Description("Edits a custom reaction, arguments are custom reactions name, index to change, and a (multiword) message | `.ecr \"%mention% disguise\" 2 Test 123`")
|
||||
.Parameter("name", ParameterType.Required)
|
||||
.Parameter("index", ParameterType.Required)
|
||||
.Parameter("message", ParameterType.Unparsed)
|
||||
.AddCheck(SimpleCheckers.OwnerOnly())
|
||||
.Do(async e =>
|
||||
{
|
||||
var name = e.GetArg("name")?.Trim();
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return;
|
||||
var indexstr = e.GetArg("index")?.Trim();
|
||||
if (string.IsNullOrWhiteSpace(indexstr))
|
||||
return;
|
||||
var msg = e.GetArg("message")?.Trim();
|
||||
if (string.IsNullOrWhiteSpace(msg))
|
||||
return;
|
||||
|
||||
|
||||
|
||||
if (!NadekoBot.Config.CustomReactions.ContainsKey(name))
|
||||
{
|
||||
await e.Channel.SendMessage("`Could not find given commandname`").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
int index;
|
||||
if (!int.TryParse(indexstr, out index) || index < 1 || index > NadekoBot.Config.CustomReactions[name].Count)
|
||||
{
|
||||
await e.Channel.SendMessage("`Invalid index.`").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
index = index - 1;
|
||||
NadekoBot.Config.CustomReactions[name][index] = msg;
|
||||
|
||||
await Task.Run(() => Classes.JSONModels.ConfigHandler.SaveConfig()).ConfigureAwait(false);
|
||||
await e.Channel.SendMessage($"Edited response #{index + 1} from `{name}`").ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "delcustreact")
|
||||
@ -99,19 +174,21 @@ namespace NadekoBot.Modules.Administration.Commands
|
||||
});
|
||||
}
|
||||
|
||||
private readonly int ItemsPerPage = 5;
|
||||
private readonly int ItemsPerPage = 30;
|
||||
|
||||
private string GetCustomsOnPage(int page)
|
||||
private IEnumerable<string> GetCustomsOnPage(int page)
|
||||
{
|
||||
var items = NadekoBot.Config.CustomReactions.Skip(page * ItemsPerPage).Take(ItemsPerPage);
|
||||
if (!items.Any())
|
||||
{
|
||||
return $"No items on page {page + 1}.";
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
return items.Select(kvp => kvp.Key);
|
||||
/*
|
||||
var message = new StringBuilder($"--- Custom reactions - page {page + 1} ---\n");
|
||||
foreach (var cr in items)
|
||||
{
|
||||
message.Append($"{ Format.Code(cr.Key)}\n");
|
||||
message.Append($"{Format.Code(cr.Key)}\n");
|
||||
int i = 1;
|
||||
var last = cr.Value.Last();
|
||||
foreach (var reaction in cr.Value)
|
||||
@ -123,6 +200,7 @@ namespace NadekoBot.Modules.Administration.Commands
|
||||
}
|
||||
}
|
||||
return message.ToString() + "\n";
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user