From 431f328bb464bf5a11c45058ac9c9350b1d540e6 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 14 Feb 2017 22:33:54 +0100 Subject: [PATCH] greet commands done and EVEN tested!1!! --- .../Commands/ServerGreetCommands.cs | 64 ++++--- .../Resources/ResponseStrings.Designer.cs | 171 ++++++++++++++++++ src/NadekoBot/Resources/ResponseStrings.resx | 57 ++++++ 3 files changed, 259 insertions(+), 33 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs index b3f79c83..b64df312 100644 --- a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs @@ -1,11 +1,9 @@ using Discord; using Discord.Commands; -using Discord.WebSocket; using NadekoBot.Attributes; using NadekoBot.DataStructures; using NadekoBot.Extensions; using NadekoBot.Services; -using NadekoBot.Services.Database; using NadekoBot.Services.Database.Models; using NLog; using System; @@ -55,7 +53,7 @@ namespace NadekoBot.Modules.Administration private new static Logger _log { get; } - private static ConcurrentDictionary GuildConfigsCache { get; } = new ConcurrentDictionary(); + private static ConcurrentDictionary guildConfigsCache { get; } static ServerGreetCommands() { @@ -63,13 +61,13 @@ namespace NadekoBot.Modules.Administration NadekoBot.Client.UserLeft += UserLeft; _log = LogManager.GetCurrentClassLogger(); - GuildConfigsCache = new ConcurrentDictionary(NadekoBot.AllGuildConfigs.ToDictionary(g => g.GuildId, (g) => GreetSettings.Create(g))); + guildConfigsCache = new ConcurrentDictionary(NadekoBot.AllGuildConfigs.ToDictionary(g => g.GuildId, GreetSettings.Create)); } private static GreetSettings GetOrAddSettingsForGuild(ulong guildId) { GreetSettings settings; - GuildConfigsCache.TryGetValue(guildId, out settings); + guildConfigsCache.TryGetValue(guildId, out settings); if (settings != null) return settings; @@ -80,7 +78,7 @@ namespace NadekoBot.Modules.Administration settings = GreetSettings.Create(gc); } - GuildConfigsCache.TryAdd(guildId, settings); + guildConfigsCache.TryAdd(guildId, settings); return settings; } @@ -234,9 +232,9 @@ namespace NadekoBot.Modules.Administration await ServerGreetCommands.SetGreetDel(Context.Guild.Id, timer).ConfigureAwait(false); if (timer > 0) - await Context.Channel.SendConfirmAsync($"🆗 Greet messages **will be deleted** after `{timer} seconds`.").ConfigureAwait(false); + await ReplyConfirmLocalized("greetdel_on", timer).ConfigureAwait(false); else - await Context.Channel.SendConfirmAsync("ℹ️ Automatic deletion of greet messages has been **disabled**.").ConfigureAwait(false); + await ReplyConfirmLocalized("greetdel_off").ConfigureAwait(false); } private static async Task SetGreetDel(ulong id, int timer) @@ -250,7 +248,7 @@ namespace NadekoBot.Modules.Administration conf.AutoDeleteGreetMessagesTimer = timer; var toAdd = GreetSettings.Create(conf); - GuildConfigsCache.AddOrUpdate(id, toAdd, (key, old) => toAdd); + guildConfigsCache.AddOrUpdate(id, toAdd, (key, old) => toAdd); await uow.CompleteAsync().ConfigureAwait(false); } @@ -264,9 +262,9 @@ namespace NadekoBot.Modules.Administration var enabled = await ServerGreetCommands.SetGreet(Context.Guild.Id, Context.Channel.Id).ConfigureAwait(false); if (enabled) - await Context.Channel.SendConfirmAsync("✅ Greeting messages **enabled** on this channel.").ConfigureAwait(false); + await ReplyConfirmLocalized("greet_on").ConfigureAwait(false); else - await Context.Channel.SendConfirmAsync("ℹ️ Greeting messages **disabled**.").ConfigureAwait(false); + await ReplyConfirmLocalized("greet_off").ConfigureAwait(false); } private static async Task SetGreet(ulong guildId, ulong channelId, bool? value = null) @@ -279,7 +277,7 @@ namespace NadekoBot.Modules.Administration conf.GreetMessageChannelId = channelId; var toAdd = GreetSettings.Create(conf); - GuildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd); + guildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd); await uow.CompleteAsync().ConfigureAwait(false); } @@ -298,15 +296,15 @@ namespace NadekoBot.Modules.Administration { channelGreetMessageText = uow.GuildConfigs.For(Context.Guild.Id, set => set).ChannelGreetMessageText; } - await Context.Channel.SendConfirmAsync("Current greet message: ", channelGreetMessageText?.SanitizeMentions()); + await ReplyConfirmLocalized("greetmsg_cur", channelGreetMessageText?.SanitizeMentions()).ConfigureAwait(false); return; } var sendGreetEnabled = ServerGreetCommands.SetGreetMessage(Context.Guild.Id, ref text); - await Context.Channel.SendConfirmAsync("🆗 New greet message **set**.").ConfigureAwait(false); + await ReplyConfirmLocalized("greetmsg_new").ConfigureAwait(false); if (!sendGreetEnabled) - await Context.Channel.SendConfirmAsync("ℹ️ Enable greet messsages by typing `.greet`").ConfigureAwait(false); + await ReplyConfirmLocalized("greetmsg_enable", $"`{Prefix}greet`").ConfigureAwait(false); } public static bool SetGreetMessage(ulong guildId, ref string message) @@ -324,7 +322,7 @@ namespace NadekoBot.Modules.Administration greetMsgEnabled = conf.SendChannelGreetMessage; var toAdd = GreetSettings.Create(conf); - GuildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd); + guildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd); uow.Complete(); } @@ -339,9 +337,9 @@ namespace NadekoBot.Modules.Administration var enabled = await ServerGreetCommands.SetGreetDm(Context.Guild.Id).ConfigureAwait(false); if (enabled) - await Context.Channel.SendConfirmAsync("🆗 DM Greet announcements **enabled**.").ConfigureAwait(false); + await ReplyConfirmLocalized("greetdm_on").ConfigureAwait(false); else - await Context.Channel.SendConfirmAsync("ℹ️ Greet announcements **disabled**.").ConfigureAwait(false); + await ReplyConfirmLocalized("greetdm_off").ConfigureAwait(false); } private static async Task SetGreetDm(ulong guildId, bool? value = null) @@ -353,7 +351,7 @@ namespace NadekoBot.Modules.Administration enabled = conf.SendDmGreetMessage = value ?? !conf.SendDmGreetMessage; var toAdd = GreetSettings.Create(conf); - GuildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd); + guildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd); await uow.CompleteAsync().ConfigureAwait(false); } @@ -372,15 +370,15 @@ namespace NadekoBot.Modules.Administration { config = uow.GuildConfigs.For(Context.Guild.Id); } - await Context.Channel.SendConfirmAsync("ℹ️ Current **DM greet** message: `" + config.DmGreetMessageText?.SanitizeMentions() + "`"); + await ReplyConfirmLocalized("greetdmmsg_cur", config.DmGreetMessageText?.SanitizeMentions()).ConfigureAwait(false); return; } var sendGreetEnabled = ServerGreetCommands.SetGreetDmMessage(Context.Guild.Id, ref text); - await Context.Channel.SendConfirmAsync("🆗 New DM greet message **set**.").ConfigureAwait(false); + await ReplyConfirmLocalized("greetdmmsg_new").ConfigureAwait(false); if (!sendGreetEnabled) - await Context.Channel.SendConfirmAsync($"ℹ️ Enable DM greet messsages by typing `{Prefix}greetdm`").ConfigureAwait(false); + await ReplyConfirmLocalized("greetdmmsg_enable", $"`{Prefix}greetdm`").ConfigureAwait(false); } public static bool SetGreetDmMessage(ulong guildId, ref string message) @@ -398,7 +396,7 @@ namespace NadekoBot.Modules.Administration greetMsgEnabled = conf.SendDmGreetMessage; var toAdd = GreetSettings.Create(conf); - GuildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd); + guildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd); uow.Complete(); } @@ -413,9 +411,9 @@ namespace NadekoBot.Modules.Administration var enabled = await ServerGreetCommands.SetBye(Context.Guild.Id, Context.Channel.Id).ConfigureAwait(false); if (enabled) - await Context.Channel.SendConfirmAsync("✅ Bye announcements **enabled** on this channel.").ConfigureAwait(false); + await ReplyConfirmLocalized("bye_on").ConfigureAwait(false); else - await Context.Channel.SendConfirmAsync("ℹ️ Bye announcements **disabled**.").ConfigureAwait(false); + await ReplyConfirmLocalized("bye_off").ConfigureAwait(false); } private static async Task SetBye(ulong guildId, ulong channelId, bool? value = null) @@ -428,7 +426,7 @@ namespace NadekoBot.Modules.Administration conf.ByeMessageChannelId = channelId; var toAdd = GreetSettings.Create(conf); - GuildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd); + guildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd); await uow.CompleteAsync(); } @@ -447,15 +445,15 @@ namespace NadekoBot.Modules.Administration { byeMessageText = uow.GuildConfigs.For(Context.Guild.Id, set => set).ChannelByeMessageText; } - await Context.Channel.SendConfirmAsync("ℹ️ Current **bye** message: `" + byeMessageText?.SanitizeMentions() + "`"); + await ReplyConfirmLocalized("byemsg_cur", byeMessageText?.SanitizeMentions()).ConfigureAwait(false); return; } var sendByeEnabled = ServerGreetCommands.SetByeMessage(Context.Guild.Id, ref text); - await Context.Channel.SendConfirmAsync("🆗 New bye message **set**.").ConfigureAwait(false); + await ReplyConfirmLocalized("byemsg_new").ConfigureAwait(false); if (!sendByeEnabled) - await Context.Channel.SendConfirmAsync($"ℹ️ Enable bye messsages by typing `{Prefix}bye`").ConfigureAwait(false); + await ReplyConfirmLocalized("byemsg_enable", $"`{Prefix}bye`").ConfigureAwait(false); } public static bool SetByeMessage(ulong guildId, ref string message) @@ -473,7 +471,7 @@ namespace NadekoBot.Modules.Administration byeMsgEnabled = conf.SendChannelByeMessage; var toAdd = GreetSettings.Create(conf); - GuildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd); + guildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd); uow.Complete(); } @@ -488,9 +486,9 @@ namespace NadekoBot.Modules.Administration await ServerGreetCommands.SetByeDel(Context.Guild.Id, timer).ConfigureAwait(false); if (timer > 0) - await Context.Channel.SendConfirmAsync($"🆗 Bye messages **will be deleted** after `{timer} seconds`.").ConfigureAwait(false); + await ReplyConfirmLocalized("byedel_on", timer).ConfigureAwait(false); else - await Context.Channel.SendConfirmAsync("ℹ️ Automatic deletion of bye messages has been **disabled**.").ConfigureAwait(false); + await ReplyConfirmLocalized("byedel_off").ConfigureAwait(false); } private static async Task SetByeDel(ulong guildId, int timer) @@ -504,7 +502,7 @@ namespace NadekoBot.Modules.Administration conf.AutoDeleteByeMessagesTimer = timer; var toAdd = GreetSettings.Create(conf); - GuildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd); + guildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd); await uow.CompleteAsync().ConfigureAwait(false); } diff --git a/src/NadekoBot/Resources/ResponseStrings.Designer.cs b/src/NadekoBot/Resources/ResponseStrings.Designer.cs index 74cc34e8..2d55b084 100644 --- a/src/NadekoBot/Resources/ResponseStrings.Designer.cs +++ b/src/NadekoBot/Resources/ResponseStrings.Designer.cs @@ -122,6 +122,69 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Bye announcements disabled.. + /// + public static string administration_bye_off { + get { + return ResourceManager.GetString("administration_bye_off", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Bye announcements enabled on this channel.. + /// + public static string administration_bye_on { + get { + return ResourceManager.GetString("administration_bye_on", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Automatic deletion of bye messages has been disabled.. + /// + public static string administration_byedel_off { + get { + return ResourceManager.GetString("administration_byedel_off", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Bye messages will be deleted after {0} seconds.. + /// + public static string administration_byedel_on { + get { + return ResourceManager.GetString("administration_byedel_on", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Current bye message: {0}. + /// + public static string administration_byemsg_cur { + get { + return ResourceManager.GetString("administration_byemsg_cur", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Enable bye messages by typing {0}. + /// + public static string administration_byemsg_enable { + get { + return ResourceManager.GetString("administration_byemsg_enable", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to New bye message set.. + /// + public static string administration_byemsg_new { + get { + return ResourceManager.GetString("administration_byemsg_new", resourceCulture); + } + } + /// /// Looks up a localized string similar to Channel Name Changed. /// @@ -212,6 +275,114 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Greet announcements disabled.. + /// + public static string administration_greet_off { + get { + return ResourceManager.GetString("administration_greet_off", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Greet announcements enabled on this channel.. + /// + public static string administration_greet_on { + get { + return ResourceManager.GetString("administration_greet_on", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Automatic deletion of greet messages has been disabled.. + /// + public static string administration_greetdel_off { + get { + return ResourceManager.GetString("administration_greetdel_off", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Greet messages will be deleted after {0} seconds.. + /// + public static string administration_greetdel_on { + get { + return ResourceManager.GetString("administration_greetdel_on", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to DM greet announcements disabled.. + /// + public static string administration_greetdm_off { + get { + return ResourceManager.GetString("administration_greetdm_off", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to DM greet announcements enabled.. + /// + public static string administration_greetdm_on { + get { + return ResourceManager.GetString("administration_greetdm_on", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Current DM greet message: {0}. + /// + public static string administration_greetdmmsg_cur { + get { + return ResourceManager.GetString("administration_greetdmmsg_cur", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Enable DM greet messages by typing {0}. + /// + public static string administration_greetdmmsg_enable { + get { + return ResourceManager.GetString("administration_greetdmmsg_enable", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to New DM greet message set.. + /// + public static string administration_greetdmmsg_new { + get { + return ResourceManager.GetString("administration_greetdmmsg_new", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Current greet message: {0}. + /// + public static string administration_greetmsg_cur { + get { + return ResourceManager.GetString("administration_greetmsg_cur", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Enable greet messages by typing {0}. + /// + public static string administration_greetmsg_enable { + get { + return ResourceManager.GetString("administration_greetmsg_enable", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to New greet message set.. + /// + public static string administration_greetmsg_new { + get { + return ResourceManager.GetString("administration_greetmsg_new", resourceCulture); + } + } + /// /// Looks up a localized string similar to Images loaded after {0} seconds!. /// diff --git a/src/NadekoBot/Resources/ResponseStrings.resx b/src/NadekoBot/Resources/ResponseStrings.resx index 382b6c14..84b45ae4 100644 --- a/src/NadekoBot/Resources/ResponseStrings.resx +++ b/src/NadekoBot/Resources/ResponseStrings.resx @@ -320,6 +320,27 @@ Bot status changed to {0} + + Automatic deletion of bye messages has been disabled. + + + Bye messages will be deleted after {0} seconds. + + + Current bye message: {0} + + + Enable bye messages by typing {0} + + + New bye message set. + + + Bye announcements disabled. + + + Bye announcements enabled on this channel. + Channel Name Changed @@ -350,6 +371,42 @@ I will stop forwarding DMs from now on. + + Automatic deletion of greet messages has been disabled. + + + Greet messages will be deleted after {0} seconds. + + + Current DM greet message: {0} + + + Enable DM greet messages by typing {0} + + + New DM greet message set. + + + DM greet announcements disabled. + + + DM greet announcements enabled. + + + Current greet message: {0} + + + Enable greet messages by typing {0} + + + New greet message set. + + + Greet announcements disabled. + + + Greet announcements enabled on this channel. + Images loaded after {0} seconds!