2017-06-12 23:40:39 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using Discord.WebSocket;
|
|
|
|
|
using NadekoBot.Extensions;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 19:42:36 +00:00
|
|
|
|
using NadekoBot.Common.Attributes;
|
|
|
|
|
using NadekoBot.Modules.Administration.Services;
|
2017-06-12 23:40:39 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Administration
|
|
|
|
|
{
|
|
|
|
|
public partial class Administration
|
|
|
|
|
{
|
|
|
|
|
[Group]
|
2017-07-15 16:34:34 +00:00
|
|
|
|
public class TimeZoneCommands : NadekoSubmodule<GuildTimezoneService>
|
2017-06-12 23:40:39 +00:00
|
|
|
|
{
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
public async Task Timezones(int page = 1)
|
|
|
|
|
{
|
2017-06-14 15:19:27 +00:00
|
|
|
|
page--;
|
2017-06-12 23:40:39 +00:00
|
|
|
|
|
|
|
|
|
if (page < 0 || page > 20)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-06-13 00:40:41 +00:00
|
|
|
|
var timezones = TimeZoneInfo.GetSystemTimeZones()
|
|
|
|
|
.OrderBy(x => x.BaseUtcOffset)
|
|
|
|
|
.ToArray();
|
2017-06-12 23:40:39 +00:00
|
|
|
|
var timezonesPerPage = 20;
|
|
|
|
|
|
2017-06-19 13:42:10 +00:00
|
|
|
|
await Context.Channel.SendPaginatedConfirmAsync((DiscordSocketClient)Context.Client, page,
|
2017-06-13 00:40:41 +00:00
|
|
|
|
(curPage) => new EmbedBuilder()
|
|
|
|
|
.WithOkColor()
|
|
|
|
|
.WithTitle(GetText("timezones_available"))
|
2017-06-14 15:19:27 +00:00
|
|
|
|
.WithDescription(string.Join("\n", timezones.Skip(curPage * timezonesPerPage).Take(timezonesPerPage).Select(x => $"`{x.Id,-25}` {(x.BaseUtcOffset < TimeSpan.Zero? "-" : "+")}{x.BaseUtcOffset:hhmm}"))),
|
2017-06-13 00:40:41 +00:00
|
|
|
|
timezones.Length / timezonesPerPage);
|
2017-06-12 23:40:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
public async Task Timezone([Remainder] string id = null)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(id))
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("timezone_guild", _service.GetTimeZoneOrUtc(Context.Guild.Id)).ConfigureAwait(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TimeZoneInfo tz;
|
|
|
|
|
try { tz = TimeZoneInfo.FindSystemTimeZoneById(id); } catch { tz = null; }
|
|
|
|
|
|
|
|
|
|
_service.SetTimeZone(Context.Guild.Id, tz);
|
|
|
|
|
|
|
|
|
|
if (tz == null)
|
|
|
|
|
{
|
2017-06-13 00:40:41 +00:00
|
|
|
|
await ReplyErrorLocalized("timezone_not_found").ConfigureAwait(false);
|
2017-06-12 23:40:39 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await Context.Channel.SendConfirmAsync(tz.ToString()).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|