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