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,43 +88,61 @@ 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"];
|
||||||
name = data["name"];
|
if (data["unavailable"] != null && data["unavailable"] == false) {
|
||||||
description = data["description"];
|
unavailable = data["unavailable"];
|
||||||
owner = data["owner_id"];
|
name = data["name"];
|
||||||
|
description = data["description"];
|
||||||
if(data["channels"] != null && data["members"] != null && data["roles"] != null) {
|
ownerId = data["owner_id"];
|
||||||
List<Channel> cc = [];
|
if (data["joined_at"] != null) {
|
||||||
for (var c in data["channels"]) {
|
joinedAt = data["joined_at"];
|
||||||
cc.add(Channel(_sender, c));
|
|
||||||
}
|
}
|
||||||
channels = ChannelManager(_sender, cc);
|
if (data["large"] != null) {
|
||||||
|
large = data["large"];
|
||||||
List<Member> mm = [];
|
|
||||||
for (var m in data["members"]) {
|
|
||||||
mm.add(Member(m));
|
|
||||||
}
|
}
|
||||||
members = MemberManager(mm, id);
|
if (data["member_count"] != null) {
|
||||||
|
memberCount = data["member_count"];
|
||||||
List<Role> rr = [];
|
}
|
||||||
for (var r in data["roles"]) {
|
|
||||||
rr.add(Role(r));
|
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);
|
||||||
|
|
||||||
|
List<Member> mm = [];
|
||||||
|
for (var m in data["members"]) {
|
||||||
|
mm.add(Member(m));
|
||||||
|
}
|
||||||
|
members = MemberManager(mm, id);
|
||||||
|
|
||||||
|
List<Role> rr = [];
|
||||||
|
for (var r in data["roles"]) {
|
||||||
|
rr.add(Role(r));
|
||||||
|
}
|
||||||
|
roles = RoleManager(rr);
|
||||||
|
} else {
|
||||||
|
channels = ChannelManager(_sender, []);
|
||||||
|
members = MemberManager([], id);
|
||||||
|
roles = RoleManager([]);
|
||||||
}
|
}
|
||||||
roles = RoleManager(rr);
|
|
||||||
} else {
|
} else {
|
||||||
channels = ChannelManager(_sender, []);
|
unavailable = data["unavailable"];
|
||||||
members = MemberManager([], id);
|
|
||||||
roles = RoleManager([]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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