Implement suggestions

This commit is contained in:
appelemac 2016-05-04 15:18:39 +02:00
parent f3ee5042b7
commit 1bd3e7481c
5 changed files with 202 additions and 141 deletions

View File

@ -851,6 +851,103 @@ namespace NadekoBot.Modules.Administration
await e.Channel.SendMessage(":ok:");
});
cgb.CreateCommand(Prefix + "addcustomreaction")
.Alias(Prefix + "acr")
.Description($"Add a custom reaction. **Owner Only!**\n**Usage**: {Prefix}acr \"hello\" I love saying hello to %user%")
.AddCheck(SimpleCheckers.OwnerOnly())
.Parameter("name", ParameterType.Required)
.Parameter("message", ParameterType.Unparsed)
.Do(async e =>
{
var name = e.GetArg("name");
var message = e.GetArg("message").Trim();
if (string.IsNullOrWhiteSpace(message))
{
await e.Channel.SendMessage($"Incorrect command usage. See -h {Prefix}acr for correct formatting").ConfigureAwait(false);
return;
}
try
{
NadekoBot.Config.CustomReactions[name].Add(message);
}
catch (System.Collections.Generic.KeyNotFoundException)
{
NadekoBot.Config.CustomReactions.Add(name, new System.Collections.Generic.List<string>() { message });
}
finally
{
Classes.JSONModels.ConfigHandler.SaveConfig();
}
await e.Channel.SendMessage($"Added {name} : {message}").ConfigureAwait(false);
});
cgb.CreateCommand(Prefix + "listcustomreactions")
.Alias(Prefix + "lcr")
.Description("Lists all current custom reactions. **Owner Only!**")
.AddCheck(SimpleCheckers.OwnerOnly())
.Do(async e =>
{
string message = $"Custom reactions:";
foreach (var cr in NadekoBot.Config.CustomReactions)
{
if (message.Length > 1500)
{
await e.Channel.SendMessage(message).ConfigureAwait(false);
message = "";
}
message += $"\n**\"{Format.Escape(cr.Key)}\"**:";
int i = 1;
foreach (var reaction in cr.Value)
{
message += "\n " + i++ + "." + Format.Code(reaction);
}
}
await e.Channel.SendMessage(message);
});
cgb.CreateCommand(Prefix + "deletecustomreaction")
.Alias(Prefix + "dcr")
.Description("Deletes a custome reaction with given name (and index)")
.Parameter("name", ParameterType.Required)
.Parameter("index", ParameterType.Optional)
.Do(async e =>
{
var name = e.GetArg("name");
if (!NadekoBot.Config.CustomReactions.ContainsKey(name))
{
await e.Channel.SendMessage("Could not find given key");
return;
}
string message = "";
int index;
if (int.TryParse(e.GetArg("index") ?? "", out index))
{
try
{
NadekoBot.Config.CustomReactions[name].RemoveAt(index - 1);
if (!NadekoBot.Config.CustomReactions[name].Any())
{
NadekoBot.Config.CustomReactions.Remove(name);
}
message = $"Deleted response #{index} from {name}";
}
catch (ArgumentOutOfRangeException)
{
await e.Channel.SendMessage("Index given was out of range").ConfigureAwait(false);
return;
}
}
else
{
NadekoBot.Config.CustomReactions.Remove(name);
message = $"Deleted custom reaction \"{name}\"";
}
Classes.JSONModels.ConfigHandler.SaveConfig();
await e.Channel.SendMessage(message);
});
});
}

View File

@ -286,6 +286,20 @@ namespace NadekoBot.Modules.Conversations
.ConfigureAwait(false);
});
cgb.CreateCommand("ab")
.Description("Try to get 'abalabahaha'")
.Do(async e =>
{
string[] strings = { "ba", "la", "ha" };
var construct = "@a";
var cnt = rng.Next(4, 7);
while (cnt-- > 0)
{
construct += strings[rng.Next(0, strings.Length)];
}
await e.Channel.SendMessage(construct).ConfigureAwait(false);
});
cgb.CreateCommand("av").Alias("avatar")
.Parameter("mention", ParameterType.Required)
.Description("Shows a mentioned person's avatar.\n**Usage**: ~av @X")

View File

@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord.Modules;
using Discord.Commands;
using NadekoBot.Modules.Permissions.Classes;
using Discord;
using NadekoBot.Extensions;
namespace NadekoBot.Modules.CustomReactions
{
@ -21,6 +19,19 @@ namespace NadekoBot.Modules.CustomReactions
{
cgb.AddCheck(PermissionChecker.Instance);
Random range = new Random();
Dictionary<string, Func<CommandEventArgs, string>> MyFuncs = new Dictionary<string, Func<CommandEventArgs, string>>
{
{"%rng%", (e) => range.Next().ToString()},
{"%mention%", (e) => NadekoBot.BotMention },
{"%user%", e => e.User.Mention },
{"%target%", e =>
{
var arg = e.GetArg("args");
return string.IsNullOrWhiteSpace(arg) ? "" : arg;
} }
};
foreach (var command in NadekoBot.Config.CustomReactions)
{
@ -31,8 +42,8 @@ namespace NadekoBot.Modules.CustomReactions
c.Parameter("args", ParameterType.Unparsed);
c.Do(async e =>
{
Random range = new Random();
var ownerMentioned = e.Message.MentionedUsers.Where(x =>/* x != e.User &&*/ NadekoBot.IsOwner(x.Id));
var ownerMentioned = e.Message.MentionedUsers.Where(x =>NadekoBot.IsOwner(x.Id));
var ownerReactions = command.Value.Where(x => x.Contains("%owner%")).ToList();
string str;
@ -50,116 +61,12 @@ namespace NadekoBot.Modules.CustomReactions
{
str = command.Value[range.Next(0, command.Value.Count())];
}
str = str.Replace("%user%", e.User.Mention);
str = str.Replace("%rng%", "" + range.Next());
if (str.Contains("%target%"))
{
var args = e.GetArg("args");
if (string.IsNullOrWhiteSpace(args)) args = string.Empty;
str = str.Replace("%target%", e.GetArg("args"));
}
MyFuncs.Keys.ForEach(k => str = str.Replace(k, MyFuncs[k](e)));
await e.Channel.SendMessage(str).ConfigureAwait(false);
});
}
cgb.CreateCommand("addcustomreaction")
.Alias("acr")
.Description($"Add a custom reaction. **Owner Only!**\n**Usage**: {Prefix}acr \"hello\" I love saying hello to %user%")
.AddCheck(SimpleCheckers.OwnerOnly())
.Parameter("name", ParameterType.Required)
.Parameter("message", ParameterType.Unparsed)
.Do(async e =>
{
var name = e.GetArg("name");
var message = e.GetArg("message").Trim();
if (string.IsNullOrWhiteSpace(message))
{
await e.Channel.SendMessage($"Incorrect command usage. See -h {Prefix}acr for correct formatting").ConfigureAwait(false);
return;
}
try
{
NadekoBot.Config.CustomReactions[name].Add(message);
}
catch (System.Collections.Generic.KeyNotFoundException)
{
NadekoBot.Config.CustomReactions.Add(name, new System.Collections.Generic.List<string>() { message });
}
finally
{
Classes.JSONModels.ConfigHandler.SaveConfig();
}
await e.Channel.SendMessage($"Added {name} : {message}").ConfigureAwait(false);
});
cgb.CreateCommand("listcustomreactions")
.Alias("lcr")
.Description("Lists all current custom reactions. **Owner Only!**")
.AddCheck(SimpleCheckers.OwnerOnly())
.Do(async e =>
{
string message = $"Custom reactions:";
foreach (var cr in NadekoBot.Config.CustomReactions)
{
if (message.Length > 1500)
{
await e.Channel.SendMessage(message).ConfigureAwait(false);
message = "";
}
message += $"\n**\"{Format.Escape(cr.Key)}\"**:";
int i = 1;
foreach (var reaction in cr.Value)
{
message += "\n " + i++ + "." + Format.Code(reaction);
}
}
await e.Channel.SendMessage(message);
});
cgb.CreateCommand("deletecustomreaction")
.Alias("dcr")
.Description("Deletes a custome reaction with given name (and index)")
.Parameter("name", ParameterType.Required)
.Parameter("index", ParameterType.Optional)
.Do(async e =>
{
var name = e.GetArg("name");
if (!NadekoBot.Config.CustomReactions.ContainsKey(name))
{
await e.Channel.SendMessage("Could not find given key");
return;
}
string message = "";
int index;
if (int.TryParse(e.GetArg("index") ?? "", out index))
{
try
{
NadekoBot.Config.CustomReactions[name].RemoveAt(index - 1);
if (!NadekoBot.Config.CustomReactions[name].Any())
{
NadekoBot.Config.CustomReactions.Remove(name);
}
message = $"Deleted response #{index} from {name}";
}
catch (ArgumentOutOfRangeException)
{
await e.Channel.SendMessage("Index given was out of range").ConfigureAwait(false);
return;
}
}
else
{
NadekoBot.Config.CustomReactions.Remove(name);
message = $"Deleted custom reaction \"{name}\"";
}
Classes.JSONModels.ConfigHandler.SaveConfig();
await e.Channel.SendMessage(message);
});
});
}
}

View File

@ -88,11 +88,6 @@ namespace NadekoBot.Classes.JSONModels
"https://cdn.discordapp.com/attachments/140007341880901632/156721724430352385/okawari_01_haruka_weird_mask.jpg",
"https://cdn.discordapp.com/attachments/140007341880901632/156721728763068417/mustache-best-girl.png"
} },
{"%mention% ab", new List<string>()
{
"abalabahaha",
//Some other varistions, I'm too lazy to add them
} }
};

View File

@ -2,6 +2,77 @@
"DontJoinServers": false,
"ForwardMessages": true,
"IsRotatingStatus": false,
"CustomReactions": {
"\\o\\": [
"/o/"
],
"/o/": [
"\\o\\"
],
"moveto": [
"(👉 ͡° ͜ʖ ͡°)👉 %target%"
],
"comeatmebro": [
"%target% (ง’̀-‘́)ง"
],
"e": [
"%user% did it 😒 🔫",
"%target% did it 😒 🔫"
],
"%mention% insult": [
"I would never insult %owner%, my beloved master.",
"%target% You are a poop.",
"%target% You're a jerk.",
"%target% I will eat you when I get my powers back."
],
"%mention% praise": [
"I don't need your permission to praise %owner%, my beloved master",
"%target% You are cool.",
"%target% You are nice!",
"%target% You did a good job.",
"%target% You did something nice.",
"%target% is awesome!",
"%target% Wow."
],
"%mention% pat": [
"http://i.imgur.com/IiQwK12.gif",
"http://i.imgur.com/JCXj8yD.gif",
"http://i.imgur.com/qqBl2bm.gif",
"http://i.imgur.com/eOJlnwP.gif",
"https://45.media.tumblr.com/229ec0458891c4dcd847545c81e760a5/tumblr_mpfy232F4j1rxrpjzo1_r2_500.gif",
"https://media.giphy.com/media/KZQlfylo73AMU/giphy.gif",
"https://media.giphy.com/media/12hvLuZ7uzvCvK/giphy.gif",
"http://gallery1.anivide.com/_full/65030_1382582341.gif",
"https://49.media.tumblr.com/8e8a099c4eba22abd3ec0f70fd087cce/tumblr_nxovj9oY861ur1mffo1_500.gif "
],
"%mention% cry": [
"http://i.imgur.com/Xg3i1Qy.gif",
"http://i.imgur.com/3K8DRrU.gif",
"http://i.imgur.com/k58BcAv.gif",
"http://i.imgur.com/I2fLXwo.gif"
],
"%mention% are you real?": [
"%user%, I will be soon."
],
"%mention% are you there?": [
"Yes. :)"
],
"%mention% draw": [
"Sorry, I don't gamble, type $draw for that function."
],
"%mention% bb": [
"Bye %target%"
],
"%mention% call": [
"Calling %target%"
],
"%mention% disguise": [
"https://cdn.discordapp.com/attachments/140007341880901632/156721710458994690/Cc5mixjUYAADgBs.jpg",
"https://cdn.discordapp.com/attachments/140007341880901632/156721715831898113/hqdefault.jpg",
"https://cdn.discordapp.com/attachments/140007341880901632/156721724430352385/okawari_01_haruka_weird_mask.jpg",
"https://cdn.discordapp.com/attachments/140007341880901632/156721728763068417/mustache-best-girl.png"
]
},
"RotatingStatuses": [],
"CommandPrefixes": {
"Administration": ".",
@ -48,29 +119,6 @@
"Definitely no",
"NO - It may cause disease contraction"
],
"DisguiseResponses": [
"https://cdn.discordapp.com/attachments/140007341880901632/156721710458994690/Cc5mixjUYAADgBs.jpg",
"https://cdn.discordapp.com/attachments/140007341880901632/156721715831898113/hqdefault.jpg",
"https://cdn.discordapp.com/attachments/140007341880901632/156721724430352385/okawari_01_haruka_weird_mask.jpg",
"https://cdn.discordapp.com/attachments/140007341880901632/156721728763068417/mustache-best-girl.png"
],
"CryResponses": [
"http://i.imgur.com/Xg3i1Qy.gif",
"http://i.imgur.com/3K8DRrU.gif",
"http://i.imgur.com/k58BcAv.gif",
"http://i.imgur.com/I2fLXwo.gif"
],
"PatResponses": [
"http://i.imgur.com/IiQwK12.gif",
"http://i.imgur.com/JCXj8yD.gif",
"http://i.imgur.com/qqBl2bm.gif",
"http://i.imgur.com/eOJlnwP.gif",
"https://45.media.tumblr.com/229ec0458891c4dcd847545c81e760a5/tumblr_mpfy232F4j1rxrpjzo1_r2_500.gif",
"https://media.giphy.com/media/KZQlfylo73AMU/giphy.gif",
"https://media.giphy.com/media/12hvLuZ7uzvCvK/giphy.gif",
"http://gallery1.anivide.com/_full/65030_1382582341.gif",
"https://49.media.tumblr.com/8e8a099c4eba22abd3ec0f70fd087cce/tumblr_nxovj9oY861ur1mffo1_500.gif "
],
"CurrencySign": "🌸",
"CurrencyName": "NadekoFlower",
"DMHelpString": "Type `-h` for help."