Added ISelfUser.ModifyStatusAsync
This commit is contained in:
@@ -394,6 +394,15 @@ namespace Discord.API
|
||||
{
|
||||
await SendGatewayAsync(GatewayOpCode.Heartbeat, lastSeq, options: options).ConfigureAwait(false);
|
||||
}
|
||||
public async Task SendStatusUpdateAsync(long? idleSince, Game game, RequestOptions options = null)
|
||||
{
|
||||
var args = new StatusUpdateParams
|
||||
{
|
||||
IdleSince = idleSince,
|
||||
Game = game
|
||||
};
|
||||
await SendGatewayAsync(GatewayOpCode.StatusUpdate, args, options: options).ConfigureAwait(false);
|
||||
}
|
||||
public async Task SendRequestMembersAsync(IEnumerable<ulong> guildIds, RequestOptions options = null)
|
||||
{
|
||||
await SendGatewayAsync(GatewayOpCode.RequestGuildMembers, new RequestMembersParams { GuildIds = guildIds, Query = "", Limit = 0 }, options: options).ConfigureAwait(false);
|
||||
|
||||
12
src/Discord.Net/API/Gateway/StatusUpdateParams.cs
Normal file
12
src/Discord.Net/API/Gateway/StatusUpdateParams.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Gateway
|
||||
{
|
||||
public class StatusUpdateParams
|
||||
{
|
||||
[JsonProperty("idle_since"), Int53]
|
||||
public long? IdleSince { get; set; }
|
||||
[JsonProperty("game")]
|
||||
public Game Game { get; set; }
|
||||
}
|
||||
}
|
||||
8
src/Discord.Net/API/Rest/ModifyPresenceParams.cs
Normal file
8
src/Discord.Net/API/Rest/ModifyPresenceParams.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
public class ModifyPresenceParams
|
||||
{
|
||||
public Optional<UserStatus> Status { get; set; }
|
||||
public Optional<Discord.Game> Game { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -14,5 +14,6 @@ namespace Discord
|
||||
bool IsMfaEnabled { get; }
|
||||
|
||||
Task ModifyAsync(Action<ModifyCurrentUserParams> func);
|
||||
Task ModifyStatusAsync(Action<ModifyPresenceParams> func);
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,18 @@ using Model = Discord.API.User;
|
||||
namespace Discord
|
||||
{
|
||||
internal class SelfUser : User, ISelfUser
|
||||
{
|
||||
{
|
||||
private long _idleSince;
|
||||
private UserStatus _status;
|
||||
private Game _game;
|
||||
|
||||
public string Email { get; private set; }
|
||||
public bool IsVerified { get; private set; }
|
||||
public bool IsMfaEnabled { get; private set; }
|
||||
|
||||
public override UserStatus Status => _status;
|
||||
public override Game Game => _game;
|
||||
|
||||
public override DiscordClient Discord { get; }
|
||||
|
||||
public SelfUser(DiscordClient discord, Model model)
|
||||
@@ -49,5 +56,27 @@ namespace Discord
|
||||
var model = await Discord.ApiClient.ModifySelfAsync(args).ConfigureAwait(false);
|
||||
Update(model, UpdateSource.Rest);
|
||||
}
|
||||
public async Task ModifyStatusAsync(Action<ModifyPresenceParams> func)
|
||||
{
|
||||
if (func == null) throw new NullReferenceException(nameof(func));
|
||||
|
||||
var args = new ModifyPresenceParams();
|
||||
func(args);
|
||||
|
||||
var game = args.Game.GetValueOrDefault(_game);
|
||||
var status = args.Status.GetValueOrDefault(_status);
|
||||
|
||||
long idleSince = _idleSince;
|
||||
if (status == UserStatus.Idle && _status != UserStatus.Idle)
|
||||
idleSince = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
var apiGame = new API.Game { Name = game.Name, StreamType = game.StreamType, StreamUrl = game.StreamUrl };
|
||||
|
||||
await Discord.ApiClient.SendStatusUpdateAsync(status == UserStatus.Idle ? _idleSince : (long?)null, apiGame).ConfigureAwait(false);
|
||||
|
||||
//Save values
|
||||
_idleSince = idleSince;
|
||||
_game = game;
|
||||
_status = status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user