Loosened type restrictions on EditMember's roles
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#pragma warning disable CS0169
|
#pragma warning disable CS0169
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Discord.API
|
namespace Discord.API
|
||||||
{
|
{
|
||||||
@@ -64,7 +65,7 @@ namespace Discord.API
|
|||||||
[JsonProperty(PropertyName = "deaf", NullValueHandling = NullValueHandling.Ignore)]
|
[JsonProperty(PropertyName = "deaf", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
public bool? Deaf;
|
public bool? Deaf;
|
||||||
[JsonProperty(PropertyName = "roles", NullValueHandling = NullValueHandling.Ignore)]
|
[JsonProperty(PropertyName = "roles", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
public string[] Roles;
|
public IEnumerable<string> Roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Messages
|
//Messages
|
||||||
@@ -73,7 +74,7 @@ namespace Discord.API
|
|||||||
[JsonProperty("content")]
|
[JsonProperty("content")]
|
||||||
public string Content;
|
public string Content;
|
||||||
[JsonProperty("mentions")]
|
[JsonProperty("mentions")]
|
||||||
public string[] Mentions;
|
public IEnumerable<string> Mentions;
|
||||||
[JsonProperty("nonce", NullValueHandling = NullValueHandling.Ignore)]
|
[JsonProperty("nonce", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
public string Nonce;
|
public string Nonce;
|
||||||
[JsonProperty("tts", NullValueHandling = NullValueHandling.Ignore)]
|
[JsonProperty("tts", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
@@ -84,7 +85,7 @@ namespace Discord.API
|
|||||||
[JsonProperty("content", NullValueHandling = NullValueHandling.Ignore)]
|
[JsonProperty("content", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
public string Content;
|
public string Content;
|
||||||
[JsonProperty("mentions", NullValueHandling = NullValueHandling.Ignore)]
|
[JsonProperty("mentions", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
public string[] Mentions;
|
public IEnumerable<string> Mentions;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Permissions
|
//Permissions
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Discord.API;
|
using Discord.API;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -133,7 +134,7 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Members
|
//Members
|
||||||
public Task EditMember(string serverId, string userId, bool? mute = null, bool? deaf = null, string[] roles = null)
|
public Task EditMember(string serverId, string userId, bool? mute = null, bool? deaf = null, IEnumerable<string> roles = null)
|
||||||
{
|
{
|
||||||
if (serverId == null) throw new ArgumentNullException(nameof(serverId));
|
if (serverId == null) throw new ArgumentNullException(nameof(serverId));
|
||||||
if (userId == null) throw new ArgumentNullException(nameof(userId));
|
if (userId == null) throw new ArgumentNullException(nameof(userId));
|
||||||
|
|||||||
@@ -222,21 +222,31 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Members
|
//Members
|
||||||
public Task EditMember(Member member, bool? mute = null, bool? deaf = null, string[] roles = null)
|
public Task EditMember(Member member, bool? mute = null, bool? deaf = null, IEnumerable<object> roles = null)
|
||||||
=> EditMember(member?.ServerId, member?.UserId, mute, deaf, roles);
|
=> EditMember(member?.ServerId, member?.UserId, mute, deaf, roles);
|
||||||
public Task EditMember(Server server, User user, bool? mute = null, bool? deaf = null, string[] roles = null)
|
public Task EditMember(Server server, User user, bool? mute = null, bool? deaf = null, IEnumerable<object> roles = null)
|
||||||
=> EditMember(server?.Id, user?.Id, mute, deaf, roles);
|
=> EditMember(server?.Id, user?.Id, mute, deaf, roles);
|
||||||
public Task EditMember(Server server, string userId, bool? mute = null, bool? deaf = null, string[] roles = null)
|
public Task EditMember(Server server, string userId, bool? mute = null, bool? deaf = null, IEnumerable<string> roles = null)
|
||||||
=> EditMember(server?.Id, userId, mute, deaf, roles);
|
=> EditMember(server?.Id, userId, mute, deaf, roles);
|
||||||
public Task EditMember(string serverId, User user, bool? mute = null, bool? deaf = null, string[] roles = null)
|
public Task EditMember(string serverId, User user, bool? mute = null, bool? deaf = null, IEnumerable<object> roles = null)
|
||||||
=> EditMember(serverId, user?.Id, mute, deaf, roles);
|
=> EditMember(serverId, user?.Id, mute, deaf, roles);
|
||||||
public Task EditMember(string serverId, string userId, bool? mute = null, bool? deaf = null, string[] roles = null)
|
public Task EditMember(string serverId, string userId, bool? mute = null, bool? deaf = null, IEnumerable<object> roles = null)
|
||||||
{
|
{
|
||||||
CheckReady();
|
CheckReady();
|
||||||
if (serverId == null) throw new NullReferenceException(nameof(serverId));
|
if (serverId == null) throw new NullReferenceException(nameof(serverId));
|
||||||
if (userId == null) throw new NullReferenceException(nameof(userId));
|
if (userId == null) throw new NullReferenceException(nameof(userId));
|
||||||
|
|
||||||
return _api.EditMember(serverId, userId, mute, deaf, roles);
|
IEnumerable<string> newRoles = roles?.Select(x =>
|
||||||
|
{
|
||||||
|
if (x is string)
|
||||||
|
return x as string;
|
||||||
|
else if (x is Role)
|
||||||
|
return (x as Role).Id;
|
||||||
|
else
|
||||||
|
throw new ArgumentException("Roles must be a collection of strings or roles.", nameof(roles));
|
||||||
|
});
|
||||||
|
|
||||||
|
return _api.EditMember(serverId, userId, mute, deaf, newRoles);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Messages
|
//Messages
|
||||||
@@ -263,7 +273,7 @@ namespace Discord
|
|||||||
CheckReady();
|
CheckReady();
|
||||||
if (channel == null) throw new ArgumentNullException(nameof(channel));
|
if (channel == null) throw new ArgumentNullException(nameof(channel));
|
||||||
if (text == null) throw new ArgumentNullException(nameof(text));
|
if (text == null) throw new ArgumentNullException(nameof(text));
|
||||||
if (mentions == null) throw new ArgumentNullException(nameof(mentions));
|
mentions = mentions ?? new string[0];
|
||||||
|
|
||||||
int blockCount = (int)Math.Ceiling(text.Length / (double)MaxMessageSize);
|
int blockCount = (int)Math.Ceiling(text.Length / (double)MaxMessageSize);
|
||||||
Message[] result = new Message[blockCount];
|
Message[] result = new Message[blockCount];
|
||||||
@@ -330,19 +340,20 @@ namespace Discord
|
|||||||
|
|
||||||
/// <summary> Edits the provided message, changing only non-null attributes. </summary>
|
/// <summary> Edits the provided message, changing only non-null attributes. </summary>
|
||||||
/// <remarks> While not required, it is recommended to include a mention reference in the text (see Mention.User). </remarks>
|
/// <remarks> While not required, it is recommended to include a mention reference in the text (see Mention.User). </remarks>
|
||||||
public Task EditMessage(Message message, string text = null, string[] mentions = null)
|
public Task EditMessage(Message message, string text = null, params string[] mentions)
|
||||||
=> EditMessage(message?.ChannelId, message?.Id, text, mentions);
|
=> EditMessage(message?.ChannelId, message?.Id, text, mentions);
|
||||||
/// <summary> Edits the provided message, changing only non-null attributes. </summary>
|
/// <summary> Edits the provided message, changing only non-null attributes. </summary>
|
||||||
/// <remarks> While not required, it is recommended to include a mention reference in the text (see Mention.User). </remarks>
|
/// <remarks> While not required, it is recommended to include a mention reference in the text (see Mention.User). </remarks>
|
||||||
public Task EditMessage(Channel channel, string messageId, string text = null, string[] mentions = null)
|
public Task EditMessage(Channel channel, string messageId, string text = null, params string[] mentions)
|
||||||
=> EditMessage(channel?.Id, messageId, text, mentions);
|
=> EditMessage(channel?.Id, messageId, text, mentions);
|
||||||
/// <summary> Edits the provided message, changing only non-null attributes. </summary>
|
/// <summary> Edits the provided message, changing only non-null attributes. </summary>
|
||||||
/// <remarks> While not required, it is recommended to include a mention reference in the text (see Mention.User). </remarks>
|
/// <remarks> While not required, it is recommended to include a mention reference in the text (see Mention.User). </remarks>
|
||||||
public async Task EditMessage(string channelId, string messageId, string text = null, string[] mentions = null)
|
public async Task EditMessage(string channelId, string messageId, string text = null, params string[] mentions)
|
||||||
{
|
{
|
||||||
CheckReady();
|
CheckReady();
|
||||||
if (channelId == null) throw new ArgumentNullException(nameof(channelId));
|
if (channelId == null) throw new ArgumentNullException(nameof(channelId));
|
||||||
if (messageId == null) throw new ArgumentNullException(nameof(messageId));
|
if (messageId == null) throw new ArgumentNullException(nameof(messageId));
|
||||||
|
mentions = mentions ?? new string[0];
|
||||||
|
|
||||||
if (text != null && text.Length > MaxMessageSize)
|
if (text != null && text.Length > MaxMessageSize)
|
||||||
text = text.Substring(0, MaxMessageSize);
|
text = text.Substring(0, MaxMessageSize);
|
||||||
|
|||||||
Reference in New Issue
Block a user