Browse Source

Move and disconnect (#165)

* Changed comments to regions

* More regions

* regions

* Added DisconnectAsync and MoveAsync
pull/1923/head
Simon Hjorthøj GitHub 3 years ago
parent
commit
6ab38537fe
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 17 deletions
  1. +15
    -0
      src/Discord.Net.Core/Entities/Guilds/IGuild.cs
  2. +21
    -3
      src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
  3. +40
    -14
      src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs

+ 15
- 0
src/Discord.Net.Core/Entities/Guilds/IGuild.cs View File

@@ -771,6 +771,12 @@ namespace Discord
/// <returns>A guild user associated with the specified <paramref name="userId" />; <see langword="null" /> if the user is already in the guild.</returns>
Task<IGuildUser> AddGuildUserAsync(ulong userId, string accessToken, Action<AddGuildUserProperties> func = null, RequestOptions options = null);
/// <summary>
/// Disconnects the user from its current voice channel
/// </summary>
/// <param name="user">The user to disconnect.</param>
/// <returns>A task that represents the asynchronous operation for disconnecting a user.</returns>
Task DisconnectAsync(IGuildUser user);
/// <summary>
/// Gets a collection of all users in this guild.
/// </summary>
/// <remarks>
@@ -951,6 +957,15 @@ namespace Discord
/// emote.
/// </returns>
Task<GuildEmote> ModifyEmoteAsync(GuildEmote emote, Action<EmoteProperties> func, RequestOptions options = null);

/// <summary>
/// Moves the user to the voice channel.
/// </summary>
/// <param name="user">The user to move.</param>
/// <param name="targetChannel">the channel where the user gets moved to.</param>
/// <returns>A task that represents the asynchronous operation for moving a user.</returns>
Task MoveAsync(IGuildUser user, IVoiceChannel targetChannel);

/// <summary>
/// Deletes an existing <see cref="GuildEmote"/> from this guild.
/// </summary>


+ 21
- 3
src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs View File

@@ -962,7 +962,7 @@ namespace Discord.Rest
public override string ToString() => Name;
private string DebuggerDisplay => $"{Name} ({Id})";

//Emotes
#region Emotes
/// <inheritdoc />
public Task<IReadOnlyCollection<GuildEmote>> GetEmotesAsync(RequestOptions options = null)
=> GuildHelper.GetEmotesAsync(this, Discord, options);
@@ -976,11 +976,20 @@ namespace Discord.Rest
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception>
public Task<GuildEmote> ModifyEmoteAsync(GuildEmote emote, Action<EmoteProperties> func, RequestOptions options = null)
=> GuildHelper.ModifyEmoteAsync(this, Discord, emote.Id, func, options);
/// <summary>
/// Moves the user to the voice channel.
/// </summary>
/// <param name="user">The user to move.</param>
/// <param name="targetChannel">the channel where the user gets moved to.</param>
/// <returns>A task that represents the asynchronous operation for moving a user.</returns>
public Task MoveAsync(IGuildUser user, IVoiceChannel targetChannel)
=> user.ModifyAsync(x => x.Channel = new Optional<IVoiceChannel>(targetChannel));
/// <inheritdoc />
public Task DeleteEmoteAsync(GuildEmote emote, RequestOptions options = null)
=> GuildHelper.DeleteEmoteAsync(this, Discord, emote.Id, options);
#endregion

//Stickers
#region Stickers
/// <summary>
/// Creates a new sticker in this guild.
/// </summary>
@@ -1087,8 +1096,9 @@ namespace Discord.Rest
/// </returns>
public Task DeleteStickerAsync(CustomSticker sticker, RequestOptions options = null)
=> sticker.DeleteAsync(options);
#endregion

//IGuild
#region IGuild
/// <inheritdoc />
bool IGuild.Available => Available;
/// <inheritdoc />
@@ -1291,6 +1301,13 @@ namespace Discord.Rest
async Task<IGuildUser> IGuild.AddGuildUserAsync(ulong userId, string accessToken, Action<AddGuildUserProperties> func, RequestOptions options)
=> await AddGuildUserAsync(userId, accessToken, func, options);

/// <summary>
/// Disconnects the user from its current voice channel
/// </summary>
/// <param name="user">The user to disconnect.</param>
/// <returns>A task that represents the asynchronous operation for disconnecting a user.</returns>
async Task IGuild.DisconnectAsync(IGuildUser user) => await user.ModifyAsync(x => x.Channel = new Optional<IVoiceChannel>());

/// <inheritdoc />
async Task<IGuildUser> IGuild.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
{
@@ -1399,5 +1416,6 @@ namespace Discord.Rest
else
return null;
}
#endregion
}
}

+ 40
- 14
src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs View File

@@ -572,7 +572,7 @@ namespace Discord.WebSocket
_emotes = emotes.ToImmutable();
}

//General
#region General
/// <inheritdoc />
public Task DeleteAsync(RequestOptions options = null)
=> GuildHelper.DeleteAsync(this, Discord, options);
@@ -596,8 +596,9 @@ namespace Discord.WebSocket
/// <inheritdoc />
public Task LeaveAsync(RequestOptions options = null)
=> GuildHelper.LeaveAsync(this, Discord, options);
#endregion

//Bans
#region Bans
/// <summary>
/// Gets a collection of all users banned in this guild.
/// </summary>
@@ -645,8 +646,9 @@ namespace Discord.WebSocket
/// <inheritdoc />
public Task RemoveBanAsync(ulong userId, RequestOptions options = null)
=> GuildHelper.RemoveBanAsync(this, Discord, userId, options);
#endregion

//Channels
#region Channels
/// <summary>
/// Gets a channel in this guild.
/// </summary>
@@ -807,8 +809,9 @@ namespace Discord.WebSocket

_channels.Clear();
}
#endregion

//Voice Regions
#region Voice Regions
/// <summary>
/// Gets a collection of all the voice regions this guild can access.
/// </summary>
@@ -819,14 +822,16 @@ namespace Discord.WebSocket
/// </returns>
public Task<IReadOnlyCollection<RestVoiceRegion>> GetVoiceRegionsAsync(RequestOptions options = null)
=> GuildHelper.GetVoiceRegionsAsync(this, Discord, options);
#endregion

//Integrations
#region Integrations
public Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(RequestOptions options = null)
=> GuildHelper.GetIntegrationsAsync(this, Discord, options);
public Task<RestGuildIntegration> CreateIntegrationAsync(ulong id, string type, RequestOptions options = null)
=> GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options);
#endregion

//Interactions
#region Interactions
/// <summary>
/// Deletes all application commands in the current guild.
/// </summary>
@@ -932,8 +937,9 @@ namespace Discord.WebSocket

return entities.ToImmutableArray();
}
#endregion

//Invites
#region Invites
/// <summary>
/// Gets a collection of all invites in this guild.
/// </summary>
@@ -1040,8 +1046,9 @@ namespace Discord.WebSocket
return sticker;
return null;
}
#endregion

//Users
#region Users
/// <inheritdoc />
public Task<RestGuildUser> AddGuildUserAsync(ulong id, string accessToken, Action<AddGuildUserProperties> func = null, RequestOptions options = null)
=> GuildHelper.AddGuildUserAsync(this, Discord, id, accessToken, func, options);
@@ -1240,7 +1247,24 @@ namespace Discord.WebSocket
public Task DeleteEmoteAsync(GuildEmote emote, RequestOptions options = null)
=> GuildHelper.DeleteEmoteAsync(this, Discord, emote.Id, options);

//Stickers
/// <summary>
/// Moves the user to the voice channel.
/// </summary>
/// <param name="user">The user to move.</param>
/// <param name="targetChannel">the channel where the user gets moved to.</param>
/// <returns>A task that represents the asynchronous operation for moving a user.</returns>
public Task MoveAsync(IGuildUser user, IVoiceChannel targetChannel)
=> user.ModifyAsync(x => x.Channel = new Optional<IVoiceChannel>(targetChannel));

/// <summary>
/// Disconnects the user from its current voice channel
/// </summary>
/// <param name="user">The user to disconnect.</param>
/// <returns>A task that represents the asynchronous operation for disconnecting a user.</returns>
async Task IGuild.DisconnectAsync(IGuildUser user) => await user.ModifyAsync(x => x.Channel = new Optional<IVoiceChannel>());
#endregion

#region Stickers
/// <summary>
/// Gets a specific sticker within this guild.
/// </summary>
@@ -1368,8 +1392,9 @@ namespace Discord.WebSocket
/// </returns>
public Task DeleteStickerAsync(SocketCustomSticker sticker, RequestOptions options = null)
=> sticker.DeleteAsync(options);
#endregion

//Voice States
#region Voice States
internal async Task<SocketVoiceState> AddOrUpdateVoiceStateAsync(ClientState state, VoiceStateModel model)
{
var voiceChannel = state.GetChannel(model.ChannelId.Value) as SocketVoiceChannel;
@@ -1413,8 +1438,9 @@ namespace Discord.WebSocket
}
return null;
}
#endregion

//Audio
#region Audio
internal AudioInStream GetAudioStream(ulong userId)
{
return _audioClient?.GetInputStream(userId);
@@ -1568,8 +1594,9 @@ namespace Discord.WebSocket
public override string ToString() => Name;
private string DebuggerDisplay => $"{Name} ({Id})";
internal SocketGuild Clone() => MemberwiseClone() as SocketGuild;
#endregion

//IGuild
#region IGuild
/// <inheritdoc />
ulong? IGuild.AFKChannelId => AFKChannelId;
/// <inheritdoc />
@@ -1781,7 +1808,6 @@ namespace Discord.WebSocket
_audioLock?.Dispose();
_audioClient?.Dispose();
}

#endregion
}
}

Loading…
Cancel
Save