コード例 #1
0
        public Task <DiscordWebhook> ModifyWebhookAsync(ulong webhook_id, string name, Stream avatar, string webhook_token, string reason)
        {
            string av64 = null;

            if (avatar != null)
            {
                using (var imgtool = new ImageTool(avatar))
                    av64 = imgtool.GetBase64();
            }

            return(this.ApiClient.ModifyWebhookAsync(webhook_id, name, av64, webhook_token, reason));
        }
コード例 #2
0
        public Task <DiscordWebhook> CreateWebhookAsync(ulong channel_id, string name, Stream avatar = null, string reason = null)
        {
            string av64 = null;

            if (avatar != null)
            {
                using (var imgtool = new ImageTool(avatar))
                    av64 = imgtool.GetBase64();
            }

            return(this.ApiClient.CreateWebhookAsync(channel_id, name, av64, reason));
        }
コード例 #3
0
        public async Task <DiscordUser> EditCurrentUserAsync(string username = null, Stream avatar = null)
        {
            string av64 = null;

            if (avatar != null)
            {
                using (var imgtool = new ImageTool(avatar))
                    av64 = imgtool.GetBase64();
            }

            return(await ApiClient.ModifyCurrentUserAsync(username, av64));
        }
コード例 #4
0
        /// <summary>
        /// Creates a guild from a template. This requires the bot to be in less than 10 guilds total.
        /// </summary>
        /// <param name="code">The template code.</param>
        /// <param name="name">Name of the guild.</param>
        /// <param name="icon">Stream containing the icon for the guild.</param>
        /// <returns>The created guild.</returns>
        /// <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> CreateGuildFromTemplateAsync(string code, string name, Optional <Stream> icon = default)
        {
            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.CreateGuildFromTemplateAsync(code, name, iconb64));
        }
コード例 #5
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));
        }
コード例 #6
0
        public async Task <DiscordGuild> ModifyGuildAsync(ulong guild_id, Action <GuildEditModel> action)
        {
            var mdl = new GuildEditModel();

            action(mdl);

            if (mdl.AfkChannel.HasValue)
            {
                if (mdl.AfkChannel.Value.Type != ChannelType.Voice)
                {
                    throw new ArgumentException("AFK channel needs to be a voice channel!");
                }
            }

            var iconb64 = Optional.FromNoValue <string>();

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

            var splashb64 = Optional.FromNoValue <string>();

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

            return(await ApiClient.ModifyGuildAsync(guild_id, mdl.Name, mdl.Region.IfPresent(x => x.Id), mdl.VerificationLevel, mdl.DefaultMessageNotifications,
                                                    mdl.MfaLevel, mdl.ExplicitContentFilter, mdl.AfkChannel.IfPresent(x => x?.Id), mdl.AfkTimeout, iconb64, mdl.Owner.IfPresent(x => x.Id),
                                                    splashb64, mdl.SystemChannel.IfPresent(x => x?.Id), mdl.AuditLogReason).ConfigureAwait(false));
        }
コード例 #7
0
        public async Task <DiscordUser> EditCurrentUserAsync(string username = null, Stream avatar = null)
        {
            string av64 = null;

            if (avatar != null)
            {
                using (var imgtool = new ImageTool(avatar))
                {
                    av64 = imgtool.GetBase64();
                }
            }

            return(new DiscordUser(await ApiClient.ModifyCurrentUserAsync(username, av64).ConfigureAwait(false))
            {
                Discord = this
            });
        }
コード例 #8
0
        /// <summary>
        /// Edits current user.
        /// </summary>
        /// <param name="username">New username.</param>
        /// <param name="avatar">New avatar.</param>
        /// <returns></returns>
        /// <exception cref="Exceptions.NotFoundException">Thrown when the user 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 async Task <DiscordUser> UpdateCurrentUserAsync(string username = null, Optional <Stream> avatar = default)
        {
            var av64 = Optional.FromNoValue <string>();

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

            var usr = await this.ApiClient.ModifyCurrentUserAsync(username, av64).ConfigureAwait(false);

            this.CurrentUser.Username      = usr.Username;
            this.CurrentUser.Discriminator = usr.Discriminator;
            this.CurrentUser.AvatarHash    = usr.AvatarHash;
            return(this.CurrentUser);
        }