added .remindmsg for custom remind message formatting.

This commit is contained in:
Master Kwoth 2016-05-11 07:20:43 +02:00
parent b26d798de0
commit fdfb6b9340
2 changed files with 31 additions and 2 deletions

View File

@ -2,6 +2,7 @@
using Discord.Commands; using Discord.Commands;
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.DataModels; using NadekoBot.DataModels;
using NadekoBot.Modules.Permissions.Classes;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -18,6 +19,13 @@ namespace NadekoBot.Modules.Administration.Commands
List<Timer> reminders = new List<Timer>(); List<Timer> reminders = new List<Timer>();
IDictionary<string, Func<Reminder, string>> replacements = new Dictionary<string, Func<Reminder, string>>
{
{ "%message%" , (r) => r.Message },
{ "%user%", (r) => $"<@!{r.UserId}>" },
{ "%target%", (r) => r.IsPrivate ? "Direct Message" : $"<#{r.ChannelId}>"}
};
public Remind(DiscordModule module) : base(module) public Remind(DiscordModule module) : base(module)
{ {
var remList = DbHandler.Instance.GetAllRows<Reminder>(); var remList = DbHandler.Instance.GetAllRows<Reminder>();
@ -53,7 +61,11 @@ namespace NadekoBot.Modules.Administration.Commands
if (ch == null) if (ch == null)
return; 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) catch (Exception ex)
{ {
@ -163,7 +175,22 @@ namespace NadekoBot.Modules.Administration.Commands
reminders.Add(StartNewReminder(rem)); 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.`");
}); });
} }
} }

View File

@ -17,6 +17,8 @@ namespace NadekoBot.Classes.JSONModels
[JsonIgnore] [JsonIgnore]
public List<PokemonType> PokemonTypes { get; set; } = new List<PokemonType>(); public List<PokemonType> PokemonTypes { get; set; } = new List<PokemonType>();
public string RemindMessageFormat { get; set; } = "❗⏰**I've been told to remind you to '%message%' now by %user%.**⏰❗";
public Dictionary<string, List<string>> CustomReactions { get; set; } = new Dictionary<string, List<string>>() public Dictionary<string, List<string>> CustomReactions { get; set; } = new Dictionary<string, List<string>>()
{ {
{@"\o\", new List<string>() {@"\o\", new List<string>()