diff --git a/lib/src/classes/guild/guild.dart b/lib/src/classes/guild/guild.dart index 4ac826a..168e84b 100644 --- a/lib/src/classes/guild/guild.dart +++ b/lib/src/classes/guild/guild.dart @@ -14,22 +14,36 @@ class Guild { MemberManager? members; RoleManager? roles; - // Param guild create | fetch | fetch-servers - late String id; // x | x | x - late bool unavailable;// x | x | - String? name; // x | x | x - String? icon; // x | x | x - String? iconHash; // x | x | - String? splash; // x | x | - String? discoverySplash;// x | x | - bool? appIsOwner; // | | x - Future? owner;// | | - String? ownerId; // x | x | - String? permissions; // | | x + // Param guild create | fetch | fetch-servers + late String id; // x | x | x + late bool unavailable; // x | x | + String? name; // x | x | x + String? icon; // x | x | x + String? iconHash; // x | x | + String? splash; // x | x | + String? discoverySplash; // x | x | + bool? appIsOwner; // | | x + Future? 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"]; } diff --git a/lib/src/classes/guild/guild_manager.dart b/lib/src/classes/guild/guild_manager.dart index 91f941d..08f7695 100644 --- a/lib/src/classes/guild/guild_manager.dart +++ b/lib/src/classes/guild/guild_manager.dart @@ -15,7 +15,13 @@ class GuildManager { Future 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; diff --git a/lib/src/classes/member/member_manager.dart b/lib/src/classes/member/member_manager.dart index 2c07a64..4d681d1 100644 --- a/lib/src/classes/member/member_manager.dart +++ b/lib/src/classes/member/member_manager.dart @@ -13,9 +13,17 @@ class MemberManager { } } - Future fetch(String id) async { - var res = await _sender.fetchMember(this.id, id); - cache.set(id, Member(res)); - return Member(res); + Future 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); + } } } \ No newline at end of file diff --git a/lib/src/main.dart b/lib/src/main.dart index 780009d..c83d70b 100644 --- a/lib/src/main.dart +++ b/lib/src/main.dart @@ -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; }