Esempio n. 1
0
        private async Task ExecuteGameInputAsync(IReactionsGame game, SocketReaction reaction, IUserMessage message, ISocketMessageChannel channel)
        {
            var userId = reaction.UserId;
            var user   = reaction.User.GetValueOrDefault() ?? client.GetUser(reaction.UserId);
            var guild  = (channel as SocketTextChannel)?.Guild;

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

            await game.InputAsync(reaction.Emote, userId);

            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, userId, pmGame.State, pmGame.Time,
                                                    user?.NameandDisc(), $"{guild?.Name}/{channel.Name}", DateTime.Now));
                }

                if (channel.BotCan(ChannelPermission.ManageMessages))
                {
                    await message.RemoveAllReactionsAsync(PmBot.DefaultOptions);
                }
            }

            game.CancelRequests();
            try { await message.ModifyAsync(game.GetMessageUpdate(), game.GetRequestOptions()); }
            catch (OperationCanceledException) { }
        }
Esempio n. 2
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);
        }