public async Task <RuntimeResult> Game(int rows = 3, SocketGuildUser other = null) { if (Service.Games.Any(x => x.Contains(Context.User))) { return(Error("You are already playing a game.")); } if (Context.Guild.VoiceChannels.Count(x => x.Name.StartsWith("ttt-")) != (rows * rows)) { var existing = Service.Games.Any(x => x.Message.Channel.Id == Context.Channel.Id); if (existing) { return(Error($"There is already a game occuring in this channel.")); } await ReplyAsync("As VCs have not been setup, you must use text messages to indicate where you wish to go. Eg, `A1` as top left"); } var game = new TTTGame(Context.Guild, rows); var msg = await ReplyAsync(embed : game.ToEmbed()); game.Message = msg; var _ = Task.Run(game.AddReactions); var role = Context.Guild.Roles.FirstOrDefault(x => x.Name == TTTService.RoleName); var self = Context.User as SocketGuildUser; await self.AddRoleAsync(role); if (other != null) { await other.AddRoleAsync(role); } Service.Games.Add(game); return(Success()); }
async Task resendMessage(TTTGame game) { var channel = game.Message.Channel; var newMsg = await channel.SendMessageAsync(embed : game.ToEmbed()); await game.Message.DeleteAndTrackAsync("resending game message"); game.Message = newMsg; var _ = Task.Run(game.AddReactions); }
async Task newPlayerTryJoin(SocketGuildUser user, TTTGame game) { if (game.GetPlayer(user) != Position.Empty) { return; } if (game.Crosses == null) { game.Crosses = user; } else { game.Naughts = user; } await game.Message.ModifyAsync(x => x.Embed = game.ToEmbed()); var role = game.Guild.Roles.FirstOrDefault(x => x.Name == TTTService.RoleName); await user.AddRoleAsync(role); await game.Message.Channel.SendMessageAsync($"{user.Mention} has joined as {game.GetPlayer(user)}s"); }