- Remove n8n

This commit is contained in:
Jahnisse
2026-03-26 15:02:24 +01:00
parent b8f12009ae
commit 6d3fd2135e
+27 -27
View File
@@ -1,46 +1,46 @@
using System.Text;
using UnityEditor; using UnityEditor;
using UnityEditor.SceneManagement; using UnityEditor.SceneManagement;
using UnityEngine; using UnityEngine;
using System.Net.Http; using UnityEngine.Networking;
using System.Text;
using System.Threading.Tasks;
[InitializeOnLoad] [InitializeOnLoad]
public class SceneNotifier public static class DiscordSceneNotifier
{ {
private static readonly string WebhookUrl = "http://n8n.homelab/webhook/unity-scene"; private const string WebhookUrl = "https://discord.com/api/webhooks/1486718530765328424/42mP_zYNTEwwBbc_lcuasPbpZppXoC4U14-Pde1YatdxatT5s9vml8lgQXTwAmm0PNe5";
private static readonly string UserName = System.Environment.UserName;
private static readonly HttpClient Http = new HttpClient(); static DiscordSceneNotifier()
static SceneNotifier()
{ {
EditorSceneManager.sceneOpened += OnSceneOpened; EditorSceneManager.sceneOpened += OnSceneOpened;
EditorSceneManager.sceneClosed += OnSceneClosed;
} }
private static void OnSceneOpened(UnityEngine.SceneManagement.Scene scene, OpenSceneMode mode) private static void OnSceneOpened(UnityEngine.SceneManagement.Scene scene, UnityEditor.SceneManagement.OpenSceneMode mode)
{ {
_ = SendNotification(scene.name, "opened"); string userName = System.Environment.UserName;
string message = $"{userName} opened scene: {scene.name}";
SendDiscordMessage(message);
} }
private static void OnSceneClosed(UnityEngine.SceneManagement.Scene scene) private static async void SendDiscordMessage(string content)
{ {
_ = SendNotification(scene.name, "closed"); string json = JsonUtility.ToJson(new DiscordMessage { content = content });
using var request = new UnityWebRequest(WebhookUrl, "POST");
byte[] bodyRaw = Encoding.UTF8.GetBytes(json);
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
request.downloadHandler = new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
await request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success)
Debug.LogWarning("Discord webhook failed: " + request.error);
} }
private static async Task SendNotification(string sceneName, string action) [System.Serializable]
private class DiscordMessage
{ {
string json = $"{{\"scene\":\"{sceneName}\",\"user\":\"{UserName}\",\"action\":\"{action}\"}}"; public string content;
try
{
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await Http.PostAsync(WebhookUrl, content);
Debug.Log($"[SceneNotifier] Sent: {json} — Status: {response.StatusCode}");
}
catch (System.Exception e)
{
Debug.LogWarning($"[SceneNotifier] Failed to notify: {e.Message}");
}
} }
} }