Exemple #1
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 <string> .FromNoValue();

            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 <string> .FromNoValue();

            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 this.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));
        }
Exemple #2
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);
        }