.timezone command added

This commit is contained in:
Master Kwoth
2017-06-13 01:40:39 +02:00
parent 2ff55a49fb
commit 891afbe7e7
18 changed files with 278 additions and 88 deletions

View File

@@ -9,6 +9,7 @@ using NadekoBot.Services;
using NadekoBot.Attributes;
using NadekoBot.Services.Database.Models;
using NadekoBot.Services.Administration;
using Discord.WebSocket;
namespace NadekoBot.Modules.Administration
{
@@ -319,7 +320,7 @@ namespace NadekoBot.Modules.Administration
var user = await Context.Guild.GetCurrentUserAsync().ConfigureAwait(false);
var enumerable = (await Context.Channel.GetMessagesAsync().Flatten())
.Where(x => x.Author.Id == user.Id && DateTime.Now - x.CreatedAt < twoWeeks);
.Where(x => x.Author.Id == user.Id && DateTime.UtcNow - x.CreatedAt < twoWeeks);
await Context.Channel.DeleteMessagesAsync(enumerable).ConfigureAwait(false);
Context.Message.DeleteAfter(3);
}
@@ -339,7 +340,7 @@ namespace NadekoBot.Modules.Administration
await Context.Message.DeleteAsync().ConfigureAwait(false);
int limit = (count < 100) ? count + 1 : 100;
var enumerable = (await Context.Channel.GetMessagesAsync(limit: limit).Flatten().ConfigureAwait(false))
.Where(x => DateTime.Now - x.CreatedAt < twoWeeks);
.Where(x => DateTime.UtcNow - x.CreatedAt < twoWeeks);
if (enumerable.FirstOrDefault()?.Id == Context.Message.Id)
enumerable = enumerable.Skip(1).ToArray();
else
@@ -363,7 +364,7 @@ namespace NadekoBot.Modules.Administration
int limit = (count < 100) ? count : 100;
var enumerable = (await Context.Channel.GetMessagesAsync(limit: limit).Flatten())
.Where(m => m.Author == user && DateTime.Now - m.CreatedAt < twoWeeks);
.Where(m => m.Author == user && DateTime.UtcNow - m.CreatedAt < twoWeeks);
await Context.Channel.DeleteMessagesAsync(enumerable).ConfigureAwait(false);
Context.Message.DeleteAfter(3);
@@ -428,45 +429,5 @@ namespace NadekoBot.Modules.Administration
}
await ReplyConfirmLocalized("donadd", don.Amount).ConfigureAwait(false);
}
//[NadekoCommand, Usage, Description, Aliases]
//[RequireContext(ContextType.Guild)]
//public async Task Timezones(int page = 1)
//{
// page -= 1;
// if (page < 0 || page > 20)
// return;
// var timezones = TimeZoneInfo.GetSystemTimeZones();
// var timezonesPerPage = 20;
// await Context.Channel.SendPaginatedConfirmAsync(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);
//}
//[NadekoCommand, Usage, Description, Aliases]
//[RequireContext(ContextType.Guild)]
//public async Task Timezone([Remainder] string id)
//{
// TimeZoneInfo tz;
// try
// {
// tz = TimeZoneInfo.FindSystemTimeZoneById(id);
// if (tz != null)
// await Context.Channel.SendConfirmAsync(tz.ToString()).ConfigureAwait(false);
// }
// catch (Exception ex)
// {
// tz = null;
// _log.Warn(ex);
// }
// if (tz == null)
// await Context.Channel.SendErrorAsync("Timezone not found. You should specify one of the timezones listed in the 'timezones' command.").ConfigureAwait(false);
//}
}
}

View File

@@ -0,0 +1,69 @@
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Services.Administration;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace NadekoBot.Modules.Administration
{
public partial class Administration
{
[Group]
public class TimeZoneCommands : NadekoSubmodule
{
private readonly GuildTimezoneService _service;
public TimeZoneCommands(GuildTimezoneService service)
{
_service = service;
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Timezones(int page = 1)
{
page -= 1;
if (page < 0 || page > 20)
return;
var timezones = TimeZoneInfo.GetSystemTimeZones();
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);
}
[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)
{
await Context.Channel.SendErrorAsync("Timezone not found. You should specify one of the timezones listed in the 'timezones' command.").ConfigureAwait(false);
return;
}
await Context.Channel.SendConfirmAsync(tz.ToString()).ConfigureAwait(false);
}
}
}
}

View File

@@ -83,7 +83,7 @@ namespace NadekoBot.Modules.Searches
// try
// {
// CachedChampionImages = CachedChampionImages
// .Where(kvp => DateTime.Now - kvp.Value.AddedAt > new TimeSpan(1, 0, 0))
// .Where(kvp => DateTime.UtcNow - kvp.Value.AddedAt > new TimeSpan(1, 0, 0))
// .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
// }
// catch { }
@@ -303,7 +303,7 @@ namespace NadekoBot.Modules.Searches
// smallImgSize));
// }
// }
// var cachedChamp = new CachedChampion { AddedAt = DateTime.Now, ImageStream = img.ToStream(System.Drawing.Imaging.ImageFormat.Png), Name = name.ToLower() + "_" + resolvedRole };
// var cachedChamp = new CachedChampion { AddedAt = DateTime.UtcNow, ImageStream = img.ToStream(System.Drawing.Imaging.ImageFormat.Png), Name = name.ToLower() + "_" + resolvedRole };
// CachedChampionImages.Add(cachedChamp.Name, cachedChamp);
// await e.Channel.SendFile(data["title"] + "_stats.png", cachedChamp.ImageStream).ConfigureAwait(false);
// }

View File

@@ -148,6 +148,56 @@ 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;
// 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
// };
// 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);
// await uow.CompleteAsync().ConfigureAwait(false);
// }
// var rep = new RepeatRunner(_client, toAdd, (ITextChannel)Context.Channel);
// _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);
//}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.ManageMessages)]

View File

@@ -96,7 +96,7 @@ namespace NadekoBot.Modules.Utility
namesAndValues[groupName] = value;
output += m.Groups[groupName].Value + " " + groupName + " ";
}
var time = DateTime.Now + new TimeSpan(30 * namesAndValues["months"] +
var time = DateTime.UtcNow + new TimeSpan(30 * namesAndValues["months"] +
7 * namesAndValues["weeks"] +
namesAndValues["days"],
namesAndValues["hours"],