Merge branch 'main' into updating-interactions
This commit is contained in:
commit
a70b976313
9 changed files with 95 additions and 73 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -1,3 +1,13 @@
|
||||||
|
# 1.3.0
|
||||||
|
- Renamed `calculateIntents` to `intentsCalculator`
|
||||||
|
- Add set slashcommands
|
||||||
|
- Add GuildDiscoverySplash
|
||||||
|
- Adding Docs in Guild Class
|
||||||
|
- Fix `guild_icon`
|
||||||
|
- Fix `guild_splash`
|
||||||
|
- Removed `base_image`
|
||||||
|
- Removed `notUpdatedGuild` from UnavailableGuild
|
||||||
|
|
||||||
# 1.2.0
|
# 1.2.0
|
||||||
- Add `client`
|
- Add `client`
|
||||||
- Add Event Emitter/Listener (`client.on`)
|
- Add Event Emitter/Listener (`client.on`)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import '../images/guild_discovery_splash.dart';
|
||||||
import '../images/guild_icon.dart';
|
import '../images/guild_icon.dart';
|
||||||
|
|
||||||
import '../../requests.dart';
|
import '../../requests.dart';
|
||||||
|
@ -17,23 +18,28 @@ class Guild {
|
||||||
MemberManager? members;
|
MemberManager? members;
|
||||||
RoleManager? roles;
|
RoleManager? roles;
|
||||||
|
|
||||||
// Param guild create | fetch | fetch-servers
|
/// The guild's id
|
||||||
/// The guild's id <br>
|
|
||||||
/// ✅ GuildCreate, GuildUpdate, GuildDelete, FetchOneGuild, FetchAllGuild
|
|
||||||
late String id;
|
late String id;
|
||||||
/// Whether the guild is available to access. If it is not available, it indicates a server outage
|
/// Whether the guild is available to access. If it is not available, it indicates a server outage
|
||||||
/// ✅ GuildCreate, GuildDelete
|
bool unavailable = false;
|
||||||
/// ❎ FetchOneGuild, FetchAllGuild, GuildUpdate
|
/// The name of this guild
|
||||||
late bool unavailable;
|
late String name;
|
||||||
late String name; // x | x | x
|
/// The icon hash of this guild
|
||||||
late GuildIcon? icon; // x | x | x
|
late String? iconHash;
|
||||||
late String? iconHash; // x | x |
|
/// The icon of this guild
|
||||||
String? splashHash; // x | x |
|
late GuildIcon? icon;
|
||||||
GuildSplash? splash;
|
/// The hash of the guild invite splash image
|
||||||
String? discoverySplash; // x | x |
|
late String? splashHash;
|
||||||
bool? appIsOwner; // | | x
|
/// The guild invite splash image of this guild
|
||||||
Future<Member>? owner; // | |
|
late GuildSplash? splash;
|
||||||
String? ownerId; // x | x |
|
/// The hash of the guild discovery splash image
|
||||||
|
late String? discoverySplashHash;
|
||||||
|
/// The guild discovery splash image of this guild
|
||||||
|
late GuildDiscoverySplash? discoverySplash;
|
||||||
|
/// The owner of this guild
|
||||||
|
late Future<Member>? owner;
|
||||||
|
/// The owner id of this guild
|
||||||
|
String? ownerId;
|
||||||
String? permissions; // | | x
|
String? permissions; // | | x
|
||||||
String? afkChannelId; // x | x |
|
String? afkChannelId; // x | x |
|
||||||
int? afkTimeout; // x | x |
|
int? afkTimeout; // x | x |
|
||||||
|
@ -66,6 +72,7 @@ class Guild {
|
||||||
String? joinedAt; // x | |
|
String? joinedAt; // x | |
|
||||||
bool? large; // x | |
|
bool? large; // x | |
|
||||||
int? memberCount; // x | |
|
int? memberCount; // x | |
|
||||||
|
// Param guild create | fetch | fetch-servers
|
||||||
|
|
||||||
Guild(this._sender, Map data) {
|
Guild(this._sender, Map data) {
|
||||||
id = data["id"];
|
id = data["id"];
|
||||||
|
@ -93,27 +100,32 @@ class Guild {
|
||||||
roles = RoleManager([]);
|
roles = RoleManager([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
unavailable = false;
|
|
||||||
name = data["name"];
|
name = data["name"];
|
||||||
if (data["icon"] != null) {
|
|
||||||
icon = GuildIcon(data["icon"], id);
|
iconHash = data["icon_hash"];
|
||||||
|
if (iconHash != null) {
|
||||||
|
icon = GuildIcon(iconHash!, id);
|
||||||
} else {
|
} else {
|
||||||
icon = null;
|
icon = null;
|
||||||
}
|
}
|
||||||
iconHash = data["icon_hash"];
|
|
||||||
splashHash = data["splash"];
|
splashHash = data["splash"];
|
||||||
if (splashHash != null) {
|
if (splashHash != null) {
|
||||||
splash = GuildSplash(splashHash.toString(), id);
|
splash = GuildSplash(splashHash!, id);
|
||||||
|
} else {
|
||||||
|
splash = null;
|
||||||
}
|
}
|
||||||
if (data["discovery_splash"] != null) {
|
|
||||||
discoverySplash = data["discovery_splash"];
|
discoverySplashHash = data["discovery_splash"];
|
||||||
|
if (discoverySplashHash != null) {
|
||||||
|
discoverySplash = GuildDiscoverySplash(discoverySplashHash!, id);
|
||||||
} else {
|
} else {
|
||||||
discoverySplash = null;
|
discoverySplash = null;
|
||||||
}
|
}
|
||||||
appIsOwner = data["owner"];
|
|
||||||
ownerId = data["owner_id"];
|
ownerId = data["owner_id"];
|
||||||
if (ownerId != null) {
|
if (ownerId != null) {
|
||||||
owner = members?.fetch(ownerId.toString());
|
owner = members!.fetch(ownerId.toString());
|
||||||
} else {
|
} else {
|
||||||
owner = null;
|
owner = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
import "guild.dart";
|
/// A guild involved in a server outage.
|
||||||
|
|
||||||
class UnavailableGuild {
|
class UnavailableGuild {
|
||||||
|
/// The guild's id
|
||||||
late String id;
|
late String id;
|
||||||
late bool unavailable;
|
/// Whether the guild is available to access. If it is not available, it indicates a server outage
|
||||||
late Guild? notUpdatedGuild;
|
bool unavailable = true;
|
||||||
|
|
||||||
UnavailableGuild(this.id, { this.notUpdatedGuild }) {
|
UnavailableGuild(this.id);
|
||||||
unavailable = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,4 +0,0 @@
|
||||||
class BaseImage {
|
|
||||||
late String hash;
|
|
||||||
BaseImage(this.hash);
|
|
||||||
}
|
|
10
lib/src/classes/images/guild_discovery_splash.dart
Normal file
10
lib/src/classes/images/guild_discovery_splash.dart
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
class GuildDiscoverySplash {
|
||||||
|
late String id;
|
||||||
|
late String hash;
|
||||||
|
|
||||||
|
GuildDiscoverySplash(this.hash, this.id);
|
||||||
|
|
||||||
|
String url({String? extension = "jpeg"}) {
|
||||||
|
return "https://cdn.discordapp.com/discovery-splashes/$id/$hash.$extension";
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +1,8 @@
|
||||||
import 'base_image.dart';
|
class GuildIcon {
|
||||||
|
|
||||||
class GuildIcon extends BaseImage {
|
|
||||||
late String id;
|
late String id;
|
||||||
|
late String hash;
|
||||||
|
|
||||||
GuildIcon(String hash, this.id) : super(hash) {
|
GuildIcon(this.hash, this.id);
|
||||||
this.hash = hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
String url({String? extension = "jpeg"}) {
|
String url({String? extension = "jpeg"}) {
|
||||||
return "https://cdn.discordapp.com/icons/$id/$hash.$extension";
|
return "https://cdn.discordapp.com/icons/$id/$hash.$extension";
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
import 'base_image.dart';
|
class GuildSplash {
|
||||||
|
|
||||||
class GuildSplash extends BaseImage {
|
|
||||||
late String id;
|
late String id;
|
||||||
|
late String hash;
|
||||||
|
|
||||||
GuildSplash(String hash, this.id) : super(hash) {
|
GuildSplash(this.hash, this.id);
|
||||||
this.hash = hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
String url({String? extension = "jpeg"}) {
|
String url({String? extension = "jpeg"}) {
|
||||||
return "https://cdn.discordapp.com/splashes/$id/$hash.$extension";
|
return "https://cdn.discordapp.com/splashes/$id/$hash.$extension";
|
||||||
|
|
|
@ -21,7 +21,7 @@ final apiURL = "https://discord.com/api/v$version";
|
||||||
/// This function calculate the intent number required from the gateway.
|
/// This function calculate the intent number required from the gateway.
|
||||||
/// [intents] is a list of multiples of two. You can use GatewayIntentBits class.
|
/// [intents] is a list of multiples of two. You can use GatewayIntentBits class.
|
||||||
/// Return a number.
|
/// Return a number.
|
||||||
int calculateIntents(List<int> intents) {
|
int intentsCalculator(List<int> intents) {
|
||||||
int intentsNumber = 0;
|
int intentsNumber = 0;
|
||||||
|
|
||||||
for (var element in intents) {
|
for (var element in intents) {
|
||||||
|
@ -45,6 +45,7 @@ class Client extends EventEmitter {
|
||||||
late User user;
|
late User user;
|
||||||
late CommandManager commands;
|
late CommandManager commands;
|
||||||
|
|
||||||
|
|
||||||
/// 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.
|
||||||
Client({this.intents = 0});
|
Client({this.intents = 0});
|
||||||
|
@ -96,23 +97,10 @@ class Client extends EventEmitter {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Sender sender = Sender(token);
|
late Sender sender;
|
||||||
var i = await sender.fetchGuilds(withCounts: true);
|
late int n;
|
||||||
|
|
||||||
List<Guild> gg = [];
|
ws.listen((event) async {
|
||||||
|
|
||||||
for (dynamic g in i) {
|
|
||||||
gg.add(Guild(sender, g));
|
|
||||||
}
|
|
||||||
|
|
||||||
channels = ChannelManager(sender, [], main: true);
|
|
||||||
|
|
||||||
sender.channels = channels;
|
|
||||||
guilds = GuildManager(sender, gg);
|
|
||||||
|
|
||||||
int n = i.length;
|
|
||||||
|
|
||||||
ws.listen((event) {
|
|
||||||
event = json.decode(event);
|
event = json.decode(event);
|
||||||
|
|
||||||
switch (event["op"]) {
|
switch (event["op"]) {
|
||||||
|
@ -132,6 +120,24 @@ class Client extends EventEmitter {
|
||||||
|
|
||||||
switch (eventName) {
|
switch (eventName) {
|
||||||
case "READY":
|
case "READY":
|
||||||
|
sender = Sender(token, event["d"]["user"]["id"]);
|
||||||
|
var i = await sender.fetchGuilds(withCounts: true);
|
||||||
|
|
||||||
|
List<Guild> gg = [];
|
||||||
|
|
||||||
|
for (dynamic g in i) {
|
||||||
|
gg.add(Guild(sender, g));
|
||||||
|
}
|
||||||
|
|
||||||
|
channels = ChannelManager(sender, [], main: true);
|
||||||
|
|
||||||
|
sender.channels = channels;
|
||||||
|
guilds = GuildManager(sender, gg);
|
||||||
|
|
||||||
|
n = i.length;
|
||||||
|
|
||||||
|
commands["set"] = sender.setCommands;
|
||||||
|
|
||||||
resumeGatewayURL = event["d"]["resume_gateway_url"];
|
resumeGatewayURL = event["d"]["resume_gateway_url"];
|
||||||
sessionID = event["d"]["session_id"];
|
sessionID = event["d"]["session_id"];
|
||||||
user = User(event["d"]["user"]);
|
user = User(event["d"]["user"]);
|
||||||
|
@ -142,9 +148,6 @@ class Client extends EventEmitter {
|
||||||
case "GUILD_CREATE":
|
case "GUILD_CREATE":
|
||||||
if (guilds.cache.has(event["d"]["id"])) {
|
if (guilds.cache.has(event["d"]["id"])) {
|
||||||
Guild oldGuild = guilds.cache.get(event["d"]["id"]);
|
Guild oldGuild = guilds.cache.get(event["d"]["id"]);
|
||||||
if (oldGuild.appIsOwner != null) {
|
|
||||||
event['d']["owner"] = oldGuild.appIsOwner;
|
|
||||||
}
|
|
||||||
if (oldGuild.permissions != null) {
|
if (oldGuild.permissions != null) {
|
||||||
event['d']["permissions"] = oldGuild.permissions;
|
event['d']["permissions"] = oldGuild.permissions;
|
||||||
}
|
}
|
||||||
|
@ -160,13 +163,11 @@ class Client extends EventEmitter {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "GUILD_DELETE":
|
case "GUILD_DELETE":
|
||||||
dynamic guild;
|
|
||||||
if (guilds.cache.has(event["d"]["id"])) {
|
if (guilds.cache.has(event["d"]["id"])) {
|
||||||
guild = guilds.cache.get(event["d"]["id"]);
|
guilds.cache.delete(event["d"]["id"]);
|
||||||
guilds.cache.set(event["d"]["id"], UnavailableGuild(event["d"]["id"], notUpdatedGuild: guild));
|
guilds.cache.set(event["d"]["id"], UnavailableGuild(event["d"]["id"],));
|
||||||
} else {
|
|
||||||
guild = event["d"];
|
|
||||||
}
|
}
|
||||||
|
var guild = event["d"];
|
||||||
emit("GUILD_DELETE", guild);
|
emit("GUILD_DELETE", guild);
|
||||||
break;
|
break;
|
||||||
case "INTERACTION_CREATE":
|
case "INTERACTION_CREATE":
|
||||||
|
|
|
@ -38,11 +38,12 @@ Future<String> requestWebSocketURL() async {
|
||||||
|
|
||||||
class Sender {
|
class Sender {
|
||||||
final String? _token;
|
final String? _token;
|
||||||
|
final String id;
|
||||||
Map<String, String> headers = {};
|
Map<String, String> headers = {};
|
||||||
dynamic channels;
|
dynamic channels;
|
||||||
String? id;
|
String? id;
|
||||||
|
|
||||||
Sender(this._token) {
|
Sender(this._token, this.id) {
|
||||||
headers = {
|
headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": "Bot $_token",
|
"Authorization": "Bot $_token",
|
||||||
|
|
Reference in a new issue