From b40b2d5b481a9d05d2b2ac58b2af70650388daed Mon Sep 17 00:00:00 2001 From: Madpeter <57852827+Madpeterz@users.noreply.github.com> Date: Thu, 27 Jun 2024 11:42:20 +0100 Subject: [PATCH] fix issues with chat fetching --- SecondBotEvents/Commands/Chat.cs | 2 + SecondBotEvents/Commands/Group.cs | 9 +++ SecondBotEvents/Commands/Inventory.cs | 33 ++++++++ SecondBotEvents/Commands/Movement.cs | 2 +- SecondBotEvents/Services/BotClientService.cs | 2 +- SecondBotEvents/Services/DataStoreService.cs | 81 +++++++++++--------- 6 files changed, 90 insertions(+), 39 deletions(-) diff --git a/SecondBotEvents/Commands/Chat.cs b/SecondBotEvents/Commands/Chat.cs index b7d7956..67efb6f 100644 --- a/SecondBotEvents/Commands/Chat.cs +++ b/SecondBotEvents/Commands/Chat.cs @@ -37,6 +37,7 @@ namespace SecondBotEvents.Commands { return Failure("Invaild channel", new [] { channel, message }); } + master.DataStoreService.BotRecordLocalchatReply(message); GetClient().Self.Chat(message, channelnum, ChatType.Normal); return BasicReply("ok"); @@ -59,6 +60,7 @@ namespace SecondBotEvents.Commands { return Failure("Message empty", new [] { avatar, message }); } + master.DataStoreService.OpenChatWindow(false, avataruuid, avataruuid); master.BotClient.SendIM(avataruuid, message); return BasicReply("ok", new [] { avatar, message }); } diff --git a/SecondBotEvents/Commands/Group.cs b/SecondBotEvents/Commands/Group.cs index 3e456de..aa448d4 100644 --- a/SecondBotEvents/Commands/Group.cs +++ b/SecondBotEvents/Commands/Group.cs @@ -325,6 +325,14 @@ namespace SecondBotEvents.Commands return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.GetGroups())); } + [About("Forces the bot to reload the groups list")] + [ReturnHints("Working on it")] + public object ForceLoadGroups() + { + master.BotClient.client.Groups.RequestCurrentGroups(); + return BasicReply("Working on it"); + } + [About("Requests the roles for the selected group")] [ReturnHints("GroupRoleDetails object")] [ReturnHintsFailure("Group is not currently known")] @@ -419,6 +427,7 @@ namespace SecondBotEvents.Commands return Failure("Unknown group", new[] { group }); } GetClient().Self.InstantMessageGroup(groupUUID, message); + master.DataStoreService.BotRecordReplyIM(groupUUID, message); return BasicReply("Sending"); } } diff --git a/SecondBotEvents/Commands/Inventory.cs b/SecondBotEvents/Commands/Inventory.cs index ef01df6..7bde09b 100644 --- a/SecondBotEvents/Commands/Inventory.cs +++ b/SecondBotEvents/Commands/Inventory.cs @@ -1,4 +1,5 @@ using BetterSecondBot.Static; +using Discord; using LibreMetaverse; using OpenMetaverse; using OpenMetaverse.Assets; @@ -186,6 +187,38 @@ namespace SecondBotEvents.Commands return BasicReply("Ok", new [] { item }); } + + [About("Replaces the current avatar outfit with the contents of the given folder")] + [ReturnHints("ok")] + [ReturnHints("Named folder value is empty")] + [ReturnHints("Cant find target folder")] + [ReturnHints("invaild folder uuid")] + [ReturnHints("target folder is empty or so full I cant get it in 5 secs...")] + [ArgHints("folder", "UUID of the folder")] + public object SwapOutfit(string folder) + { + UUID folderUUID = UUID.Zero; + if(UUID.TryParse(folder, out folderUUID) == false) + { + return Failure("invaild folder uuid", new[] { folder }); + } + List contents = GetClient().Inventory.FolderContents(folderUUID, GetClient().Self.AgentID, true, true, InventorySortOrder.ByName, 5 * 1000); + List wareables = new(); + if (contents == null) + { + return Failure("target folder is empty or so full I cant get it in 5 secs...", new[] { folder }); + } + foreach (InventoryBase item in contents) + { + if ((item is InventoryWearable) || (item is InventoryObject)) + { + wareables.Add((InventoryItem)item); + } + } + master.CurrentOutfitFolder.ReplaceOutfit(wareables); + return BasicReply("ok", new[] { folder }); + } + [About("Replaces the current avatar outfit with the Clothing/[NAME] folder
Please note: This does not use the outfits folder!
Please do not use links in the folder!")] [ReturnHints("ok")] [ReturnHints("Named folder value is empty")] diff --git a/SecondBotEvents/Commands/Movement.cs b/SecondBotEvents/Commands/Movement.cs index 6692718..a17c379 100644 --- a/SecondBotEvents/Commands/Movement.cs +++ b/SecondBotEvents/Commands/Movement.cs @@ -67,7 +67,7 @@ namespace SecondBotEvents.Commands return BasicReply("ok", new [] { x, y, z }); } - [About("Attempt to teleport to a new region")] + [About("Stop the auto pilot system from walking")] [ReturnHints("ok")] public object AutoPilotStop() { diff --git a/SecondBotEvents/Services/BotClientService.cs b/SecondBotEvents/Services/BotClientService.cs index bd63ccd..c3c1c3b 100644 --- a/SecondBotEvents/Services/BotClientService.cs +++ b/SecondBotEvents/Services/BotClientService.cs @@ -93,7 +93,7 @@ namespace SecondBotEvents.Services } public void SendIM(UUID avatar, string message) { - // @todo add message to IM chat + master.DataStoreService.BotRecordReplyIM(avatar,message); client.Self.InstantMessage(avatar, message); } diff --git a/SecondBotEvents/Services/DataStoreService.cs b/SecondBotEvents/Services/DataStoreService.cs index dc45394..a44aaa9 100644 --- a/SecondBotEvents/Services/DataStoreService.cs +++ b/SecondBotEvents/Services/DataStoreService.cs @@ -7,6 +7,8 @@ using System.Collections; using System.Collections.Generic; using System.Threading; using SecondBotEvents.Commands; +using OpenMetaverse.ImportExport.Collada14; +using System.Threading.Tasks; namespace SecondBotEvents.Services { @@ -281,6 +283,7 @@ namespace SecondBotEvents.Services { return new List(); } + chatWindowsUnread[group] = false; return chatWindows[group]; } @@ -385,6 +388,23 @@ namespace SecondBotEvents.Services return groupMembers[Group]; } + public void BotRecordReplyIM(UUID sessionid,string message) + { + RecordChat(sessionid, "Bot", message); + } + public void BotRecordLocalchatReply(string message) + { + lock (localChatHistory) + { + localChatHistory.Add("{BOT} " + GetClient().Self.Name + ": " + message); + if (localChatHistory.Count <= myConfig.GetLocalChatHistoryLimit()) + { + return; + } + localChatHistory.RemoveAt(0); + } + } + protected void RecordChat(UUID sessionID, string fromname, string message) { lock (chatWindows) @@ -438,7 +458,7 @@ namespace SecondBotEvents.Services } - protected void OpenChatWindow(bool group, UUID sessionID, UUID ownerID) + public void OpenChatWindow(bool group, UUID sessionID, UUID ownerID) { lock (chatWindows) { @@ -492,15 +512,6 @@ namespace SecondBotEvents.Services return groupsKey2Name.ContainsValue(name); } - public List GetGroupChat(UUID groupId) - { - if(chatWindows.ContainsKey(groupId) == false) - { - return new List(); - } - return chatWindows[groupId]; - } - /* * checks if the avatar is known to the system * if not the bot will attempt to @@ -645,28 +656,6 @@ namespace SecondBotEvents.Services return avatarsName2Key[name].ToString(); } - public List GetAvatarIms(UUID avatarId) - { - if(chatWindowsOwner.ContainsValue(avatarId) == false) - { - return new List(); - } - UUID sessionID = UUID.Zero; - foreach(KeyValuePair links in chatWindowsOwner) - { - if(links.Value == avatarId) - { - sessionID = links.Key; - break; - } - } - if (sessionID == UUID.Zero) - { - return new List(); - } - return chatWindows[sessionID]; - } - public Dictionary GetAvatarImWindows() { Dictionary windows = new(); @@ -704,6 +693,7 @@ namespace SecondBotEvents.Services { return new List(); } + chatWindowsUnread[sessionID] = false; return chatWindows[sessionID]; } @@ -869,6 +859,19 @@ namespace SecondBotEvents.Services protected void BotLoggedIn(object o, SimConnectedEventArgs e) { GetClient().Network.SimConnected -= BotLoggedIn; + botConnected = true; + LogFormater.Info("DataStore Service [Attaching]"); + GetAvatarName(GetClient().Self.AgentID); + Task.Factory.StartNew(() => + { + Thread.Sleep(2000); + attachEventsAfterDelay(); + }); + + } + + protected void attachEventsAfterDelay() + { GetClient().Groups.CurrentGroups += GroupCurrent; GetClient().Groups.GroupJoinedReply += GroupJoin; GetClient().Groups.GroupLeaveReply += GroupLeave; @@ -881,9 +884,6 @@ namespace SecondBotEvents.Services GetClient().Groups.GroupRoleDataReply += GroupRoles; GetClient().Estate.EstateBansReply += EstateBans; GetClient().Groups.RequestCurrentGroups(); - botConnected = true; - LogFormater.Info("DataStore Service [Active]"); - GetAvatarName(GetClient().Self.AgentID); } readonly string[] hard_blocked_agents = new[] { "secondlife", "second life" }; protected void ChatFromSim(object o, ChatEventArgs e) @@ -898,7 +898,11 @@ namespace SecondBotEvents.Services { break; } - string source = "{Av}"; + if (e.SourceID == GetClient().Self.AgentID) + { + break; + } + string source = "{Av}"; if (e.SourceType == ChatSourceType.Object) { source = "{Obj}"; @@ -1035,7 +1039,10 @@ namespace SecondBotEvents.Services } AddAvatar(e.IM.FromAgentID, e.IM.FromAgentName); OpenChatWindow(false, e.IM.IMSessionID, e.IM.FromAgentID); - RecordChat(e.IM.IMSessionID, e.IM.FromAgentName, e.IM.Message); + if (e.IM.FromAgentID != GetClient().Self.AgentID) + { + RecordChat(e.IM.IMSessionID, e.IM.FromAgentName, e.IM.Message); + } break; } default: