2016-08-25 01:19:06 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
2016-10-09 20:40:14 +00:00
|
|
|
|
using NadekoBot.Extensions;
|
2017-10-13 04:14:54 +00:00
|
|
|
|
using NadekoBot.Core.Services;
|
|
|
|
|
using NadekoBot.Core.Services.Database.Models;
|
2016-08-25 01:19:06 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 19:42:36 +00:00
|
|
|
|
using NadekoBot.Common.Attributes;
|
2016-08-25 01:19:06 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Administration
|
|
|
|
|
{
|
2016-08-25 12:38:38 +00:00
|
|
|
|
public partial class Administration
|
2016-08-25 01:19:06 +00:00
|
|
|
|
{
|
2016-08-25 13:09:17 +00:00
|
|
|
|
[Group]
|
2017-07-15 16:34:34 +00:00
|
|
|
|
public class ServerGreetCommands : NadekoSubmodule<GreetSettingsService>
|
2016-08-25 01:19:06 +00:00
|
|
|
|
{
|
2017-05-29 04:13:22 +00:00
|
|
|
|
private readonly DbService _db;
|
2017-01-29 12:12:07 +00:00
|
|
|
|
|
2017-07-15 16:34:34 +00:00
|
|
|
|
public ServerGreetCommands(DbService db)
|
2016-08-25 12:38:38 +00:00
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
_db = db;
|
2016-08-25 01:19:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-25 12:38:38 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageGuild)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task GreetDel(int timer = 30)
|
2016-08-25 01:19:06 +00:00
|
|
|
|
{
|
2016-11-22 10:42:26 +00:00
|
|
|
|
if (timer < 0 || timer > 600)
|
|
|
|
|
return;
|
2016-08-25 01:19:06 +00:00
|
|
|
|
|
2017-07-15 16:34:34 +00:00
|
|
|
|
await _service.SetGreetDel(Context.Guild.Id, timer).ConfigureAwait(false);
|
2016-08-25 01:19:06 +00:00
|
|
|
|
|
2016-11-22 10:42:26 +00:00
|
|
|
|
if (timer > 0)
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("greetdel_on", timer).ConfigureAwait(false);
|
2016-08-25 12:38:38 +00:00
|
|
|
|
else
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("greetdel_off").ConfigureAwait(false);
|
2016-08-25 01:19:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-25 12:38:38 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageGuild)]
|
|
|
|
|
public async Task Greet()
|
2016-08-25 01:19:06 +00:00
|
|
|
|
{
|
2017-07-15 16:34:34 +00:00
|
|
|
|
var enabled = await _service.SetGreet(Context.Guild.Id, Context.Channel.Id).ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
|
|
|
|
|
if (enabled)
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("greet_on").ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
else
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("greet_off").ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-25 12:38:38 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageGuild)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task GreetMsg([Remainder] string text = null)
|
2016-08-25 01:19:06 +00:00
|
|
|
|
{
|
2016-11-16 04:35:14 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(text))
|
2016-08-25 12:38:38 +00:00
|
|
|
|
{
|
2016-12-03 13:14:37 +00:00
|
|
|
|
string channelGreetMessageText;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-08-25 12:38:38 +00:00
|
|
|
|
{
|
2016-12-16 21:44:26 +00:00
|
|
|
|
channelGreetMessageText = uow.GuildConfigs.For(Context.Guild.Id, set => set).ChannelGreetMessageText;
|
2016-08-25 12:38:38 +00:00
|
|
|
|
}
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("greetmsg_cur", channelGreetMessageText?.SanitizeMentions()).ConfigureAwait(false);
|
2016-08-25 12:38:38 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-11-16 04:35:14 +00:00
|
|
|
|
|
2017-07-15 16:34:34 +00:00
|
|
|
|
var sendGreetEnabled = _service.SetGreetMessage(Context.Guild.Id, ref text);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("greetmsg_new").ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
if (!sendGreetEnabled)
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("greetmsg_enable", $"`{Prefix}greet`").ConfigureAwait(false);
|
2016-08-25 01:19:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-25 12:38:38 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageGuild)]
|
|
|
|
|
public async Task GreetDm()
|
2016-08-25 13:09:17 +00:00
|
|
|
|
{
|
2017-07-15 16:34:34 +00:00
|
|
|
|
var enabled = await _service.SetGreetDm(Context.Guild.Id).ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
|
|
|
|
|
if (enabled)
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("greetdm_on").ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
else
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("greetdm_off").ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-25 13:09:17 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageGuild)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task GreetDmMsg([Remainder] string text = null)
|
2016-08-25 12:38:38 +00:00
|
|
|
|
{
|
2016-11-16 04:35:14 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(text))
|
2016-08-25 12:38:38 +00:00
|
|
|
|
{
|
2016-11-16 04:35:14 +00:00
|
|
|
|
GuildConfig config;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-08-25 12:38:38 +00:00
|
|
|
|
{
|
2016-12-16 21:44:26 +00:00
|
|
|
|
config = uow.GuildConfigs.For(Context.Guild.Id);
|
2016-08-25 12:38:38 +00:00
|
|
|
|
}
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("greetdmmsg_cur", config.DmGreetMessageText?.SanitizeMentions()).ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
return;
|
2016-08-25 12:38:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-15 16:34:34 +00:00
|
|
|
|
var sendGreetEnabled = _service.SetGreetDmMessage(Context.Guild.Id, ref text);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("greetdmmsg_new").ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
if (!sendGreetEnabled)
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("greetdmmsg_enable", $"`{Prefix}greetdm`").ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-25 12:38:38 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageGuild)]
|
|
|
|
|
public async Task Bye()
|
2016-08-25 01:19:06 +00:00
|
|
|
|
{
|
2017-07-15 16:34:34 +00:00
|
|
|
|
var enabled = await _service.SetBye(Context.Guild.Id, Context.Channel.Id).ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
|
|
|
|
|
if (enabled)
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("bye_on").ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
else
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("bye_off").ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-25 12:38:38 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageGuild)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task ByeMsg([Remainder] string text = null)
|
2016-08-25 01:19:06 +00:00
|
|
|
|
{
|
2016-11-16 04:35:14 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(text))
|
2016-08-25 12:38:38 +00:00
|
|
|
|
{
|
2016-12-03 13:14:37 +00:00
|
|
|
|
string byeMessageText;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-08-25 12:38:38 +00:00
|
|
|
|
{
|
2016-12-16 21:44:26 +00:00
|
|
|
|
byeMessageText = uow.GuildConfigs.For(Context.Guild.Id, set => set).ChannelByeMessageText;
|
2016-08-25 12:38:38 +00:00
|
|
|
|
}
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("byemsg_cur", byeMessageText?.SanitizeMentions()).ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
return;
|
2016-08-25 12:38:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-15 16:34:34 +00:00
|
|
|
|
var sendByeEnabled = _service.SetByeMessage(Context.Guild.Id, ref text);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("byemsg_new").ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
if (!sendByeEnabled)
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("byemsg_enable", $"`{Prefix}bye`").ConfigureAwait(false);
|
2016-11-16 04:35:14 +00:00
|
|
|
|
}
|
2016-12-28 05:31:39 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-25 13:09:17 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageGuild)]
|
2016-12-21 08:33:47 +00:00
|
|
|
|
public async Task ByeDel(int timer = 30)
|
2016-08-25 13:09:17 +00:00
|
|
|
|
{
|
2017-07-15 16:34:34 +00:00
|
|
|
|
await _service.SetByeDel(Context.Guild.Id, timer).ConfigureAwait(false);
|
2016-08-25 13:09:17 +00:00
|
|
|
|
|
2016-11-22 10:42:26 +00:00
|
|
|
|
if (timer > 0)
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("byedel_on", timer).ConfigureAwait(false);
|
2016-08-25 13:09:17 +00:00
|
|
|
|
else
|
2017-02-14 21:33:54 +00:00
|
|
|
|
await ReplyConfirmLocalized("byedel_off").ConfigureAwait(false);
|
2016-08-25 13:09:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 01:19:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|