Merge branch 'issue/379' into dev

This commit is contained in:
RogueException
2016-12-16 11:12:50 -04:00
26 changed files with 583 additions and 57 deletions

View File

@@ -0,0 +1,30 @@
namespace Discord
{
/// <summary>
/// Modify an IGuildChannel with the specified changes.
/// </summary>
/// <example>
/// <code language="c#">
/// await (Context.Channel as ITextChannel)?.ModifyAsync(x =>
/// {
/// x.Name = "do-not-enter";
/// });
/// </code>
/// </example>
public class ModifyGuildChannelParams
{
/// <summary>
/// Set the channel to this name
/// </summary>
/// <remarks>
/// When modifying an ITextChannel, the Name MUST be alphanumeric with dashes.
/// It must match the following RegEx: [a-z0-9-_]{2,100}
/// </remarks>
/// <exception cref="Net.HttpException">A BadRequest will be thrown if the name does not match the above RegEx.</exception>
public Optional<string> Name { get; set; }
/// <summary>
/// Move the channel to the following position. This is 0-based!
/// </summary>
public Optional<int> Position { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
namespace Discord
{
public class ModifyGuildChannelsParams
{
/// <summary>
/// The id of the channel to apply this position to.
/// </summary>
public ulong Id { get; set; }
/// <summary>
/// The new zero-based position of this channel.
/// </summary>
public int Position { get; set; }
public ModifyGuildChannelsParams(ulong id, int position)
{
Id = id;
Position = position;
}
}
}

View File

@@ -0,0 +1,11 @@
namespace Discord
{
/// <inheritdoc />
public class ModifyTextChannelParams : ModifyGuildChannelParams
{
/// <summary>
/// What the topic of the channel should be set to.
/// </summary>
public Optional<string> Topic { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
namespace Discord
{
/// <inheritdoc />
public class ModifyVoiceChannelParams : ModifyGuildChannelParams
{
/// <summary>
/// The bitrate of the voice connections in this channel. Must be greater than 8000
/// </summary>
public Optional<int> Bitrate { get; set; }
/// <summary>
/// The maximum number of users that can be present in a channel.
/// </summary>
public Optional<int> UserLimit { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
namespace Discord
{
/// <summary>
/// Modify the widget of an IGuild with the specified parameters
/// </summary>
public class ModifyGuildEmbedParams
{
/// <summary>
/// Should the widget be enabled?
/// </summary>
public Optional<bool> Enabled { get; set; }
/// <summary>
/// What channel should the invite place users in, if not null.
/// </summary>
public Optional<IChannel> Channel { get; set; }
/// <summary>
/// What channel should the invite place users in, if not null.
/// </summary>
public Optional<ulong?> ChannelId { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
namespace Discord
{
public class ModifyGuildIntegrationParams
{
public Optional<int> ExpireBehavior { get; set; }
public Optional<int> ExpireGracePeriod { get; set; }
public Optional<bool> EnableEmoticons { get; set; }
}
}

View File

@@ -0,0 +1,71 @@
namespace Discord
{
/// <summary>
/// Modify an IGuild with the specified changes
/// </summary>
/// <example>
/// <code language="c#">
/// await Context.Guild.ModifyAsync(async x =>
/// {
/// x.Name = "aaaaaah";
/// x.RegionId = (await Context.Client.GetOptimalVoiceRegionAsync()).Id;
/// });
/// </code>
/// </example>
/// <see cref="IGuild"/>
public class ModifyGuildParams
{
public Optional<string> Username { get; set; }
/// <summary>
/// The name of the Guild
/// </summary>
public Optional<string> Name { get; set; }
/// <summary>
/// The region for the Guild's voice connections
/// </summary>
public Optional<IVoiceRegion> Region { get; set; }
/// <summary>
/// The ID of the region for the Guild's voice connections
/// </summary>
public Optional<string> RegionId { get; set; }
/// <summary>
/// What verification level new users need to achieve before speaking
/// </summary>
public Optional<VerificationLevel> VerificationLevel { get; set; }
/// <summary>
/// The default message notification state for the guild
/// </summary>
public Optional<DefaultMessageNotifications> DefaultMessageNotifications { get; set; }
/// <summary>
/// How many seconds before a user is sent to AFK. This value MUST be one of: (60, 300, 900, 1800, 3600).
/// </summary>
public Optional<int> AfkTimeout { get; set; }
/// <summary>
/// The icon of the guild
/// </summary>
public Optional<Image?> Icon { get; set; }
/// <summary>
/// The guild's splash image
/// </summary>
/// <remarks>
/// The guild must be partnered for this value to have any effect.
/// </remarks>
public Optional<Image?> Splash { get; set; }
/// <summary>
/// The IVoiceChannel where AFK users should be sent.
/// </summary>
public Optional<IVoiceChannel> AfkChannel { get; set; }
/// <summary>
/// The ID of the IVoiceChannel where AFK users should be sent.
/// </summary>
public Optional<ulong?> AfkChannelId { get; set; }
/// <summary>
/// The owner of this guild.
/// </summary>
public Optional<IUser> Owner { get; set; }
/// <summary>
/// The ID of the owner of this guild.
/// </summary>
public Optional<ulong> OwnerId { get; set; }
}
}

View File

@@ -0,0 +1,34 @@
using System.IO;
namespace Discord
{
/// <summary>
/// An image that will be uploaded to Discord.
/// </summary>
public struct Image
{
public Stream Stream { get; }
/// <summary>
/// Create the image with a Stream.
/// </summary>
/// <param name="stream">This must be some type of stream with the contents of a file in it.</param>
/// <seealso cref="File.OpenRead(string)"/>
public Image(Stream stream)
{
Stream = stream;
}
#if NETSTANDARD1_3
/// <summary>
/// Create the image from a file path.
/// </summary>
/// <remarks>
/// This file path is NOT validated, and is passed directly into a <see cref="File.OpenRead(string)"/>
/// </remarks>
/// <param name="path">The path to the file.</param>
public Image(string path)
{
Stream = File.OpenRead(path);
}
#endif
}
}

View File

@@ -5,7 +5,7 @@ using Field = Discord.API.EmbedField;
using Author = Discord.API.EmbedAuthor;
using Footer = Discord.API.EmbedFooter;
using Thumbnail = Discord.API.EmbedThumbnail;
using Image = Discord.API.EmbedImage;
using ImageEmbed = Discord.API.EmbedImage;
namespace Discord
{
@@ -110,7 +110,7 @@ namespace Discord
_model.Footer = Footer?.ToModel();
_model.Timestamp = Timestamp?.ToUniversalTime();
_model.Thumbnail = ThumbnailUrl != null ? new Thumbnail { Url = ThumbnailUrl } : null;
_model.Image = ImageUrl != null ? new Image { Url = ImageUrl } : null;
_model.Image = ImageUrl != null ? new ImageEmbed { Url = ImageUrl } : null;
_model.Fields = _fields.ToArray();
return _model;
}

View File

@@ -1,12 +1,37 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Discord
namespace Discord
{
/// <summary>
/// Modify a message with the specified parameters.
/// </summary>
/// <remarks>
/// The content of a message can be cleared with String.Empty; if and only if an Embed is present.
/// </remarks>
/// <example>
/// <code language="c#">
/// var message = await ReplyAsync("abc");
/// await message.ModifyAsync(x =>
/// {
/// x.Content = "";
/// x.Embed = new EmbedBuilder()
/// .WithColor(new Color(40, 40, 120))
/// .WithAuthor(a => a.Name = "foxbot")
/// .WithTitle("Embed!")
/// .WithDescription("This is an embed.");
/// });
/// </code>
/// </example>
public class ModifyMessageParams
{
/// <summary>
/// The content of the message
/// </summary>
/// <remarks>
/// This must be less than 2000 characters.
/// </remarks>
public Optional<string> Content { get; set; }
/// <summary>
/// The embed the message should display
/// </summary>
public Optional<EmbedBuilder> Embed { get; set; }
}
}

View File

@@ -0,0 +1,51 @@
namespace Discord
{
/// <summary>
/// Modify an IRole with the specified parameters
/// </summary>
/// <example>
/// <code language="c#">
/// await role.ModifyAsync(x =>
/// {
/// x.Color = new Color(180, 15, 40);
/// x.Hoist = true;
/// });
/// </code>
/// </example>
/// <seealso cref="IRole"/>
public class ModifyGuildRoleParams
{
/// <summary>
/// The name of the role
/// </summary>
/// <remarks>
/// If this role is the EveryoneRole, this value may not be set.
/// </remarks>
public Optional<string> Name { get; set; }
/// <summary>
/// The role's GuildPermissions
/// </summary>
public Optional<GuildPermissions> Permissions { get; set; }
/// <summary>
/// The position of the role. This is 0-based!
/// </summary>
/// <remarks>
/// If this role is the EveryoneRole, this value may not be set.
/// </remarks>
public Optional<int> Position { get; set; }
/// <summary>
/// The color of the Role.
/// </summary>
/// <remarks>
/// If this role is the EveryoneRole, this value may not be set.
/// </remarks>
public Optional<Color> Color { get; set; }
/// <summary>
/// Whether or not this role should be displayed independently in the userlist.
/// </summary>
/// <remarks>
/// If this role is the EveryoneRole, this value may not be set.
/// </remarks>
public Optional<bool> Hoist { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
namespace Discord
{
public class ModifyGuildRolesParams : ModifyGuildRoleParams
{
/// <summary>
/// The id of the role to be edited
/// </summary>
public ulong Id { get; }
public ModifyGuildRolesParams(ulong id)
{
Id = id;
}
}
}

View File

@@ -0,0 +1,12 @@
namespace Discord
{
public class ModifyCurrentUserNickParams
{
public string Nickname { get; }
public ModifyCurrentUserNickParams(string nickname)
{
Nickname = nickname;
}
}
}

View File

@@ -0,0 +1,26 @@
namespace Discord
{
/// <summary>
/// Modify the current user with the specified arguments
/// </summary>
/// <example>
/// <code language="c#">
/// await Context.Client.CurrentUser.ModifyAsync(x =>
/// {
/// x.Avatar = new Image(File.OpenRead("avatar.jpg"));
/// });
/// </code>
/// </example>
/// <seealso cref="ISelfUser"/>
public class ModifyCurrentUserParams
{
/// <summary>
/// Your username
/// </summary>
public Optional<string> Username { get; set; }
/// <summary>
/// Your avatar
/// </summary>
public Optional<Image> Avatar { get; set; }
}
}

View File

@@ -0,0 +1,64 @@
using System.Collections.Generic;
namespace Discord
{
/// <summary>
/// Modify an IGuildUser with the following parameters.
/// </summary>
/// <example>
/// <code language="c#">
/// await (Context.User as IGuildUser)?.ModifyAsync(x =>
/// {
/// x.Nickname = $"festive {Context.User.Username}";
/// });
/// </code>
/// </example>
/// <seealso cref="IGuildUser"/>
public class ModifyGuildMemberParams
{
/// <summary>
/// Should the user be guild-muted in a voice channel?
/// </summary>
/// <remarks>
/// If this value is set to true, no user will be able to hear this user speak in the guild.
/// </remarks>
public Optional<bool> Mute { get; set; }
/// <summary>
/// Should the user be guild-deafened in a voice channel?
/// </summary>
/// <remarks>
/// If this value is set to true, this user will not be able to hear anyone speak in the guild.
/// </remarks>
public Optional<bool> Deaf { get; set; }
/// <summary>
/// Should the user have a nickname set?
/// </summary>
/// <remarks>
/// To clear the user's nickname, this value can be set to null.
/// </remarks>
public Optional<string> Nickname { get; set; }
/// <summary>
/// What roles should the user have?
/// </summary>
/// <remarks>
/// To add a role to a user: <see cref="GuildUserExtensions.AddRolesAsync(IGuildUser, IRole[])"/>
/// To remove a role from a user: <see cref="GuildUserExtensions.RemoveRolesAsync(IGuildUser, IRole[])"/>
/// </remarks>
public Optional<IEnumerable<IRole>> Roles { get; set; }
/// <summary>
/// What roles should the user have?
/// </summary>
/// <remarks>
/// To add a role to a user: <see cref="GuildUserExtensions.AddRolesAsync(IGuildUser, IRole[])"/>
/// To remove a role from a user: <see cref="GuildUserExtensions.RemoveRolesAsync(IGuildUser, IRole[])"/>
/// </remarks>
public Optional<IEnumerable<ulong>> RoleIds { get; set; }
/// <summary>
/// Move a user to a voice channel.
/// </summary>
/// <remarks>
/// This user MUST already be in a Voice Channel for this to work.
/// </remarks>
public Optional<IVoiceChannel> Channel { get; set; }
}
}