mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-12 18:28:27 -04:00
- Fixed some possible nullref exceptions - Methods signatures now have up to 3 parameters before breakaing down each parameter in a separate line - Method invocations have the same rule, except the first parameter will be in the same line as the invocation to prevent some ugliness when passing lambas as arguments - Applied many more codestyles - Extensions folder fully reformatted
52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using NadekoBot.Modules.Games.Common;
|
|
using NadekoBot.Modules.Games.Services;
|
|
|
|
namespace NadekoBot.Modules.Games;
|
|
|
|
public partial class Games
|
|
{
|
|
[Group]
|
|
public class TicTacToeCommands : NadekoSubmodule<GamesService>
|
|
{
|
|
private readonly SemaphoreSlim _sem = new(1, 1);
|
|
private readonly DiscordSocketClient _client;
|
|
|
|
public TicTacToeCommands(DiscordSocketClient client)
|
|
=> _client = client;
|
|
|
|
[NadekoCommand, 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 var game))
|
|
{
|
|
var _ = Task.Run(async () =>
|
|
{
|
|
await game.Start((IGuildUser)ctx.User).ConfigureAwait(false);
|
|
});
|
|
return;
|
|
}
|
|
game = new(base.Strings, this._client, channel, (IGuildUser)ctx.User, options, _eb);
|
|
_service.TicTacToeGames.Add(channel.Id, game);
|
|
await ReplyConfirmLocalizedAsync(strs.ttt_created).ConfigureAwait(false);
|
|
|
|
game.OnEnded += g =>
|
|
{
|
|
_service.TicTacToeGames.Remove(channel.Id);
|
|
_sem.Dispose();
|
|
};
|
|
}
|
|
finally
|
|
{
|
|
_sem.Release();
|
|
}
|
|
}
|
|
}
|
|
} |