Add discord webhooks

This commit is contained in:
zontreck 2024-06-16 16:42:50 -07:00
parent cbf0279c42
commit a17e0452a0
6 changed files with 208 additions and 2 deletions

View file

@ -6,6 +6,7 @@ import 'package:libac_dart/utils/IOTools.dart';
import 'package:libac_dart/utils/TimeUtils.dart';
import 'package:servermanager/game.dart';
import 'package:servermanager/structs/SessionData.dart';
import 'package:servermanager/structs/discordHookHelper.dart';
import 'package:servermanager/structs/mod.dart';
import 'package:servermanager/structs/settings.dart';
import 'package:servermanager/wine.dart';
@ -130,6 +131,12 @@ class StateMachine {
PacketServer.socket!.close();
});
DiscordHookHelper.sendWebHook(
settings.inst!.discord,
DiscordHookProps.OFFLINE_ALERT,
"Server is now offline",
"The server is shutting down");
changeState(States.Inactive);
} else if (currentState == States.Starting) {
// Server startup in progress
@ -213,6 +220,12 @@ class StateMachine {
SessionData.timer = settings.inst!.timer.time.copy();
changeState(States.PreStart);
DiscordHookHelper.sendWebHook(
settings.inst!.discord,
DiscordHookProps.ONLINE_ALERT,
"Server is now starting up",
"The server is starting up now, it should appear on the server list in a few minutes");
resetKillswitch();
SessionData.enableRestartTimer = settings.inst!.timer.enabled;
@ -284,14 +297,24 @@ class StateMachine {
if (send && SessionData.enableRestartTimer) {
// Send the alert message
SessionData.CURRENT_INTERVAL = current;
int alertColor = 0;
if (current.type == WarnType.Intrusive) {
print("Sending alert '${current.warning}'");
settings.sendRconCommand("broadcast ${current.warning}");
// Set discord alert color
alertColor = DiscordHookProps.ALERT_INTRUSIVE;
} else if (current.type == WarnType.NonIntrusive) {
print("Sending chat message '${current.warning}'");
settings.sendRconCommand(
"ast chat \"global\" \"${current.warning}\"");
//settings.sendRconCommand(
// "ast chat \"global\" \"${current.warning}\"");
// Set discord alert color
alertColor = DiscordHookProps.ALERT;
}
DiscordHookHelper.sendWebHook(settings.inst!.discord, alertColor,
"Server Restart Alert", "${current.warning}");
}
// Check Shutdown Pending