Updating guilds
This commit is contained in:
parent
fbb179e803
commit
51e0c294b5
5 changed files with 38 additions and 13 deletions
|
@ -3,6 +3,7 @@ import '../images/guild_icon.dart';
|
|||
import '../../requests.dart';
|
||||
import '../channel/channel.dart';
|
||||
import '../channel/channel_manager.dart';
|
||||
import '../images/guild_splash.dart';
|
||||
import '../member/member.dart';
|
||||
import '../member/member_manager.dart';
|
||||
import '../role/role.dart';
|
||||
|
@ -27,7 +28,8 @@ class Guild {
|
|||
late String name; // x | x | x
|
||||
late GuildIcon? icon; // x | x | x
|
||||
late String? iconHash; // x | x |
|
||||
String? splash; // x | x |
|
||||
String? splashHash; // x | x |
|
||||
GuildSplash? splash;
|
||||
String? discoverySplash; // x | x |
|
||||
bool? appIsOwner; // | | x
|
||||
Future<Member>? owner; // | |
|
||||
|
@ -93,9 +95,16 @@ class Guild {
|
|||
|
||||
unavailable = false;
|
||||
name = data["name"];
|
||||
icon = GuildIcon(data["icon"], id);
|
||||
if (data["icon"] != null) {
|
||||
icon = GuildIcon(data["icon"], id);
|
||||
} else {
|
||||
icon = null;
|
||||
}
|
||||
iconHash = data["icon_hash"];
|
||||
splash = data["splash"];
|
||||
splashHash = data["splash"];
|
||||
if (splashHash != null) {
|
||||
splash = GuildSplash(splashHash.toString(), id);
|
||||
}
|
||||
if (data["discovery_splash"] != null) {
|
||||
discoverySplash = data["discovery_splash"];
|
||||
} else {
|
||||
|
@ -103,7 +112,11 @@ class Guild {
|
|||
}
|
||||
appIsOwner = data["owner"];
|
||||
ownerId = data["owner_id"];
|
||||
owner = members?.fetch(ownerId.toString());
|
||||
if (ownerId != null) {
|
||||
owner = members?.fetch(ownerId.toString());
|
||||
} else {
|
||||
owner = null;
|
||||
}
|
||||
permissions = data["permissions"];
|
||||
afkChannelId = data["afk_channel_id"];
|
||||
afkTimeout = data["afk_timeout"];
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
import '../../requests.dart';
|
||||
import "guild.dart";
|
||||
|
||||
class UnavailableGuild {
|
||||
final Sender _sender;
|
||||
late String id;
|
||||
late bool unavailable;
|
||||
late Guild? notUpdatedData;
|
||||
|
||||
UnavailableGuild(this._sender, this.id, { this.notUpdatedData }) {
|
||||
UnavailableGuild(this.id, { this.notUpdatedData }) {
|
||||
unavailable = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,11 +2,12 @@ import 'base_image.dart';
|
|||
|
||||
class GuildIcon extends BaseImage {
|
||||
late String id;
|
||||
|
||||
GuildIcon(String hash, this.id) : super(hash) {
|
||||
this.hash = hash;
|
||||
}
|
||||
|
||||
String url(String? extension) {
|
||||
return "https://cdn.discordapp.com/guild-icons/$id/$hash.$extension";
|
||||
String url({String? extension = "jpeg"}) {
|
||||
return "https://cdn.discordapp.com/icons/$id/$hash.$extension";
|
||||
}
|
||||
}
|
13
lib/src/classes/images/guild_splash.dart
Normal file
13
lib/src/classes/images/guild_splash.dart
Normal file
|
@ -0,0 +1,13 @@
|
|||
import 'base_image.dart';
|
||||
|
||||
class GuildSplash extends BaseImage {
|
||||
late String id;
|
||||
|
||||
GuildSplash(String hash, this.id) : super(hash) {
|
||||
this.hash = hash;
|
||||
}
|
||||
|
||||
String url({String? extension = "jpeg"}) {
|
||||
return "https://cdn.discordapp.com/splashes/$id/$hash.$extension";
|
||||
}
|
||||
}
|
|
@ -4,10 +4,10 @@ import "../../requests.dart";
|
|||
|
||||
class MemberManager {
|
||||
final Collection cache = Collection();
|
||||
String id;
|
||||
String guildId;
|
||||
final Sender _sender;
|
||||
|
||||
MemberManager(this._sender, List<Member> members, this.id) {
|
||||
MemberManager(this._sender, List<Member> members, this.guildId) {
|
||||
for (var member in members) {
|
||||
cache.set(member.id, member);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ class MemberManager {
|
|||
return await fetch(id, forceFetch: true);
|
||||
}
|
||||
} else {
|
||||
var res = await _sender.fetchMember(this.id, id);
|
||||
var res = await _sender.fetchMember(guildId, id);
|
||||
cache.set(id, Member(res));
|
||||
return Member(res);
|
||||
}
|
||||
|
|
Reference in a new issue