示例#1
0
        public static async Task <EmbedBuilder> CreateMotdEmbed(this GuildMotd motd, IUser actor, RestAction action, IServiceProvider provider)
        {
            var translator = provider.GetService <Translator>();

            await translator.SetContext(motd.GuildId);

            EmbedBuilder embed = CreateBasicEmbed(action, provider, actor);

            if (actor != null)
            {
                embed.WithThumbnailUrl(actor.GetAvatarOrDefaultUrl());
            }

            embed.WithTitle(translator.T().MotD());

            switch (action)
            {
            case RestAction.Created:
                embed.WithDescription(translator.T().NotificationMotdInternalCreate(actor));
                break;

            case RestAction.Updated:
                embed.WithDescription(translator.T().NotificationMotdInternalEdited(actor));
                break;
            }

            embed.AddField(translator.T().NotificationMotdShow(), motd.ShowMotd ? CHECK : X_CHECK, false);
            embed.AddField(translator.T().Message(), motd.Message.Truncate(1000), false);

            return(embed);
        }
示例#2
0
 public GuildMotdView(GuildMotd motd)
 {
     Id        = motd.Id;
     GuildId   = motd.GuildId.ToString();
     UserId    = motd.UserId.ToString();
     CreatedAt = motd.CreatedAt;
     Message   = motd.Message;
     ShowMotd  = motd.ShowMotd;
 }
示例#3
0
 public GuildRecord(int id, string name, ContextGuildEmblem emblem, ulong experience,
                    int maxTaxCollectors, List <ContextGuildMember> members, GuildMotd motd)
 {
     this.Id               = id;
     this.Name             = name;
     this.Emblem           = emblem;
     this.Experience       = experience;
     this.MaxTaxCollectors = maxTaxCollectors;
     this.Members          = members;
     this.Motd             = motd;
 }
        public async Task <IActionResult> GetMotd([FromRoute] ulong guildId)
        {
            await RequirePermission(guildId, DiscordPermission.Moderator);

            Identity identity = await GetIdentity();

            GuildMotd motd = await GuildMotdRepository.CreateDefault(_serviceProvider, identity).GetMotd(guildId);

            IUser creator = await _discordAPI.FetchUserInfo(motd.UserId, CacheBehavior.Default);

            return(Ok(new GuildMotdExpandedView(motd, creator)));
        }
        private async Task AnnounceMotd(GuildMotd motd, IUser actor, RestAction action)
        {
            using var scope = _serviceProvider.CreateScope();

            _logger.LogInformation($"Announcing motd {motd.GuildId} ({motd.Id}).");

            GuildConfig guildConfig = await GuildConfigRepository.CreateDefault(scope.ServiceProvider).GetGuildConfig(motd.GuildId);

            if (!string.IsNullOrEmpty(guildConfig.ModInternalNotificationWebhook))
            {
                _logger.LogInformation($"Sending internal webhook for motd {motd.GuildId} ({motd.Id}) to {guildConfig.ModInternalNotificationWebhook}.");

                try
                {
                    EmbedBuilder embed = await motd.CreateMotdEmbed(actor, action, _serviceProvider);

                    await _discordAPI.ExecuteWebhook(guildConfig.ModInternalNotificationWebhook, embed.Build());
                }
                catch (Exception e)
                {
                    _logger.LogError(e, $"Error while announcing motd {motd.GuildId} ({motd.Id}) to {guildConfig.ModInternalNotificationWebhook}.");
                }
            }
        }