Dashboard enhancements: LoadURL relay, nearby object scanning, and bug fixes

This commit is contained in:
RebeccaNod1 2026-05-11 16:29:44 -06:00
parent 4c9c85e907
commit ad2aab419f
4 changed files with 105 additions and 5 deletions

View file

@ -314,11 +314,11 @@ namespace SecondBotEvents.Commands
[CmdTypeDo()]
public object Key2Name(string uuid)
{
if (UUID.TryParse(uuid, out _) == false)
if (UUID.TryParse(uuid, out UUID parsedUUID) == false)
{
return Failure("Not a vaild UUID");
}
return BasicReply(master.DataStoreService.GetAvatarName(UUID.Zero));
return BasicReply(master.DataStoreService.GetAvatarName(parsedUUID));
}
[About("searchs the AV database if not found triggers a lookup")]

View file

@ -1,5 +1,7 @@
using OpenMetaverse;
using OpenMetaverse;
using SecondBotEvents.Services;
using System.Text.Json;
using System.Collections.Generic;
namespace SecondBotEvents.Commands
@ -84,5 +86,13 @@ namespace SecondBotEvents.Commands
return BasicReply(master.DialogService.DialogAction(dialogidnum, buttontext));
}
[About("Lists all active dialogs currently waiting for a response")]
[ReturnHints("A JSON array of active dialogs")]
[CmdTypeGet()]
public object GetDialogs()
{
var dialogs = master.DialogService.GetActiveDialogs();
return BasicReply(JsonSerializer.Serialize(dialogs, JsonOptions.UnsafeRelaxed));
}
}
}

View file

@ -200,6 +200,59 @@ namespace SecondBotEvents.Commands
if (rules == null) return BasicReply("[]");
return BasicReply(JsonSerializer.Serialize(rules, JsonOptions.UnsafeRelaxed));
}
[About("Lists objects near the bot (within 20m)")]
[ReturnHints("A JSON array of nearby objects")]
[CmdTypeGet()]
public object GetNearbyObjects()
{
if (GetClient().Network.CurrentSim == null) return Failure("Not in a sim");
Vector3 botPos = GetClient().Self.SimPosition;
uint sittingOn = GetClient().Self.SittingOn;
List<uint> localIDsToRequest = [];
// First pass: Find objects and collect localIDs for properties we don't have
foreach (var prim in GetClient().Network.CurrentSim.ObjectsPrimitives.Values)
{
if (prim.ParentID != 0) continue;
if (Vector3.Distance(botPos, prim.Position) <= 20.0f)
{
if (prim.Properties == null) localIDsToRequest.Add(prim.LocalID);
}
}
// If we have missing names, request them and wait a short moment
if (localIDsToRequest.Count > 0)
{
GetClient().Objects.SelectObjects(GetClient().Network.CurrentSim, localIDsToRequest.ToArray());
Thread.Sleep(500); // Wait for properties to arrive
}
List<object> reply = [];
foreach (var prim in GetClient().Network.CurrentSim.ObjectsPrimitives.Values)
{
if (prim.ParentID != 0) continue;
float dist = Vector3.Distance(botPos, prim.Position);
if (dist <= 20.0f)
{
string name = prim.Properties?.Name;
if (string.IsNullOrEmpty(name)) name = "Object #" + prim.LocalID;
reply.Add(new {
name = name,
uuid = prim.ID.ToString(),
local_id = prim.LocalID,
dist = Math.Round(dist, 1),
pos = prim.Position.ToString(),
is_sitting = (prim.LocalID == sittingOn)
});
}
}
return BasicReply(JsonSerializer.Serialize(reply, JsonOptions.UnsafeRelaxed));
}
}
public class SculptysInfo

View file

@ -1,4 +1,4 @@
using OpenMetaverse;
using OpenMetaverse;
using SecondBotEvents.Config;
using System;
using System.Collections.Generic;
@ -108,6 +108,28 @@ namespace SecondBotEvents.Services
}
}
public List<DialogWindow> GetActiveDialogs()
{
lock (DialogWindows)
{
CleanUp();
List<DialogWindow> reply = [];
foreach (var kvp in DialogWindows)
{
var e = kvp.Value;
reply.Add(new DialogWindow
{
buttons = [.. e.ButtonLabels],
dialogid = kvp.Key,
message = e.Message,
objectname = e.ObjectName,
expires = DialogWindowsExpire[kvp.Key]
});
}
return reply;
}
}
public string DialogAction(int dialogID, string button)
{
lock(DialogWindows)
@ -141,7 +163,7 @@ namespace SecondBotEvents.Services
List<int> removeids = [];
foreach(KeyValuePair<int,long> a in DialogWindowsExpire)
{
if(a.Value > unixtime)
if(a.Value < unixtime)
{
removeids.Add(a.Key);
}
@ -240,6 +262,7 @@ namespace SecondBotEvents.Services
if (GetClient() != null)
{
GetClient().Self.ScriptDialog -= DialogWindowEvent;
GetClient().Self.LoadURL -= LoadUrlEvent;
}
}
@ -249,6 +272,20 @@ namespace SecondBotEvents.Services
botConnected = true;
// attach events
GetClient().Self.ScriptDialog += DialogWindowEvent;
GetClient().Self.LoadURL += LoadUrlEvent;
}
protected void LoadUrlEvent(object sender, LoadUrlEventArgs e)
{
// We'll relay this as a special chat message so it shows up in the dashboard chat log
// In this version of LibOMV, the property is 'URL' (all caps).
string address = e.URL;
string message = " [SYSTEM] Object '" + e.ObjectName + "' sent a link: " + e.Message + " URL: " + address;
// Record it in the bot's local chat history so the dashboard picks it up on the next poll
master.DataStoreService.BotRecordLocalchatReply(message, "[SYSTEM] ");
LogFormater.Info("[LoadURL] " + e.ObjectName + " sent: " + e.Message + " (" + address + ")");
}
public override void Start(bool updateEnabled = false, bool setEnabledTo = false)