adding to guild
This commit is contained in:
parent
efbba335a7
commit
2d0183f797
2 changed files with 55 additions and 32 deletions
|
@ -27,11 +27,10 @@ int calculateIntents(List<int> intents) {
|
||||||
class Client extends EventEmitter {
|
class Client extends EventEmitter {
|
||||||
String? token;
|
String? token;
|
||||||
int intents;
|
int intents;
|
||||||
dynamic ws;
|
late WebSocket ws;
|
||||||
String resumeGatewayURL = "";
|
String resumeGatewayURL = "";
|
||||||
String sessionID = "";
|
String sessionID = "";
|
||||||
dynamic guilds;
|
late GuildManager guilds;
|
||||||
dynamic ready;
|
|
||||||
|
|
||||||
/// Create a new Client.
|
/// Create a new Client.
|
||||||
/// [intents] Intents to enable for this connection, it's a multiple of two.
|
/// [intents] Intents to enable for this connection, it's a multiple of two.
|
||||||
|
|
|
@ -88,20 +88,35 @@ class Collection {
|
||||||
|
|
||||||
/// Represents a guild (aka server) on Discord.
|
/// Represents a guild (aka server) on Discord.
|
||||||
class Guild {
|
class Guild {
|
||||||
String id = '';
|
|
||||||
String name = '';
|
|
||||||
String? owner;
|
|
||||||
String? description;
|
|
||||||
late ChannelManager channels;
|
|
||||||
late MemberManager members;
|
|
||||||
late RoleManager roles;
|
|
||||||
final Sender _sender;
|
final Sender _sender;
|
||||||
|
ChannelManager? channels;
|
||||||
|
MemberManager? members;
|
||||||
|
RoleManager? roles;
|
||||||
|
String id = '';
|
||||||
|
String? name = '';
|
||||||
|
String? ownerId;
|
||||||
|
String? description;
|
||||||
|
String? joinedAt;
|
||||||
|
bool? large;
|
||||||
|
bool? unavailable;
|
||||||
|
int? memberCount;
|
||||||
|
|
||||||
Guild(this._sender, Map data) {
|
Guild(this._sender, Map data) {
|
||||||
id = data["id"];
|
id = data["id"];
|
||||||
|
if (data["unavailable"] != null && data["unavailable"] == false) {
|
||||||
|
unavailable = data["unavailable"];
|
||||||
name = data["name"];
|
name = data["name"];
|
||||||
description = data["description"];
|
description = data["description"];
|
||||||
owner = data["owner_id"];
|
ownerId = data["owner_id"];
|
||||||
|
if (data["joined_at"] != null) {
|
||||||
|
joinedAt = data["joined_at"];
|
||||||
|
}
|
||||||
|
if (data["large"] != null) {
|
||||||
|
large = data["large"];
|
||||||
|
}
|
||||||
|
if (data["member_count"] != null) {
|
||||||
|
memberCount = data["member_count"];
|
||||||
|
}
|
||||||
|
|
||||||
if(data["channels"] != null && data["members"] != null && data["roles"] != null) {
|
if(data["channels"] != null && data["members"] != null && data["roles"] != null) {
|
||||||
List<Channel> cc = [];
|
List<Channel> cc = [];
|
||||||
|
@ -126,6 +141,9 @@ class Guild {
|
||||||
members = MemberManager([], id);
|
members = MemberManager([], id);
|
||||||
roles = RoleManager([]);
|
roles = RoleManager([]);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
unavailable = data["unavailable"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +160,11 @@ class GuildManager {
|
||||||
Future<Guild> fetch(String id) async {
|
Future<Guild> fetch(String id) async {
|
||||||
var res = await _sender.fetchGuild(id);
|
var res = await _sender.fetchGuild(id);
|
||||||
final guild = Guild(_sender, res);
|
final guild = Guild(_sender, res);
|
||||||
|
final oldGuild = cache.get(guild.id);
|
||||||
|
guild.joinedAt = oldGuild.joinedAt;
|
||||||
|
guild.large = oldGuild.large;
|
||||||
|
guild.unavailable = oldGuild.unavailable;
|
||||||
|
guild.memberCount = oldGuild.memberCount;
|
||||||
cache.set(guild.id, guild);
|
cache.set(guild.id, guild);
|
||||||
return guild;
|
return guild;
|
||||||
}
|
}
|
||||||
|
@ -283,6 +306,7 @@ class Message {
|
||||||
String? content;
|
String? content;
|
||||||
Message({ this.content });
|
Message({ this.content });
|
||||||
|
|
||||||
|
/// Returns an object rapresentation of the message
|
||||||
exportable() {
|
exportable() {
|
||||||
return {
|
return {
|
||||||
"content": content,
|
"content": content,
|
||||||
|
|
Reference in a new issue