private async Task OnMessage(SocketMessage message)
        {
            if (!message.Content.StartsWith("!"))
            {
                return;
            }

            using var scope = _factory.CreateScope();
            try
            {
                var payload = new DiscordMessageEvent
                {
                    Id            = message.Id,
                    Content       = message.Content,
                    IsDirector    = _roleHelper.HasRole(DiscordRole.Director, message),
                    IsTokenSeller = _roleHelper.HasRole(DiscordRole.TokenSeller, message),
                    IsBot         = message.Author.IsBot,
                    Username      = message.Author.Username,
                    Discriminator = message.Author.Discriminator,
                    UserId        = message.Author.Id,
                    InGuild       = _roleHelper.InGuild(message),
                    Channel       = message.Channel.Name,
                    ChannelId     = message.Channel.Id,
                    GuildId       = _roleHelper.GetGuildId(message),
                    Processor     = EnviromentExtensions.Idenitifer
                };
                var mediator = scope.ServiceProvider.GetService <IMediator>();
                await mediator.Publish(payload);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Failed to process discord message.");
            }
        }
Exemplo n.º 2
0
 protected void DiscordMessageHandler(object sender, DiscordMessageEvent e)
 {
     _ = TriggerRelay("discord", e.name, e.message, "" + e.server.ToString() + "@" + e.channel.ToString(), e.server.ToString(), e.channel.ToString());
 }