added .repinv

This commit is contained in:
Master Kwoth 2016-05-23 22:50:16 +02:00
parent 0855fa3022
commit a52108d32d
2 changed files with 48 additions and 29 deletions

View File

@ -44,16 +44,16 @@ namespace NadekoBot.Modules.Administration.Commands
});
cgb.CreateCommand(Prefix + "listcustomreactions")
.Alias(Prefix + "lcr")
.Description($"Lists all current custom reactions (paginated with 5 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);
});
.Alias(Prefix + "lcr")
.Description($"Lists all current custom reactions (paginated with 5 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);
});
cgb.CreateCommand(Prefix + "deletecustomreaction")
.Alias(Prefix + "dcr")

View File

@ -4,6 +4,7 @@ using NadekoBot.Classes;
using NadekoBot.Modules.Permissions.Classes;
using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using System.Timers;
namespace NadekoBot.Modules.Administration.Commands
@ -27,31 +28,49 @@ namespace NadekoBot.Modules.Administration.Commands
public Repeater Start()
{
MessageTimer = new Timer { Interval = Interval };
MessageTimer.Elapsed += async (s, e) =>
{
var ch = RepeatingChannel;
var msg = RepeatingMessage;
if (ch != null && !string.IsNullOrWhiteSpace(msg))
{
try
{
if (lastMessage != null)
await lastMessage.Delete().ConfigureAwait(false);
}
catch { }
try
{
lastMessage = await ch.SendMessage(msg).ConfigureAwait(false);
}
catch { }
}
};
MessageTimer.Elapsed += async (s, e) => await Invoke();
return this;
}
public async Task Invoke()
{
var ch = RepeatingChannel;
var msg = RepeatingMessage;
if (ch != null && !string.IsNullOrWhiteSpace(msg))
{
try
{
if (lastMessage != null)
await lastMessage.Delete().ConfigureAwait(false);
}
catch { }
try
{
lastMessage = await ch.SendMessage(msg).ConfigureAwait(false);
}
catch { }
}
}
}
internal override void Init(CommandGroupBuilder cgb)
{
cgb.CreateCommand(Module.Prefix + "repeatinvoke")
.Alias(Module.Prefix + "repinv")
.Description("Immediately shows the repeat message and restarts the timer.")
.AddCheck(SimpleCheckers.ManageMessages())
.Do(async e =>
{
Repeater rep;
if (!repeaters.TryGetValue(e.Server, out rep))
{
await e.Channel.SendMessage("`No repeating message found on this server.`");
return;
}
await rep.Invoke();
});
cgb.CreateCommand(Module.Prefix + "repeat")
.Description("Repeat a message every X minutes. If no parameters are specified, " +
"repeat is disabled. Requires manage messages.\n**Usage**:`.repeat 5 Hello there`")