Esempio n. 1
0
        private async Task ExecuteGameInputAsync(IReactionsGame game, SocketReaction reaction, IUserMessage gameMessage)
        {
            var user    = reaction.User.IsSpecified ? reaction.User.Value : client.GetUser(reaction.UserId);
            var channel = gameMessage.Channel;
            var guild   = (channel as IGuildChannel)?.Guild;

            await logger.Log(LogSeverity.Verbose, game.Name,
                             $"Input {PacManGame.GameInputs[reaction.Emote].ToString().Align(5)} " +
                             $"by {user.FullName()} in {channel.FullName()}");

            game.Input(reaction.Emote, user.Id);

            if (game.State != State.Active)
            {
                storage.DeleteGame(game);

                if (game is PacManGame pmGame && pmGame.State != State.Cancelled && !pmGame.custom)
                {
                    storage.AddScore(new ScoreEntry(pmGame.score, user.Id, pmGame.State, pmGame.Time,
                                                    user.NameandNum(), $"{guild?.Name}/{channel.Name}", DateTime.Now));
                }
                if (channel.BotCan(ChannelPermission.ManageMessages))
                {
                    await gameMessage.RemoveAllReactionsAsync(Bot.DefaultOptions);
                }
            }

            game.CancelRequests();
            await gameMessage.ModifyAsync(game.UpdateMessage, game.RequestOptions);
        }
Esempio n. 2
0
        private async Task ExecuteGameInputAsync(IReactionsGame game, SocketReaction reaction, IUserMessage gameMessage)
        {
            var user    = gameMessage.Author;
            var channel = gameMessage.Channel;
            var guild   = (channel as IGuildChannel)?.Guild;

            log.Verbose(
                $"Input {reaction.Emote.ReadableName()} by {user.FullName()} in {channel.FullName()}",
                game.GameName);

            game.Input(reaction.Emote, user.Id);

            if (game.State != GameState.Active)
            {
                if (!(game is IUserGame))
                {
                    games.Remove(game);
                }

                if (game is PacManGame pmGame && pmGame.State != GameState.Cancelled && !pmGame.custom)
                {
                    storage.AddScore(new ScoreEntry(pmGame.score, user.Id, pmGame.State, pmGame.Time,
                                                    user.NameandDisc(), $"{guild?.Name}/{channel.Name}", DateTime.Now));
                }

                if (await channel.BotCanAsync(ChannelPermission.ManageMessages))
                {
                    await gameMessage.RemoveAllReactionsAsync(PmBot.DefaultOptions);
                }
            }

            game.CancelRequests();
            try { await gameMessage.ModifyAsync(game.GetMessageUpdate(), game.GetRequestOptions()); }
            catch (OperationCanceledException) { }
        }