Exemplo n.º 1
0
        private async Task HandleMessageFromRegisteredUser(MessageCreateEvent @event, TraceContext trace, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var user = await userService.GetIdentityServiceUserId(@event.Message.Author, cancellationToken);

            var userId = user.Id.ToString();

            if (!user.Enabled)
            {
                return;
            }

            logger.LogInformation("Message author is registered, parsing for possible command & emitting message.");
            _ = emitter.Emit(@event.Message, @event.Message.ChannelId, cancellationToken);

            var result = await commandsService.ParseAndExecuteCommandAsUser(
                message : @event.Message.Content,
                userId : userId,
                sourceSystemId : @event.Message.ChannelId,
                cancellationToken : cancellationToken
                );

            logger.LogInformation("Got result: {@result}", result);

            if (result?.ReplyImmediately == true)
            {
                var createMessagePayload = new CreateMessagePayload
                {
                    Content = result.Response,
                    Embed   = GetDebugEmbed(user, trace),
                };

                await discordChannelClient.CreateMessage(@event.Message.ChannelId, createMessagePayload, cancellationToken);
            }
        }