[Feature] Support for setting custom status (#2749)
This commit is contained in:
@@ -11,6 +11,20 @@ namespace Discord
|
|||||||
{
|
{
|
||||||
internal CustomStatusGame() { }
|
internal CustomStatusGame() { }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new custom status activity.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Bots can't set custom status emoji.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="state">The string displayed as bot's custom status.</param>
|
||||||
|
public CustomStatusGame(string state)
|
||||||
|
{
|
||||||
|
Name = "Custom Status";
|
||||||
|
State = state;
|
||||||
|
Type = ActivityType.CustomStatus;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the emote, if it is set.
|
/// Gets the emote, if it is set.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -227,6 +227,16 @@ namespace Discord.WebSocket
|
|||||||
/// A task that represents the asynchronous set operation.
|
/// A task that represents the asynchronous set operation.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public abstract Task SetActivityAsync(IActivity activity);
|
public abstract Task SetActivityAsync(IActivity activity);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the custom status of the logged-in user.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="status">The string that will be displayed as status.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// A task that represents the asynchronous set operation.
|
||||||
|
/// </returns>
|
||||||
|
public abstract Task SetCustomStatusAsync(string status);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempts to download users into the user cache for the selected guilds.
|
/// Attempts to download users into the user cache for the selected guilds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -412,6 +412,14 @@ namespace Discord.WebSocket
|
|||||||
await _shards[i].SetActivityAsync(activity).ConfigureAwait(false);
|
await _shards[i].SetActivityAsync(activity).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override async Task SetCustomStatusAsync(string status)
|
||||||
|
{
|
||||||
|
var statusGame = new CustomStatusGame(status);
|
||||||
|
for (int i = 0; i < _shards.Length; i++)
|
||||||
|
await _shards[i].SetActivityAsync(statusGame).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
private void RegisterEvents(DiscordSocketClient client, bool isPrimary)
|
private void RegisterEvents(DiscordSocketClient client, bool isPrimary)
|
||||||
{
|
{
|
||||||
client.Log += (msg) => _logEvent.InvokeAsync(msg);
|
client.Log += (msg) => _logEvent.InvokeAsync(msg);
|
||||||
|
|||||||
@@ -694,6 +694,7 @@ namespace Discord.WebSocket
|
|||||||
Activity = null;
|
Activity = null;
|
||||||
await SendStatusAsync().ConfigureAwait(false);
|
await SendStatusAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task SetActivityAsync(IActivity activity)
|
public override async Task SetActivityAsync(IActivity activity)
|
||||||
{
|
{
|
||||||
@@ -701,11 +702,20 @@ namespace Discord.WebSocket
|
|||||||
await SendStatusAsync().ConfigureAwait(false);
|
await SendStatusAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override async Task SetCustomStatusAsync(string status)
|
||||||
|
{
|
||||||
|
var statusGame = new CustomStatusGame(status);
|
||||||
|
await SetActivityAsync(statusGame);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task SendStatusAsync()
|
private async Task SendStatusAsync()
|
||||||
{
|
{
|
||||||
if (CurrentUser == null)
|
if (CurrentUser == null)
|
||||||
return;
|
return;
|
||||||
var activities = _activity.IsSpecified ? ImmutableList.Create(_activity.Value) : null;
|
var activities = _activity.IsSpecified
|
||||||
|
? ImmutableList.Create(_activity.Value)
|
||||||
|
: null;
|
||||||
CurrentUser.Presence = new SocketPresence(Status, null, activities);
|
CurrentUser.Presence = new SocketPresence(Status, null, activities);
|
||||||
|
|
||||||
var presence = BuildCurrentStatus() ?? (UserStatus.Online, false, null, null);
|
var presence = BuildCurrentStatus() ?? (UserStatus.Online, false, null, null);
|
||||||
@@ -738,6 +748,8 @@ namespace Discord.WebSocket
|
|||||||
gameModel.Type = Activity.Type;
|
gameModel.Type = Activity.Type;
|
||||||
if (Activity is StreamingGame streamGame)
|
if (Activity is StreamingGame streamGame)
|
||||||
gameModel.StreamUrl = streamGame.Url;
|
gameModel.StreamUrl = streamGame.Url;
|
||||||
|
if (Activity is CustomStatusGame customStatus)
|
||||||
|
gameModel.State = customStatus.State;
|
||||||
game = gameModel;
|
game = gameModel;
|
||||||
}
|
}
|
||||||
else if (activity.IsSpecified)
|
else if (activity.IsSpecified)
|
||||||
|
|||||||
Reference in New Issue
Block a user