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