mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
Fixed some crashes in response strings source generator, reorganized more submodules into their folders
This commit is contained in:
54
src/NadekoBot/Modules/Games/TicTacToe/TicTacToeCommands.cs
Normal file
54
src/NadekoBot/Modules/Games/TicTacToe/TicTacToeCommands.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
#nullable disable
|
||||
using NadekoBot.Modules.Games.Common;
|
||||
using NadekoBot.Modules.Games.Services;
|
||||
|
||||
namespace NadekoBot.Modules.Games;
|
||||
|
||||
public partial class Games
|
||||
{
|
||||
[Group]
|
||||
public partial class TicTacToeCommands : NadekoSubmodule<GamesService>
|
||||
{
|
||||
private readonly SemaphoreSlim _sem = new(1, 1);
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
public TicTacToeCommands(DiscordSocketClient client)
|
||||
=> _client = client;
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[NadekoOptions(typeof(TicTacToe.Options))]
|
||||
public async partial Task TicTacToe(params string[] args)
|
||||
{
|
||||
var (options, _) = OptionsParser.ParseFrom(new TicTacToe.Options(), args);
|
||||
var channel = (ITextChannel)ctx.Channel;
|
||||
|
||||
await _sem.WaitAsync(1000);
|
||||
try
|
||||
{
|
||||
if (_service.TicTacToeGames.TryGetValue(channel.Id, out var game))
|
||||
{
|
||||
var _ = Task.Run(async () =>
|
||||
{
|
||||
await game.Start((IGuildUser)ctx.User);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
game = new(Strings, _client, channel, (IGuildUser)ctx.User, options, _eb);
|
||||
_service.TicTacToeGames.Add(channel.Id, game);
|
||||
await ReplyConfirmLocalizedAsync(strs.ttt_created);
|
||||
|
||||
game.OnEnded += _ =>
|
||||
{
|
||||
_service.TicTacToeGames.Remove(channel.Id);
|
||||
_sem.Dispose();
|
||||
};
|
||||
}
|
||||
finally
|
||||
{
|
||||
_sem.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user