greet commands done and EVEN tested!1!!

This commit is contained in:
Kwoth 2017-02-14 22:33:54 +01:00
parent fdc41caed1
commit 431f328bb4
3 changed files with 259 additions and 33 deletions

View File

@ -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<ulong, GreetSettings> GuildConfigsCache { get; } = new ConcurrentDictionary<ulong, GreetSettings>();
private static ConcurrentDictionary<ulong, GreetSettings> guildConfigsCache { get; }
static ServerGreetCommands()
{
@ -63,13 +61,13 @@ namespace NadekoBot.Modules.Administration
NadekoBot.Client.UserLeft += UserLeft;
_log = LogManager.GetCurrentClassLogger();
GuildConfigsCache = new ConcurrentDictionary<ulong, GreetSettings>(NadekoBot.AllGuildConfigs.ToDictionary(g => g.GuildId, (g) => GreetSettings.Create(g)));
guildConfigsCache = new ConcurrentDictionary<ulong, GreetSettings>(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<bool> 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<bool> 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<bool> 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);
}

View File

@ -122,6 +122,69 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Bye announcements disabled..
/// </summary>
public static string administration_bye_off {
get {
return ResourceManager.GetString("administration_bye_off", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Bye announcements enabled on this channel..
/// </summary>
public static string administration_bye_on {
get {
return ResourceManager.GetString("administration_bye_on", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Automatic deletion of bye messages has been disabled..
/// </summary>
public static string administration_byedel_off {
get {
return ResourceManager.GetString("administration_byedel_off", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Bye messages will be deleted after {0} seconds..
/// </summary>
public static string administration_byedel_on {
get {
return ResourceManager.GetString("administration_byedel_on", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Current bye message: {0}.
/// </summary>
public static string administration_byemsg_cur {
get {
return ResourceManager.GetString("administration_byemsg_cur", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Enable bye messages by typing {0}.
/// </summary>
public static string administration_byemsg_enable {
get {
return ResourceManager.GetString("administration_byemsg_enable", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to New bye message set..
/// </summary>
public static string administration_byemsg_new {
get {
return ResourceManager.GetString("administration_byemsg_new", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Channel Name Changed.
/// </summary>
@ -212,6 +275,114 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Greet announcements disabled..
/// </summary>
public static string administration_greet_off {
get {
return ResourceManager.GetString("administration_greet_off", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Greet announcements enabled on this channel..
/// </summary>
public static string administration_greet_on {
get {
return ResourceManager.GetString("administration_greet_on", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Automatic deletion of greet messages has been disabled..
/// </summary>
public static string administration_greetdel_off {
get {
return ResourceManager.GetString("administration_greetdel_off", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Greet messages will be deleted after {0} seconds..
/// </summary>
public static string administration_greetdel_on {
get {
return ResourceManager.GetString("administration_greetdel_on", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to DM greet announcements disabled..
/// </summary>
public static string administration_greetdm_off {
get {
return ResourceManager.GetString("administration_greetdm_off", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to DM greet announcements enabled..
/// </summary>
public static string administration_greetdm_on {
get {
return ResourceManager.GetString("administration_greetdm_on", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Current DM greet message: {0}.
/// </summary>
public static string administration_greetdmmsg_cur {
get {
return ResourceManager.GetString("administration_greetdmmsg_cur", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Enable DM greet messages by typing {0}.
/// </summary>
public static string administration_greetdmmsg_enable {
get {
return ResourceManager.GetString("administration_greetdmmsg_enable", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to New DM greet message set..
/// </summary>
public static string administration_greetdmmsg_new {
get {
return ResourceManager.GetString("administration_greetdmmsg_new", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Current greet message: {0}.
/// </summary>
public static string administration_greetmsg_cur {
get {
return ResourceManager.GetString("administration_greetmsg_cur", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Enable greet messages by typing {0}.
/// </summary>
public static string administration_greetmsg_enable {
get {
return ResourceManager.GetString("administration_greetmsg_enable", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to New greet message set..
/// </summary>
public static string administration_greetmsg_new {
get {
return ResourceManager.GetString("administration_greetmsg_new", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Images loaded after {0} seconds!.
/// </summary>

View File

@ -320,6 +320,27 @@
<data name="administration_bot_status" xml:space="preserve">
<value>Bot status changed to {0}</value>
</data>
<data name="administration_byedel_off" xml:space="preserve">
<value>Automatic deletion of bye messages has been disabled.</value>
</data>
<data name="administration_byedel_on" xml:space="preserve">
<value>Bye messages will be deleted after {0} seconds.</value>
</data>
<data name="administration_byemsg_cur" xml:space="preserve">
<value>Current bye message: {0}</value>
</data>
<data name="administration_byemsg_enable" xml:space="preserve">
<value>Enable bye messages by typing {0}</value>
</data>
<data name="administration_byemsg_new" xml:space="preserve">
<value>New bye message set.</value>
</data>
<data name="administration_bye_off" xml:space="preserve">
<value>Bye announcements disabled.</value>
</data>
<data name="administration_bye_on" xml:space="preserve">
<value>Bye announcements enabled on this channel.</value>
</data>
<data name="administration_ch_name_change" xml:space="preserve">
<value>Channel Name Changed</value>
</data>
@ -350,6 +371,42 @@
<data name="administration_fwdm_stop" xml:space="preserve">
<value>I will stop forwarding DMs from now on.</value>
</data>
<data name="administration_greetdel_off" xml:space="preserve">
<value>Automatic deletion of greet messages has been disabled.</value>
</data>
<data name="administration_greetdel_on" xml:space="preserve">
<value>Greet messages will be deleted after {0} seconds.</value>
</data>
<data name="administration_greetdmmsg_cur" xml:space="preserve">
<value>Current DM greet message: {0}</value>
</data>
<data name="administration_greetdmmsg_enable" xml:space="preserve">
<value>Enable DM greet messages by typing {0}</value>
</data>
<data name="administration_greetdmmsg_new" xml:space="preserve">
<value>New DM greet message set.</value>
</data>
<data name="administration_greetdm_off" xml:space="preserve">
<value>DM greet announcements disabled.</value>
</data>
<data name="administration_greetdm_on" xml:space="preserve">
<value>DM greet announcements enabled.</value>
</data>
<data name="administration_greetmsg_cur" xml:space="preserve">
<value>Current greet message: {0}</value>
</data>
<data name="administration_greetmsg_enable" xml:space="preserve">
<value>Enable greet messages by typing {0}</value>
</data>
<data name="administration_greetmsg_new" xml:space="preserve">
<value>New greet message set.</value>
</data>
<data name="administration_greet_off" xml:space="preserve">
<value>Greet announcements disabled.</value>
</data>
<data name="administration_greet_on" xml:space="preserve">
<value>Greet announcements enabled on this channel.</value>
</data>
<data name="administration_images_loaded" xml:space="preserve">
<value>Images loaded after {0} seconds!</value>
</data>