-
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 #85 from mineral-dart/feat-improve-users
feat: Improve users
- Loading branch information
Showing
29 changed files
with
270 additions
and
41 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
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 |
---|---|---|
@@ -1,5 +1,30 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:http/http.dart'; | ||
import 'package:mineral/core.dart'; | ||
import 'package:mineral/core/api.dart'; | ||
import 'package:mineral/exception.dart'; | ||
import 'package:mineral/framework.dart'; | ||
import 'package:mineral/src/api/managers/cache_manager.dart'; | ||
import 'package:mineral_ioc/ioc.dart'; | ||
|
||
class UserManager extends CacheManager<User> { | ||
Future<User> resolve (Snowflake id) async { | ||
if (cache.containsKey(id)) { | ||
return cache.getOrFail(id); | ||
} | ||
|
||
final Response response = await ioc.use<DiscordApiHttpService>() | ||
.get(url: '/users/$id') | ||
.build(); | ||
|
||
if (response.statusCode == 200) { | ||
User user = User.from(jsonDecode(response.body)); | ||
cache.putIfAbsent(user.id, () => user); | ||
|
||
return user; | ||
} | ||
|
||
throw ApiException('Unable to fetch channel with id #$id'); | ||
} | ||
} |
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,9 @@ | ||
enum PremiumType { | ||
none(0), | ||
classicNitro(1), | ||
nitro(2), | ||
basicNitro(3); | ||
|
||
final int value; | ||
const PremiumType(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,19 @@ | ||
import 'package:mineral/core.dart'; | ||
import 'package:mineral/core/api.dart'; | ||
|
||
class UserDecoration { | ||
final String _discriminator; | ||
|
||
final ImageFormater? _avatar; | ||
final ImageFormater? _avatarDecoration; | ||
|
||
UserDecoration(this._discriminator, this._avatar, this._avatarDecoration); | ||
|
||
ImageFormater? get avatar => _avatar; | ||
ImageFormater? get avatarDecoration => _avatarDecoration; | ||
|
||
/// ### Returns the absolute url to the user's avatar | ||
String get defaultAvatarUrl => _avatar != null | ||
? '${_avatar?.url}' | ||
: '${Constants.cdnUrl}/embed/avatars/${int.parse(_discriminator) % 5 }.png'; | ||
} |
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,57 @@ | ||
import 'package:mineral/core/api.dart'; | ||
import 'package:mineral/src/api/users/user_flags/active_developer_flag.dart'; | ||
import 'package:mineral/src/api/users/user_flags/bot_http_interactions_flag.dart'; | ||
import 'package:mineral/src/api/users/user_flags/bug_hunter_level_1_flag.dart'; | ||
import 'package:mineral/src/api/users/user_flags/bug_hunter_level_2_flag.dart'; | ||
import 'package:mineral/src/api/users/user_flags/certified_moderator_flag.dart'; | ||
import 'package:mineral/src/api/users/user_flags/hype_squad_flag.dart'; | ||
import 'package:mineral/src/api/users/user_flags/hype_squad_online_house_1_flag.dart'; | ||
import 'package:mineral/src/api/users/user_flags/hype_squad_online_house_2_flag.dart'; | ||
import 'package:mineral/src/api/users/user_flags/hype_squad_online_house_3_flag.dart'; | ||
import 'package:mineral/src/api/users/user_flags/partner_flag.dart'; | ||
import 'package:mineral/src/api/users/user_flags/premium_early_supporter_flag.dart'; | ||
import 'package:mineral/src/api/users/user_flags/staff_flag.dart'; | ||
import 'package:mineral/src/api/users/user_flags/team_pseudo_user_flag.dart'; | ||
import 'package:mineral/src/api/users/user_flags/verified_bot_flag.dart'; | ||
import 'package:mineral/src/api/users/user_flags/verified_developer_flag.dart'; | ||
|
||
class UserFlag { | ||
static get staff => StaffFlag(); | ||
static get partner => PartnerFlag(); | ||
static get hypeSquad => HypeSquadFlag(); | ||
static get bugHunterLevel1 => BugHunterLevel1Flag(); | ||
static get hypeSquadOnlineHouse1 => HypeSquadOnlineHouse1Flag(); | ||
static get hypeSquadOnlineHouse2 => HypeSquadOnlineHouse2Flag(); | ||
static get hypeSquadOnlineHouse3 => HypeSquadOnlineHouse3Flag(); | ||
static get premiumEarlySupporter => PremiumEarlySupporterFlag(); | ||
static get teamPseudoUser => TeamPseudoUserFlag(); | ||
static get bugHunterLevel2 => BugHunterLevel2Flag(); | ||
static get verifiedBot => VerifiedBotFlag(); | ||
static get verifiedDeveloper => VerifiedDeveloperFlag(); | ||
static get certifiedModerator => CertifiedModeratorFlag(); | ||
static get botHttpInteractions => BotHttpInteractionsFlag(); | ||
static get activeDeveloper => ActiveDeveloperFlag(); | ||
|
||
static final List<UserFlagContract> _flags = [ | ||
UserFlag.staff, | ||
UserFlag.partner, | ||
UserFlag.hypeSquad, | ||
UserFlag.bugHunterLevel1, | ||
UserFlag.hypeSquadOnlineHouse1, | ||
UserFlag.hypeSquadOnlineHouse2, | ||
UserFlag.hypeSquadOnlineHouse3, | ||
UserFlag.premiumEarlySupporter, | ||
UserFlag.teamPseudoUser, | ||
UserFlag.bugHunterLevel2, | ||
UserFlag.verifiedBot, | ||
UserFlag.verifiedDeveloper, | ||
UserFlag.certifiedModerator, | ||
UserFlag.botHttpInteractions, | ||
UserFlag.activeDeveloper, | ||
]; | ||
|
||
static UserFlagContract find (int value) => _flags.firstWhere((element) => element.value == value); | ||
|
||
static get values => _flags.map((e) => e.value); | ||
UserFlag._(); | ||
} |
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,5 @@ | ||
import 'package:mineral/core/api.dart'; | ||
|
||
class ActiveDeveloperFlag extends UserFlagContract { | ||
ActiveDeveloperFlag(): super('User is an active developer', 1 << 22, '26c7a60fb1654315e0be26107bd47470.svg'); | ||
} |
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,5 @@ | ||
import 'package:mineral/core/api.dart'; | ||
|
||
class BotHttpInteractionsFlag extends UserFlagContract { | ||
BotHttpInteractionsFlag(): super('Bot use only HTTP interactions', 1 << 19, '498591d63b352256a1bf18061eff9d57.svg'); | ||
} |
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,5 @@ | ||
import 'package:mineral/core/api.dart'; | ||
|
||
class BugHunterLevel1Flag extends UserFlagContract { | ||
BugHunterLevel1Flag(): super('Bug Hunter Level 1', 1 << 3, '8353d89b529e13365c415aef08d1d1f4.svg'); | ||
} |
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,5 @@ | ||
import 'package:mineral/core/api.dart'; | ||
|
||
class BugHunterLevel2Flag extends UserFlagContract { | ||
BugHunterLevel2Flag(): super('Bug Hunter Level 2', 1 << 14, 'f599063762165e0d23e8b11b684765a8.svg'); | ||
} |
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,5 @@ | ||
import 'package:mineral/core/api.dart'; | ||
|
||
class CertifiedModeratorFlag extends UserFlagContract { | ||
CertifiedModeratorFlag(): super('Moderator Programs Alumni', 1 << 18, 'b945002f0e0fd7f11990d800e98b5504.svg'); | ||
} |
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,5 @@ | ||
import 'package:mineral/core/api.dart'; | ||
|
||
class HypeSquadFlag extends UserFlagContract { | ||
HypeSquadFlag(): super('HypeSquad Events Member', 1 << 2, 'e666a84a7a5ea2abbbfa73adf22e627b.svg'); | ||
} |
5 changes: 5 additions & 0 deletions
5
lib/src/api/users/user_flags/hype_squad_online_house_1_flag.dart
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,5 @@ | ||
import 'package:mineral/core/api.dart'; | ||
|
||
class HypeSquadOnlineHouse1Flag extends UserFlagContract { | ||
HypeSquadOnlineHouse1Flag(): super('House Bravery Member', 1 << 6, '34306011e46e87f8ef25f3415d3b99ca.svg'); | ||
} |
5 changes: 5 additions & 0 deletions
5
lib/src/api/users/user_flags/hype_squad_online_house_2_flag.dart
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,5 @@ | ||
import 'package:mineral/core/api.dart'; | ||
|
||
class HypeSquadOnlineHouse2Flag extends UserFlagContract { | ||
HypeSquadOnlineHouse2Flag(): super('House Brilliance Member', 1 << 7, 'ec8e92568a7c8f19a052ef42f862ff18.svg'); | ||
} |
5 changes: 5 additions & 0 deletions
5
lib/src/api/users/user_flags/hype_squad_online_house_3_flag.dart
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,5 @@ | ||
import 'package:mineral/core/api.dart'; | ||
|
||
class HypeSquadOnlineHouse3Flag extends UserFlagContract { | ||
HypeSquadOnlineHouse3Flag(): super('House Balance Member', 1 << 8, '9f00b18e292e10fc0ae84ff5332e8b0b.svg'); | ||
} |
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,5 @@ | ||
import 'package:mineral/core/api.dart'; | ||
|
||
class PartnerFlag extends UserFlagContract { | ||
PartnerFlag(): super('Partnered Server Owner', 1 << 1, '34306011e46e87f8ef25f3415d3b99ca.svg'); | ||
} |
5 changes: 5 additions & 0 deletions
5
lib/src/api/users/user_flags/premium_early_supporter_flag.dart
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,5 @@ | ||
import 'package:mineral/core/api.dart'; | ||
|
||
class PremiumEarlySupporterFlag extends UserFlagContract { | ||
PremiumEarlySupporterFlag(): super('Early Nitro Supporter', 1 << 9, 'b802e9af134ff492276d94220e36ec5c.svg'); | ||
} |
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,5 @@ | ||
import 'package:mineral/core/api.dart'; | ||
|
||
class StaffFlag extends UserFlagContract { | ||
StaffFlag(): super('Discord Employee', 1 << 0, '48d5bdcffe9e7848067c2e187f1ef951.svg'); | ||
} |
Oops, something went wrong.