Added correct time guild time based on set .timezone to reminders confirmation message, and logs, close #1328

This commit is contained in:
Master Kwoth 2017-07-05 13:41:50 +02:00
parent d0326ad680
commit 6b51dbd330
3 changed files with 44 additions and 25 deletions

View File

@ -3,6 +3,7 @@ using Discord.Commands;
using NadekoBot.Attributes; using NadekoBot.Attributes;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Services; using NadekoBot.Services;
using NadekoBot.Services.Administration;
using NadekoBot.Services.Database.Models; using NadekoBot.Services.Database.Models;
using NadekoBot.Services.Utility; using NadekoBot.Services.Utility;
using System; using System;
@ -19,11 +20,13 @@ namespace NadekoBot.Modules.Utility
{ {
private readonly RemindService _service; private readonly RemindService _service;
private readonly DbService _db; private readonly DbService _db;
private readonly GuildTimezoneService _tz;
public RemindCommands(RemindService service, DbService db) public RemindCommands(RemindService service, DbService db, GuildTimezoneService tz)
{ {
_service = service; _service = service;
_db = db; _db = db;
_tz = tz;
} }
public enum MeOrHere public enum MeOrHere
@ -119,6 +122,7 @@ namespace NadekoBot.Modules.Utility
await uow.CompleteAsync(); await uow.CompleteAsync();
} }
var gTime = TimeZoneInfo.ConvertTime(time, _tz.GetTimeZoneOrUtc(Context.Guild.Id));
try try
{ {
await Context.Channel.SendConfirmAsync( await Context.Channel.SendConfirmAsync(
@ -126,7 +130,7 @@ namespace NadekoBot.Modules.Utility
Format.Bold(!isPrivate ? $"<#{targetId}>" : Context.User.Username), Format.Bold(!isPrivate ? $"<#{targetId}>" : Context.User.Username),
Format.Bold(message.SanitizeMentions()), Format.Bold(message.SanitizeMentions()),
Format.Bold(output), Format.Bold(output),
time, time)).ConfigureAwait(false); gTime, gTime)).ConfigureAwait(false);
} }
catch catch
{ {

View File

@ -204,8 +204,8 @@ namespace NadekoBot
var playingRotateService = new PlayingRotateService(Client, BotConfig, musicService, Db); var playingRotateService = new PlayingRotateService(Client, BotConfig, musicService, Db);
var gameVcService = new GameVoiceChannelService(Client, Db, AllGuildConfigs); var gameVcService = new GameVoiceChannelService(Client, Db, AllGuildConfigs);
var autoAssignRoleService = new AutoAssignRoleService(Client, AllGuildConfigs); var autoAssignRoleService = new AutoAssignRoleService(Client, AllGuildConfigs);
var logCommandService = new LogCommandService(Client, Strings, AllGuildConfigs, Db, muteService, protectionService);
var guildTimezoneService = new GuildTimezoneService(Client, AllGuildConfigs, Db); var guildTimezoneService = new GuildTimezoneService(Client, AllGuildConfigs, Db);
var logCommandService = new LogCommandService(Client, Strings, AllGuildConfigs, Db, muteService, protectionService, guildTimezoneService);
#endregion #endregion
#region pokemon #region pokemon

View File

@ -19,8 +19,21 @@ namespace NadekoBot.Services.Administration
private readonly DiscordSocketClient _client; private readonly DiscordSocketClient _client;
private readonly Logger _log; private readonly Logger _log;
private string PrettyCurrentTime => $"【{DateTime.UtcNow:HH:mm:ss}】"; private string PrettyCurrentTime(IGuild g)
private string CurrentTime => $"{DateTime.UtcNow:HH:mm:ss}"; {
var time = DateTime.UtcNow;
if(g != null)
time = TimeZoneInfo.ConvertTime(time, _tz.GetTimeZoneOrUtc(g.Id));
return $"【{time:HH:mm:ss}】";
}
private string CurrentTime(IGuild g)
{
DateTime time = DateTime.UtcNow;
if (g != null)
time = TimeZoneInfo.ConvertTime(time, _tz.GetTimeZoneOrUtc(g.Id));
return $"{time:HH:mm:ss}";
}
public ConcurrentDictionary<ulong, LogSetting> GuildLogSettings { get; } public ConcurrentDictionary<ulong, LogSetting> GuildLogSettings { get; }
@ -30,9 +43,10 @@ namespace NadekoBot.Services.Administration
private readonly DbService _db; private readonly DbService _db;
private readonly MuteService _mute; private readonly MuteService _mute;
private readonly ProtectionService _prot; private readonly ProtectionService _prot;
private readonly GuildTimezoneService _tz;
public LogCommandService(DiscordSocketClient client, NadekoStrings strings, public LogCommandService(DiscordSocketClient client, NadekoStrings strings,
IEnumerable<GuildConfig> gcs, DbService db, MuteService mute, ProtectionService prot) IEnumerable<GuildConfig> gcs, DbService db, MuteService mute, ProtectionService prot, GuildTimezoneService tz)
{ {
_client = client; _client = client;
_log = LogManager.GetCurrentClassLogger(); _log = LogManager.GetCurrentClassLogger();
@ -40,6 +54,7 @@ namespace NadekoBot.Services.Administration
_db = db; _db = db;
_mute = mute; _mute = mute;
_prot = prot; _prot = prot;
_tz = tz;
GuildLogSettings = gcs GuildLogSettings = gcs
.ToDictionary(g => g.GuildId, g => g.LogSetting) .ToDictionary(g => g.GuildId, g => g.LogSetting)
@ -124,7 +139,7 @@ namespace NadekoBot.Services.Administration
.WithDescription($"{before.Username}#{before.Discriminator} | {before.Id}") .WithDescription($"{before.Username}#{before.Discriminator} | {before.Id}")
.AddField(fb => fb.WithName("Old Name").WithValue($"{before.Username}").WithIsInline(true)) .AddField(fb => fb.WithName("Old Name").WithValue($"{before.Username}").WithIsInline(true))
.AddField(fb => fb.WithName("New Name").WithValue($"{after.Username}").WithIsInline(true)) .AddField(fb => fb.WithName("New Name").WithValue($"{after.Username}").WithIsInline(true))
.WithFooter(fb => fb.WithText(CurrentTime)) .WithFooter(fb => fb.WithText(CurrentTime(g)))
.WithOkColor(); .WithOkColor();
} }
else if (before.AvatarId != after.AvatarId) else if (before.AvatarId != after.AvatarId)
@ -133,7 +148,7 @@ namespace NadekoBot.Services.Administration
.WithDescription($"{before.Username}#{before.Discriminator} | {before.Id}") .WithDescription($"{before.Username}#{before.Discriminator} | {before.Id}")
.WithThumbnailUrl(before.GetAvatarUrl()) .WithThumbnailUrl(before.GetAvatarUrl())
.WithImageUrl(after.GetAvatarUrl()) .WithImageUrl(after.GetAvatarUrl())
.WithFooter(fb => fb.WithText(CurrentTime)) .WithFooter(fb => fb.WithText(CurrentTime(g)))
.WithOkColor(); .WithOkColor();
} }
else else
@ -244,7 +259,7 @@ namespace NadekoBot.Services.Administration
var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName(mutes)) var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName(mutes))
.WithTitle($"{usr.Username}#{usr.Discriminator} | {usr.Id}") .WithTitle($"{usr.Username}#{usr.Discriminator} | {usr.Id}")
.WithFooter(fb => fb.WithText(CurrentTime)) .WithFooter(fb => fb.WithText(CurrentTime(usr.Guild)))
.WithOkColor(); .WithOkColor();
await logChannel.EmbedAsync(embed).ConfigureAwait(false); await logChannel.EmbedAsync(embed).ConfigureAwait(false);
@ -287,7 +302,7 @@ namespace NadekoBot.Services.Administration
var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName(mutes)) var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName(mutes))
.WithTitle($"{usr.Username}#{usr.Discriminator} | {usr.Id}") .WithTitle($"{usr.Username}#{usr.Discriminator} | {usr.Id}")
.WithFooter(fb => fb.WithText($"{CurrentTime}")) .WithFooter(fb => fb.WithText($"{CurrentTime(usr.Guild)}"))
.WithOkColor(); .WithOkColor();
await logChannel.EmbedAsync(embed).ConfigureAwait(false); await logChannel.EmbedAsync(embed).ConfigureAwait(false);
@ -335,7 +350,7 @@ namespace NadekoBot.Services.Administration
var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName($"🛡 Anti-{protection}")) var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName($"🛡 Anti-{protection}"))
.WithTitle(GetText(logChannel.Guild, "users") + " " + punishment) .WithTitle(GetText(logChannel.Guild, "users") + " " + punishment)
.WithDescription(string.Join("\n", users.Select(u => u.ToString()))) .WithDescription(string.Join("\n", users.Select(u => u.ToString())))
.WithFooter(fb => fb.WithText($"{CurrentTime}")) .WithFooter(fb => fb.WithText(CurrentTime(logChannel.Guild)))
.WithOkColor(); .WithOkColor();
await logChannel.EmbedAsync(embed).ConfigureAwait(false); await logChannel.EmbedAsync(embed).ConfigureAwait(false);
@ -361,7 +376,7 @@ namespace NadekoBot.Services.Administration
ITextChannel logChannel; ITextChannel logChannel;
if ((logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.UserUpdated)) == null) if ((logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.UserUpdated)) == null)
return; return;
var embed = new EmbedBuilder().WithOkColor().WithFooter(efb => efb.WithText(CurrentTime)) var embed = new EmbedBuilder().WithOkColor().WithFooter(efb => efb.WithText(CurrentTime(before.Guild)))
.WithTitle($"{before.Username}#{before.Discriminator} | {before.Id}"); .WithTitle($"{before.Username}#{before.Discriminator} | {before.Id}");
if (before.Nickname != after.Nickname) if (before.Nickname != after.Nickname)
{ {
@ -417,7 +432,7 @@ namespace NadekoBot.Services.Administration
if ((logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.ChannelUpdated)) == null) if ((logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.ChannelUpdated)) == null)
return; return;
var embed = new EmbedBuilder().WithOkColor().WithFooter(efb => efb.WithText(CurrentTime)); var embed = new EmbedBuilder().WithOkColor().WithFooter(efb => efb.WithText(CurrentTime(before.Guild)));
var beforeTextChannel = cbefore as ITextChannel; var beforeTextChannel = cbefore as ITextChannel;
var afterTextChannel = cafter as ITextChannel; var afterTextChannel = cafter as ITextChannel;
@ -477,7 +492,7 @@ namespace NadekoBot.Services.Administration
.WithOkColor() .WithOkColor()
.WithTitle("🆕 " + title) .WithTitle("🆕 " + title)
.WithDescription($"{ch.Name} | {ch.Id}") .WithDescription($"{ch.Name} | {ch.Id}")
.WithFooter(efb => efb.WithText(CurrentTime))).ConfigureAwait(false); .WithFooter(efb => efb.WithText(CurrentTime(ch.Guild)))).ConfigureAwait(false);
} }
catch catch
{ {
@ -515,7 +530,7 @@ namespace NadekoBot.Services.Administration
.WithOkColor() .WithOkColor()
.WithTitle("🆕 " + title) .WithTitle("🆕 " + title)
.WithDescription($"{ch.Name} | {ch.Id}") .WithDescription($"{ch.Name} | {ch.Id}")
.WithFooter(efb => efb.WithText(CurrentTime))).ConfigureAwait(false); .WithFooter(efb => efb.WithText(CurrentTime(ch.Guild)))).ConfigureAwait(false);
} }
catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
}); });
@ -549,19 +564,19 @@ namespace NadekoBot.Services.Administration
string str = null; string str = null;
if (beforeVch?.Guild == afterVch?.Guild) if (beforeVch?.Guild == afterVch?.Guild)
{ {
str = "🎙" + Format.Code(PrettyCurrentTime) + GetText(logChannel.Guild, "user_vmoved", str = "🎙" + Format.Code(PrettyCurrentTime(usr.Guild)) + GetText(logChannel.Guild, "user_vmoved",
"👤" + Format.Bold(usr.Username + "#" + usr.Discriminator), "👤" + Format.Bold(usr.Username + "#" + usr.Discriminator),
Format.Bold(beforeVch?.Name ?? ""), Format.Bold(afterVch?.Name ?? "")); Format.Bold(beforeVch?.Name ?? ""), Format.Bold(afterVch?.Name ?? ""));
} }
else if (beforeVch == null) else if (beforeVch == null)
{ {
str = "🎙" + Format.Code(PrettyCurrentTime) + GetText(logChannel.Guild, "user_vjoined", str = "🎙" + Format.Code(PrettyCurrentTime(usr.Guild)) + GetText(logChannel.Guild, "user_vjoined",
"👤" + Format.Bold(usr.Username + "#" + usr.Discriminator), "👤" + Format.Bold(usr.Username + "#" + usr.Discriminator),
Format.Bold(afterVch.Name ?? "")); Format.Bold(afterVch.Name ?? ""));
} }
else if (afterVch == null) else if (afterVch == null)
{ {
str = "🎙" + Format.Code(PrettyCurrentTime) + GetText(logChannel.Guild, "user_vleft", str = "🎙" + Format.Code(PrettyCurrentTime(usr.Guild)) + GetText(logChannel.Guild, "user_vleft",
"👤" + Format.Bold(usr.Username + "#" + usr.Discriminator), "👤" + Format.Bold(usr.Username + "#" + usr.Discriminator),
Format.Bold(beforeVch.Name ?? "")); Format.Bold(beforeVch.Name ?? ""));
} }
@ -597,7 +612,7 @@ namespace NadekoBot.Services.Administration
// return; // return;
// string str = ""; // string str = "";
// if (before.Status != after.Status) // if (before.Status != after.Status)
// str = "🎭" + Format.Code(PrettyCurrentTime) + // str = "🎭" + Format.Code(PrettyCurrentTime(g)) +
// GetText(logChannel.Guild, "user_status_change", // GetText(logChannel.Guild, "user_status_change",
// "👤" + Format.Bold(usr.Username), // "👤" + Format.Bold(usr.Username),
// Format.Bold(after.Status.ToString())); // Format.Bold(after.Status.ToString()));
@ -639,7 +654,7 @@ namespace NadekoBot.Services.Administration
.WithThumbnailUrl(usr.GetAvatarUrl()) .WithThumbnailUrl(usr.GetAvatarUrl())
.WithDescription(usr.ToString()) .WithDescription(usr.ToString())
.AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString())) .AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString()))
.WithFooter(efb => efb.WithText(CurrentTime))).ConfigureAwait(false); .WithFooter(efb => efb.WithText(CurrentTime(usr.Guild)))).ConfigureAwait(false);
} }
catch catch
{ {
@ -669,7 +684,7 @@ namespace NadekoBot.Services.Administration
.WithThumbnailUrl(usr.GetAvatarUrl()) .WithThumbnailUrl(usr.GetAvatarUrl())
.WithDescription($"{usr}") .WithDescription($"{usr}")
.AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString())) .AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString()))
.WithFooter(efb => efb.WithText(CurrentTime))).ConfigureAwait(false); .WithFooter(efb => efb.WithText(CurrentTime(usr.Guild)))).ConfigureAwait(false);
} }
catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
}); });
@ -696,7 +711,7 @@ namespace NadekoBot.Services.Administration
.WithThumbnailUrl(usr.GetAvatarUrl()) .WithThumbnailUrl(usr.GetAvatarUrl())
.WithDescription(usr.ToString()) .WithDescription(usr.ToString())
.AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString())) .AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString()))
.WithFooter(efb => efb.WithText(CurrentTime))).ConfigureAwait(false); .WithFooter(efb => efb.WithText(CurrentTime(guild)))).ConfigureAwait(false);
} }
catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
}); });
@ -722,7 +737,7 @@ namespace NadekoBot.Services.Administration
.WithThumbnailUrl(usr.GetAvatarUrl()) .WithThumbnailUrl(usr.GetAvatarUrl())
.WithDescription(usr.ToString()) .WithDescription(usr.ToString())
.AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString())) .AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString()))
.WithFooter(efb => efb.WithText(CurrentTime))).ConfigureAwait(false); .WithFooter(efb => efb.WithText(CurrentTime(guild)))).ConfigureAwait(false);
} }
catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
}); });
@ -757,7 +772,7 @@ namespace NadekoBot.Services.Administration
.WithDescription(msg.Author.ToString()) .WithDescription(msg.Author.ToString())
.AddField(efb => efb.WithName(GetText(logChannel.Guild, "content")).WithValue(string.IsNullOrWhiteSpace(msg.Content) ? "-" : msg.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false)) .AddField(efb => efb.WithName(GetText(logChannel.Guild, "content")).WithValue(string.IsNullOrWhiteSpace(msg.Content) ? "-" : msg.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false))
.AddField(efb => efb.WithName("Id").WithValue(msg.Id.ToString()).WithIsInline(false)) .AddField(efb => efb.WithName("Id").WithValue(msg.Id.ToString()).WithIsInline(false))
.WithFooter(efb => efb.WithText(CurrentTime)); .WithFooter(efb => efb.WithText(CurrentTime(channel.Guild)));
if (msg.Attachments.Any()) if (msg.Attachments.Any())
embed.AddField(efb => efb.WithName(GetText(logChannel.Guild, "attachments")).WithValue(string.Join(", ", msg.Attachments.Select(a => a.Url))).WithIsInline(false)); embed.AddField(efb => efb.WithName(GetText(logChannel.Guild, "attachments")).WithValue(string.Join(", ", msg.Attachments.Select(a => a.Url))).WithIsInline(false));
@ -809,7 +824,7 @@ namespace NadekoBot.Services.Administration
.AddField(efb => efb.WithName(GetText(logChannel.Guild, "old_msg")).WithValue(string.IsNullOrWhiteSpace(before.Content) ? "-" : before.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false)) .AddField(efb => efb.WithName(GetText(logChannel.Guild, "old_msg")).WithValue(string.IsNullOrWhiteSpace(before.Content) ? "-" : before.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false))
.AddField(efb => efb.WithName(GetText(logChannel.Guild, "new_msg")).WithValue(string.IsNullOrWhiteSpace(after.Content) ? "-" : after.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false)) .AddField(efb => efb.WithName(GetText(logChannel.Guild, "new_msg")).WithValue(string.IsNullOrWhiteSpace(after.Content) ? "-" : after.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false))
.AddField(efb => efb.WithName("Id").WithValue(after.Id.ToString()).WithIsInline(false)) .AddField(efb => efb.WithName("Id").WithValue(after.Id.ToString()).WithIsInline(false))
.WithFooter(efb => efb.WithText(CurrentTime)); .WithFooter(efb => efb.WithText(CurrentTime(channel.Guild)));
await logChannel.EmbedAsync(embed).ConfigureAwait(false); await logChannel.EmbedAsync(embed).ConfigureAwait(false);
} }