Пример #1
0
        public async Task OnModerationActionCreatedAsync(long moderationActionId, ModerationActionCreationData data)
        {
            var logChannelIds = await ModerationService.GetLogChannelIdsAsync(data.GuildId);

            if (!logChannelIds.Any())
            {
                return;
            }

            try
            {
                var moderationAction = await ModerationService.GetModerationActionSummaryAsync(moderationActionId);

                if (!_renderTemplates.TryGetValue((moderationAction.Type, moderationAction.Infraction.Type), out var renderTemplate))
                {
                    return;
                }

                var message = string.Format(renderTemplate,
                                            moderationAction.Id,
                                            moderationAction.Created.UtcDateTime.ToString("HH:mm:ss"),
                                            moderationAction.CreatedBy.DisplayName,
                                            moderationAction.Infraction.Subject.DisplayName,
                                            moderationAction.Infraction.Subject.Id,
                                            moderationAction.Infraction.Reason);

                foreach (var logChannelId in logChannelIds)
                {
                    await(await DiscordClient.GetChannelAsync(logChannelId) as IMessageChannel)
                    .SendMessageAsync(message);
                }
            }
            catch (Exception ex)
            {
                var text = Newtonsoft.Json.JsonConvert.SerializeObject(ex);
            }
        }