コード例 #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) { }
        }
コード例 #2
0
        private async void HandleReaction(SocketReaction reaction, Cacheable <IUserMessage, ulong> messageData, ISocketMessageChannel channel)
        {
            try
            {
                if (!channel.BotCan(ChannelPermission.SendMessages | ChannelPermission.ReadMessageHistory))
                {
                    return;
                }

                var message = reaction.Message.GetValueOrDefault() ?? await messageData.GetOrDownloadAsync();

                if (reaction.UserId != client.CurrentUser.Id && message?.Author.Id == client.CurrentUser.Id)
                {
                    await ReactionGameInputAsync(reaction, message, channel);
                }
            }
            catch (Exception e)
            {
                log.Exception($"In {channel.FullName()}", e);
            }
        }