2016-11-07 22:50:00 +01:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using NadekoBot.Services;
|
2016-12-31 13:21:18 +01:00
|
|
|
|
using System;
|
2016-11-07 22:50:00 +01:00
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 21:42:36 +02:00
|
|
|
|
using NadekoBot.Common.Attributes;
|
|
|
|
|
using NadekoBot.Modules.Games.Services;
|
2017-07-20 22:58:19 +02:00
|
|
|
|
using NadekoBot.Modules.Games.Common.ChatterBot;
|
2016-11-07 22:50:00 +01:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Games
|
|
|
|
|
{
|
|
|
|
|
public partial class Games
|
|
|
|
|
{
|
|
|
|
|
[Group]
|
2017-07-20 22:58:19 +02:00
|
|
|
|
public class ChatterBotCommands : NadekoSubmodule<ChatterBotService>
|
2016-11-07 22:50:00 +01:00
|
|
|
|
{
|
2017-05-29 06:13:22 +02:00
|
|
|
|
private readonly DbService _db;
|
2016-11-07 22:50:00 +01:00
|
|
|
|
|
2017-07-20 22:58:19 +02:00
|
|
|
|
public ChatterBotCommands(DbService db)
|
2017-04-04 01:50:27 +02:00
|
|
|
|
{
|
2017-05-27 10:19:27 +02:00
|
|
|
|
_db = db;
|
2016-11-07 22:50:00 +01:00
|
|
|
|
}
|
2017-01-07 13:29:22 +01:00
|
|
|
|
|
2016-11-07 22:50:00 +01:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-01-07 19:56:44 +01:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageMessages)]
|
2016-12-16 19:43:57 +01:00
|
|
|
|
public async Task Cleverbot()
|
2016-11-07 22:50:00 +01:00
|
|
|
|
{
|
2016-12-31 13:21:18 +01:00
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
|
|
|
|
|
2017-07-25 18:31:30 +02:00
|
|
|
|
if (_service.ChatterBotGuilds.TryRemove(channel.Guild.Id, out _))
|
2016-11-07 22:50:00 +01:00
|
|
|
|
{
|
2017-05-27 10:19:27 +02:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-11-07 22:50:00 +01:00
|
|
|
|
{
|
2016-12-16 20:45:46 +01:00
|
|
|
|
uow.GuildConfigs.SetCleverbotEnabled(Context.Guild.Id, false);
|
2016-11-07 22:50:00 +01:00
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
2017-02-23 23:30:38 +01:00
|
|
|
|
await ReplyConfirmLocalized("cleverbot_disabled").ConfigureAwait(false);
|
2016-11-07 22:50:00 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 22:58:19 +02:00
|
|
|
|
_service.ChatterBotGuilds.TryAdd(channel.Guild.Id, new Lazy<IChatterBotSession>(() => _service.CreateSession(), true));
|
2016-11-07 22:50:00 +01:00
|
|
|
|
|
2017-05-27 10:19:27 +02:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-11-07 22:50:00 +01:00
|
|
|
|
{
|
2016-12-16 20:45:46 +01:00
|
|
|
|
uow.GuildConfigs.SetCleverbotEnabled(Context.Guild.Id, true);
|
2016-11-08 19:27:44 +01:00
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
2016-11-07 22:50:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-23 23:30:38 +01:00
|
|
|
|
await ReplyConfirmLocalized("cleverbot_enabled").ConfigureAwait(false);
|
2016-11-07 22:50:00 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-06 20:13:06 +01:00
|
|
|
|
|
2017-05-27 10:19:27 +02:00
|
|
|
|
|
2016-11-07 22:50:00 +01:00
|
|
|
|
}
|
2016-12-30 05:46:13 +01:00
|
|
|
|
}
|