From fdfb6b9340544d927dc0c4f02519df3d37843b2c Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 11 May 2016 07:20:43 +0200 Subject: [PATCH] added .remindmsg for custom remind message formatting. --- .../Modules/Administration/Commands/Remind.cs | 31 +++++++++++++++++-- NadekoBot/_Models/JSONModels/Configuration.cs | 2 ++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/NadekoBot/Modules/Administration/Commands/Remind.cs b/NadekoBot/Modules/Administration/Commands/Remind.cs index 51741198..667ef82b 100644 --- a/NadekoBot/Modules/Administration/Commands/Remind.cs +++ b/NadekoBot/Modules/Administration/Commands/Remind.cs @@ -2,6 +2,7 @@ using Discord.Commands; using NadekoBot.Classes; using NadekoBot.DataModels; +using NadekoBot.Modules.Permissions.Classes; using System; using System.Collections.Generic; using System.Linq; @@ -18,6 +19,13 @@ namespace NadekoBot.Modules.Administration.Commands List reminders = new List(); + IDictionary> replacements = new Dictionary> + { + { "%message%" , (r) => r.Message }, + { "%user%", (r) => $"<@!{r.UserId}>" }, + { "%target%", (r) => r.IsPrivate ? "Direct Message" : $"<#{r.ChannelId}>"} + }; + public Remind(DiscordModule module) : base(module) { var remList = DbHandler.Instance.GetAllRows(); @@ -53,7 +61,11 @@ namespace NadekoBot.Modules.Administration.Commands if (ch == null) return; - await ch.SendMessage($"❗⏰**I've been told to remind you to '{r.Message}' now by <@{r.UserId}>.**⏰❗").ConfigureAwait(false); + await ch.SendMessage( + replacements.Aggregate(NadekoBot.Config.RemindMessageFormat, + (cur, replace) => cur.Replace(replace.Key, replace.Value(r))) + ).ConfigureAwait(false); //it works trust me + } catch (Exception ex) { @@ -163,7 +175,22 @@ namespace NadekoBot.Modules.Administration.Commands reminders.Add(StartNewReminder(rem)); - await e.Channel.SendMessage($"⏰ I will remind \"{ch.Name}\" to \"{e.GetArg("message").ToString()}\" in {output}. ({time:d.M.yyyy.} at {time:HH:m})").ConfigureAwait(false); + await e.Channel.SendMessage($"⏰ I will remind \"{ch.Name}\" to \"{e.GetArg("message").ToString()}\" in {output}. ({time:d.M.yyyy.} at {time:HH:mm})").ConfigureAwait(false); + }); + cgb.CreateCommand(Module.Prefix + "remindmsg") + .Description("Sets message for when the remind is triggered. " + + " Available placeholders are %user% - user who ran the command, %message% -" + + " Message specified in the remind, %target% - target channel of the remind. **Owner only!**") + .Parameter("msg", ParameterType.Unparsed) + .AddCheck(SimpleCheckers.OwnerOnly()) + .Do(async e => + { + var arg = e.GetArg("msg")?.Trim(); + if (string.IsNullOrWhiteSpace(arg)) + return; + + NadekoBot.Config.RemindMessageFormat = arg; + await e.Channel.SendMessage("`New remind message set.`"); }); } } diff --git a/NadekoBot/_Models/JSONModels/Configuration.cs b/NadekoBot/_Models/JSONModels/Configuration.cs index 2eaea57f..37312588 100644 --- a/NadekoBot/_Models/JSONModels/Configuration.cs +++ b/NadekoBot/_Models/JSONModels/Configuration.cs @@ -17,6 +17,8 @@ namespace NadekoBot.Classes.JSONModels [JsonIgnore] public List PokemonTypes { get; set; } = new List(); + public string RemindMessageFormat { get; set; } = "❗⏰**I've been told to remind you to '%message%' now by %user%.**⏰❗"; + public Dictionary> CustomReactions { get; set; } = new Dictionary>() { {@"\o\", new List()