Updating guild class
Co-authored-by: birlino <Birlino@users.noreply.github.com>
This commit is contained in:
parent
ad9426a871
commit
0d7c0bbd7d
4 changed files with 68 additions and 22 deletions
|
@ -26,10 +26,24 @@ class Guild {
|
|||
Future<Member>? owner; // | |
|
||||
String? ownerId; // x | x |
|
||||
String? permissions; // | | x
|
||||
String? afkChannelId; // x | x |
|
||||
int? afkTimeout; // x | x |
|
||||
bool? widgetEnabled; // x | x |
|
||||
String? widgetChannelId; // x | x |
|
||||
int? verificationLevel; // x | x |
|
||||
int? defaultMessageNotifications; // x | x |
|
||||
int? explicitContentFilter; // x | x |
|
||||
List? features; // | | x
|
||||
int? mfaLevel; // x | x |
|
||||
String? applicationId; // x | x |
|
||||
String? systemChannelId; // x | x |
|
||||
int? systemChannelFlags; // x | x |
|
||||
String? rulesChannelId; // x | x |
|
||||
|
||||
String? description;
|
||||
String? joinedAt;
|
||||
bool? large;
|
||||
int? memberCount;
|
||||
String? joinedAt; // x | |
|
||||
bool? large; // x | |
|
||||
int? memberCount; // x | |
|
||||
|
||||
Guild(this._sender, Map data) {
|
||||
id = data["id"];
|
||||
|
@ -60,7 +74,7 @@ class Guild {
|
|||
roles = RoleManager([]);
|
||||
}
|
||||
|
||||
unavailable = data["unavailable"];
|
||||
unavailable = data["unavailable"] ?? false;
|
||||
name = data["name"];
|
||||
icon = data["icon"];
|
||||
iconHash = data["icon_hash"];
|
||||
|
@ -74,7 +88,22 @@ class Guild {
|
|||
ownerId = data["owner_id"];
|
||||
owner = members?.fetch(ownerId.toString());
|
||||
permissions = data["permissions"];
|
||||
afkChannelId = data["afk_channel_id"];
|
||||
afkTimeout = data["afk_timeout"];
|
||||
widgetEnabled = data["widget_enabled"];
|
||||
widgetChannelId = data["widget_channel_id"];
|
||||
verificationLevel = data["verification_level"];
|
||||
defaultMessageNotifications = data["default_message_notifications"];
|
||||
explicitContentFilter = data["explicit_content_filter"];
|
||||
features = data["features"];
|
||||
mfaLevel = data["mfa_level"];
|
||||
applicationId = data["application_id"];
|
||||
systemChannelId = data["system_channel_id"];
|
||||
systemChannelFlags = data["system_channel_flags"];
|
||||
rulesChannelId = data["rules_channel_id"];
|
||||
description = data["description"];
|
||||
|
||||
// GuildCreate only
|
||||
if (data["joined_at"] != null) {
|
||||
joinedAt = data["joined_at"];
|
||||
}
|
||||
|
|
|
@ -15,7 +15,13 @@ class GuildManager {
|
|||
Future<Guild> fetch(String id) async {
|
||||
var res = await _sender.fetchGuild(id);
|
||||
final guild = Guild(_sender, res);
|
||||
final oldGuild = cache.get(guild.id);
|
||||
Guild oldGuild = cache.get(guild.id);
|
||||
oldGuild.members?.cache.values().forEach((member) {
|
||||
guild.members?.cache.set(member.id, member);
|
||||
});
|
||||
oldGuild.channels?.cache.values().forEach((channel) {
|
||||
guild.channels?.cache.set(channel.id, channel);
|
||||
});
|
||||
guild.joinedAt = oldGuild.joinedAt;
|
||||
guild.large = oldGuild.large;
|
||||
guild.unavailable = oldGuild.unavailable;
|
||||
|
|
|
@ -13,9 +13,17 @@ class MemberManager {
|
|||
}
|
||||
}
|
||||
|
||||
Future<Member> fetch(String id) async {
|
||||
Future<Member> fetch(String id, {bool forceFetch = false}) async {
|
||||
if (!forceFetch) {
|
||||
if (cache.has(id)) {
|
||||
return cache.get(id);
|
||||
} else {
|
||||
return await fetch(id, forceFetch: true);
|
||||
}
|
||||
} else {
|
||||
var res = await _sender.fetchMember(this.id, id);
|
||||
cache.set(id, Member(res));
|
||||
return Member(res);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -133,8 +133,11 @@ class Client extends EventEmitter {
|
|||
guilds.cache.set(event['d']["id"], Guild(sender, event['d']));
|
||||
if (n > 1) {
|
||||
n--;
|
||||
} else {
|
||||
} else if (n == 1) {
|
||||
n--;
|
||||
emit("READY");
|
||||
} else {
|
||||
emit("GUILD_CREATE");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
Reference in a new issue