NadekoBot/NadekoBot.Modules.Games/CleverBotCommands.cs

56 lines
1.8 KiB
C#
Raw Normal View History

2016-11-07 21:50:00 +00:00
using Discord;
using Discord.Commands;
using NadekoBot.Core.Services;
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;
using NadekoBot.Modules.Games.Common.ChatterBot;
2016-11-07 21:50:00 +00:00
namespace NadekoBot.Modules.Games
{
public partial class Games
{
[Group]
public class ChatterBotCommands : NadekoSubmodule<ChatterBotService>
2016-11-07 21:50:00 +00:00
{
private readonly DbService _db;
2016-11-07 21:50:00 +00:00
public ChatterBotCommands(DbService db)
{
2017-05-27 08:19:27 +00:00
_db = db;
2016-11-07 21:50:00 +00:00
}
2016-11-07 21:50:00 +00:00
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.ManageMessages)]
2016-12-16 18:43:57 +00:00
public async Task Cleverbot()
2016-11-07 21:50:00 +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);
}
await ReplyConfirmLocalized("cleverbot_disabled").ConfigureAwait(false);
2016-11-07 21:50:00 +00:00
return;
}
_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
}
await ReplyConfirmLocalized("cleverbot_enabled").ConfigureAwait(false);
2016-11-07 21:50:00 +00:00
}
}
2017-05-27 08:19:27 +00:00
2016-11-07 21:50:00 +00:00
}
}