This commit is contained in:
KillerBossOriginal 2023-08-07 16:43:34 +02:00
parent b20f043551
commit fbb179e803
4 changed files with 117 additions and 86 deletions

View file

@ -1,3 +1,5 @@
import '../images/guild_icon.dart';
import '../../requests.dart'; import '../../requests.dart';
import '../channel/channel.dart'; import '../channel/channel.dart';
import '../channel/channel_manager.dart'; import '../channel/channel_manager.dart';
@ -15,11 +17,16 @@ class Guild {
RoleManager? roles; RoleManager? roles;
// Param guild create | fetch | fetch-servers // Param guild create | fetch | fetch-servers
late String id; // x | x | x /// The guild's id <br>
late bool unavailable; // x | x | /// GuildCreate, GuildUpdate, GuildDelete, FetchOneGuild, FetchAllGuild
String? name; // x | x | x late String id;
String? icon; // x | x | x /// Whether the guild is available to access. If it is not available, it indicates a server outage
String? iconHash; // x | x | /// GuildCreate, GuildDelete
/// FetchOneGuild, FetchAllGuild, GuildUpdate
late bool unavailable;
late String name; // x | x | x
late GuildIcon? icon; // x | x | x
late String? iconHash; // x | x |
String? splash; // x | x | String? splash; // x | x |
String? discoverySplash; // x | x | String? discoverySplash; // x | x |
bool? appIsOwner; // | | x bool? appIsOwner; // | | x
@ -60,92 +67,87 @@ class Guild {
Guild(this._sender, Map data) { Guild(this._sender, Map data) {
id = data["id"]; id = data["id"];
if(data["channels"] != null && data["members"] != null && data["roles"] != null) {
List<Channel> cc = [];
for (var c in data["channels"]) {
cc.add(Channel(_sender, c));
}
channels = ChannelManager(_sender, cc);
// Without discord outages List<Member> mm = [];
if (data["unavailable"] != null && !data["unavailable"]) { for (var m in data["members"]) {
if(data["channels"] != null && data["members"] != null && data["roles"] != null) { mm.add(Member(m));
List<Channel> cc = []; }
for (var c in data["channels"]) { members = MemberManager(_sender, mm, id);
cc.add(Channel(_sender, c));
}
channels = ChannelManager(_sender, cc);
List<Member> mm = []; List<Role> rr = [];
for (var m in data["members"]) { for (var r in data["roles"]) {
mm.add(Member(m)); rr.add(Role(r));
} }
members = MemberManager(_sender, mm, id); roles = RoleManager(rr);
} else {
channels = ChannelManager(_sender, []);
members = MemberManager(_sender, [], id);
roles = RoleManager([]);
}
List<Role> rr = []; unavailable = false;
for (var r in data["roles"]) { name = data["name"];
rr.add(Role(r)); icon = GuildIcon(data["icon"], id);
} iconHash = data["icon_hash"];
roles = RoleManager(rr); splash = data["splash"];
} else { if (data["discovery_splash"] != null) {
channels = ChannelManager(_sender, []); discoverySplash = data["discovery_splash"];
members = MemberManager(_sender, [], id); } else {
roles = RoleManager([]); discoverySplash = null;
} }
appIsOwner = data["owner"];
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"];
maxPresences = data["max_presences"];
maxMembers = data["max_members"];
vanityUrlCode = data["vanity_url_code"];
description = data["description"];
banner = data["banner"];
premiumTier = data["premium_tier"];
premiumSubscriptionCount = data["premium_subscription_count"];
preferredLocale = data["preferred_locale"];
publicUpdatesChannelId = data["public_updates_channel_id"];
maxVideoChannelUsers = data["max_video_channel_users"];
maxStageVideoChannelUsers = data["max_stage_video_channel_users"];
premiumProgressBarEnabled = data["premium_progress_bar_enabled"];
safetyAlertsChannelId = data["safety_alerts_channel_id"];
unavailable = data["unavailable"] ?? false; if (data["approximate_member_count"] != null) {
name = data["name"]; approximateMemberCount = data["approximate_member_count"];
icon = data["icon"]; }
iconHash = data["icon_hash"]; if (data["approximate_presence_count"] != null) {
splash = data["splash"]; approximatePresenceCount = data["approximate_presence_count"];
if (data["discovery_splash"] != null) { }
discoverySplash = data["discovery_splash"];
} else {
discoverySplash = null;
}
appIsOwner = data["owner"];
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"];
maxPresences = data["max_presences"];
maxMembers = data["max_members"];
vanityUrlCode = data["vanity_url_code"];
description = data["description"];
banner = data["banner"];
premiumTier = data["premium_tier"];
premiumSubscriptionCount = data["premium_subscription_count"];
preferredLocale = data["preferred_locale"];
publicUpdatesChannelId = data["public_updates_channel_id"];
maxVideoChannelUsers = data["max_video_channel_users"];
maxStageVideoChannelUsers = data["max_stage_video_channel_users"];
premiumProgressBarEnabled = data["premium_progress_bar_enabled"];
safetyAlertsChannelId = data["safety_alerts_channel_id"];
if (data["approximate_member_count"] != null) { // GuildCreate only
approximateMemberCount = data["approximate_member_count"]; if (data["joined_at"] != null) {
} joinedAt = data["joined_at"];
if (data["approximate_presence_count"] != null) { }
approximatePresenceCount = data["approximate_presence_count"]; if (data["large"] != null) {
} large = data["large"];
// GuildCreate only }
if (data["joined_at"] != null) { if (data["member_count"] != null) {
joinedAt = data["joined_at"]; memberCount = data["member_count"];
}
if (data["large"] != null) {
large = data["large"];
}
if (data["member_count"] != null) {
memberCount = data["member_count"];
}
} else if (data["unavailable"] != null) {
unavailable = data["unavailable"];
} }
} }
} }

View file

@ -0,0 +1,13 @@
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 }) {
unavailable = true;
}
}

View file

@ -0,0 +1,4 @@
class BaseImage {
late String hash;
BaseImage(this.hash);
}

View file

@ -0,0 +1,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";
}
}