using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Discord.API;
using Discord.Rest;
namespace Discord.WebSocket
{
public abstract partial class BaseSocketClient : BaseDiscordClient, IDiscordClient
{
protected readonly DiscordSocketConfig BaseConfig;
///
/// Gets the estimated round-trip latency, in milliseconds, to the gateway server.
///
public abstract int Latency { get; protected set; }
///
/// Gets the status for the logged-in user.
///
public abstract UserStatus Status { get; protected set; }
///
/// Gets the activity for the logged-in user.
///
public abstract IActivity Activity { get; protected set; }
internal new DiscordSocketApiClient ApiClient => base.ApiClient as DiscordSocketApiClient;
///
/// Gets the current logged-in user.
///
public new SocketSelfUser CurrentUser { get => base.CurrentUser as SocketSelfUser; protected set => base.CurrentUser = value; }
///
/// Gets a collection of guilds that the logged-in user is currently in.
///
public abstract IReadOnlyCollection Guilds { get; }
///
/// Gets a collection of private channels that are currently open for the logged-in user.
///
public abstract IReadOnlyCollection PrivateChannels { get; }
///
/// Gets a collection of available voice regions for the logged-in user.
///
public abstract IReadOnlyCollection VoiceRegions { get; }
internal BaseSocketClient(DiscordSocketConfig config, DiscordRestApiClient client)
: base(config, client) => BaseConfig = config;
private static DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config)
=> new DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent);
///
/// Gets a Discord application information for the logged-in user.
///
///
/// This method reflects your application information you submitted when creating a Discord application via
/// the Developer Portal.
///
/// The options to be used when sending the request.
///
/// An awaitable containing the application information.
///
public abstract Task GetApplicationInfoAsync(RequestOptions options = null);
///
/// Gets a user.
///
/// The user snowflake ID.
///
/// This method gets the user present in the WebSocket cache with the given condition.
///
/// Sometimes a user may return null due to Discord not sending offline users in large
/// guilds (i.e. guild with 100+ members) actively. To download users on startup, consider enabling
/// .
///
///
/// This method does not attempt to fetch users that the logged-in user does not have access to (i.e.
/// users who don't share mutual guild(s) with the current user).
///
///
///
/// A generic WebSocket-based user; null when the user cannot be found.
///
public abstract SocketUser GetUser(ulong id);
///
/// Gets a user.
///
/// The name of the user.
/// The discriminator value of the user.
///
/// This method gets the user present in the WebSocket cache with the given condition.
///
/// Sometimes a user may return null due to Discord not sending offline users in large
/// guilds (i.e. guild with 100+ members) actively. To download users on startup, consider enabling
/// .
///
///
/// This method does not attempt to fetch users that the logged-in user does not have access to (i.e.
/// users who don't share mutual guild(s) with the current user).
///
///
///
/// A generic WebSocket-based user; null when the user cannot be found.
///
public abstract SocketUser GetUser(string username, string discriminator);
///
/// Gets a channel.
///
/// The channel snowflake ID.
///
/// A generic WebSocket-based channel object (voice, text, category, etc.); null when the
/// channel cannot be found.
///
public abstract SocketChannel GetChannel(ulong id);
///
/// Gets a guild.
///
/// The guild snowflake ID.
///
/// A WebSocket-based guild; null when the guild cannot be found.
///
public abstract SocketGuild GetGuild(ulong id);
///
/// Gets a voice region.
///
/// The unique identifier of the voice region.
///
/// A REST-based voice region; null if none can be found.
///
public abstract RestVoiceRegion GetVoiceRegion(string id);
///
public abstract Task StartAsync();
///
public abstract Task StopAsync();
///
/// Sets the current status of the logged-in user (e.g. Online, Do not Disturb).
///
/// The new status to be set.
///
/// An awaitable .
///
public abstract Task SetStatusAsync(UserStatus status);
///
/// Sets the game of the logged-in user.
///
/// The name of the game.
/// If streaming, the URL of the stream. Must be a valid Twitch URL.
/// The type of the game.
///
/// An awaitable .
///
public abstract Task SetGameAsync(string name, string streamUrl = null, ActivityType type = ActivityType.Playing);
///
/// Sets the of the logged-in user.
///
///
/// This method sets the of the user.
///
/// Discord will only accept setting of name and the type of activity.
///
///
/// Rich Presence cannot be set via this method or client. Rich Presence is strictly limited to RPC
/// clients only.
///
///
/// The activty to be set.
///
/// An awaitable .
///
public abstract Task SetActivityAsync(IActivity activity);
///
/// Attempts to download users into the user cache for the selected guilds.
///
/// The guilds to download the members from.
///
/// An awaitable .
///
public abstract Task DownloadUsersAsync(IEnumerable guilds);
///
/// Creates a guild for the logged-in user who is in less than 10 active guilds.
///
///
/// This method creates a new guild on behalf of the logged-in user.
///
/// Due to Discord's limitation, this method will only work for users that are in less than 10 guilds.
///
///
/// The name of the new guild.
/// The voice region to create the guild with.
/// The icon of the guild.
/// The options to be used when sending the request.
///
/// An awaitable containing the newly created guild.
///
public Task CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null, RequestOptions options = null)
=> ClientHelper.CreateGuildAsync(this, name, region, jpegIcon, options ?? RequestOptions.Default);
///
/// Gets the connections that the logged-in user has set up.
///
/// The options to be used when sending the request.
///
/// An awaitable containing a collection of connections.
///
public Task> GetConnectionsAsync(RequestOptions options = null)
=> ClientHelper.GetConnectionsAsync(this, options ?? RequestOptions.Default);
///
/// Gets an invite with the provided invite identifier.
///
/// The invitation identifier.
/// The options to be used when sending the request.
///
/// An awaitable containing the invite information.
///
public Task GetInviteAsync(string inviteId, bool withCount = false, RequestOptions options = null)
=> ClientHelper.GetInviteAsync(this, inviteId, withCount, options ?? RequestOptions.Default);
// IDiscordClient
///
async Task IDiscordClient.GetApplicationInfoAsync(RequestOptions options)
=> await GetApplicationInfoAsync(options).ConfigureAwait(false);
///
Task IDiscordClient.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult(GetChannel(id));
///
Task> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult>(PrivateChannels);
///
async Task> IDiscordClient.GetConnectionsAsync(RequestOptions options)
=> await GetConnectionsAsync(options).ConfigureAwait(false);
///
async Task IDiscordClient.GetInviteAsync(string inviteId, bool withCount, RequestOptions options)
=> await GetInviteAsync(inviteId, withCount, options).ConfigureAwait(false);
///
Task IDiscordClient.GetGuildAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult(GetGuild(id));
///
Task> IDiscordClient.GetGuildsAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult>(Guilds);
///
async Task IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon, RequestOptions options)
=> await CreateGuildAsync(name, region, jpegIcon, options).ConfigureAwait(false);
///
Task IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult(GetUser(id));
///
Task IDiscordClient.GetUserAsync(string username, string discriminator, RequestOptions options)
=> Task.FromResult(GetUser(username, discriminator));
///
Task IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options)
=> Task.FromResult(GetVoiceRegion(id));
///
Task> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options)
=> Task.FromResult>(VoiceRegions);
}
}