diff --git a/NadekoBot/Classes/Extensions.cs b/NadekoBot/Classes/Extensions.cs index eae8e6a4..d38aee23 100644 --- a/NadekoBot/Classes/Extensions.cs +++ b/NadekoBot/Classes/Extensions.cs @@ -12,6 +12,8 @@ using NadekoBot.Classes; namespace NadekoBot.Extensions { public static class Extensions { + private static Random rng = new Random(); + public static string Scramble(this string word) { var letters = word.ToArray(); @@ -32,7 +34,7 @@ namespace NadekoBot.Extensions { } return "`"+string.Join(" ", letters)+"`"; } - public static string TrimTo(this string str, int num) { + public static string TrimTo(this string str, int num, bool hideDots = false) { if (num < 0) throw new ArgumentOutOfRangeException(nameof(num), "TrimTo argument cannot be less than 0"); if (num == 0) @@ -41,7 +43,7 @@ namespace NadekoBot.Extensions { return string.Join("", str.Select(c => '.')); if (str.Length < num) return str; - return string.Join("", str.Take(num - 3)) + "..."; + return string.Join("", str.Take(num - 3)) + (hideDots ? "" : "..."); } /// /// Removes trailing S or ES (if specified) on the given string if the num is 1 @@ -162,6 +164,11 @@ namespace NadekoBot.Extensions { /// public static string GetRuntime(this DiscordClient c) => ".Net Framework 4.5.2"; + public static string Matrix(this string s) + => + string.Join("", s.Select(c => c.ToString() + " ̵̢̬̜͉̞̭̖̰͋̉̎ͬ̔̇̌̀".TrimTo(rng.Next(0, 12), true))); + //.Replace("`", ""); + public static void ForEach(this IEnumerable source, Action action) { foreach (var element in source) { action(element); diff --git a/NadekoBot/Classes/JSONModels/Configuration.cs b/NadekoBot/Classes/JSONModels/Configuration.cs index 7c762cfd..3cd319e1 100644 --- a/NadekoBot/Classes/JSONModels/Configuration.cs +++ b/NadekoBot/Classes/JSONModels/Configuration.cs @@ -16,6 +16,13 @@ namespace NadekoBot.Classes.JSONModels { 143515953525817344 }; + public string[] DisguiseResponses { get; } = { + "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" + }; + public string[] CryResponses { get; } = { "http://i.imgur.com/Xg3i1Qy.gif", "http://i.imgur.com/3K8DRrU.gif", diff --git a/NadekoBot/Classes/Trivia/TriviaQuestion.cs b/NadekoBot/Classes/Trivia/TriviaQuestion.cs index 8e6888db..ab1dbf69 100644 --- a/NadekoBot/Classes/Trivia/TriviaQuestion.cs +++ b/NadekoBot/Classes/Trivia/TriviaQuestion.cs @@ -8,11 +8,10 @@ namespace NadekoBot.Classes.Trivia { public class TriviaQuestion { //represents the min size to judge levDistance with private static readonly HashSet> strictness = new HashSet> { - new Tuple(6, 0), - new Tuple(7, 1), - new Tuple(12, 2), - new Tuple(17, 3), - new Tuple(22, 4), + new Tuple(9, 0), + new Tuple(14, 1), + new Tuple(19, 2), + new Tuple(22, 3), }; public static int maxStringLength = 22; diff --git a/NadekoBot/Commands/LogCommand.cs b/NadekoBot/Commands/LogCommand.cs index 98cf93c9..b5415fb2 100644 --- a/NadekoBot/Commands/LogCommand.cs +++ b/NadekoBot/Commands/LogCommand.cs @@ -10,29 +10,10 @@ using NadekoBot.Classes.Permissions; namespace NadekoBot.Commands { internal class LogCommand : IDiscordCommand { - private class Repeater { - public readonly Timer MessageTimer = new Timer(); - public Channel ReChannel { get; set; } - public string ReMessage { get; set; } - - public Repeater() { - MessageTimer.Elapsed += async (s, e) => { - try { - var ch = ReChannel; - var msg = ReMessage; - if (ch != null && !string.IsNullOrWhiteSpace(msg)) - await ch.SendMessage(msg); - } catch { } - }; - } - } - private readonly ConcurrentDictionary logs = new ConcurrentDictionary(); private readonly ConcurrentDictionary loggingPresences = new ConcurrentDictionary(); private readonly ConcurrentDictionary voiceChannelLog = new ConcurrentDictionary(); - private readonly ConcurrentDictionary repeaters = new ConcurrentDictionary(); - public LogCommand() { NadekoBot.Client.MessageReceived += MsgRecivd; NadekoBot.Client.MessageDeleted += MsgDltd; @@ -139,44 +120,6 @@ namespace NadekoBot.Commands { } public void Init(CommandGroupBuilder cgb) { - cgb.CreateCommand(".repeat") - .Description("Repeat a message every X minutes. If no parameters are specified, repeat is disabled. Requires manage messages.") - .Parameter("minutes", ParameterType.Optional) - .Parameter("msg", ParameterType.Unparsed) - .AddCheck(SimpleCheckers.ManageMessages()) - .Do(async e => { - var minutesStr = e.GetArg("minutes"); - var msg = e.GetArg("msg"); - - // if both null, disable - if (string.IsNullOrWhiteSpace(msg) && string.IsNullOrWhiteSpace(minutesStr)) { - await e.Channel.SendMessage("Repeating disabled"); - Repeater rep; - if (repeaters.TryGetValue(e.Server, out rep)) - rep.MessageTimer.Stop(); - return; - } - int minutes; - if (!int.TryParse(minutesStr, out minutes) || minutes < 1 || minutes > 720) { - await e.Channel.SendMessage("Invalid value"); - return; - } - - var repeater = repeaters.GetOrAdd(e.Server, s => new Repeater()); - - repeater.ReChannel = e.Channel; - repeater.MessageTimer.Interval = minutes * 60 * 1000; - - if (!string.IsNullOrWhiteSpace(msg)) - repeater.ReMessage = msg; - - repeater.MessageTimer.Stop(); - repeater.MessageTimer.Start(); - - await e.Channel.SendMessage(String.Format("👌 Repeating `{0}` every " + - "**{1}** minutes on {2} channel.", - repeater.ReMessage, minutes, repeater.ReChannel)); - }); cgb.CreateCommand(".logserver") .Description("Toggles logging in this channel. Logs every message sent/deleted/edited on the server. BOT OWNER ONLY. SERVER OWNER ONLY.") diff --git a/NadekoBot/Commands/MessageRepeater.cs b/NadekoBot/Commands/MessageRepeater.cs new file mode 100644 index 00000000..1833cf97 --- /dev/null +++ b/NadekoBot/Commands/MessageRepeater.cs @@ -0,0 +1,89 @@ +using System; +using System.Timers; +using System.Collections.Concurrent; +using Discord; +using NadekoBot.Classes.Permissions; +using Discord.Commands; + +namespace NadekoBot.Commands { + class MessageRepeater : IDiscordCommand { + private readonly ConcurrentDictionary repeaters = new ConcurrentDictionary(); + private class Repeater { + [Newtonsoft.Json.JsonIgnore] + public readonly Timer MessageTimer; + [Newtonsoft.Json.JsonIgnore] + public Channel RepeatingChannel { get; } + + public ulong RepeatingServerId { get; set; } + public ulong RepeatingChannelId { get; set; } + public string RepeatingMessage { get; set; } + public int Interval { get; set; } + + private Repeater(int interval) { + this.Interval = interval; + MessageTimer = new Timer {Interval = Interval}; + MessageTimer.Elapsed += async (s, e) => { + var ch = RepeatingChannel; + var msg = RepeatingMessage; + if (ch != null && !string.IsNullOrWhiteSpace(msg)) { + try { + await ch.SendMessage(msg); + } catch { } + } + }; + } + + private Repeater(int interval, ulong channelId, ulong serverId) : this(interval) { + this.RepeatingChannelId = channelId; + this.RepeatingServerId = serverId; + } + + public Repeater(int interval, ulong channelId, ulong serverId, Channel channel) + : this(interval,channelId,serverId) { + this.RepeatingChannel = channel; + } + } + public void Init(CommandGroupBuilder cgb) { + + cgb.CreateCommand(".repeat") + .Description("Repeat a message every X minutes. If no parameters are specified, " + + "repeat is disabled. Requires manage messages.") + .Parameter("minutes", ParameterType.Optional) + .Parameter("msg", ParameterType.Unparsed) + .AddCheck(SimpleCheckers.ManageMessages()) + .Do(async e => { + var minutesStr = e.GetArg("minutes"); + var msg = e.GetArg("msg"); + + // if both null, disable + if (string.IsNullOrWhiteSpace(msg) && string.IsNullOrWhiteSpace(minutesStr)) { + await e.Channel.SendMessage("Repeating disabled"); + Repeater rep; + if (repeaters.TryGetValue(e.Server, out rep)) + rep.MessageTimer.Stop(); + return; + } + int minutes; + if (!int.TryParse(minutesStr, out minutes) || minutes < 1 || minutes > 720) { + await e.Channel.SendMessage("Invalid value"); + return; + } + + var repeater = repeaters.GetOrAdd( + e.Server, + s => new Repeater(minutes * 60 * 1000, e.Channel.Id, e.Server.Id, e.Channel) + ); + + if (!string.IsNullOrWhiteSpace(msg)) + repeater.RepeatingMessage = msg; + + repeater.MessageTimer.Stop(); + repeater.MessageTimer.Start(); + + await e.Channel.SendMessage(String.Format("👌 Repeating `{0}` every " + + "**{1}** minutes on {2} channel.", + repeater.RepeatingMessage, minutes, repeater.RepeatingChannel)); + }); + } + } +} diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs index 41fd1467..a0db1ef9 100644 --- a/NadekoBot/Modules/Administration.cs +++ b/NadekoBot/Modules/Administration.cs @@ -17,8 +17,9 @@ namespace NadekoBot.Modules { public Administration() { commands.Add(new ServerGreetCommand()); commands.Add(new LogCommand()); + commands.Add(new MessageRepeater()); commands.Add(new PlayingRotate()); - commands.Add(new Commands.RatelimitCommand()); + commands.Add(new RatelimitCommand()); } public override string Prefix { get; } = "."; @@ -392,6 +393,13 @@ namespace NadekoBot.Modules { .Do(async e => { await e.Channel.SendMessage(await NadekoStats.Instance.GetStats()); }); + + cgb.CreateCommand(Prefix + "dysyd") + .Description("Shows some basic stats for Nadeko.") + .Do(async e => { + await e.Channel.SendMessage((await NadekoStats.Instance.GetStats()).Matrix().TrimTo(1990)); + }); + cgb.CreateCommand(Prefix + "heap") .Description("Shows allocated memory - OWNER ONLY") .AddCheck(SimpleCheckers.OwnerOnly()) diff --git a/NadekoBot/Modules/Conversations.cs b/NadekoBot/Modules/Conversations.cs index 793e438b..3eedc2b4 100644 --- a/NadekoBot/Modules/Conversations.cs +++ b/NadekoBot/Modules/Conversations.cs @@ -190,6 +190,18 @@ namespace NadekoBot.Modules { } }); + cgb.CreateCommand("disguise") + .Description("Tell Nadeko to disguise herself.") + .Do(async e => { + try { + await + e.Channel.SendMessage( + $"{NadekoBot.Config.DisguiseResponses[rng.Next(0, NadekoBot.Config.DisguiseResponses.Length)]}"); + } catch { + await e.Channel.SendMessage("Error while handling DisguiseResponses check your data/config.json"); + } + }); + cgb.CreateCommand("are you real") .Description("Useless.") .Do(async e => { diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index 52959f2a..3210915f 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -121,7 +121,7 @@ namespace NadekoBot { modules.Add(new Conversations(), "Conversations", ModuleFilter.None); modules.Add(new Gambling(), "Gambling", ModuleFilter.None); modules.Add(new Games(), "Games", ModuleFilter.None); - modules.Add(new Music(), "Music", ModuleFilter.None); + //modules.Add(new Music(), "Music", ModuleFilter.None); modules.Add(new Searches(), "Searches", ModuleFilter.None); modules.Add(new NSFW(), "NSFW", ModuleFilter.None); if (!string.IsNullOrWhiteSpace(Creds.TrelloAppKey)) diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index 533bc20d..a3115583 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -144,6 +144,7 @@ + diff --git a/NadekoBot/bin/Debug/data/config_example.json b/NadekoBot/bin/Debug/data/config_example.json index 200d3bf3..e04fca5e 100644 --- a/NadekoBot/bin/Debug/data/config_example.json +++ b/NadekoBot/bin/Debug/data/config_example.json @@ -11,6 +11,12 @@ 119174277298782216, 143515953525817344 ], + "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",