adding other
This commit is contained in:
parent
87e2fd02fa
commit
26c2288b28
4 changed files with 68 additions and 6 deletions
9
lib/src/error_handler.dart
Normal file
9
lib/src/error_handler.dart
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import 'package:http/http.dart';
|
||||||
|
|
||||||
|
void handleCode(int code, Response fullResponse) {
|
||||||
|
switch (code) {
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
|
@ -1,7 +1,12 @@
|
||||||
import "package:events_emitter/events_emitter.dart";
|
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 "types.dart";
|
||||||
import "util.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 {
|
class Client extends EventEmitter {
|
||||||
Client({List<GatewayIntentBits> intents = const []});
|
Client({List<GatewayIntentBits> intents = const []});
|
||||||
|
@ -22,11 +27,39 @@ class WebhookClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void send(String content) async {
|
void sendText(String content) async {
|
||||||
final url = Uri.parse("https://discord.com/api/webhooks/$id/$token");
|
Map<String, String> body = {"content": content};
|
||||||
|
Response res = await sendWH(body, token, id);
|
||||||
|
|
||||||
|
handleCode(res.statusCode, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
void send({String content = "", List<Embed> 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<String, String> body = {"content": content};
|
||||||
|
Response res = await editWH(body, token, this.id, id);
|
||||||
|
|
||||||
|
handleCode(res.statusCode, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
void edit(String id, {String content = "", List<Embed> embeds = const []}) async {
|
||||||
|
Map body = {"content": content, "embeds": embeds};
|
||||||
|
Response res = await editWH(body, token, this.id, id);
|
||||||
|
|
||||||
|
handleCode(res.statusCode, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
lib/src/message.dart
Normal file
17
lib/src/message.dart
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import 'package:tn_discord/src/index.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
Future<http.Response> sendWH(Map content, String token, String id) {
|
||||||
|
final url = Uri.parse("$apiURL/webhooks/$id/$token");
|
||||||
|
return http.post(url, body: content);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<http.Response> 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<http.Response> getWH(String token, String id, String mid) {
|
||||||
|
final url = Uri.parse("$apiURL/webhooks/$id/$token/messages/$mid");
|
||||||
|
return http.get(url);
|
||||||
|
}
|
|
@ -21,3 +21,6 @@ class GatewayIntentBits {
|
||||||
static const AutoModerationConfiguration = 1048576;
|
static const AutoModerationConfiguration = 1048576;
|
||||||
static const AutoModerationExecution = 2097152;
|
static const AutoModerationExecution = 2097152;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef Embed = Map<String, String>;
|
||||||
|
typedef Message = Map<String, String>;
|
Reference in a new issue