From 16eaf7dfc57e0c5d6cfc6ad50b74d6b8345f5b87 Mon Sep 17 00:00:00 2001 From: KillerBossOriginal Date: Sun, 13 Aug 2023 13:56:37 +0200 Subject: [PATCH] Add set commands --- CHANGELOG.md | 3 ++- lib/src/main.dart | 38 ++++++++++++++++++++++---------------- lib/src/requests.dart | 12 +++++++++++- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c557534..6866a2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # 1.3.0 - Renamed `calculateIntents` to `intentsCalculator` -- Add Docs in Guild Class +- Add set slashcommands - Add GuildDiscoverySplash +- Adding Docs in Guild Class - Fix `guild_icon` - Fix `guild_splash` - Removed `base_image` diff --git a/lib/src/main.dart b/lib/src/main.dart index db31a76..a817acf 100644 --- a/lib/src/main.dart +++ b/lib/src/main.dart @@ -42,6 +42,7 @@ class Client extends EventEmitter { late ChannelManager channels; bool ready = false; late User user; + var commands = {}; /// Create a new Client. /// [intents] Intents to enable for this connection, it's a multiple of two. @@ -94,23 +95,10 @@ class Client extends EventEmitter { }); } - Sender sender = Sender(token); - var i = await sender.fetchGuilds(withCounts: true); + late Sender sender; + late int n; - List gg = []; - - 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) { + ws.listen((event) async { event = json.decode(event); switch (event["op"]) { @@ -130,6 +118,24 @@ class Client extends EventEmitter { switch (eventName) { case "READY": + sender = Sender(token, event["d"]["user"]["id"]); + var i = await sender.fetchGuilds(withCounts: true); + + List 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"]; sessionID = event["d"]["session_id"]; user = User(event["d"]["user"]); diff --git a/lib/src/requests.dart b/lib/src/requests.dart index 3aa9269..f9444e9 100644 --- a/lib/src/requests.dart +++ b/lib/src/requests.dart @@ -36,10 +36,11 @@ Future requestWebSocketURL() async { class Sender { final String? _token; + final String id; Map headers = {}; dynamic channels; - Sender(this._token) { + Sender(this._token, this.id) { headers = { "Content-Type": "application/json", "Authorization": "Bot $_token", @@ -86,6 +87,15 @@ class Sender { res = json.decode(res.body); return res; } + + Future setCommands(List commands) async { + dynamic res = await http.put(Uri.parse("$apiURL/applications/$id/commands"), headers: headers, body: json.encode(commands)); + if (res.statusCode != 200 || res.statusCode != 201) { + throw Exception("Error ${res.statusCode} receiving the member"); + } + res = json.decode(res.body); + return res; + } } Future interactionReply(String id, String token, Map content) async {