From 26c2288b28fef76cb154ae62f837e785f511e68d Mon Sep 17 00:00:00 2001 From: Killer Boss Original <73131550+killerbossoriginal@users.noreply.github.com> Date: Sun, 30 Jul 2023 23:19:42 +0200 Subject: [PATCH] adding other --- lib/src/error_handler.dart | 9 ++++++++ lib/src/index.dart | 45 +++++++++++++++++++++++++++++++++----- lib/src/message.dart | 17 ++++++++++++++ lib/src/types.dart | 3 +++ 4 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 lib/src/error_handler.dart create mode 100644 lib/src/message.dart diff --git a/lib/src/error_handler.dart b/lib/src/error_handler.dart new file mode 100644 index 0000000..3d77433 --- /dev/null +++ b/lib/src/error_handler.dart @@ -0,0 +1,9 @@ +import 'package:http/http.dart'; + +void handleCode(int code, Response fullResponse) { + switch (code) { + default: + break; + } + return; +} diff --git a/lib/src/index.dart b/lib/src/index.dart index c4da277..6838e4e 100644 --- a/lib/src/index.dart +++ b/lib/src/index.dart @@ -1,7 +1,12 @@ import "package:events_emitter/events_emitter.dart"; +import "package:http/http.dart"; +import "package:tn_discord/src/error_handler.dart"; +import "package:tn_discord/src/message.dart"; import "types.dart"; import "util.dart"; -import 'package:http/http.dart' as http; + +final version = "10"; +final apiURL = "https://discord.com/api/v$version"; class Client extends EventEmitter { Client({List intents = const []}); @@ -22,11 +27,39 @@ class WebhookClient { } } - void send(String content) async { - final url = Uri.parse("https://discord.com/api/webhooks/$id/$token"); + void sendText(String content) async { + Map body = {"content": content}; + Response res = await sendWH(body, token, id); + + handleCode(res.statusCode, res); + } + + void send({String content = "", List embeds = const []}) async { + Map body = {"content": content, "embeds": embeds}; + + Response res = await sendWH(body, token, id); + + handleCode(res.statusCode, res); + } + + void editText(String id, String content) async { + Map body = {"content": content}; + Response res = await editWH(body, token, this.id, id); + + handleCode(res.statusCode, res); + } + + void edit(String id, {String content = "", List embeds = const []}) async { + Map body = {"content": content, "embeds": embeds}; + Response res = await editWH(body, token, this.id, id); + + handleCode(res.statusCode, res); + } + + Future get(String id) async { + Response res = await getWH(token, this.id, id); + + handleCode(res.statusCode, res); - final body = {"content": content}; - - await http.post(url, body: body); } } diff --git a/lib/src/message.dart b/lib/src/message.dart new file mode 100644 index 0000000..c17ad52 --- /dev/null +++ b/lib/src/message.dart @@ -0,0 +1,17 @@ +import 'package:tn_discord/src/index.dart'; +import 'package:http/http.dart' as http; + +Future sendWH(Map content, String token, String id) { + final url = Uri.parse("$apiURL/webhooks/$id/$token"); + return http.post(url, body: content); +} + +Future editWH(Map content, String token, String id, String mid) { + final url = Uri.parse("$apiURL/webhooks/$id/$token/messages/$mid"); + return http.patch(url, body: content); +} + +Future getWH(String token, String id, String mid) { + final url = Uri.parse("$apiURL/webhooks/$id/$token/messages/$mid"); + return http.get(url); +} diff --git a/lib/src/types.dart b/lib/src/types.dart index 1dd99eb..c3be6da 100644 --- a/lib/src/types.dart +++ b/lib/src/types.dart @@ -21,3 +21,6 @@ class GatewayIntentBits { static const AutoModerationConfiguration = 1048576; static const AutoModerationExecution = 2097152; } + +typedef Embed = Map; +typedef Message = Map; \ No newline at end of file