Ejemplo n.º 1
0
 internal GuildInfo(int?afkTimeout, DefaultMessageNotifications?defaultNotifs,
                    ulong?afkChannel, string name, string region, string icon,
                    VerificationLevel?verification, IUser owner, MfaLevel?mfa, int?filter)
 {
     AfkTimeout = afkTimeout;
     DefaultMessageNotifications = defaultNotifs;
     AfkChannelId       = afkChannel;
     Name               = name;
     RegionId           = region;
     IconHash           = icon;
     VerificationLevel  = verification;
     Owner              = owner;
     MfaLevel           = mfa;
     ContentFilterLevel = filter;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a guild. This requires the bot to be in less than 10 guilds total.
        /// </summary>
        /// <param name="name">Name of the guild.</param>
        /// <param name="region">Voice region of the guild.</param>
        /// <param name="icon">Stream containing the icon for the guild.</param>
        /// <param name="verificationLevel">Verification level for the guild.</param>
        /// <param name="defaultMessageNotifications">Default message notification settings for the guild.</param>
        /// <returns>The created guild.</returns>
        /// <exception cref="Exceptions.NotFoundException">Thrown when the channel does not exist.</exception>
        /// <exception cref="Exceptions.BadRequestException">Thrown when an invalid parameter was provided.</exception>
        /// <exception cref="Exceptions.ServerErrorException">Thrown when Discord is unable to process the request.</exception>
        public Task <DiscordGuild> CreateGuildAsync(string name, string region = null, Optional <Stream> icon = default, VerificationLevel?verificationLevel = null,
                                                    DefaultMessageNotifications?defaultMessageNotifications = null)
        {
            var iconb64 = Optional.FromNoValue <string>();

            if (icon.HasValue && icon.Value != null)
            {
                using (var imgtool = new ImageTool(icon.Value))
                    iconb64 = imgtool.GetBase64();
            }
            else if (icon.HasValue)
            {
                iconb64 = null;
            }

            return(this.ApiClient.CreateGuildAsync(name, region, iconb64, verificationLevel, defaultMessageNotifications));
        }
Ejemplo n.º 3
0
 internal GuildInfo(int?afkTimeout, DefaultMessageNotifications?defaultNotifs,
                    ulong?afkChannel, string name, string region, string icon,
                    VerificationLevel?verification, IUser owner, MfaLevel?mfa, ExplicitContentFilterLevel?filter,
                    ulong?systemChannel, ulong?widgetChannel, bool?widget)
 {
     AfkTimeout = afkTimeout;
     DefaultMessageNotifications = defaultNotifs;
     AfkChannelId          = afkChannel;
     Name                  = name;
     RegionId              = region;
     IconHash              = icon;
     VerificationLevel     = verification;
     Owner                 = owner;
     MfaLevel              = mfa;
     ExplicitContentFilter = filter;
     SystemChannelId       = systemChannel;
     EmbedChannelId        = widgetChannel;
     IsEmbeddable          = widget;
 }
Ejemplo n.º 4
0
 public Task <DiscordGuild> ModifyGuildAsync(ulong guild_id, string name, string region, VerificationLevel?verification_level, DefaultMessageNotifications?default_message_notifications,
                                             MfaLevel?mfa_level, ExplicitContentFilter?explicit_content_filter, ulong?afk_channel_id, int?afk_timeout, string iconb64, ulong?owner_id, string splashb64, string reason)
 => ApiClient.ModifyGuildAsync(guild_id, name, region, verification_level, default_message_notifications, mfa_level, explicit_content_filter, afk_channel_id, afk_timeout, iconb64,
                               owner_id, splashb64, reason);
Ejemplo n.º 5
0
 public Task <DiscordGuild> CreateGuildAsync(string name, string region_id, string iconb64, VerificationLevel?verification_level, DefaultMessageNotifications?default_message_notifications)
 => ApiClient.CreateGuildAsync(name, region_id, iconb64, verification_level, default_message_notifications);
Ejemplo n.º 6
0
        internal static GuildUpdateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
        {
            var changes = entry.Changes;

            var afkTimeoutModel = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout");
            var defaultMessageNotificationsModel = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout");
            var afkChannelModel        = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout");
            var nameModel              = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout");
            var regionIdModel          = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout");
            var iconHashModel          = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout");
            var verificationLevelModel = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout");
            var ownerIdModel           = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout");
            var mfaLevelModel          = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout");
            var contentFilterModel     = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout");

            int?oldAfkTimeout = afkTimeoutModel?.OldValue?.ToObject <int>(discord.ApiClient.Serializer),
               newAfkTimeout  = afkTimeoutModel?.NewValue?.ToObject <int>(discord.ApiClient.Serializer);
            DefaultMessageNotifications?oldDefaultMessageNotifications = defaultMessageNotificationsModel?.OldValue?.ToObject <DefaultMessageNotifications>(discord.ApiClient.Serializer),
                                       newDefaultMessageNotifications  = defaultMessageNotificationsModel?.NewValue?.ToObject <DefaultMessageNotifications>(discord.ApiClient.Serializer);
            ulong?oldAfkChannelId = afkChannelModel?.OldValue?.ToObject <ulong>(discord.ApiClient.Serializer),
                 newAfkChannelId  = afkChannelModel?.NewValue?.ToObject <ulong>(discord.ApiClient.Serializer);
            string oldName        = nameModel?.OldValue?.ToObject <string>(discord.ApiClient.Serializer),
                   newName        = nameModel?.NewValue?.ToObject <string>(discord.ApiClient.Serializer);
            string oldRegionId    = regionIdModel?.OldValue?.ToObject <string>(discord.ApiClient.Serializer),
                   newRegionId    = regionIdModel?.NewValue?.ToObject <string>(discord.ApiClient.Serializer);
            string oldIconHash    = iconHashModel?.OldValue?.ToObject <string>(discord.ApiClient.Serializer),
                   newIconHash    = iconHashModel?.NewValue?.ToObject <string>(discord.ApiClient.Serializer);
            VerificationLevel?oldVerificationLevel = verificationLevelModel?.OldValue?.ToObject <VerificationLevel>(discord.ApiClient.Serializer),
                             newVerificationLevel  = verificationLevelModel?.NewValue?.ToObject <VerificationLevel>(discord.ApiClient.Serializer);
            ulong?oldOwnerId     = ownerIdModel?.OldValue?.ToObject <ulong>(discord.ApiClient.Serializer),
                 newOwnerId      = ownerIdModel?.NewValue?.ToObject <ulong>(discord.ApiClient.Serializer);
            MfaLevel?oldMfaLevel = mfaLevelModel?.OldValue?.ToObject <MfaLevel>(discord.ApiClient.Serializer),
                    newMfaLevel  = mfaLevelModel?.NewValue?.ToObject <MfaLevel>(discord.ApiClient.Serializer);
            int?oldContentFilter = contentFilterModel?.OldValue?.ToObject <int>(discord.ApiClient.Serializer),
               newContentFilter  = contentFilterModel?.NewValue?.ToObject <int>(discord.ApiClient.Serializer);

            IUser oldOwner = null;

            if (oldOwnerId != null)
            {
                var oldOwnerInfo = log.Users.FirstOrDefault(x => x.Id == oldOwnerId.Value);
                oldOwner = RestUser.Create(discord, oldOwnerInfo);
            }

            IUser newOwner = null;

            if (newOwnerId != null)
            {
                var newOwnerInfo = log.Users.FirstOrDefault(x => x.Id == newOwnerId.Value);
                newOwner = RestUser.Create(discord, newOwnerInfo);
            }

            var before = new GuildInfo(oldAfkTimeout, oldDefaultMessageNotifications,
                                       oldAfkChannelId, oldName, oldRegionId, oldIconHash, oldVerificationLevel, oldOwner,
                                       oldMfaLevel, oldContentFilter);
            var after = new GuildInfo(newAfkTimeout, newDefaultMessageNotifications,
                                      newAfkChannelId, newName, newRegionId, newIconHash, newVerificationLevel, newOwner,
                                      newMfaLevel, newContentFilter);

            return(new GuildUpdateAuditLogData(before, after));
        }
Ejemplo n.º 7
0
        internal static GuildUpdateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
        {
            var changes = entry.Changes;

            var afkTimeoutModel = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout");
            var defaultMessageNotificationsModel = changes.FirstOrDefault(x => x.ChangedProperty == "default_message_notifications");
            var afkChannelModel        = changes.FirstOrDefault(x => x.ChangedProperty == "afk_channel_id");
            var nameModel              = changes.FirstOrDefault(x => x.ChangedProperty == "name");
            var regionIdModel          = changes.FirstOrDefault(x => x.ChangedProperty == "region");
            var iconHashModel          = changes.FirstOrDefault(x => x.ChangedProperty == "icon_hash");
            var verificationLevelModel = changes.FirstOrDefault(x => x.ChangedProperty == "verification_level");
            var ownerIdModel           = changes.FirstOrDefault(x => x.ChangedProperty == "owner_id");
            var mfaLevelModel          = changes.FirstOrDefault(x => x.ChangedProperty == "mfa_level");
            var contentFilterModel     = changes.FirstOrDefault(x => x.ChangedProperty == "explicit_content_filter");
            var systemChannelIdModel   = changes.FirstOrDefault(x => x.ChangedProperty == "system_channel_id");
            var widgetChannelIdModel   = changes.FirstOrDefault(x => x.ChangedProperty == "widget_channel_id");
            var widgetEnabledModel     = changes.FirstOrDefault(x => x.ChangedProperty == "widget_enabled");

            int?oldAfkTimeout = afkTimeoutModel?.OldValue?.ToObject <int>(discord.ApiClient.Serializer),
               newAfkTimeout  = afkTimeoutModel?.NewValue?.ToObject <int>(discord.ApiClient.Serializer);
            DefaultMessageNotifications?oldDefaultMessageNotifications = defaultMessageNotificationsModel?.OldValue?.ToObject <DefaultMessageNotifications>(discord.ApiClient.Serializer),
                                       newDefaultMessageNotifications  = defaultMessageNotificationsModel?.NewValue?.ToObject <DefaultMessageNotifications>(discord.ApiClient.Serializer);
            ulong?oldAfkChannelId = afkChannelModel?.OldValue?.ToObject <ulong>(discord.ApiClient.Serializer),
                 newAfkChannelId  = afkChannelModel?.NewValue?.ToObject <ulong>(discord.ApiClient.Serializer);
            string oldName        = nameModel?.OldValue?.ToObject <string>(discord.ApiClient.Serializer),
                   newName        = nameModel?.NewValue?.ToObject <string>(discord.ApiClient.Serializer);
            string oldRegionId    = regionIdModel?.OldValue?.ToObject <string>(discord.ApiClient.Serializer),
                   newRegionId    = regionIdModel?.NewValue?.ToObject <string>(discord.ApiClient.Serializer);
            string oldIconHash    = iconHashModel?.OldValue?.ToObject <string>(discord.ApiClient.Serializer),
                   newIconHash    = iconHashModel?.NewValue?.ToObject <string>(discord.ApiClient.Serializer);
            VerificationLevel?oldVerificationLevel = verificationLevelModel?.OldValue?.ToObject <VerificationLevel>(discord.ApiClient.Serializer),
                             newVerificationLevel  = verificationLevelModel?.NewValue?.ToObject <VerificationLevel>(discord.ApiClient.Serializer);
            ulong?oldOwnerId     = ownerIdModel?.OldValue?.ToObject <ulong>(discord.ApiClient.Serializer),
                 newOwnerId      = ownerIdModel?.NewValue?.ToObject <ulong>(discord.ApiClient.Serializer);
            MfaLevel?oldMfaLevel = mfaLevelModel?.OldValue?.ToObject <MfaLevel>(discord.ApiClient.Serializer),
                    newMfaLevel  = mfaLevelModel?.NewValue?.ToObject <MfaLevel>(discord.ApiClient.Serializer);
            ExplicitContentFilterLevel?oldContentFilter = contentFilterModel?.OldValue?.ToObject <ExplicitContentFilterLevel>(discord.ApiClient.Serializer),
                                      newContentFilter  = contentFilterModel?.NewValue?.ToObject <ExplicitContentFilterLevel>(discord.ApiClient.Serializer);
            ulong?oldSystemChannelId = systemChannelIdModel?.OldValue?.ToObject <ulong>(discord.ApiClient.Serializer),
                 newSystemChannelId  = systemChannelIdModel?.NewValue?.ToObject <ulong>(discord.ApiClient.Serializer);
            ulong?oldWidgetChannelId = widgetChannelIdModel?.OldValue?.ToObject <ulong>(discord.ApiClient.Serializer),
                 newWidgetChannelId  = widgetChannelIdModel?.NewValue?.ToObject <ulong>(discord.ApiClient.Serializer);
            bool?oldWidgetEnabled    = widgetEnabledModel?.OldValue?.ToObject <bool>(discord.ApiClient.Serializer),
                newWidgetEnabled     = widgetEnabledModel?.NewValue?.ToObject <bool>(discord.ApiClient.Serializer);

            IUser oldOwner = null;

            if (oldOwnerId != null)
            {
                var oldOwnerInfo = log.Users.FirstOrDefault(x => x.Id == oldOwnerId.Value);
                oldOwner = RestUser.Create(discord, oldOwnerInfo);
            }

            IUser newOwner = null;

            if (newOwnerId != null)
            {
                var newOwnerInfo = log.Users.FirstOrDefault(x => x.Id == newOwnerId.Value);
                newOwner = RestUser.Create(discord, newOwnerInfo);
            }

            var before = new GuildInfo(oldAfkTimeout, oldDefaultMessageNotifications,
                                       oldAfkChannelId, oldName, oldRegionId, oldIconHash, oldVerificationLevel, oldOwner,
                                       oldMfaLevel, oldContentFilter, oldSystemChannelId, oldWidgetChannelId, oldWidgetEnabled);
            var after = new GuildInfo(newAfkTimeout, newDefaultMessageNotifications,
                                      newAfkChannelId, newName, newRegionId, newIconHash, newVerificationLevel, newOwner,
                                      newMfaLevel, newContentFilter, newSystemChannelId, newWidgetChannelId, newWidgetEnabled);

            return(new GuildUpdateAuditLogData(before, after));
        }
Ejemplo n.º 8
0
 public async Task <DiscordGuild> ModifyGuildAsync(ulong guild_id, string name, string region, VerificationLevel?verification_level,
                                                   DefaultMessageNotifications?default_message_notifications, ulong?afk_channel_id, int?afk_timeout, string iconb64, ulong?owner_id, string splashb64, string reason)
 => await ApiClient.ModifyGuildAsync(guild_id, name, region, verification_level, default_message_notifications, afk_channel_id, afk_timeout, iconb64, owner_id, splashb64, reason);