Added the ability to specify time of day for repeaters.

This commit is contained in:
Master Kwoth
2017-06-13 02:40:41 +02:00
parent 891afbe7e7
commit 877ef81296
10 changed files with 1667 additions and 65 deletions

View File

@@ -31,14 +31,17 @@ namespace NadekoBot.Modules.Administration
if (page < 0 || page > 20)
return;
var timezones = TimeZoneInfo.GetSystemTimeZones();
var timezones = TimeZoneInfo.GetSystemTimeZones()
.OrderBy(x => x.BaseUtcOffset)
.ToArray();
var timezonesPerPage = 20;
await Context.Channel.SendPaginatedConfirmAsync((DiscordShardedClient)Context.Client, page + 1, (curPage) => new EmbedBuilder()
.WithOkColor()
.WithTitle("Available Timezones")
.WithDescription(string.Join("\n", timezones.Skip((curPage - 1) * timezonesPerPage).Take(timezonesPerPage).Select(x => $"`{x.Id,-25}` UTC{x.BaseUtcOffset:hhmm}"))),
timezones.Count / timezonesPerPage);
await Context.Channel.SendPaginatedConfirmAsync((DiscordShardedClient)Context.Client, page + 1,
(curPage) => new EmbedBuilder()
.WithOkColor()
.WithTitle(GetText("timezones_available"))
.WithDescription(string.Join("\n", timezones.Skip((curPage - 1) * timezonesPerPage).Take(timezonesPerPage).Select(x => $"`{x.Id,-25}` {(x.BaseUtcOffset < TimeSpan.Zero? "-" : "+")}{x.BaseUtcOffset:hhmm}"))),
timezones.Length / timezonesPerPage);
}
[NadekoCommand, Usage, Description, Aliases]
@@ -58,7 +61,7 @@ namespace NadekoBot.Modules.Administration
if (tz == null)
{
await Context.Channel.SendErrorAsync("Timezone not found. You should specify one of the timezones listed in the 'timezones' command.").ConfigureAwait(false);
await ReplyErrorLocalized("timezone_not_found").ConfigureAwait(false);
return;
}

View File

@@ -12,6 +12,7 @@ using System.Text;
using System.Threading.Tasks;
using Discord.WebSocket;
using NadekoBot.Services.Utility;
using NadekoBot.TypeReaders;
namespace NadekoBot.Modules.Utility
{
@@ -132,7 +133,7 @@ namespace NadekoBot.Modules.Utility
await uow.CompleteAsync().ConfigureAwait(false);
}
var rep = new RepeatRunner(_client, toAdd, (ITextChannel) Context.Channel);
var rep = new RepeatRunner(_client, toAdd);
_service.Repeaters.AddOrUpdate(Context.Guild.Id, new ConcurrentQueue<RepeatRunner>(new[] {rep}), (key, old) =>
{
@@ -148,55 +149,57 @@ namespace NadekoBot.Modules.Utility
Format.Bold(rep.Repeater.Interval.Minutes.ToString()))).ConfigureAwait(false);
}
//[NadekoCommand, Usage, Description, Aliases]
//[RequireContext(ContextType.Guild)]
//[RequireUserPermission(GuildPermission.ManageMessages)]
//[Priority(1)]
//public async Task Repeat(GuildTime gt, int minutes, [Remainder] string message)
//{
// if (!_service.RepeaterReady)
// return;
// if (minutes < 1 || minutes > 10080)
// return;
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.ManageMessages)]
[Priority(0)]
public async Task Repeat(GuildDateTime gt, [Remainder] string message)
{
if (!_service.RepeaterReady)
return;
// if (string.IsNullOrWhiteSpace(message))
// return;
if (string.IsNullOrWhiteSpace(message))
return;
// var toAdd = new GuildRepeater()
// {
// ChannelId = Context.Channel.Id,
// GuildId = Context.Guild.Id,
// Interval = TimeSpan.FromMinutes(minutes),
// StartTimeOfDay = gt.BotTime,
// Message = message
// };
var toAdd = new GuildRepeater()
{
ChannelId = Context.Channel.Id,
GuildId = Context.Guild.Id,
Interval = TimeSpan.FromHours(24),
StartTimeOfDay = gt.InputTimeUtc.TimeOfDay,
Message = message
};
// using (var uow = _db.UnitOfWork)
// {
// var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.GuildRepeaters));
using (var uow = _db.UnitOfWork)
{
var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.GuildRepeaters));
// if (gc.GuildRepeaters.Count >= 5)
// return;
// gc.GuildRepeaters.Add(toAdd);
if (gc.GuildRepeaters.Count >= 5)
return;
gc.GuildRepeaters.Add(toAdd);
// await uow.CompleteAsync().ConfigureAwait(false);
// }
await uow.CompleteAsync().ConfigureAwait(false);
}
// var rep = new RepeatRunner(_client, toAdd, (ITextChannel)Context.Channel);
var rep = new RepeatRunner(_client, toAdd);
// _service.Repeaters.AddOrUpdate(Context.Guild.Id, new ConcurrentQueue<RepeatRunner>(new[] { rep }), (key, old) =>
// {
// old.Enqueue(rep);
// return old;
// });
_service.Repeaters.AddOrUpdate(Context.Guild.Id, new ConcurrentQueue<RepeatRunner>(new[] { rep }), (key, old) =>
{
old.Enqueue(rep);
return old;
});
// await Context.Channel.SendConfirmAsync(
// "🔁 " + GetText("repeater",
// Format.Bold(((IGuildUser)Context.User).GuildPermissions.MentionEveryone ? rep.Repeater.Message : rep.Repeater.Message.SanitizeMentions()),
// Format.Bold(rep.Repeater.Interval.Days.ToString()),
// Format.Bold(rep.Repeater.Interval.Hours.ToString()),
// Format.Bold(rep.Repeater.Interval.Minutes.ToString()))).ConfigureAwait(false);
//}
var secondPart = GetText("repeater_initial",
Format.Bold(rep.InitialInterval.Hours.ToString()),
Format.Bold(rep.InitialInterval.Minutes.ToString()));
await Context.Channel.SendConfirmAsync(
"🔁 " + GetText("repeater",
Format.Bold(((IGuildUser)Context.User).GuildPermissions.MentionEveryone ? rep.Repeater.Message : rep.Repeater.Message.SanitizeMentions()),
Format.Bold(rep.Repeater.Interval.Days.ToString()),
Format.Bold(rep.Repeater.Interval.Hours.ToString()),
Format.Bold(rep.Repeater.Interval.Minutes.ToString())) + " " + secondPart).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]