Here is a small preliminary draft for the later integration into the grid, but really only a PRELIMINARY DRAFT:
using LibreMetaverse; // spätere Referenz hinzufügen
using System.Net.Http;
using System.Text;
using System.Text.Json;
class DorenaBot {
static GridClient client = new GridClient();
static HttpClient http = new HttpClient();
static async Task AskDorena(string text) {
var payload = JsonSerializer.Serialize(new { user_input = text });
var resp = await http.PostAsync("
http://SERVER:5050/chat",
new StringContent(payload, Encoding.UTF8, "application/json"));
var json = await resp.Content.ReadAsStringAsync();
using var doc = JsonDocument.Parse(json);
return doc.RootElement.GetProperty("reply").GetString() ?? "(keine Antwort)";
}
static async Task Main() {
client.Settings.MULTIPLE_SIMS = false;
client.Network.Login("Vorname", "Nachname", "PASSWORT",
"DorenaBot", "you@example.com", "
http://ROBUST-LOGIN-URI", "home", "");
client.Self.ChatFromSimulator += async (s, e) => {
var msg = e.Message?.Trim() ?? "";
if (!msg.StartsWith("Dorena", StringComparison.OrdinalIgnoreCase)) return;
var q = msg.Substring("Dorena".Length).TrimStart(' ', ',', ':');
var a = await AskDorena(q);
client.Self.Chat(a, 0, ChatType.Normal);
};
// loop
while (client.Network.Connected) await Task.Delay(500);
}
}