finish implementation
This commit is contained in:
parent
a17e0452a0
commit
23d93a7f9a
8 changed files with 90 additions and 55 deletions
|
@ -1,13 +1,14 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:libac_dart/nbt/NbtUtils.dart';
|
||||
import 'package:libac_dart/nbt/impl/CompoundTag.dart';
|
||||
import 'package:libac_dart/nbt/impl/StringTag.dart';
|
||||
|
||||
class DiscordHookHelper {
|
||||
static Future<void> sendWebHook(DiscordHookProps? props, int colorCode,
|
||||
static Future<void> sendWebHook(DiscordHookProps props, int colorCode,
|
||||
String title, String content) async {
|
||||
if (props == null) return; // The webhook setting is not yet set up
|
||||
if (!props.enabled) return; // The webhook setting is not yet set up
|
||||
var js = json.encode({
|
||||
"content": "",
|
||||
"embeds": [
|
||||
|
@ -29,13 +30,16 @@ class DiscordHookHelper {
|
|||
class DiscordHookProps {
|
||||
String url;
|
||||
String serverName;
|
||||
bool enabled = false;
|
||||
|
||||
DiscordHookProps({required this.url, required this.serverName});
|
||||
DiscordHookProps(
|
||||
{required this.url, required this.serverName, required this.enabled});
|
||||
|
||||
CompoundTag serialize() {
|
||||
CompoundTag ct = CompoundTag();
|
||||
ct.put(TAG_URL, StringTag.valueOf(url));
|
||||
ct.put(TAG_SERVER_NAME, StringTag.valueOf(serverName));
|
||||
NbtUtils.writeBoolean(ct, TAG_ENABLED, enabled);
|
||||
|
||||
return ct;
|
||||
}
|
||||
|
@ -43,12 +47,14 @@ class DiscordHookProps {
|
|||
static DiscordHookProps deserialize(CompoundTag ct) {
|
||||
return DiscordHookProps(
|
||||
url: ct.get(TAG_URL)!.asString(),
|
||||
serverName: ct.get(TAG_SERVER_NAME)!.asString());
|
||||
serverName: ct.get(TAG_SERVER_NAME)!.asString(),
|
||||
enabled: NbtUtils.readBoolean(ct, TAG_ENABLED));
|
||||
}
|
||||
|
||||
static const String TAG_URL = "url";
|
||||
static const String TAG_SERVER_NAME = "serverName";
|
||||
static const String TAG_NAME = "discord";
|
||||
static const String TAG_ENABLED = "enabled";
|
||||
|
||||
static const int ONLINE_ALERT = 1869056;
|
||||
static const int OFFLINE_ALERT = 8716288;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue