mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
Restructured folders and project names, ci should be fixed
This commit is contained in:
62
src/NadekoBot/Modules/Games/TicTacToeCommands.cs
Normal file
62
src/NadekoBot/Modules/Games/TicTacToeCommands.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Common.Attributes;
|
||||
using NadekoBot.Core.Common;
|
||||
using NadekoBot.Modules.Games.Common;
|
||||
using NadekoBot.Modules.Games.Services;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Games
|
||||
{
|
||||
public partial class Games
|
||||
{
|
||||
[Group]
|
||||
public class TicTacToeCommands : NadekoSubmodule<GamesService>
|
||||
{
|
||||
private readonly SemaphoreSlim _sem = new SemaphoreSlim(1, 1);
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
public TicTacToeCommands(DiscordSocketClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[NadekoOptions(typeof(TicTacToe.Options))]
|
||||
public async Task TicTacToe(params string[] args)
|
||||
{
|
||||
var (options, _) = OptionsParser.ParseFrom(new TicTacToe.Options(), args);
|
||||
var channel = (ITextChannel)ctx.Channel;
|
||||
|
||||
await _sem.WaitAsync(1000).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
if (_service.TicTacToeGames.TryGetValue(channel.Id, out TicTacToe game))
|
||||
{
|
||||
var _ = Task.Run(async () =>
|
||||
{
|
||||
await game.Start((IGuildUser)ctx.User).ConfigureAwait(false);
|
||||
});
|
||||
return;
|
||||
}
|
||||
game = new TicTacToe(base.Strings, this._client, channel, (IGuildUser)ctx.User, options);
|
||||
_service.TicTacToeGames.Add(channel.Id, game);
|
||||
await ReplyConfirmLocalizedAsync("ttt_created").ConfigureAwait(false);
|
||||
|
||||
game.OnEnded += (g) =>
|
||||
{
|
||||
_service.TicTacToeGames.Remove(channel.Id);
|
||||
_sem.Dispose();
|
||||
};
|
||||
}
|
||||
finally
|
||||
{
|
||||
_sem.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user