Added support for initial presence
[ci skip]
This commit is contained in:
parent
aea584cea9
commit
76d8f2ae82
|
@ -72,6 +72,7 @@ part "src/events/InviteEvents.dart";
|
|||
|
||||
part "src/utils/builders/Builder.dart";
|
||||
|
||||
part "src/utils/builders/PresenceBuilder.dart";
|
||||
part "src/utils/builders/AttachmentBuilder.dart";
|
||||
part "src/utils/builders/PermissionsBuilder.dart";
|
||||
part "src/utils/builders/EmbedBuilder.dart";
|
||||
|
|
|
@ -39,6 +39,9 @@ class ClientOptions {
|
|||
/// Enables dispatching of guild subscription events (presence and typing events)
|
||||
bool guildSubscriptions;
|
||||
|
||||
/// Initial bot presence
|
||||
PresenceBuilder? initialPresence;
|
||||
|
||||
/// Makes a new `ClientOptions` object.
|
||||
ClientOptions(
|
||||
{this.allowedMentions,
|
||||
|
@ -50,7 +53,8 @@ class ClientOptions {
|
|||
this.ignoredEvents = const [],
|
||||
this.gatewayIntents,
|
||||
this.compressedGatewayPayloads = true,
|
||||
this.guildSubscriptions = true });
|
||||
this.guildSubscriptions = true,
|
||||
this.initialPresence });
|
||||
}
|
||||
|
||||
/// When identifying to the gateway, you can specify an intents parameter which
|
||||
|
|
|
@ -353,8 +353,8 @@ class Nyxx implements Disposable {
|
|||
/// bot.setPresence(game: Activity.of("Super duper game", type: ActivityType.streaming, url: "https://twitch.tv/l7ssha"))
|
||||
/// ```
|
||||
/// `url` property in `Activity` can be only set when type is set to `streaming`
|
||||
void setPresence({UserStatus? status, bool? afk, Activity? game, DateTime? since}) {
|
||||
this.shardManager.setPresence(status: status, afk: afk, game: game, since: since);
|
||||
void setPresence(PresenceBuilder presenceBuilder) {
|
||||
this.shardManager.setPresence(presenceBuilder);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -29,9 +29,9 @@ class ShardManager implements Disposable {
|
|||
}
|
||||
|
||||
/// Sets presences on every shard
|
||||
void setPresence({UserStatus? status, bool? afk, Activity? game, DateTime? since}) {
|
||||
void setPresence(PresenceBuilder presenceBuilder) {
|
||||
for (final shard in shards) {
|
||||
shard.setPresence(status: status, afk: afk, game: game, since: since);
|
||||
shard.setPresence(presenceBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,20 +110,8 @@ class Shard implements Disposable {
|
|||
}
|
||||
|
||||
/// Allows to set presence for current shard.
|
||||
void setPresence({UserStatus? status, bool? afk, Activity? game, DateTime? since}) {
|
||||
final packet = <String, dynamic> {
|
||||
"status": (status != null) ? status.toString() : UserStatus.online.toString(),
|
||||
"afk": (afk != null) ? afk : false,
|
||||
if (game != null)
|
||||
"game": <String, dynamic>{
|
||||
"name": game.name,
|
||||
"type": game.type.value,
|
||||
if (game.type == ActivityType.streaming) "url": game.url
|
||||
},
|
||||
"since": (since != null) ? since.millisecondsSinceEpoch : null
|
||||
};
|
||||
|
||||
this.send(OPCodes.statusUpdate, packet);
|
||||
void setPresence(PresenceBuilder presenceBuilder) {
|
||||
this.send(OPCodes.statusUpdate, presenceBuilder._build());
|
||||
}
|
||||
|
||||
/// Syncs all guilds
|
||||
|
@ -238,7 +226,9 @@ class Shard implements Disposable {
|
|||
},
|
||||
"large_threshold": manager._ws._client._options.largeThreshold,
|
||||
"compress": manager._ws._client._options.compressedGatewayPayloads,
|
||||
"guild_subscriptions" : manager._ws._client._options.guildSubscriptions
|
||||
"guild_subscriptions" : manager._ws._client._options.guildSubscriptions,
|
||||
if (manager._ws._client._options.initialPresence != null)
|
||||
"presence" : manager._ws._client._options.initialPresence!._build()
|
||||
};
|
||||
|
||||
if (manager._ws._client._options.gatewayIntents != null) {
|
||||
|
|
24
nyxx/lib/src/utils/builders/PresenceBuilder.dart
Normal file
24
nyxx/lib/src/utils/builders/PresenceBuilder.dart
Normal file
|
@ -0,0 +1,24 @@
|
|||
part of nyxx;
|
||||
|
||||
class PresenceBuilder implements Builder {
|
||||
final UserStatus? status;
|
||||
final bool? afk;
|
||||
final Activity? game;
|
||||
DateTime? since;
|
||||
|
||||
PresenceBuilder({this.status, this.afk, this.game, this.since});
|
||||
|
||||
@override
|
||||
Map<String, dynamic> _build() =>
|
||||
<String, dynamic> {
|
||||
"status": (status != null) ? status.toString() : UserStatus.online.toString(),
|
||||
"afk": (afk != null) ? afk : false,
|
||||
if (game != null)
|
||||
"game": <String, dynamic>{
|
||||
"name": game!.name,
|
||||
"type": game!.type.value,
|
||||
if (game!.type == ActivityType.streaming) "url": game!.url
|
||||
},
|
||||
"since": (since != null) ? since!.millisecondsSinceEpoch : null
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue