-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from mineral-dart/feat-implement-user-status
feat: Implement user presences
- Loading branch information
Showing
19 changed files
with
314 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:mineral/core/builders.dart'; | ||
|
||
class Md { | ||
Md._(); | ||
|
||
static String bold (dynamic value) => '**$value**'; | ||
|
||
static String underline (dynamic value) => '__${value}__'; | ||
|
||
static String strikethrough (dynamic value) => '~~$value~~'; | ||
|
||
static String code (String value) => '```$value```'; | ||
|
||
static String italic (String value) => '*$value*'; | ||
|
||
static String spoil (dynamic value) => '||$value||'; | ||
|
||
static String timestamp (DateTime value, { TimestampStyle? style }) => style != null | ||
? '<t:${(value.millisecondsSinceEpoch / 1000).round()}:${style.value}>' | ||
: '<t:${(value.millisecondsSinceEpoch / 1000).round()}>'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
enum TimestampStyle { | ||
shortTime('t'), | ||
longTime('T'), | ||
shortDate('d'), | ||
longDate('D'), | ||
shortDateTime('f*'), | ||
longDateTime('F'), | ||
relativeTime('R'); | ||
|
||
final String value; | ||
const TimestampStyle(this.value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
enum ActivityType { | ||
game(0), | ||
streaming(1), | ||
listening(2), | ||
watching(3), | ||
custom(4), | ||
competing(5); | ||
|
||
final int value; | ||
const ActivityType(this.value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:mineral/core/api.dart'; | ||
|
||
class AssetsActivity { | ||
final ImageFormater? _smallImage; | ||
final String? _smallText; | ||
final ImageFormater? _largeImage; | ||
final String? _largeText; | ||
|
||
AssetsActivity(this._smallImage, this._smallText, this._largeImage, this._largeText); | ||
|
||
ImageFormater? get smallImage => _smallImage; | ||
String? get smallText => _smallText; | ||
ImageFormater? get largeImage => _largeImage; | ||
String? get largeText => _largeText; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:mineral/core/api.dart'; | ||
import 'package:mineral/src/api/emoji.dart'; | ||
import 'package:mineral/src/api/guilds/activities/guild_member_activity.dart'; | ||
import 'package:mineral/src/api/guilds/activities/secret_activity.dart'; | ||
|
||
class CustomActivity extends GuildMemberActivity { | ||
final String _id; | ||
final String? _state; | ||
final PartialEmoji? _emoji; | ||
final String _createdAt; | ||
final SecretActivity _secrets; | ||
|
||
CustomActivity( | ||
String name, | ||
this._id, | ||
this._state, | ||
this._emoji, | ||
this._createdAt, | ||
this._secrets, | ||
): super(ActivityType.custom, name); | ||
|
||
String get id => _id; | ||
String? get state => _state; | ||
PartialEmoji? get emoji => _emoji; | ||
String get createdAt => _createdAt; | ||
SecretActivity get secrets => _secrets; | ||
|
||
factory CustomActivity.from(Snowflake guildId, dynamic payload) => CustomActivity( | ||
payload['name'], | ||
payload['id'], | ||
payload['state'], | ||
payload['emoji'] != null | ||
? PartialEmoji(payload['emoji']['id'], payload['emoji']['name'], payload['emoji']['animated']) | ||
: null, | ||
payload['created_at'], | ||
SecretActivity( | ||
payload['secrets']?['join'], | ||
payload['secrets']?['spectate'], | ||
payload['secrets']?['match'], | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import 'package:mineral/core/api.dart'; | ||
import 'package:mineral/src/api/guilds/activities/assets_activity.dart'; | ||
import 'package:mineral/src/api/guilds/activities/guild_member_activity.dart'; | ||
import 'package:mineral/src/api/guilds/activities/secret_activity.dart'; | ||
|
||
class GameActivity extends GuildMemberActivity { | ||
final String _id; | ||
final String? _state; | ||
final int? _startingAt; | ||
final int? _endAt; | ||
final int _createdAt; | ||
final String? _details; | ||
final String? _applicationId; | ||
final AssetsActivity _assets; | ||
final SecretActivity _secrets; | ||
|
||
GameActivity( | ||
String name, | ||
this._id, | ||
this._state, | ||
this._startingAt, | ||
this._endAt, | ||
this._createdAt, | ||
this._details, | ||
this._applicationId, | ||
this._assets, | ||
this._secrets, | ||
): super(ActivityType.game, name); | ||
|
||
String get id => _id; | ||
|
||
String? get state => _state; | ||
|
||
int? get startingAt => _startingAt; | ||
|
||
DateTime? get endAt => _endAt != null | ||
? DateTime.fromMicrosecondsSinceEpoch(_endAt!) | ||
: null; | ||
|
||
DateTime get createdAt => DateTime.fromMicrosecondsSinceEpoch(_createdAt); | ||
|
||
String? get details => _details; | ||
|
||
String? get applicationId => _applicationId; | ||
|
||
AssetsActivity get assets => _assets; | ||
|
||
SecretActivity get secrets => _secrets; | ||
|
||
factory GameActivity.from(Snowflake guildId, dynamic payload) => GameActivity( | ||
payload['name'], | ||
payload['id'], | ||
payload['state'], | ||
payload['timestamps']?['start'], | ||
payload['timestamps']?['end'], | ||
payload['created_at'], | ||
payload['details'], | ||
payload['application_id'], | ||
AssetsActivity( | ||
payload['assets']?['small_image'] != null | ||
? ImageFormater(payload['assets']['large_image'], 'app-assets/${payload['application_id']}') | ||
: null, | ||
payload['assets']?['small_text'], | ||
payload['assets']?['large_image'] != null | ||
? ImageFormater(payload['assets']['large_image'], 'app-assets/${payload['application_id']}') | ||
: null, | ||
payload['assets']?['large_text'], | ||
), | ||
SecretActivity( | ||
payload['secrets']?['join'], | ||
payload['secrets']?['spectate'], | ||
payload['secrets']?['match'], | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:mineral/core/api.dart'; | ||
|
||
class GuildMemberActivity { | ||
final ActivityType _type; | ||
final String _name; | ||
|
||
GuildMemberActivity(this._type, this._name); | ||
|
||
ActivityType get type => _type; | ||
String get name => _name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class SecretActivity { | ||
final String? _join; | ||
final String? _spectate; | ||
final String? _match; | ||
|
||
SecretActivity(this._join, this._spectate, this._match); | ||
|
||
String? get join => _join; | ||
String? get spectate => _spectate; | ||
String? get match => _match; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:mineral/core/api.dart'; | ||
import 'package:mineral/src/api/guilds/activities/guild_member_activity.dart'; | ||
|
||
class StreamingActivity extends GuildMemberActivity { | ||
final String _state; | ||
final String? _details; | ||
final String _url; | ||
|
||
StreamingActivity( | ||
String name, | ||
this._state, | ||
this._details, | ||
this._url, | ||
): super(ActivityType.streaming, name); | ||
|
||
String get state => _state; | ||
String? get details => _details; | ||
String get url => _url; | ||
|
||
factory StreamingActivity.from(Snowflake guildId, dynamic payload) => StreamingActivity( | ||
payload['name'], | ||
payload['state'], | ||
payload['details'], | ||
payload['url'], | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class ClientStatusBucket { | ||
final String? _desktop; | ||
final String? _web; | ||
final String? _mobile; | ||
|
||
ClientStatusBucket(this._desktop, this._web, this._mobile); | ||
|
||
String? get desktop => _desktop; | ||
String? get web => _web; | ||
String? get mobile => _mobile; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:mineral/core/api.dart'; | ||
import 'package:mineral/src/api/guilds/activities/guild_member_activity.dart'; | ||
import 'package:mineral/src/api/guilds/client_status_bucket.dart'; | ||
|
||
class GuildMemberPresence { | ||
final Snowflake _guildId; | ||
final String _status; | ||
final String? _premiumSince; | ||
final ClientStatusBucket _clientStatus; | ||
final List<GuildMemberActivity> _activities; | ||
|
||
GuildMemberPresence(this._guildId, this._status, this._premiumSince, this._clientStatus, this._activities); | ||
|
||
StatusType get status => StatusType.values.firstWhere((element) => element.value == _status); | ||
DateTime? get premiumSince => _premiumSince != null | ||
? DateTime.parse(_premiumSince!) | ||
: null; | ||
ClientStatusBucket get clientStatus => _clientStatus; | ||
List<GuildMemberActivity> get activities => _activities; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.