2017-02-08 20:44:32 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using Discord.WebSocket;
|
2017-02-08 20:44:32 +00:00
|
|
|
|
using NadekoBot.Extensions;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
2017-02-09 02:09:06 +00:00
|
|
|
|
using System.Threading;
|
2017-02-08 20:44:32 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 19:42:36 +00:00
|
|
|
|
using NadekoBot.Common.Attributes;
|
|
|
|
|
using NadekoBot.Services.Impl;
|
2017-10-04 22:51:12 +00:00
|
|
|
|
using NadekoBot.Modules.Games.Services;
|
|
|
|
|
using NadekoBot.Modules.Games.Common;
|
2017-02-08 20:44:32 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Games
|
|
|
|
|
{
|
|
|
|
|
public partial class Games
|
|
|
|
|
{
|
|
|
|
|
[Group]
|
2017-10-04 22:51:12 +00:00
|
|
|
|
public class TicTacToeCommands : NadekoSubmodule<GamesService>
|
2017-02-08 20:44:32 +00:00
|
|
|
|
{
|
2017-02-23 22:30:38 +00:00
|
|
|
|
private readonly SemaphoreSlim _sem = new SemaphoreSlim(1, 1);
|
2017-06-19 13:42:10 +00:00
|
|
|
|
private readonly DiscordSocketClient _client;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
|
2017-06-19 13:42:10 +00:00
|
|
|
|
public TicTacToeCommands(DiscordSocketClient client)
|
2017-05-27 08:19:27 +00:00
|
|
|
|
{
|
|
|
|
|
_client = client;
|
|
|
|
|
}
|
2017-02-09 02:09:06 +00:00
|
|
|
|
|
2017-02-08 20:44:32 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-02-09 02:09:06 +00:00
|
|
|
|
public async Task TicTacToe()
|
2017-02-08 20:44:32 +00:00
|
|
|
|
{
|
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
|
|
|
|
|
2017-02-23 22:30:38 +00:00
|
|
|
|
await _sem.WaitAsync(1000);
|
2017-02-09 02:09:06 +00:00
|
|
|
|
try
|
2017-02-08 20:44:32 +00:00
|
|
|
|
{
|
2017-10-04 22:51:12 +00:00
|
|
|
|
if (_service.TicTacToeGames.TryGetValue(channel.Id, out TicTacToe game))
|
2017-02-08 20:44:32 +00:00
|
|
|
|
{
|
2017-02-09 02:09:06 +00:00
|
|
|
|
var _ = Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
await game.Start((IGuildUser)Context.User);
|
|
|
|
|
});
|
2017-02-08 20:44:32 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-10-04 22:51:12 +00:00
|
|
|
|
game = new TicTacToe(base._strings, this._client, channel, (IGuildUser)Context.User);
|
|
|
|
|
_service.TicTacToeGames.Add(channel.Id, game);
|
2017-02-23 22:30:38 +00:00
|
|
|
|
await ReplyConfirmLocalized("ttt_created").ConfigureAwait(false);
|
2017-02-09 02:09:06 +00:00
|
|
|
|
|
|
|
|
|
game.OnEnded += (g) =>
|
|
|
|
|
{
|
2017-10-04 22:51:12 +00:00
|
|
|
|
_service.TicTacToeGames.Remove(channel.Id);
|
2017-02-09 02:09:06 +00:00
|
|
|
|
};
|
2017-02-08 20:44:32 +00:00
|
|
|
|
}
|
2017-02-09 02:09:06 +00:00
|
|
|
|
finally
|
2017-02-08 20:44:32 +00:00
|
|
|
|
{
|
2017-02-23 22:30:38 +00:00
|
|
|
|
_sem.Release();
|
2017-02-08 20:44:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-09 02:09:06 +00:00
|
|
|
|
}
|