From bc5ca854898c4eecf0945b53fda6070553474501 Mon Sep 17 00:00:00 2001 From: Madpeter <57852827+Madpeterz@users.noreply.github.com> Date: Wed, 12 Feb 2025 20:25:52 +0000 Subject: [PATCH] cleanup and CommandHistoryLogResults --- Dockerfile | 1 + SecondBotEvents/Commands/Animation.cs | 16 +- SecondBotEvents/Commands/Avatars.cs | 61 +++--- SecondBotEvents/Commands/Chat.cs | 24 +-- SecondBotEvents/Commands/Core.cs | 5 +- SecondBotEvents/Commands/Dialogs.cs | 8 +- SecondBotEvents/Commands/Discord.cs | 33 ++-- SecondBotEvents/Commands/Estate.cs | 51 +++-- SecondBotEvents/Commands/Friends.cs | 52 +++-- SecondBotEvents/Commands/Funds.cs | 27 ++- SecondBotEvents/Commands/Group.cs | 106 +++++------ SecondBotEvents/Commands/Info.cs | 36 ++-- SecondBotEvents/Commands/Inventory.cs | 140 +++++++------- SecondBotEvents/Commands/Movement.cs | 67 +++---- SecondBotEvents/Commands/Notecard.cs | 50 +++-- SecondBotEvents/Commands/ParcelCommands.cs | 178 +++++++++--------- SecondBotEvents/Commands/Self.cs | 48 +++-- SecondBotEvents/Commands/Services.cs | 10 +- SecondBotEvents/Commands/StreamAdmin.cs | 23 +-- SecondBotEvents/Config/BasicConfig.cs | 3 +- SecondBotEvents/Config/ChatGptConfig.cs | 3 +- SecondBotEvents/Config/CommandsConfig.cs | 10 +- .../Config/CustomCommandsConfig.cs | 4 +- SecondBotEvents/Config/DataStoreConfig.cs | 4 +- SecondBotEvents/Config/DialogRelayConfig.cs | 3 +- SecondBotEvents/Config/DiscordConfig.cs | 3 +- SecondBotEvents/Config/EventsConfig.cs | 3 +- SecondBotEvents/Config/HomeboundConfig.cs | 3 +- SecondBotEvents/Config/HttpConfig.cs | 3 +- SecondBotEvents/Config/InteractionConfig.cs | 3 +- SecondBotEvents/Config/OnEventConfig.cs | 3 +- SecondBotEvents/Config/RelayConfig.cs | 12 +- SecondBotEvents/Config/RlvConfig.cs | 3 +- SecondBotEvents/Config/SmtpConfig.cs | 3 +- SecondBotEvents/Config/config.cs | 10 +- SecondBotEvents/EventsSecondBot.cs | 25 +-- SecondBotEvents/RLV/RLVEventArgs.cs | 9 +- SecondBotEvents/Services/BotClientService.cs | 12 +- SecondBotEvents/Services/ChatGptService.cs | 30 +-- SecondBotEvents/Services/CommandsService.cs | 66 ++++--- .../Services/CurrentOutfitFolder.cs | 23 +-- .../Services/CustomCommandsService.cs | 12 +- SecondBotEvents/Services/DataStoreService.cs | 151 +++++++-------- SecondBotEvents/Services/DialogService.cs | 26 +-- SecondBotEvents/Services/DiscordService.cs | 87 ++++----- SecondBotEvents/Services/EventsService.cs | 106 ++++++----- SecondBotEvents/Services/HomeboundService.cs | 2 +- SecondBotEvents/Services/HttpService.cs | 65 ++----- .../Services/InteractionService.cs | 34 ++-- SecondBotEvents/Services/RLVService.cs | 48 +++-- SecondBotEvents/Services/RecoveryService.cs | 8 +- SecondBotEvents/Services/RelayService.cs | 14 +- SecondBotEvents/Services/Services.cs | 8 +- SecondBotEvents/Services/SmtpService.cs | 2 +- .../Services/TriggerOnEventService.cs | 76 ++++---- SecondBotEvents/Static/Helpers.cs | 4 +- SecondBotEvents/Static/Inventory.cs | 40 ++-- SecondBotEvents/Static/LogFormater.cs | 4 +- .../Static/http_commands_helper.cs | 40 ++-- SecondBotEvents/Static/parcel.cs | 4 +- SecondBotEvents/WikiService.cs | 4 +- 61 files changed, 885 insertions(+), 1024 deletions(-) diff --git a/Dockerfile b/Dockerfile index 113d92d..8728342 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,6 +38,7 @@ ENV basic_Username='' \ commands_Enabled='true' \ commands_ObjectMasterOptout='false' \ commands_AllowServiceControl='false' \ + commands_CommandHistoryLogResults='false' \ datastore_AutoCleanAvatars='true' \ datastore_AvatarsCleanAfterMins=10 \ datastore_LocalChatHistoryLimit=120 \ diff --git a/SecondBotEvents/Commands/Animation.cs b/SecondBotEvents/Commands/Animation.cs index 4852f4f..9b2c0bb 100644 --- a/SecondBotEvents/Commands/Animation.cs +++ b/SecondBotEvents/Commands/Animation.cs @@ -7,14 +7,8 @@ using System.Linq; namespace SecondBotEvents.Commands { [ClassInfo("Animations and Gestures")] - internal class AnimationCommands : CommandsAPI + internal class AnimationCommands(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - - - public AnimationCommands(EventsSecondBot setmaster) : base(setmaster) - { - } - [About("Toggles if animation requests from this avatar (used for remote poseballs) are accepted")] [ReturnHints("Granted perm animation")] [ReturnHints("Removed perm animation")] @@ -25,7 +19,7 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return BasicReply("avatar lookup", new [] { avatar }); + return BasicReply("avatar lookup", [avatar]); } // @todo accept storage return Failure("@todo"); @@ -39,18 +33,18 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(gesture, out UUID gestureUUID) == false) { - return BasicReply("Error with gesture", new [] { gesture }); + return BasicReply("Error with gesture", [gesture]); } InventoryItem itm = GetClient().Inventory.FetchItem(gestureUUID, GetClient().Self.AgentID, TimeSpan.FromSeconds(15)); GetClient().Self.PlayGesture(itm.AssetUUID); - return BasicReply("Accepted", new [] { gesture }); + return BasicReply("Accepted", [gesture]); } [About("Resets the animation stack for the bot")] [ReturnHints("Accepted - X stopped animations")] public object ResetAnimations() { - List animations = GetClient().Self.SignaledAnimations.Copy().Keys.ToList(); + List animations = [.. GetClient().Self.SignaledAnimations.Copy().Keys]; foreach (UUID anim in animations) { GetClient().Self.AnimationStop(anim, true); diff --git a/SecondBotEvents/Commands/Avatars.cs b/SecondBotEvents/Commands/Avatars.cs index db9622a..1580add 100644 --- a/SecondBotEvents/Commands/Avatars.cs +++ b/SecondBotEvents/Commands/Avatars.cs @@ -8,13 +8,8 @@ using System.Threading.Tasks; namespace SecondBotEvents.Commands { [ClassInfo("Avatars near me and Key2Name and Name2Key lookups")] - public class Avatars : CommandsAPI + public class Avatars(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public Avatars(EventsSecondBot setmaster) : base(setmaster) - { - } - - [About("Adds avatars to the one time accept list for interactions")] [ReturnHints("ok")] [ReturnHintsFailure("Invaild avatar uuid")] @@ -28,7 +23,7 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("Invaild avatar uuid", new[] { store, avatar, remove }); + return Failure("Invaild avatar uuid", [store, avatar, remove]); } bool toberemoved = false; if((remove == "true") || (remove == "True")) @@ -37,13 +32,13 @@ namespace SecondBotEvents.Commands } if(master.DataStoreService.KnownStoreType(store) == false) { - return Failure("Unknown store type", new[] { store, avatar, remove }); + return Failure("Unknown store type", [store, avatar, remove]); } if (master.DataStoreService.AddToAcceptNext(store, avataruuid, toberemoved) == false) { - return Failure("Unable to process request store", new[] { store, avatar, remove }); + return Failure("Unable to process request store", [store, avatar, remove]); } - return BasicReply("ok", new[] { store, avatar, remove }); + return BasicReply("ok", [store, avatar, remove]); } [About("Checks if the avatar is on the accept next list (without using the token) for the given store")] [ReturnHints("true")] @@ -57,17 +52,17 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("Invaild avatar uuid", new[] { store, avatar }); + return Failure("Invaild avatar uuid", [store, avatar]); } if (master.DataStoreService.KnownStoreType(store) == false) { - return Failure("Unknown store type", new[] { store, avatar }); + return Failure("Unknown store type", [store, avatar]); } if(master.DataStoreService.IsInAcceptNext(store,avataruuid) == false) { - return BasicReply("false", new[] { store, avatar }); + return BasicReply("false", [store, avatar]); } - return BasicReply("true", new[] { store, avatar }); + return BasicReply("true", [store, avatar]); } @@ -80,19 +75,21 @@ namespace SecondBotEvents.Commands { return BasicReply("Error not in a sim"); } - List BetterNearMe = new List(); + List BetterNearMe = []; Dictionary avcopy = GetClient().Network.CurrentSim.ObjectsAvatars.Copy(); foreach (Avatar av in avcopy.Values) { if (av.ID != GetClient().Self.AgentID) { - NearMeDetails details = new NearMeDetails(); - details.id = av.ID.ToString(); - details.name = av.Name; - details.x = (int)Math.Round(av.Position.X); - details.y = (int)Math.Round(av.Position.Y); - details.z = (int)Math.Round(av.Position.Z); - details.range = (int)Math.Round(Vector3.Distance(av.Position, GetClient().Self.SimPosition)); + NearMeDetails details = new() + { + id = av.ID.ToString(), + name = av.Name, + x = (int)Math.Round(av.Position.X), + y = (int)Math.Round(av.Position.Y), + z = (int)Math.Round(av.Position.Z), + range = (int)Math.Round(Vector3.Distance(av.Position, GetClient().Self.SimPosition)) + }; BetterNearMe.Add(details); } } @@ -109,12 +106,12 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("Invaild avatar uuid", new[] { avatar }); + return Failure("Invaild avatar uuid", [avatar]); } KeyValuePair reply = master.DataStoreService.GetAvatarAvatarProperties(avataruuid); if(reply.Key == false) { - return Failure("Requesting avatar details [Retry later]", new[] { avatar }); + return Failure("Requesting avatar details [Retry later]", [avatar]); } return BasicReply(reply.Value.ProfileImage.ToString()); } @@ -128,12 +125,12 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(texture, out UUID textureUUID) == false) { - return Failure("Invaild texture uuid\"", new[] { texture }); + return Failure("Invaild texture uuid\"", [texture]); } KeyValuePair reply = master.DataStoreService.GetAvatarAvatarProperties(GetClient().Self.AgentID); if (reply.Key == false) { - return Failure("Requesting avatar details [Retry later]", new[] { texture }); + return Failure("Requesting avatar details [Retry later]", [texture]); } Avatar.AvatarProperties props = reply.Value; props.ProfileImage = textureUUID; @@ -151,12 +148,12 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("Invaild avatar uuid", new[] { avatar }); + return Failure("Invaild avatar uuid", [avatar]); } KeyValuePair reply = master.DataStoreService.GetAvatarAvatarProperties(avataruuid); if (reply.Key == false) { - return Failure("Requesting avatar details [Retry later]", new[] { avatar }); + return Failure("Requesting avatar details [Retry later]", [avatar]); } return BasicReply(reply.Value.AboutText.ToString()); } @@ -171,16 +168,16 @@ namespace SecondBotEvents.Commands { if(abouttext.Length < 10) { - return Failure("About text to short", new string[] { abouttext }); + return Failure("About text to short", [abouttext]); } else if (abouttext.Length > 300) { - return Failure("About text to long", new string[] { abouttext }); + return Failure("About text to long", [abouttext]); } KeyValuePair reply = master.DataStoreService.GetAvatarAvatarProperties(GetClient().Self.AgentID); if (reply.Key == false) { - return Failure("Requesting avatar details [Retry later]", new[] { abouttext }); + return Failure("Requesting avatar details [Retry later]", [abouttext]); } Avatar.AvatarProperties props = reply.Value; props.AboutText = abouttext; @@ -199,7 +196,7 @@ namespace SecondBotEvents.Commands { return BasicReply("Error not in a sim"); } - Dictionary NearMe = new Dictionary(); + Dictionary NearMe = []; Dictionary avcopy = GetClient().Network.CurrentSim.ObjectsAvatars.Copy(); foreach (Avatar av in avcopy.Values) { diff --git a/SecondBotEvents/Commands/Chat.cs b/SecondBotEvents/Commands/Chat.cs index 3baaa6b..a1e07c1 100644 --- a/SecondBotEvents/Commands/Chat.cs +++ b/SecondBotEvents/Commands/Chat.cs @@ -5,12 +5,8 @@ using SecondBotEvents.Services; namespace SecondBotEvents.Commands { [ClassInfo("Text based interaction,message status and history")] - public class Chat : CommandsAPI + public class Chat(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public Chat(EventsSecondBot setmaster) : base(setmaster) - { - } - [About("fetchs the last localchat messages")] [ReturnHints("json encoded array")] public object LocalChatHistory() @@ -27,11 +23,11 @@ namespace SecondBotEvents.Commands { if (SecondbotHelpers.isempty(message) == true) { - return Failure("Message empty", new [] { channel, message }); + return Failure("Message empty", [channel, message]); } if(int.TryParse(channel,out int channelnum) == false) { - return Failure("Invaild channel", new [] { channel, message }); + return Failure("Invaild channel", [channel, message]); } master.DataStoreService.BotRecordLocalchatReply(message); GetClient().Self.Chat(message, channelnum, ChatType.Normal); @@ -47,11 +43,11 @@ namespace SecondBotEvents.Commands { if (SecondbotHelpers.isempty(message) == true) { - return Failure("Message empty", new[] { channel, message }); + return Failure("Message empty", [channel, message]); } if (int.TryParse(channel, out int channelnum) == false) { - return Failure("Invaild channel", new[] { channel, message }); + return Failure("Invaild channel", [channel, message]); } master.DataStoreService.BotRecordLocalchatReply(message); GetClient().Self.Chat(message, channelnum, ChatType.Shout); @@ -67,11 +63,11 @@ namespace SecondBotEvents.Commands { if (SecondbotHelpers.isempty(message) == true) { - return Failure("Message empty", new[] { channel, message }); + return Failure("Message empty", [channel, message]); } if (int.TryParse(channel, out int channelnum) == false) { - return Failure("Invaild channel", new[] { channel, message }); + return Failure("Invaild channel", [channel, message]); } master.DataStoreService.BotRecordLocalchatReply(message); GetClient().Self.Chat(message, channelnum, ChatType.Whisper); @@ -91,15 +87,15 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if(avataruuid == UUID.Zero) { - return Failure("avatar lookup", new [] { avatar, message }); + return Failure("avatar lookup", [avatar, message]); } if (SecondbotHelpers.isempty(message) == true) { - return Failure("Message empty", new [] { avatar, message }); + return Failure("Message empty", [avatar, message]); } master.DataStoreService.OpenChatWindow(false, avataruuid, avataruuid); master.BotClient.SendIM(avataruuid, message); - return BasicReply("ok", new [] { avatar, message }); + return BasicReply("ok", [avatar, message]); } [About("gets a full list of all avatar chat windows")] diff --git a/SecondBotEvents/Commands/Core.cs b/SecondBotEvents/Commands/Core.cs index 24081c9..45889a5 100644 --- a/SecondBotEvents/Commands/Core.cs +++ b/SecondBotEvents/Commands/Core.cs @@ -3,11 +3,8 @@ namespace SecondBotEvents.Commands { [ClassInfo("Used to test interaction with the bot... hello world for avartars")] - public class Core : CommandsAPI + public class Core(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public Core(EventsSecondBot setmaster) : base(setmaster) - { - } [About("Used to check connections")] [ReturnHints("world")] public object Hello() diff --git a/SecondBotEvents/Commands/Dialogs.cs b/SecondBotEvents/Commands/Dialogs.cs index d62a663..e6d7f5e 100644 --- a/SecondBotEvents/Commands/Dialogs.cs +++ b/SecondBotEvents/Commands/Dialogs.cs @@ -5,12 +5,8 @@ using SecondBotEvents.Services; namespace SecondBotEvents.Commands { [ClassInfo("Script dialog box interaction / events when displayed")] - public class Dialogs : CommandsAPI + public class Dialogs(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public Dialogs(EventsSecondBot setmaster) : base(setmaster) - { - } - [About("adds a avatar dialog relay target [or removes if it exists]")] [ReturnHints("added")] [ReturnHints("removed")] @@ -79,7 +75,7 @@ namespace SecondBotEvents.Commands { if (int.TryParse(dialogid, out int dialogidnum) == false) { - return Failure("bad dialog id", new [] { dialogid, buttontext }); + return Failure("bad dialog id", [dialogid, buttontext]); } return BasicReply(master.DialogService.DialogAction(dialogidnum, buttontext)); } diff --git a/SecondBotEvents/Commands/Discord.cs b/SecondBotEvents/Commands/Discord.cs index 2a220a1..e4604bd 100644 --- a/SecondBotEvents/Commands/Discord.cs +++ b/SecondBotEvents/Commands/Discord.cs @@ -6,11 +6,8 @@ using System.Linq; namespace SecondBotEvents.Commands { [ClassInfo("Control discord from the grid")] - public class DiscordCommands : CommandsAPI + public class DiscordCommands(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public DiscordCommands(EventsSecondBot setmaster) : base(setmaster) - { - } [About("Adds a discord server role to the selected member")] [ReturnHintsFailure("Discord client not ready")] [ReturnHints("true|false")] @@ -23,7 +20,7 @@ namespace SecondBotEvents.Commands { return Failure("Discord client not ready"); } - return BasicReply(master.DiscordService.AddRoleToMember(serverid, roleid, memberid).Result.ToString(), new [] { serverid, roleid, memberid }); + return BasicReply(master.DiscordService.AddRoleToMember(serverid, roleid, memberid).Result.ToString(), [serverid, roleid, memberid]); } [About("Adds the selected user to the ban list - Disallows rejoining untill they are removed from the list")] @@ -41,9 +38,9 @@ namespace SecondBotEvents.Commands } if (SecondbotHelpers.notempty(why) == false) { - return Failure("Why empty", new [] { serverid, memberid, why }); + return Failure("Why empty", [serverid, memberid, why]); } - return BasicReply(master.DiscordService.BanMember(serverid, memberid, why).Result.ToString(), new [] { serverid, memberid, why }); + return BasicReply(master.DiscordService.BanMember(serverid, memberid, why).Result.ToString(), [serverid, memberid, why]); } public object Discord_GetMemberRoles(string serverid, string memberid) @@ -71,7 +68,7 @@ namespace SecondBotEvents.Commands { return Failure("Discord client not ready"); } - return BasicReply(master.DiscordService.ClearMessages(serverid, memberid).Result.ToString(), new[] { serverid, memberid }); + return BasicReply(master.DiscordService.ClearMessages(serverid, memberid).Result.ToString(), [serverid, memberid]); } [About("Sends a message directly to the user [They must be in the server]\n This command requires the SERVER MEMBERS INTENT found in discord app dev")] @@ -86,7 +83,7 @@ namespace SecondBotEvents.Commands { return Failure("Discord client not ready"); } - return BasicReply(master.DiscordService.MessageMember(serverid, memberid, message).Result.ToString(), new [] { serverid, memberid, message }); + return BasicReply(master.DiscordService.MessageMember(serverid, memberid, message).Result.ToString(), [serverid, memberid, message]); } [About("Returns a list of members in a server \n collection is userid: username \n if the user has set a nickname: userid: nickname|username \n" + @@ -101,7 +98,7 @@ namespace SecondBotEvents.Commands { return Failure("Discord client not ready"); } - return BasicReply(master.DiscordService.ListMembers(serverid).Result.ToString(), new[] { serverid }); + return BasicReply(master.DiscordService.ListMembers(serverid).Result.ToString(), [serverid]); } [About("Sends a message to the selected channel - Optional TTS usage")] @@ -120,9 +117,9 @@ namespace SecondBotEvents.Commands } if (SecondbotHelpers.notempty(message) == false) { - return Failure("message empty", new [] { serverid, channelid, tts, message }); + return Failure("message empty", [serverid, channelid, tts, message]); } - return BasicReply(master.DiscordService.MessageChannel(serverid, channelid, message, tts).Result.ToString(), new [] { serverid, channelid, tts, message }); + return BasicReply(master.DiscordService.MessageChannel(serverid, channelid, message, tts).Result.ToString(), [serverid, channelid, tts, message]); } [About("Sends a message to the selected channel - Optional TTS usage")] @@ -137,7 +134,7 @@ namespace SecondBotEvents.Commands { return Failure("Discord client not ready"); } - return BasicReply(master.DiscordService.MuteMember(serverid, memberid, mode).Result.ToString(), new [] { serverid, memberid, mode }); + return BasicReply(master.DiscordService.MuteMember(serverid, memberid, mode).Result.ToString(), [serverid, memberid, mode]); } [About("returns a collection of settings for the given role \n This command requires Discord full client mode enabled and connected")] @@ -152,7 +149,7 @@ namespace SecondBotEvents.Commands { return Failure("Discord client not ready"); } - return BasicReply(master.DiscordService.RoleSettings(serverid, roleid).ToString(), new [] { serverid, roleid }); + return BasicReply(master.DiscordService.RoleSettings(serverid, roleid).ToString(), [serverid, roleid]); } [About("Updates perm flags for the selected role \n example CSV format: Speak=True,SendMessages=False \n for a full list of perms see output of Discord_Role_GetSettings \n" + @@ -168,7 +165,7 @@ namespace SecondBotEvents.Commands { return Failure("Discord client not ready"); } - return BasicReply(master.DiscordService.UpdateRolePerms(serverid, roleid, flagscsv).Result.ToString(), new [] { serverid, roleid, flagscsv }); + return BasicReply(master.DiscordService.UpdateRolePerms(serverid, roleid, flagscsv).Result.ToString(), [serverid, roleid, flagscsv]); } [About("Updates perm flags for the selected role \n example CSV format: Speak=True,SendMessages=False \n for a full list of perms see output of Discord_Role_GetSettings \n" + @@ -183,7 +180,7 @@ namespace SecondBotEvents.Commands { return Failure("Discord client not ready"); } - return BasicReply(master.DiscordService.CreateRole(serverid, role).Result.ToString(), new[] { serverid, role }); + return BasicReply(master.DiscordService.CreateRole(serverid, role).Result.ToString(), [serverid, role]); } [About("Returns a list of roles and their ids in collection \n This command requires Discord full client mode enabled and connected")] @@ -196,7 +193,7 @@ namespace SecondBotEvents.Commands { return Failure("Discord client not ready"); } - return BasicReply(master.DiscordService.ListRoles(serverid).ToString(), new [] { serverid }); + return BasicReply(master.DiscordService.ListRoles(serverid).ToString(), [serverid]); } [About("Remove a role from a server \n This command requires Discord full client mode enabled and connected")] @@ -209,7 +206,7 @@ namespace SecondBotEvents.Commands { return Failure("Discord client not ready"); } - return BasicReply(master.DiscordService.RemoveRole(serverid, roleid).Result.ToString(), new [] { serverid, roleid }); + return BasicReply(master.DiscordService.RemoveRole(serverid, roleid).Result.ToString(), [serverid, roleid]); } [About("Returns a list of text channels in a server")] diff --git a/SecondBotEvents/Commands/Estate.cs b/SecondBotEvents/Commands/Estate.cs index 8644225..2a20c85 100644 --- a/SecondBotEvents/Commands/Estate.cs +++ b/SecondBotEvents/Commands/Estate.cs @@ -6,11 +6,8 @@ using System.Collections.Generic; namespace SecondBotEvents.Commands { [ClassInfo("Look after a sim as the estate manager")] - public class Estate : CommandsAPI + public class Estate(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public Estate(EventsSecondBot setmaster) : base(setmaster) - { - } [About("Sends the message to the current sim")] [ReturnHints("restarting")] [ReturnHintsFailure("Not an estate manager here")] @@ -22,22 +19,21 @@ namespace SecondBotEvents.Commands { if (GetClient().Network.CurrentSim.IsEstateManager == false) { - return Failure("Not an estate manager here", new [] { delay, mode }); + return Failure("Not an estate manager here", [delay, mode]); } bool.TryParse(mode, out bool modeflag); if (modeflag == false) { GetClient().Estate.CancelRestart(); - return BasicReply("canceled", new [] { delay, mode }); + return BasicReply("canceled", [delay, mode]); } - int delay_restart = 60; - int.TryParse(delay, out delay_restart); - if((delay_restart < 30) || (delay_restart > 240)) + int.TryParse(delay, out int delay_restart); + if ((delay_restart < 30) || (delay_restart > 240)) { delay_restart = 240; } GetClient().Estate.RestartRegion(delay_restart); - return BasicReply("restarting", new [] { delay, mode }); + return BasicReply("restarting", [delay, mode]); } [About("Sends the message to the current sim")] @@ -49,14 +45,14 @@ namespace SecondBotEvents.Commands { if (SecondbotHelpers.notempty(message) == false) { - return Failure("Message empty", new [] { message }); + return Failure("Message empty", [message]); } if (GetClient().Network.CurrentSim.IsEstateManager == false) { - return Failure("Not an estate manager here", new [] { message }); + return Failure("Not an estate manager here", [message]); } GetClient().Estate.SimulatorMessage(message); - return BasicReply("ok", new [] { message }); + return BasicReply("ok", [message]); } [About("Fetchs the regions map tile")] @@ -67,9 +63,9 @@ namespace SecondBotEvents.Commands { if (GetClient().Grid.GetGridRegion(regionname, GridLayerType.Objects, out GridRegion region) == false) { - return Failure("Unable to find region", new [] { regionname }); + return Failure("Unable to find region", [regionname]); } - return BasicReply(region.MapImageID.ToString(), new [] { regionname }); + return BasicReply(region.MapImageID.ToString(), [regionname]); } [About("Reclaims ownership of the current parcel")] @@ -94,12 +90,14 @@ namespace SecondBotEvents.Commands { if (GetClient().Grid.GetGridRegion(regionname, GridLayerType.Objects, out GridRegion region) == false) { - return Failure("Unable to find region", new [] { regionname }); + return Failure("Unable to find region", [regionname]); } - Dictionary reply = new Dictionary(); - reply.Add("region", regionname); - reply.Add("X", region.X.ToString()); - reply.Add("Y", region.Y.ToString()); + Dictionary reply = new() + { + { "region", regionname }, + { "X", region.X.ToString() }, + { "Y", region.Y.ToString() } + }; return BasicReply(JsonConvert.SerializeObject(reply)); } @@ -124,25 +122,24 @@ namespace SecondBotEvents.Commands { if (GetClient().Network.CurrentSim.IsEstateManager == false) { - return Failure("Not an estate manager on region " + GetClient().Network.CurrentSim.Name, new [] { avatar, mode, global }); + return Failure("Not an estate manager on region " + GetClient().Network.CurrentSim.Name, [avatar, mode, global]); } UUID avataruuid = UUID.Zero; if (UUID.TryParse(avatar, out avataruuid) == false) { - return Failure("Unable to find avatar UUID", new [] { avatar, mode, global }); + return Failure("Unable to find avatar UUID", [avatar, mode, global]); } - bool globalban = false; - if (bool.TryParse(global, out globalban) == false) + if (bool.TryParse(global, out bool globalban) == false) { - return Failure("Unable to process global value please use true or false", new [] { avatar, mode, global }); + return Failure("Unable to process global value please use true or false", [avatar, mode, global]); } if (mode != "add") { GetClient().Estate.UnbanUser(avataruuid, globalban); - return BasicReply("Unban request accepted", new [] { avatar, mode, global }); + return BasicReply("Unban request accepted", [avatar, mode, global]); } GetClient().Estate.BanUser(avataruuid, globalban); - return BasicReply("Ban request accepted", new [] { avatar, mode, global }); + return BasicReply("Ban request accepted", [avatar, mode, global]); } } } diff --git a/SecondBotEvents/Commands/Friends.cs b/SecondBotEvents/Commands/Friends.cs index bf62560..6e0c139 100644 --- a/SecondBotEvents/Commands/Friends.cs +++ b/SecondBotEvents/Commands/Friends.cs @@ -6,12 +6,8 @@ using System.Collections.Generic; namespace SecondBotEvents.Commands { [ClassInfo("The power of friendship")] - public class Friends : CommandsAPI + public class Friends(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public Friends(EventsSecondBot setmaster) : base(setmaster) - { - } - [About("Gets the location of a friend if map access was given \n also requests a update")] [ReturnHints("a json object of global region X,Y sim X,Y,Z and time it was updated")] [ReturnHintsFailure("avatar lookup")] @@ -23,20 +19,20 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("avatar lookup", new[] { avatar }); + return Failure("avatar lookup", [avatar]); } Dictionary FriendListCopy = GetClient().Friends.FriendList.Copy(); if(FriendListCopy.ContainsKey(avataruuid) == false) { - return Failure("not in friends list (updating)", new[] { avatar }); + return Failure("not in friends list (updating)", [avatar]); } GetClient().Friends.MapFriend(avataruuid); FriendLocations loc = master.DataStoreService.GetFriendMap(avataruuid); if(loc == null) { - return Failure("no map access or updating", new[] { avatar }); + return Failure("no map access or updating", [avatar]); } - return BasicReply(JsonConvert.SerializeObject(loc), new[] { avatar }); + return BasicReply(JsonConvert.SerializeObject(loc), [avatar]); } [About("Gets the friendslist")] @@ -44,14 +40,16 @@ namespace SecondBotEvents.Commands public object Friendslist() { Dictionary FriendListCopy = GetClient().Friends.FriendList.Copy(); - List< FriendListEntry > CleanedFriendsList = new List< FriendListEntry >(); + List< FriendListEntry > CleanedFriendsList = []; int index = 0; foreach (FriendInfo A in FriendListCopy.Values) { - FriendListEntry entry = new FriendListEntry(); - entry.id = A.UUID.ToString(); - entry.name = A.Name; - entry.online = A.IsOnline; + FriendListEntry entry = new() + { + id = A.UUID.ToString(), + name = A.Name, + online = A.IsOnline + }; CleanedFriendsList.Add(entry); index++; } @@ -71,24 +69,23 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("avatar lookup", new [] { avatar, state }); + return Failure("avatar lookup", [avatar, state]); } - bool status = false; - if (bool.TryParse(state, out status) == false) + if (bool.TryParse(state, out bool status) == false) { - return Failure("state invaild", new [] { avatar, state }); + return Failure("state invaild", [avatar, state]); } if (GetClient().Friends.FriendList.ContainsKey(avataruuid) == false) { - return Failure("Not A friend", new [] { avatar, state }); + return Failure("Not A friend", [avatar, state]); } if (status == true) { GetClient().Friends.GrantRights(avataruuid, FriendRights.CanSeeOnline | FriendRights.CanSeeOnMap | FriendRights.CanModifyObjects); - return BasicReply("granted", new [] { avatar, state }); + return BasicReply("granted", [avatar, state]); } GetClient().Friends.GrantRights(avataruuid, FriendRights.None); - return BasicReply("removed", new [] { avatar, state }); + return BasicReply("removed", [avatar, state]); } [About("Updates the friend perms for avatar avatar to State \n if true grants (Online/Map/Modify) perms")] @@ -105,27 +102,26 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("avatar lookup", new [] { avatar, state }); + return Failure("avatar lookup", [avatar, state]); } - bool status = false; - if (bool.TryParse(state, out status) == false) + if (bool.TryParse(state, out bool status) == false) { - return Failure("state invaild", new [] { avatar, state }); + return Failure("state invaild", [avatar, state]); } if (GetClient().Friends.FriendList.ContainsKey(avataruuid) == true) { if (status == false) { GetClient().Friends.TerminateFriendship(avataruuid); - return BasicReply("Removed", new [] { avatar, state }); + return BasicReply("Removed", [avatar, state]); } } if (status == false) { - return Failure("Not in friendslist", new [] { avatar, state }); + return Failure("Not in friendslist", [avatar, state]); } GetClient().Friends.OfferFriendship(avataruuid); - return BasicReply("Request sent", new [] { avatar, state }); + return BasicReply("Request sent", [avatar, state]); } } diff --git a/SecondBotEvents/Commands/Funds.cs b/SecondBotEvents/Commands/Funds.cs index db57bab..400d399 100644 --- a/SecondBotEvents/Commands/Funds.cs +++ b/SecondBotEvents/Commands/Funds.cs @@ -5,11 +5,8 @@ using SecondBotEvents.Services; namespace SecondBotEvents.Commands { [ClassInfo("Money makes the world go round")] - public class Funds : CommandsAPI + public class Funds(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public Funds(EventsSecondBot setmaster) : base(setmaster) - { - } [About("Requests the current balance and requests the balance to update.")] [ReturnHints("Current fund level")] [ReturnHintsFailure("Funds commands are disabled")] @@ -35,24 +32,24 @@ namespace SecondBotEvents.Commands { if (master.CommandsService.myConfig.GetAllowFundsCommands() == false) { - return Failure("Transfer funds to avatars disabled", new [] { avatar, amount }); + return Failure("Transfer funds to avatars disabled", [avatar, amount]); } ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return BasicReply("avatar lookup", new [] { avatar, amount }); + return BasicReply("avatar lookup", [avatar, amount]); } if (int.TryParse(amount, out int amountvalue) == false) { - return Failure("Invaild amount", new [] { avatar, amount }); + return Failure("Invaild amount", [avatar, amount]); } if ((amountvalue < 0) || (amountvalue > GetClient().Self.Balance)) { GetClient().Self.RequestBalance(); - return Failure("Amount out of range current max: "+ GetClient().Self.Balance.ToString(), new [] { avatar, amount }); + return Failure("Amount out of range current max: "+ GetClient().Self.Balance.ToString(), [avatar, amount]); } GetClient().Self.GiveAvatarMoney(avataruuid, amountvalue); - return BasicReply("Accepted", new [] { avatar, amount }); + return BasicReply("Accepted", [avatar, amount]); } [About("Makes the bot pay a object")] @@ -69,26 +66,26 @@ namespace SecondBotEvents.Commands { if (master.CommandsService.myConfig.GetAllowFundsCommands() == false) { - return Failure("Funds commands are disabled", new [] { objectuuid, primname, amount }); + return Failure("Funds commands are disabled", [objectuuid, primname, amount]); } if (UUID.TryParse(objectuuid, out UUID objectUUID) == false) { - return Failure("Invaild object UUID", new [] { objectuuid, primname, amount }); + return Failure("Invaild object UUID", [objectuuid, primname, amount]); } if (int.TryParse(amount, out int amountvalue) == false) { - return Failure("Invaild amount", new [] { objectuuid, primname, amount }); + return Failure("Invaild amount", [objectuuid, primname, amount]); } if((amountvalue < 0) || (amountvalue > GetClient().Self.Balance)) { - return Failure("Amount out of range", new [] { objectuuid, primname, amount }); + return Failure("Amount out of range", [objectuuid, primname, amount]); } if(SecondbotHelpers.notempty(primname) == false) { - return Failure("Primname is empty", new [] { objectuuid, primname, amount }); + return Failure("Primname is empty", [objectuuid, primname, amount]); } GetClient().Self.GiveObjectMoney(objectUUID, amountvalue, primname); - return BasicReply("ok", new [] { objectuuid, primname, amount }); + return BasicReply("ok", [objectuuid, primname, amount]); } } } diff --git a/SecondBotEvents/Commands/Group.cs b/SecondBotEvents/Commands/Group.cs index d0a7b42..e2451f8 100644 --- a/SecondBotEvents/Commands/Group.cs +++ b/SecondBotEvents/Commands/Group.cs @@ -6,12 +6,8 @@ using System.Collections.Generic; namespace SecondBotEvents.Commands { [ClassInfo("Control groups with ease")] - public class GroupCommands : CommandsAPI + public class GroupCommands(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public GroupCommands(EventsSecondBot setmaster) : base(setmaster) - { - } - [About("Checks if the given UUID is in the given group
Note: if group membership data is more than 60 secs old this will return Updating
Please wait and retry later")] [ReturnHints("Membership reply with [membershipStatus,AvatarUUID,AvatarnameIfKnown,GroupUUID]")] [ReturnHintsFailure("Updating")] @@ -24,7 +20,7 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(group, out UUID groupuuid) == false) { - return Failure("Invaild group UUID", new [] { group, avatar }); + return Failure("Invaild group UUID", [group, avatar]); } ProcessAvatar(avatar); return BasicReply(master.DataStoreService.IsGroupMember(groupuuid, avataruuid).ToString()); @@ -41,7 +37,7 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(group, out UUID groupuuid) == false) { - return Failure("Invaild group UUID", new [] { group }); + return Failure("Invaild group UUID", [group]); } return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.GetGroupMembers(groupuuid))); } @@ -60,27 +56,27 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(group, out UUID groupuuid) == false) { - return Failure("Invaild group UUID", new[] { group, avatar, state }); + return Failure("Invaild group UUID", [group, avatar, state]); } if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false) { - return Failure("Unknown group", new[] { group, avatar, state }); + return Failure("Unknown group", [group, avatar, state]); } ProcessAvatar(avatar); if(avataruuid == UUID.Zero) { - return Failure("Unknown avatar", new[] { group, avatar, state }); + return Failure("Unknown avatar", [group, avatar, state]); } GroupBanAction Action = GroupBanAction.Ban; if (state == "false") { Action = GroupBanAction.Unban; } - List avatarstoaction = new() - { + List avatarstoaction = + [ avataruuid - }; - GetClient().Groups.RequestBanAction(groupuuid, Action, avatarstoaction.ToArray()); + ]; + GetClient().Groups.RequestBanAction(groupuuid, Action, [.. avatarstoaction]); return BasicReply("Accepted"); } @@ -100,16 +96,16 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(group, out UUID groupuuid) == false) { - return Failure("Invaild group UUID", new [] { group, avatar }); + return Failure("Invaild group UUID", [group, avatar]); } if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false) { - return Failure("Unknown group", new[] { group, avatar }); + return Failure("Unknown group", [group, avatar]); } ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("Unknown avatar", new[] { group, avatar}); + return Failure("Unknown avatar", [group, avatar]); } GetClient().Groups.EjectUser(groupuuid, avataruuid); return BasicReply("Accepted"); @@ -129,20 +125,20 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(group, out UUID groupuuid) == false) { - return Failure("Invaild group UUID", new [] { group, avatar }); + return Failure("Invaild group UUID", [group, avatar]); } if (UUID.TryParse(role, out UUID roleuuid) == false) { - return Failure("Invaild role UUID", new [] { group, avatar }); + return Failure("Invaild role UUID", [group, avatar]); } if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false) { - return Failure("Unknown group", new[] { group, avatar, role }); + return Failure("Unknown group", [group, avatar, role]); } ProcessAvatar(avatar); if(master.DataStoreService.IsGroupMember(groupuuid, avataruuid) == false) { - GetClient().Groups.Invite(groupuuid, new List() { UUID.Zero, roleuuid }, avataruuid); + GetClient().Groups.Invite(groupuuid, [UUID.Zero, roleuuid], avataruuid); return BasicReply("Invite sent"); } GetClient().Groups.AddToRole(groupuuid, roleuuid, avataruuid); @@ -164,31 +160,31 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(group, out UUID groupuuid) == false) { - return Failure("Invaild group UUID", new [] { group, avatar, role }); + return Failure("Invaild group UUID", [group, avatar, role]); } if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false) { - return Failure("Unknown group", new[] { group, avatar, role }); + return Failure("Unknown group", [group, avatar, role]); } ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("avatar lookup", new [] { group, avatar, role }); + return Failure("avatar lookup", [group, avatar, role]); } - List roles = new() - { + List roles = + [ UUID.Zero - }; + ]; if (role != "everyone") { if (UUID.TryParse(role, out UUID roleuuid) == false) { - return Failure("Unable to process role UUID", new[] { group, avatar, role }); + return Failure("Unable to process role UUID", [group, avatar, role]); } roles.Add(roleuuid); } GetClient().Groups.Invite(groupuuid, roles, avataruuid); - return BasicReply("Invite sent", new [] { group, avatar, role }); + return BasicReply("Invite sent", [group, avatar, role]); } [About("Sends a group notice (No attachments please use GroupnoticeWithAttachment to attach items!)")] @@ -205,19 +201,19 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(group, out UUID groupuuid) == false) { - return Failure("Invaild group UUID", new [] { group, title, message }); + return Failure("Invaild group UUID", [group, title, message]); } if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false) { - return Failure("Unknown group", new [] { group, title, message }); + return Failure("Unknown group", [group, title, message]); } if (SecondbotHelpers.notempty(title) == false) { - return Failure("Title empty", new [] { group, title, message }); + return Failure("Title empty", [group, title, message]); } if (SecondbotHelpers.notempty(message) == false) { - return Failure("Message empty", new [] { group, title, message }); + return Failure("Message empty", [group, title, message]); } GroupNotice NewNotice = new() { @@ -226,7 +222,7 @@ namespace SecondBotEvents.Commands OwnerID = GetClient().Self.AgentID }; GetClient().Groups.SendGroupNotice(groupuuid, NewNotice); - return BasicReply("Sending notice", new [] { group, title, message }); + return BasicReply("Sending notice", [group, title, message]); } [About("Activates the selected title")] @@ -240,18 +236,18 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(group, out UUID groupuuid) == false) { - return Failure("Invaild group UUID", new [] { group, role }); + return Failure("Invaild group UUID", [group, role]); } if (UUID.TryParse(role, out UUID roleuuid) == false) { - return Failure("Invaild role UUID", new [] { group, role }); + return Failure("Invaild role UUID", [group, role]); } if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false) { - return Failure("Unknown group", new [] { group, role }); + return Failure("Unknown group", [group, role]); } GetClient().Groups.ActivateTitle(groupuuid, roleuuid); - return BasicReply("Switching title", new [] { group, role }); + return BasicReply("Switching title", [group, role]); } [About("Sets the selected group to the active group")] @@ -263,14 +259,14 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(group, out UUID groupuuid) == false) { - return Failure("Invaild group UUID", new [] { group }); + return Failure("Invaild group UUID", [group]); } if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false) { - return Failure("Unknown group", new[] { group }); + return Failure("Unknown group", [group]); } GetClient().Groups.ActivateGroup(groupuuid); - return BasicReply("Switching active group", new [] { group }); + return BasicReply("Switching active group", [group]); } [About("Sends a group notice with an attachment")] @@ -289,23 +285,23 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(group, out UUID groupuuid) == false) { - return Failure("Invaild group UUID", new [] { group, title, message, attachment }); + return Failure("Invaild group UUID", [group, title, message, attachment]); } if (UUID.TryParse(attachment, out UUID inventoryuuid) == false) { - return Failure("Invaild inventory UUID", new [] { group, title, message, attachment }); + return Failure("Invaild inventory UUID", [group, title, message, attachment]); } if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false) { - return Failure("Unknown group", new [] { group, title, message, attachment }); + return Failure("Unknown group", [group, title, message, attachment]); } if (SecondbotHelpers.notempty(title) == false) { - return Failure("Title empty", new [] { group, title, message, attachment }); + return Failure("Title empty", [group, title, message, attachment]); } if (SecondbotHelpers.notempty(message) == false) { - return Failure("Message empty", new [] { group, title, message, attachment }); + return Failure("Message empty", [group, title, message, attachment]); } GroupNotice NewNotice = new() { @@ -315,7 +311,7 @@ namespace SecondBotEvents.Commands AttachmentID = inventoryuuid }; GetClient().Groups.SendGroupNotice(groupuuid, NewNotice); - return BasicReply("Sending notice with attachment", new [] { group, title, message, attachment }); + return BasicReply("Sending notice with attachment", [group, title, message, attachment]); } @@ -344,11 +340,11 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(group, out UUID groupuuid) == false) { - return Failure("Invaild group UUID", new [] { group }); + return Failure("Invaild group UUID", [group]); } if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false) { - return Failure("Unknown group", new [] { group }); + return Failure("Unknown group", [group]); } return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.GetGroupRoles(groupuuid))); } @@ -369,11 +365,11 @@ namespace SecondBotEvents.Commands { if(UUID.TryParse(group,out UUID groupUUID) == false) { - return Failure("group value is invaild", new [] { group }); + return Failure("group value is invaild", [group]); } if(GetClient().Groups.GroupName2KeyCache.ContainsKey(groupUUID) == false) { - return Failure("Unknown group", new [] { group }); + return Failure("Unknown group", [group]); } return BasicReply(master.DataStoreService.GetGroupChatHasUnread(groupUUID).ToString()); } @@ -402,7 +398,7 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(group, out UUID groupUUID) == false) { - return Failure("Group UUID invaild", new [] { group }); + return Failure("Group UUID invaild", [group]); } return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.GetGroupChatHistory(groupUUID))); } @@ -417,15 +413,15 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(group, out UUID groupUUID) == false) { - return Failure("group value is invaild", new [] { group, message }); + return Failure("group value is invaild", [group, message]); } if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupUUID) == false) { - return Failure("Unknown group", new [] { group, message }); + return Failure("Unknown group", [group, message]); } if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupUUID) == false) { - return Failure("Unknown group", new[] { group }); + return Failure("Unknown group", [group]); } GetClient().Self.InstantMessageGroup(groupUUID, message); master.DataStoreService.BotRecordReplyIM(groupUUID, message); diff --git a/SecondBotEvents/Commands/Info.cs b/SecondBotEvents/Commands/Info.cs index 497d262..a34388d 100644 --- a/SecondBotEvents/Commands/Info.cs +++ b/SecondBotEvents/Commands/Info.cs @@ -7,20 +7,16 @@ using System.Collections.Generic; namespace SecondBotEvents.Commands { [ClassInfo("What is going on with the bot")] - public class Info : CommandsAPI + public class Info(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public Info(EventsSecondBot setmaster) : base(setmaster) - { - } - [About("Lists objects that are sculpty type in the current sim that the bot can see")] [ReturnHints("A json object")] public object ListSculptys() { Dictionary objects_copy = GetClient().Network.CurrentSim.ObjectsPrimitives.Copy(); - Dictionary mapLocalID = new Dictionary(); - Dictionary sculpts = new Dictionary(); + Dictionary mapLocalID = []; + Dictionary sculpts = []; foreach (KeyValuePair Obj in objects_copy) { mapLocalID.Add(Obj.Value.LocalID, Obj.Key); @@ -29,7 +25,7 @@ namespace SecondBotEvents.Commands sculpts.Add(Obj.Key, Obj.Value); } } - List reply = new List(); + List reply = []; foreach (KeyValuePair Obj in sculpts) { Vector3 pos = Obj.Value.Position; @@ -56,12 +52,14 @@ namespace SecondBotEvents.Commands key = wip.ID; } } - SculptysInfo A = new SculptysInfo(); - A.isLinked = asLink.ToString(); - A.name = name.ToString(); - A.owner = owner.ToString(); - A.uuid = key.ToString(); - A.pos = pos.ToString(); + SculptysInfo A = new() + { + isLinked = asLink.ToString(), + name = name.ToString(), + owner = owner.ToString(), + uuid = key.ToString(), + pos = pos.ToString() + }; reply.Add(A); } if (reply.Count == 0) @@ -132,10 +130,12 @@ namespace SecondBotEvents.Commands { return Failure("Error not in a sim"); } - Dictionary pos = new Dictionary(); - pos.Add("x", (int)Math.Round(GetClient().Self.SimPosition.X)); - pos.Add("y", (int)Math.Round(GetClient().Self.SimPosition.Y)); - pos.Add("z", (int)Math.Round(GetClient().Self.SimPosition.Z)); + Dictionary pos = new() + { + { "x", (int)Math.Round(GetClient().Self.SimPosition.X) }, + { "y", (int)Math.Round(GetClient().Self.SimPosition.Y) }, + { "z", (int)Math.Round(GetClient().Self.SimPosition.Z) } + }; return BasicReply(JsonConvert.SerializeObject(pos)); } } diff --git a/SecondBotEvents/Commands/Inventory.cs b/SecondBotEvents/Commands/Inventory.cs index 289b132..bba612c 100644 --- a/SecondBotEvents/Commands/Inventory.cs +++ b/SecondBotEvents/Commands/Inventory.cs @@ -12,12 +12,8 @@ using System.Linq; namespace SecondBotEvents.Commands { [ClassInfo("Inventory controls for sending items and so on")] - public class InventoryCommands : CommandsAPI + public class InventoryCommands(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public InventoryCommands(EventsSecondBot setmaster) : base(setmaster) - { - } - [About("Attachs an event for inventory changes")] [ReturnHints("cleared")] [ReturnHints("No action")] @@ -72,15 +68,15 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(item, out UUID targetitem) == false) { - return Failure("Invaild item UUID: "+ item, new [] { item }); + return Failure("Invaild item UUID: "+ item, [item]); } InventoryItem itm = GetClient().Inventory.FetchItem(targetitem, GetClient().Self.AgentID, TimeSpan.FromSeconds(15)); if (itm == null) { - return Failure("Unable to find item: " + item, new [] { item }); + return Failure("Unable to find item: " + item, [item]); } UUID rezedobject = GetClient().Inventory.RequestRezFromInventory(GetClient().Network.CurrentSim, GetClient().Self.SimRotation, GetClient().Self.RelativePosition, itm); - return BasicReply(rezedobject.ToString(), new [] { item }); + return BasicReply(rezedobject.ToString(), [item]); } @@ -95,20 +91,20 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(item, out UUID target) == false) { - return Failure("invaild item uuid", new [] { item, newname }); + return Failure("invaild item uuid", [item, newname]); } if (newname.Length < 3) { - return Failure("Item name is to short", new [] { item, newname }); + return Failure("Item name is to short", [item, newname]); } InventoryItem realitem = HelperInventory.getItemByInventoryUUID(GetClient(), target); if (realitem == null) { - return Failure("Unable to find inventory item", new [] { item, newname }); + return Failure("Unable to find inventory item", [item, newname]); } realitem.Name = newname; GetClient().Inventory.RequestUpdateItem(realitem); - return BasicReply("Ok", new [] { item, newname }); + return BasicReply("Ok", [item, newname]); } [About("Attempts to Remove the given inventory item")] @@ -119,10 +115,10 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(item, out UUID target) == false) { - return Failure("invaild item uuid", new [] { item }); + return Failure("invaild item uuid", [item]); } - GetClient().Inventory.Remove(new List() { target }, new List()); - return BasicReply("Ok", new [] { item }); + GetClient().Inventory.Remove([target], []); + return BasicReply("Ok", [item]); } [About("Attempts to Remove the given inventory folder")] @@ -133,10 +129,10 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(folder, out UUID target) == false) { - return Failure("invaild folder uuid", new [] { folder }); + return Failure("invaild folder uuid", [folder]); } - GetClient().Inventory.Remove(new List(), new List() { target }); - return BasicReply("Ok", new [] { folder }); + GetClient().Inventory.Remove([], [target]); + return BasicReply("Ok", [folder]); } [About("Attempts to attach the given inventory item")] @@ -147,11 +143,11 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(item,out UUID itemuuid) == false) { - return Failure("invaild item uuid", new [] { item }); + return Failure("invaild item uuid", [item]); } InventoryItem realitem = HelperInventory.getItemByInventoryUUID(GetClient(), itemuuid); - GetClient().Appearance.AddAttachments(new List() { realitem }, false, false); - return BasicReply("Ok", new [] { item }); + GetClient().Appearance.AddAttachments([realitem], false, false); + return BasicReply("Ok", [item]); } [About("Attempts to Detach the given inventory item (or attachment point)")] @@ -163,7 +159,7 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(item, out UUID itemuuid) == false) { - List toBeRemoved = new List(); + List toBeRemoved = []; foreach (KeyValuePair pair in GetClient().Appearance.GetAttachmentsByItemId()) { if((pair.Value.ToString() != item) || (item == "*")) @@ -174,18 +170,18 @@ namespace SecondBotEvents.Commands } if(toBeRemoved.Count == 0) { - return Failure("invaild item uuid pr invaild attach point", new[] { item }); + return Failure("invaild item uuid pr invaild attach point", [item]); } foreach(InventoryItem A in toBeRemoved) { GetClient().Appearance.RemoveFromOutfit(A); } - return BasicReply("ok", new[] { item }); + return BasicReply("ok", [item]); } InventoryItem realitem = HelperInventory.getItemByInventoryUUID(GetClient(), itemuuid); GetClient().Appearance.RemoveFromOutfit(realitem); - return BasicReply("Ok", new [] { item }); + return BasicReply("Ok", [item]); } @@ -201,13 +197,13 @@ namespace SecondBotEvents.Commands UUID folderUUID = UUID.Zero; if(UUID.TryParse(folder, out folderUUID) == false) { - return Failure("invaild folder uuid", new[] { folder }); + return Failure("invaild folder uuid", [folder]); } List contents = GetClient().Inventory.FolderContents(folderUUID, GetClient().Self.AgentID, true, true, InventorySortOrder.ByName, TimeSpan.FromSeconds(15)); - List wareables = new(); + List wareables = []; if (contents == null) { - return Failure("target folder is empty or so full I cant get it in 5 secs...", new[] { folder }); + return Failure("target folder is empty or so full I cant get it in 5 secs...", [folder]); } foreach (InventoryBase item in contents) { @@ -217,7 +213,7 @@ namespace SecondBotEvents.Commands } } master.CurrentOutfitFolder.ReplaceOutfit(wareables); - return BasicReply("ok", new[] { folder }); + return BasicReply("ok", [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!")] @@ -231,7 +227,7 @@ namespace SecondBotEvents.Commands { if (SecondbotHelpers.notempty(name) == false) { - return Failure("Named folder value is empty", new [] { name }); + return Failure("Named folder value is empty", [name]); } // uses the Clothing folder // must be a full outfit (shapes/eyes ect) @@ -248,7 +244,7 @@ namespace SecondBotEvents.Commands } if (AA == null) { - return Failure("Cant find Clothing folder", new [] { name }); + return Failure("Cant find Clothing folder", [name]); } T = GetClient().Inventory.Store.GetContents(AA); AA = null; @@ -262,13 +258,13 @@ namespace SecondBotEvents.Commands } if (AA == null) { - return Failure("Cant find target folder", new [] { name }); + return Failure("Cant find target folder", [name]); } List contents = GetClient().Inventory.FolderContents(AA.UUID, GetClient().Self.AgentID, true, true, InventorySortOrder.ByName, TimeSpan.FromSeconds(15)); - List wareables = new(); + List wareables = []; if (contents == null) { - return Failure("target folder is empty or so full I cant get it in 5 secs...", new [] { name }); + return Failure("target folder is empty or so full I cant get it in 5 secs...", [name]); } foreach (InventoryBase item in contents) { @@ -278,7 +274,7 @@ namespace SecondBotEvents.Commands } } GetClient().Appearance.ReplaceOutfit(wareables, false); - return BasicReply("ok", new [] { name }); + return BasicReply("ok", [name]); } @@ -302,7 +298,7 @@ namespace SecondBotEvents.Commands { return Failure("Unable to find notecard folder"); } - List purge_notecards = new(); + List purge_notecards = []; List contents = GetClient().Inventory.FolderContents(NotecardFolder.UUID, GetClient().Self.AgentID, true, true, InventorySortOrder.ByDate, TimeSpan.FromSeconds(15)); foreach (InventoryBase C in contents) { @@ -318,7 +314,7 @@ namespace SecondBotEvents.Commands } if (purge_notecards.Count > 0) { - GetClient().Inventory.Remove(purge_notecards, new List()); + GetClient().Inventory.Remove(purge_notecards, []); } return BasicReply("Ok"); } @@ -331,10 +327,10 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(item, out UUID itemUUID) == false) { - return Failure("Invaild item uuid", new [] { item }); + return Failure("Invaild item uuid", [item]); } UUID reply = HelperInventory.GetAssetUUID(GetClient(), itemUUID); - return BasicReply(reply.ToString(), new [] { item }); + return BasicReply(reply.ToString(), [item]); } [About("sends a item to an avatar via a path")] @@ -349,20 +345,20 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("Invaild avatar uuid", new[] { path, avatar }); + return Failure("Invaild avatar uuid", [path, avatar]); } UUID targetitem = GetClient().Inventory.FindObjectByPath(GetClient().Inventory.Store.RootFolder.UUID, GetClient().Self.AgentID, path, TimeSpan.FromSeconds(15)); if(targetitem == UUID.Zero) { - return Failure("Unable to find item via path", new[] { path, avatar }); + return Failure("Unable to find item via path", [path, avatar]); } InventoryItem itm = GetClient().Inventory.FetchItem(targetitem, GetClient().Self.AgentID, TimeSpan.FromSeconds(15)); if (itm == null) { - return Failure("Unable to find item with found uuid", new[] { path, avatar }); + return Failure("Unable to find item with found uuid", [path, avatar]); } GetClient().Inventory.GiveItem(itm.UUID, itm.Name, itm.AssetType, avataruuid, false); - return BasicReply("ok", new[] { path, avatar }); + return BasicReply("ok", [path, avatar]); } [About("sends a item to an avatar")] @@ -378,19 +374,19 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if(avataruuid == UUID.Zero) { - return Failure("Invaild avatar uuid", new [] { item, avatar }); + return Failure("Invaild avatar uuid", [item, avatar]); } if (UUID.TryParse(item, out UUID targetitem) == false) { - return Failure("Invaild item uuid", new [] { item, avatar }); + return Failure("Invaild item uuid", [item, avatar]); } InventoryItem itm = GetClient().Inventory.FetchItem(targetitem, GetClient().Self.AgentID, TimeSpan.FromSeconds(15)); if (itm == null) { - return Failure("Unable to find item", new [] { item, avatar }); + return Failure("Unable to find item", [item, avatar]); } GetClient().Inventory.GiveItem(itm.UUID, itm.Name, itm.AssetType, avataruuid, false); - return BasicReply("ok", new [] { item, avatar }); + return BasicReply("ok", [item, avatar]); } [About("Sends a folder to an avatar")] [ReturnHints("ok")] @@ -403,15 +399,15 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("Invaild avatar uuid", new[] { path, avatar }); + return Failure("Invaild avatar uuid", [path, avatar]); } InventoryFolder FindFolderHelper = HelperInventory.FindFolderByPath(GetClient(), path); if (FindFolderHelper == null) { - return Failure("Unable to find folder", new[] { path, avatar }); + return Failure("Unable to find folder", [path, avatar]); } GetClient().Inventory.GiveFolder(FindFolderHelper.UUID, FindFolderHelper.Name, avataruuid, false); - return BasicReply("ok", new[] { path, avatar }); + return BasicReply("ok", [path, avatar]); } @@ -428,19 +424,19 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("Invaild avatar uuid", new [] { folder, avatar }); + return Failure("Invaild avatar uuid", [folder, avatar]); } if (UUID.TryParse(folder, out UUID targetfolder) == false) { - return Failure("Invaild folder uuid", new [] { folder, avatar }); + return Failure("Invaild folder uuid", [folder, avatar]); } InventoryBase FindFolderHelper = HelperInventory.FindFolder(GetClient(), GetClient().Inventory.Store.RootFolder, targetfolder); if (FindFolderHelper == null) { - return Failure("Unable to find folder", new [] { folder, avatar }); + return Failure("Unable to find folder", [folder, avatar]); } GetClient().Inventory.GiveFolder(FindFolderHelper.UUID, FindFolderHelper.Name, avataruuid, false); - return BasicReply("ok", new [] { folder, avatar }); + return BasicReply("ok", [folder, avatar]); } [About("Transfers a item [ARG 2] to a objects inventory [ARG 1] (And if set with the script running state [ARG 3])")] @@ -458,21 +454,21 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(item, out UUID itemuuid) == false) { - return Failure("Invaild item uuid", new [] { item, objectuuid, running }); + return Failure("Invaild item uuid", [item, objectuuid, running]); } if (UUID.TryParse(objectuuid, out UUID objectUUID) == false) { - return Failure("Invaild object uuid", new [] { item, objectuuid, running }); + return Failure("Invaild object uuid", [item, objectuuid, running]); } if (bool.TryParse(running, out bool runscript) == false) { - return Failure("Invaild running", new [] { item, objectuuid, running }); + return Failure("Invaild running", [item, objectuuid, running]); } InventoryItem itm = GetClient().Inventory.FetchItem(itemuuid, GetClient().Self.AgentID, TimeSpan.FromSeconds(15)); if (itm == null) { - return Failure("Unable to find inventory", new [] { item, objectuuid, running }); + return Failure("Unable to find inventory", [item, objectuuid, running]); } Dictionary objects_copy = GetClient().Network.CurrentSim.ObjectsPrimitives.Copy(); KeyValuePair RealObject = new(0, null); @@ -495,7 +491,7 @@ namespace SecondBotEvents.Commands break; } } - return Failure("Unable to find object", new [] { item, objectuuid, running }); + return Failure("Unable to find object", [item, objectuuid, running]); } bool scriptState = runscript; if (itm.AssetType != AssetType.LSLText) @@ -505,10 +501,10 @@ namespace SecondBotEvents.Commands if (itm.AssetType == AssetType.LSLText) { GetClient().Inventory.CopyScriptToTask(RealObject.Key, itm, scriptState); - return BasicReply("Transfering script [state: "+scriptState.ToString()+"]", new [] { item, objectuuid, running }); + return BasicReply("Transfering script [state: "+scriptState.ToString()+"]", [item, objectuuid, running]); } GetClient().Inventory.UpdateTaskInventory(RealObject.Key, itm); - return BasicReply("Transfering inventory", new [] { item, objectuuid, running }); + return BasicReply("Transfering inventory", [item, objectuuid, running]); } [About("Requests the inventory folder layout as a json object InventoryMapFolder
Formated as follows
InventoryMapItem
  • id: UUID
  • name: String
  • subfolders: InventoryMapFolder[]
")] @@ -540,9 +536,9 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(folderUUID, out UUID folder) == false) { - return Failure("Invaild folder UUID", new [] { folderUUID }); + return Failure("Invaild folder UUID", [folderUUID]); } - return BasicReply(HelperInventory.MapFolderInventoryJson(GetClient(), folder), new [] { folderUUID }); + return BasicReply(HelperInventory.MapFolderInventoryJson(GetClient(), folder), [folderUUID]); } [About("creates a folder in a folder")] @@ -555,15 +551,15 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(parentFolder, out UUID parentFolderUUID) == false) { - return Failure("invaild parent folder UUID", new[] { parentFolder }); + return Failure("invaild parent folder UUID", [parentFolder]); } if (folderName.Length < 3) { - return Failure("new folder name is too short, must be longer than 3 characters.", new[] { folderName }); + return Failure("new folder name is too short, must be longer than 3 characters.", [folderName]); } UUID folder = GetClient().Inventory.CreateFolder(parentFolderUUID, folderName); string uuid = folder.ToString(); - return BasicReply("Ok", new string[] { uuid }); + return BasicReply("Ok", [uuid]); } @@ -577,14 +573,14 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(item, out UUID itemUUID) == false) { - return Failure("invaild item uuid", new[] { item, folder }); + return Failure("invaild item uuid", [item, folder]); } if (UUID.TryParse(folder, out UUID folderUUID) == false) { - return Failure("invaild folder uuid", new[] { item, folder }); + return Failure("invaild folder uuid", [item, folder]); } GetClient().Inventory.MoveItem(itemUUID, folderUUID); - return BasicReply("Ok", new string[] { item }); + return BasicReply("Ok", [item]); } [About("moves a folder to another folder")] @@ -597,14 +593,14 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(sourceFolder, out UUID sourceFolderUUID) == false) { - return Failure("invaild source folder uuid", new[] { sourceFolder, destFolder }); + return Failure("invaild source folder uuid", [sourceFolder, destFolder]); } if (UUID.TryParse(destFolder, out UUID destFolderUUID) == false) { - return Failure("invaild dest folder uuid", new[] { sourceFolder, destFolder }); + return Failure("invaild dest folder uuid", [sourceFolder, destFolder]); } GetClient().Inventory.MoveFolder(sourceFolderUUID, destFolderUUID); - return BasicReply("Ok", new string[] { sourceFolder, destFolder }); + return BasicReply("Ok", [sourceFolder, destFolder]); } } } diff --git a/SecondBotEvents/Commands/Movement.cs b/SecondBotEvents/Commands/Movement.cs index 0d6b189..80f6ff0 100644 --- a/SecondBotEvents/Commands/Movement.cs +++ b/SecondBotEvents/Commands/Movement.cs @@ -8,12 +8,8 @@ using System.Threading; namespace SecondBotEvents.Commands { [ClassInfo("Dont like this place lets try somewhere else")] - public class Movement : CommandsAPI + public class Movement(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public Movement(EventsSecondBot setmaster) : base(setmaster) - { - } - [About("Adjusts Hover height")] [ReturnHints("ok")] [ReturnHintsFailure("Convert to float has failed")] @@ -23,14 +19,14 @@ namespace SecondBotEvents.Commands { if (double.TryParse(height, out double level) == false) { - return Failure("Convert to float has failed", new[] { height }); + return Failure("Convert to float has failed", [height]); } if (SecondbotHelpers.inrange(level, -2.0, 2.0) == false) { - return Failure("height value out of range(-2.0 to 2.0)", new[] { height }); + return Failure("height value out of range(-2.0 to 2.0)", [height]); } GetClient().Self.SetHoverHeight(level); - return BasicReply("ok", new[] { height }); + return BasicReply("ok", [height]); } [About("uses the AutoPilot to move to a location")] @@ -45,27 +41,26 @@ namespace SecondBotEvents.Commands { if (Vector3.TryParse("<" + x + "," + y + "," + z + ">", out Vector3 pos) == false) { - return Failure("Convert to vector has failed", new [] { x, y, z }); + return Failure("Convert to vector has failed", [x, y, z]); } if (SecondbotHelpers.inrange(pos.X, 0, 255) == false) { - return Failure("x value out of range 0-255", new [] { x, y, z }); + return Failure("x value out of range 0-255", [x, y, z]); } if (SecondbotHelpers.inrange(pos.Y, 0, 255) == false) { - return Failure("y value out of range 0-255", new [] { x, y, z }); + return Failure("y value out of range 0-255", [x, y, z]); } if (SecondbotHelpers.inrange(pos.Z, 0, 5000) == false) { - return Failure("z value out of range 0-5000", new [] { x, y, z }); + return Failure("z value out of range 0-5000", [x, y, z]); } GetClient().Self.AutoPilotCancel(); GetClient().Self.Movement.TurnToward(pos, true); Thread.Sleep(500); - uint Globalx, Globaly; - Utils.LongToUInts(GetClient().Network.CurrentSim.Handle, out Globalx, out Globaly); + Utils.LongToUInts(GetClient().Network.CurrentSim.Handle, out uint Globalx, out uint Globaly); GetClient().Self.AutoPilot((ulong)(Globalx + pos.X), (ulong)(Globaly + pos.Y), pos.Z); - return BasicReply("ok", new [] { x, y, z }); + return BasicReply("ok", [x, y, z]); } [About("Stop the auto pilot system from walking")] @@ -85,10 +80,10 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if(avataruuid == UUID.Zero) { - return Failure("Invaild avatar UUID", new [] { avatar }); + return Failure("Invaild avatar UUID", [avatar]); } GetClient().Self.SendTeleportLure(avataruuid); - return BasicReply("ok", new [] { avatar }); + return BasicReply("ok", [avatar]); } [About("Sends a teleport request (Move the bot to the avatar)")] @@ -100,11 +95,11 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("Invaild avatar UUID", new [] { avatar }); + return Failure("Invaild avatar UUID", [avatar]); } // @todo action from event log with accept GetClient().Self.SendTeleportLureRequest(avataruuid, "I would like to teleport to you"); - return BasicReply("ok", new [] { avatar }); + return BasicReply("ok", [avatar]); } [About("Makes the bot fly (or not)")] @@ -115,11 +110,11 @@ namespace SecondBotEvents.Commands { if (bool.TryParse(mode, out bool flymode) == false) { - return Failure("Invaild mode", new [] { mode }); + return Failure("Invaild mode", [mode]); } GetClient().Self.Movement.Fly = flymode; GetClient().Self.Movement.SendUpdate(); - return BasicReply("ok", new [] { mode }); + return BasicReply("ok", [mode]); } [About("Rotates the bot to face a vector from its current location")] @@ -131,21 +126,21 @@ namespace SecondBotEvents.Commands { if (Vector3.TryParse(vector, out Vector3 pos) == false) { - return Failure("Invaild vector", new [] { vector }); + return Failure("Invaild vector", [vector]); } if (SecondbotHelpers.inrange(pos.X, 0, 255) == false) { - return Failure("Vector x value is out of range 0-255", new [] { vector }); + return Failure("Vector x value is out of range 0-255", [vector]); } if (SecondbotHelpers.inrange(pos.Y, 0, 255) == false) { - return Failure("Vector y value is out of range 0-255", new [] { vector }); + return Failure("Vector y value is out of range 0-255", [vector]); } if (SecondbotHelpers.inrange(pos.Z, 0, 5000) == false) { - return Failure("Vector z value is out of range 0-5000", new [] { vector }); + return Failure("Vector z value is out of range 0-5000", [vector]); } - return BasicReply(GetClient().Self.Movement.TurnToward(pos, true).ToString(), new [] { vector }); + return BasicReply(GetClient().Self.Movement.TurnToward(pos, true).ToString(), [vector]); } [About("Rotates the bot to face a avatar")] @@ -158,13 +153,13 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if(avataruuid == UUID.Zero) { - return Failure("Invaild avatar UUID", new [] { avatar }); + return Failure("Invaild avatar UUID", [avatar]); } if (GetClient().Network.CurrentSim.AvatarPositions.ContainsKey(avataruuid) == false) { - return Failure("Unable to see avatar", new [] { avatar }); + return Failure("Unable to see avatar", [avatar]); } - return BasicReply(GetClient().Self.Movement.TurnToward(GetClient().Network.CurrentSim.AvatarPositions[avataruuid], true).ToString(), new [] { avatar }); + return BasicReply(GetClient().Self.Movement.TurnToward(GetClient().Network.CurrentSim.AvatarPositions[avataruuid], true).ToString(), [avatar]); } [About("Rotates the avatar to face a rotation from north in Degrees")] @@ -175,7 +170,7 @@ namespace SecondBotEvents.Commands { if (float.TryParse(deg, out float target_yaw) == true) { - return Failure("Unable to process rotation", new [] { deg }); + return Failure("Unable to process rotation", [deg]); } float yaw = target_yaw; GetClient().Self.Movement.BodyRotation.GetEulerAngles(out float roll, out float pitch, out _); @@ -198,7 +193,7 @@ namespace SecondBotEvents.Commands result.Z = cosYawOver2 * cosPitchOver2 * sinRollOver2 - sinYawOver2 * sinPitchOver2 * cosRollOver2; GetClient().Self.Movement.BodyRotation = result; GetClient().Self.Movement.SendUpdate(); - return BasicReply("ok", new [] { deg }); + return BasicReply("ok", [deg]); } @@ -215,9 +210,9 @@ namespace SecondBotEvents.Commands bool status = TeleportRequest(region+"/"+x+"/"+y+"/"+z); if (status == false) { - return Failure("Error Unable to Teleport to location", new [] { region, x, y, z }); + return Failure("Error Unable to Teleport to location", [region, x, y, z]); } - return BasicReply("Accepted", new [] { region, x, y, z }); + return BasicReply("Accepted", [region, x, y, z]); } @@ -229,16 +224,16 @@ namespace SecondBotEvents.Commands { if (SecondbotHelpers.notempty(slurl) == false) { - return Failure("slurl is empty", new [] { slurl }); + return Failure("slurl is empty", [slurl]); } - return BasicReply(TeleportRequest(slurl).ToString(), new [] { slurl }); + return BasicReply(TeleportRequest(slurl).ToString(), [slurl]); } protected bool TeleportRequest(string url) { // Viserion/66/166/23 GetClient().Self.AutoPilotCancel(); - SimSlURL A = new SimSlURL(url); + SimSlURL A = new(url); if(A.name == null) { return false; diff --git a/SecondBotEvents/Commands/Notecard.cs b/SecondBotEvents/Commands/Notecard.cs index 68542b9..0809531 100644 --- a/SecondBotEvents/Commands/Notecard.cs +++ b/SecondBotEvents/Commands/Notecard.cs @@ -7,12 +7,8 @@ using SecondBotEvents.Services; namespace SecondBotEvents.Commands { [ClassInfo("Why this is not a built in script command I will never know, but its due to needing this that the bot was made")] - public class Notecard : CommandsAPI + public class Notecard(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public Notecard(EventsSecondBot setmaster) : base(setmaster) - { - } - [About("Reads the notecards content, if it is able to read the notecard will give a json reply of notecarduuid name and contents")] [ReturnHintsFailure("Not a vaild UUID")] [ReturnHintsFailure("Unable to find inventory item")] @@ -27,28 +23,30 @@ namespace SecondBotEvents.Commands { return Failure("replytarget not set"); } - NotecardReadReply reply = new NotecardReadReply(); - reply.uuid = notecardInventoryUUID; - reply.name = "?"; - reply.status = false; - reply.content = "Not a vaild UUID"; + NotecardReadReply reply = new() + { + uuid = notecardInventoryUUID, + name = "?", + status = false, + content = "Not a vaild UUID" + }; if (UUID.TryParse(notecardInventoryUUID, out var uuid) == false) { master.CommandsService.SmartCommandReply(replytarget, JsonConvert.SerializeObject(reply), "NotecardRead"); - return Failure(reply.content, new[] { notecardInventoryUUID }); + return Failure(reply.content, [notecardInventoryUUID]); } reply.content = "Unable to find inventory item"; InventoryItem item = GetClient().Inventory.FetchItem(uuid, GetClient().Self.AgentID, new System.TimeSpan(0, 1, 30)); if (item == null) { master.CommandsService.SmartCommandReply(replytarget, JsonConvert.SerializeObject(reply), "NotecardRead"); - return Failure(reply.content, new[] { notecardInventoryUUID }); + return Failure(reply.content, [notecardInventoryUUID]); } reply.content = "Inventory item is not a notecard"; if (item.InventoryType != InventoryType.Notecard) { master.CommandsService.SmartCommandReply(replytarget, JsonConvert.SerializeObject(reply), "NotecardRead"); - return Failure(reply.content, new[] { notecardInventoryUUID }); ; + return Failure(reply.content, [notecardInventoryUUID]); ; } InventoryNotecard notecard = (InventoryNotecard)item; GetClient().Assets.RequestInventoryAsset(notecard, true, UUID.Random(), (AssetDownload transfer, Asset asset) => @@ -95,14 +93,14 @@ namespace SecondBotEvents.Commands { if (SecondbotHelpers.notempty(collection) == false) { - return Failure("Collection value is empty", new [] { collection, content }); + return Failure("Collection value is empty", [collection, content]); } if (SecondbotHelpers.notempty(content) == false) { - return Failure("Content value is empty", new [] { collection, content }); + return Failure("Content value is empty", [collection, content]); } master.DataStoreService.AppendKeyValue("notecard_"+collection, content); - return BasicReply("ok", new [] { collection, master.DataStoreService.GetKeyValue("notecard_"+collection).Length.ToString() }); + return BasicReply("ok", [collection, master.DataStoreService.GetKeyValue("notecard_"+collection).Length.ToString()]); } [About("Clears the contents of a collection")] @@ -113,7 +111,7 @@ namespace SecondBotEvents.Commands { if (SecondbotHelpers.notempty(collection) == false) { - return Failure("Collection value is empty", new [] { collection }); + return Failure("Collection value is empty", [collection]); } master.DataStoreService.ClearKeyValue("notecard_" + collection); return BasicReply("ok"); @@ -132,26 +130,26 @@ namespace SecondBotEvents.Commands { if (SecondbotHelpers.notempty(collection) == false) { - return Failure("Collection value is empty", new [] { avatar, collection, notecardname }); + return Failure("Collection value is empty", [avatar, collection, notecardname]); } if (SecondbotHelpers.notempty(notecardname) == false) { - return Failure("Notecardname value is empty", new [] { avatar, collection, notecardname }); + return Failure("Notecardname value is empty", [avatar, collection, notecardname]); } ProcessAvatar(avatar); if(avataruuid == UUID.Zero) { - return Failure("Invaild avatar uuid", new [] { avatar, collection, notecardname }); + return Failure("Invaild avatar uuid", [avatar, collection, notecardname]); } string content = master.DataStoreService.GetKeyValue("notecard_" + collection); if(content.Length <= 3) { - return Failure("No content in notecard storage ?", new[] { avatar, collection, notecardname }); + return Failure("No content in notecard storage ?", [avatar, collection, notecardname]); } bool result = master.BotClient.SendNotecard(notecardname, content, avataruuid); if (result == false) { - return Failure("Failed to create/send notecard", new[] { avatar, content, notecardname }); + return Failure("Failed to create/send notecard", [avatar, content, notecardname]); } master.DataStoreService.ClearKeyValue("notecard_" + collection); return BasicReply("ok"); @@ -169,21 +167,21 @@ namespace SecondBotEvents.Commands { if (SecondbotHelpers.notempty(notecardname) == false) { - return Failure("notecardname value is empty", new[] { avatar, content, notecardname }); + return Failure("notecardname value is empty", [avatar, content, notecardname]); } if (SecondbotHelpers.notempty(content) == false) { - return Failure("content value is empty", new[] { avatar, content, notecardname }); + return Failure("content value is empty", [avatar, content, notecardname]); } ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("Invaild avatar uuid", new[] { avatar, content, notecardname }); + return Failure("Invaild avatar uuid", [avatar, content, notecardname]); } bool result = master.BotClient.SendNotecard(notecardname, content, avataruuid); if(result == false) { - return Failure("Failed to create/send notecard", new[] { avatar, content, notecardname }); + return Failure("Failed to create/send notecard", [avatar, content, notecardname]); } return BasicReply("ok"); } diff --git a/SecondBotEvents/Commands/ParcelCommands.cs b/SecondBotEvents/Commands/ParcelCommands.cs index a694400..b939144 100644 --- a/SecondBotEvents/Commands/ParcelCommands.cs +++ b/SecondBotEvents/Commands/ParcelCommands.cs @@ -13,12 +13,12 @@ using static OpenMetaverse.Stats.UtilizationStatistics; namespace SecondBotEvents.Commands { - public class parcelPacketReply + public class ParcelPacketReply { - public List groupuuids = new List(); - public List parcels = new List(); + public List groupuuids = []; + public List parcels = []; } - public class parcelPacketData + public class ParcelPacketData { public int area; public int groupindex; @@ -30,12 +30,8 @@ namespace SecondBotEvents.Commands } [ClassInfo("Control the land under our feet")] - public partial class ParcelCommands : CommandsAPI + public partial class ParcelCommands(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public ParcelCommands(EventsSecondBot setmaster) : base(setmaster) - { - } - [About("Requests the bot update its list of parcels ready for other commands")] [ReturnHints("ok")] public object UpdateListOfParcels() @@ -47,8 +43,8 @@ namespace SecondBotEvents.Commands [ReturnHints("json encoded object")] public object GetParcelListSnapshots() { - Dictionary reply = new Dictionary(); - List Parcels = GetClient().Network.CurrentSim.Parcels.Copy().Values.ToList(); + Dictionary reply = []; + List Parcels = [.. GetClient().Network.CurrentSim.Parcels.Copy().Values]; foreach (Parcel A in Parcels) { reply.Add(A.Name, A.SnapshotID.ToString()); @@ -61,32 +57,32 @@ namespace SecondBotEvents.Commands public object GetSimParcelLayers() { Dictionary data = GetClient().Network.CurrentSim.Parcels.Copy(); - Dictionary parcelbox = new Dictionary(); + Dictionary parcelbox = []; uint SimWidth = GetClient().Network.CurrentSim.SizeX; uint SimHeight = GetClient().Network.CurrentSim.SizeY; - Dictionary maps = new Dictionary(); + Dictionary maps = []; int lastparcelid = 0; uint lowX = 0; uint lowY = 0; - Random rnd = new Random(); + Random rnd = new(); uint startX = 4; string svg = ""; uint boxheight = 0; var color = ""; Parcel P = null; - string parcelname = "?"; int checkparcel = GetClient().Parcels.GetParcelLocalID(GetClient().Network.CurrentSim, new Vector3(startX, 4, 20)); while (startX < SimWidth) { uint startY = 4; + string parcelname; while (startY < SimHeight) { checkparcel = GetClient().Parcels.GetParcelLocalID(GetClient().Network.CurrentSim, new Vector3(startX, startY, 20)); if ((checkparcel != lastparcelid) || (startY >= SimHeight)) { - if(lastparcelid == 0) + if (lastparcelid == 0) { lastparcelid = checkparcel; lowX = startX - 4; @@ -94,7 +90,7 @@ namespace SecondBotEvents.Commands } else { - boxheight = (startY-4) - lowY; + boxheight = (startY - 4) - lowY; color = ""; if (maps.ContainsKey(lastparcelid) == false) { @@ -140,7 +136,7 @@ namespace SecondBotEvents.Commands lastparcelid = 0; startX += 4; } - svg = svg + ""; + svg += ""; return BasicReply(svg); } @@ -149,8 +145,8 @@ namespace SecondBotEvents.Commands [ReturnHints("json encoded object")] public object GetListOfParcels() { - parcelPacketReply reply = new parcelPacketReply(); - List Parcels = GetClient().Network.CurrentSim.Parcels.Copy().Values.ToList(); + ParcelPacketReply reply = new(); + List Parcels = [.. GetClient().Network.CurrentSim.Parcels.Copy().Values]; foreach (Parcel A in Parcels) { int index = reply.groupuuids.IndexOf(A.GroupID.ToString()); @@ -159,14 +155,16 @@ namespace SecondBotEvents.Commands reply.groupuuids.Add(A.GroupID.ToString()); index = reply.groupuuids.IndexOf(A.GroupID.ToString()); } - parcelPacketData R = new parcelPacketData(); - R.groupindex = index; - R.area = A.Area; - R.startbox = A.AABBMin.ToString(); - R.endbox = A.AABBMax.ToString(); - R.currentprims = A.TotalPrims; - R.maxprims = A.MaxPrims; - R.name = A.Name; + ParcelPacketData R = new() + { + groupindex = index, + area = A.Area, + startbox = A.AABBMin.ToString(), + endbox = A.AABBMax.ToString(), + currentprims = A.TotalPrims, + maxprims = A.MaxPrims, + name = A.Name + }; reply.parcels.Add(R); } return BasicReply(JsonConvert.SerializeObject(reply)); @@ -201,11 +199,11 @@ namespace SecondBotEvents.Commands KeyValuePair tests = SetupCurrentParcel(); if(tests.Key == false) { - return Failure(tests.Value, new [] { amount, avatar }); + return Failure(tests.Value, [amount, avatar]); } if (int.TryParse(amount,out int amountvalue) == false) { - return Failure("Invaild amount", new [] { amount, avatar }); + return Failure("Invaild amount", [amount, avatar]); } int minAmount = 1; @@ -220,14 +218,14 @@ namespace SecondBotEvents.Commands } if ((amountvalue < minAmount) || (amountvalue > 9999999)) { - return Failure("Invaild amount", new [] { amount, avatar }); + return Failure("Invaild amount", [amount, avatar]); } targetparcel.SalePrice = amountvalue; targetparcel.AuthBuyerID = avataruuid; ParcelStatic.ParcelSetFlag(ParcelFlags.ForSale, targetparcel, true); ParcelStatic.ParcelSetFlag(ParcelFlags.ForSaleObjects, targetparcel, false); targetparcel.Update(GetClient()); - return BasicReply("ok", new [] { amount, avatar }); + return BasicReply("ok", [amount, avatar]); } @@ -257,7 +255,7 @@ namespace SecondBotEvents.Commands { return Failure(tests.Value); } - Dictionary collection = new Dictionary(); + Dictionary collection = []; collection.Add("ForSale", targetparcel.Flags.HasFlag(ParcelFlags.ForSale).ToString()); collection.Add("Cost", targetparcel.SalePrice.ToString()); collection.Add("SaleTarget", targetparcel.AuthBuyerID.ToString()); @@ -320,8 +318,8 @@ namespace SecondBotEvents.Commands { return Failure("timeout must be >= 2000 and <= 7000"); } - AutoResetEvent landresultsTimeout = new AutoResetEvent(false); - List collection = new List(); + AutoResetEvent landresultsTimeout = new(false); + List collection = []; void LandSearchResultsReply(object sender, DirLandReplyEventArgs e) { int counter = (100 * GetpageNum); @@ -344,7 +342,7 @@ namespace SecondBotEvents.Commands GetClient().Directory.DirLandReply -= LandSearchResultsReply; string reply = JsonConvert.SerializeObject(collection); - return BasicReply(reply, new string[] { filterRegion, filterPrice, filterArea, pageNum, timeout }); + return BasicReply(reply, [filterRegion, filterPrice, filterArea, pageNum, timeout]); } @@ -361,24 +359,24 @@ namespace SecondBotEvents.Commands KeyValuePair tests = SetupCurrentParcel(); if (tests.Key == false) { - return Failure(tests.Value, new [] { x, y, z }); + return Failure(tests.Value, [x, y, z]); } if(int.TryParse(x,out int X) == false) { - return Failure("Unable to process landing point x value", new [] { x, y, z }); + return Failure("Unable to process landing point x value", [x, y, z]); } if (int.TryParse(y, out int Y) == false) { - return Failure("Unable to process landing point y value", new [] { x, y, z }); + return Failure("Unable to process landing point y value", [x, y, z]); } if (int.TryParse(z, out int Z) == false) { - return Failure("Unable to process landing point z value", new [] { x, y, z }); + return Failure("Unable to process landing point z value", [x, y, z]); } targetparcel.Landing = LandingType.LandingPoint; targetparcel.UserLocation = new Vector3(X, Y, Z); targetparcel.Update(GetClient()); - return BasicReply("ok", new [] { x, y, z }); + return BasicReply("ok", [x, y, z]); } @@ -393,15 +391,15 @@ namespace SecondBotEvents.Commands KeyValuePair tests = SetupCurrentParcel(); if (tests.Key == false) { - return Failure(tests.Value, new [] { name }); + return Failure(tests.Value, [name]); } if (SecondbotHelpers.notempty(name) == false) { - return Failure("Parcel name is empty", new [] { name }); + return Failure("Parcel name is empty", [name]); } targetparcel.Name = name; targetparcel.Update(GetClient()); - return BasicReply("ok", new [] { name }); + return BasicReply("ok", [name]); } [About("Updates the current parcels description")] @@ -414,11 +412,11 @@ namespace SecondBotEvents.Commands KeyValuePair tests = SetupCurrentParcel(); if (tests.Key == false) { - return Failure(tests.Value, new [] { desc }); + return Failure(tests.Value, [desc]); } targetparcel.Desc = desc; targetparcel.Update(GetClient()); - return BasicReply("ok", new [] { desc }); + return BasicReply("ok", [desc]); } [About("Fetchs the current parcels desc")] @@ -447,7 +445,7 @@ namespace SecondBotEvents.Commands return Failure(tests.Value); } Dictionary flags = ParcelStatic.GetFlagsList(); - Dictionary collection = new(); + Dictionary collection = []; foreach (ParcelFlags cfg in flags.Values) { collection.Add(cfg.ToString(), targetparcel.Flags.HasFlag(cfg).ToString()); @@ -464,10 +462,10 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if(avataruuid == UUID.Zero) { - return Failure("Invaild avatar", new [] { avatar }); + return Failure("Invaild avatar", [avatar]); } GetClient().Parcels.EjectUser(avataruuid, false); - return BasicReply("ok", new [] { avatar }); + return BasicReply("ok", [avatar]); } [About("Abandons the parcel the bot is currently on, returning it to Linden's or Estate owner")] @@ -496,12 +494,12 @@ namespace SecondBotEvents.Commands KeyValuePair tests = SetupCurrentParcel(); if (tests.Key == false) { - return Failure(tests.Value, new [] { avatar }); + return Failure(tests.Value, [avatar]); } ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("Invaild avatar", new [] { avatar }); + return Failure("Invaild avatar", [avatar]); } bool alreadyBanned = false; foreach (ParcelAccessEntry E in targetparcel.AccessBlackList) @@ -514,7 +512,7 @@ namespace SecondBotEvents.Commands } if (alreadyBanned == true) { - return BasicReply("Avatar is in the blacklist", new [] { avatar }); + return BasicReply("Avatar is in the blacklist", [avatar]); } ParcelAccessEntry entry = new() { @@ -524,7 +522,7 @@ namespace SecondBotEvents.Commands }; targetparcel.AccessBlackList.Add(entry); targetparcel.Update(GetClient()); - return BasicReply("ok", new [] { avatar }); + return BasicReply("ok", [avatar]); } [About("Unbans an avatar from a parcel")] @@ -539,12 +537,12 @@ namespace SecondBotEvents.Commands KeyValuePair tests = SetupCurrentParcel(); if (tests.Key == false) { - return Failure(tests.Value, new [] { avatar }); + return Failure(tests.Value, [avatar]); } ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("Invaild avatar", new [] { avatar }); + return Failure("Invaild avatar", [avatar]); } bool alreadyBanned = false; ParcelAccessEntry removeentry = new(); @@ -559,11 +557,11 @@ namespace SecondBotEvents.Commands } if (alreadyBanned == false) { - return BasicReply("Avatar is already unbanned", new [] { avatar }); + return BasicReply("Avatar is already unbanned", [avatar]); } targetparcel.AccessBlackList.Remove(removeentry); targetparcel.Update(GetClient()); - return BasicReply("ok", new [] { avatar }); + return BasicReply("ok", [avatar]); } @@ -577,10 +575,10 @@ namespace SecondBotEvents.Commands KeyValuePair tests = SetupCurrentParcel(); if (tests.Key == false) { - return Failure(tests.Value, new [] { musicurl }); + return Failure(tests.Value, [musicurl]); } bool status = ParcelStatic.SetParcelMusic(GetClient(), targetparcel, musicurl); - return BasicReply(status.ToString(), new [] { musicurl }); + return BasicReply(status.ToString(), [musicurl]); } [About("Updates the current parcels name")] @@ -598,13 +596,13 @@ namespace SecondBotEvents.Commands KeyValuePair tests = SetupCurrentParcel(); if (tests.Key == false) { - return Failure(tests.Value, new [] { escapedflagdata }); + return Failure(tests.Value, [escapedflagdata]); } - List acceptablewords = new(); + List acceptablewords = []; Dictionary flags = ParcelStatic.GetFlagsList(); - acceptablewords.AddRange(new[] { "True", "False" }); + acceptablewords.AddRange(["True", "False"]); - Dictionary setflags = new(); + Dictionary setflags = []; string[] args = escapedflagdata.Split(":::"); foreach (string a in args) { @@ -627,11 +625,11 @@ namespace SecondBotEvents.Commands } if (setflags.Count == 0) { - return Failure("No accepted flags", new [] { escapedflagdata }); + return Failure("No accepted flags", [escapedflagdata]); } if (ParcelStatic.HasParcelPerm(targetparcel, GetClient()) == false) { - return Failure("Incorrect perms to control parcel", new [] { escapedflagdata }); + return Failure("Incorrect perms to control parcel", [escapedflagdata]); } foreach (KeyValuePair cfg in setflags) { @@ -641,7 +639,7 @@ namespace SecondBotEvents.Commands } } targetparcel.Update(GetClient()); - return BasicReply("Applying perms", new [] { escapedflagdata }); + return BasicReply("Applying perms", [escapedflagdata]); } [About("Returns all objects from the current parcel for the selected avatar")] @@ -655,15 +653,15 @@ namespace SecondBotEvents.Commands KeyValuePair tests = SetupCurrentParcel(); if (tests.Key == false) { - return Failure(tests.Value, new [] { avatar }); + return Failure(tests.Value, [avatar]); } ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("Invaild avatar UUID", new [] { avatar }); + return Failure("Invaild avatar UUID", [avatar]); } - GetClient().Parcels.ReturnObjects(GetClient().Network.CurrentSim, targetparcel.LocalID, ObjectReturnType.None, new List() { avataruuid }); - return BasicReply("ok", new [] { avatar }); + GetClient().Parcels.ReturnObjects(GetClient().Network.CurrentSim, targetparcel.LocalID, ObjectReturnType.None, [avataruuid]); + return BasicReply("ok", [avatar]); } @@ -679,22 +677,22 @@ namespace SecondBotEvents.Commands KeyValuePair tests = SetupCurrentParcel(); if (tests.Key == false) { - return Failure(tests.Value, new [] { group }); + return Failure(tests.Value, [group]); } if (UUID.TryParse(group, out UUID groupuuid) == false) { - return Failure("Invaild group uuid", new [] { group }); + return Failure("Invaild group uuid", [group]); } if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false) { - return Failure("Not in group", new [] { group }); + return Failure("Not in group", [group]); } ParcelStatic.ParcelSetFlag(ParcelFlags.AllowDeedToGroup, targetparcel, true); targetparcel.GroupID = groupuuid; targetparcel.Update(GetClient()); Thread.Sleep(500); GetClient().Parcels.DeedToGroup(GetClient().Network.CurrentSim, targetparcel.LocalID, groupuuid); - return BasicReply("ok", new [] { group }); + return BasicReply("ok", [group]); } [About("Attempts to buy the parcel the bot is standing on, the amount must match the sale price for the land!")] @@ -712,11 +710,11 @@ namespace SecondBotEvents.Commands KeyValuePair tests = SetupCurrentParcel(); if (tests.Key == false) { - return Failure(tests.Value, new [] { amount }); + return Failure(tests.Value, [amount]); } if ((targetparcel.AuthBuyerID != UUID.Zero) && (targetparcel.AuthBuyerID != GetClient().Self.AgentID)) { - return Failure("Parcel sale locked to other avatars", new[] { amount }); + return Failure("Parcel sale locked to other avatars", [amount]); } int minAmount = 1; if (targetparcel.AuthBuyerID == GetClient().Self.AgentID) @@ -725,22 +723,22 @@ namespace SecondBotEvents.Commands } if (int.TryParse(amount, out int amountvalue) == false) { - return Failure("Invaild amount", new [] { amount }); + return Failure("Invaild amount", [amount]); } if (amountvalue < minAmount) { - return Failure("Invaild amount", new [] { amount }); + return Failure("Invaild amount", [amount]); }; if (targetparcel.Flags.HasFlag(ParcelFlags.ForSale) == false) { - return Failure("Parcel not for sale", new [] { amount }); + return Failure("Parcel not for sale", [amount]); } if (targetparcel.SalePrice != amountvalue) { - return Failure("Parcel sale price and amount do not match", new [] { amount }); + return Failure("Parcel sale price and amount do not match", [amount]); } GetClient().Parcels.Buy(GetClient().Network.CurrentSim, targetparcel.LocalID, false, UUID.Zero, false, targetparcel.Area, amountvalue); - return BasicReply("ok", new [] { amount }); + return BasicReply("ok", [amount]); } [About("Freezes an avatar")] @@ -753,15 +751,15 @@ namespace SecondBotEvents.Commands { if (bool.TryParse(state, out bool freezestate) == false) { - return Failure("Invaild state", new [] { avatar, state }); + return Failure("Invaild state", [avatar, state]); } ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("Invaild avatar UUID", new [] { avatar, state }); + return Failure("Invaild avatar UUID", [avatar, state]); } GetClient().Parcels.FreezeUser(avataruuid, freezestate); - return BasicReply("ok", new [] { avatar, state }); + return BasicReply("ok", [avatar, state]); } @@ -815,7 +813,7 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(objectuuid, out UUID targetobject) == false) { - return Failure("Invaild object uuid", new [] { objectuuid }); + return Failure("Invaild object uuid", [objectuuid]); } bool found = false; Dictionary objects_copy = GetClient().Network.CurrentSim.ObjectsPrimitives.Copy(); @@ -830,9 +828,9 @@ namespace SecondBotEvents.Commands } if(found == false) { - return Failure("Unable to find object", new [] { objectuuid }); + return Failure("Unable to find object", [objectuuid]); } - return BasicReply("ok", new [] { objectuuid }); + return BasicReply("ok", [objectuuid]); } [About("Updates the current parcels media settings \n" + @@ -854,7 +852,7 @@ namespace SecondBotEvents.Commands KeyValuePair tests = SetupCurrentParcel(); if (tests.Key == false) { - return Failure(tests.Value, new [] { escapedflagdata }); + return Failure(tests.Value, [escapedflagdata]); } string[] args = escapedflagdata.Split(":::"); foreach (string A in args) @@ -915,7 +913,7 @@ namespace SecondBotEvents.Commands } } targetparcel.Update(GetClient()); - return BasicReply("ok", new [] { escapedflagdata }); + return BasicReply("ok", [escapedflagdata]); } protected static bool UpdateParcelMediaType(Parcel targetparcel, string value) @@ -952,7 +950,7 @@ namespace SecondBotEvents.Commands public class GetParcelBanlistObject { - public Dictionary entrys = new(); + public Dictionary entrys = []; public string parcelName = ""; public string regionName = ""; public int delay = 0; diff --git a/SecondBotEvents/Commands/Self.cs b/SecondBotEvents/Commands/Self.cs index dc4df33..a747ba2 100644 --- a/SecondBotEvents/Commands/Self.cs +++ b/SecondBotEvents/Commands/Self.cs @@ -7,12 +7,8 @@ using System.Linq; namespace SecondBotEvents.Commands { [ClassInfo("The more we know about our self the better we are")] - public class Self : CommandsAPI + public class Self(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public Self(EventsSecondBot setmaster) : base(setmaster) - { - } - [About("use the SMTP service to send a email (requires AllowCommandSendMail to be true)")] [ReturnHints("sending")] [ReturnHintsFailure("Send was rejected because: X")] @@ -57,7 +53,7 @@ namespace SecondBotEvents.Commands { if (GetClient().Network.CurrentSim.AvatarPositions.ContainsKey(avataruuid) == false) { - return Failure("Cant find UUID in sim", new [] { targetUUID }); + return Failure("Cant find UUID in sim", [targetUUID]); } ProcessAvatar(targetUUID); GetClient().Self.Stand(); @@ -66,7 +62,7 @@ namespace SecondBotEvents.Commands GetClient().Self.AnimationStart(Animations.POINT_YOU, true); GetClient().Self.PointAtEffect(GetClient().Self.AgentID, avataruuid, new Vector3d(0, 0, 0), PointAtType.Select, UUID.Random()); GetClient().Self.BeamEffect(GetClient().Self.AgentID, avataruuid, new Vector3d(0, 0, 2), new Color4(255, 255, 255, 1), (float)3.0, UUID.Random()); - return BasicReply("ok", new [] { targetUUID }); + return BasicReply("ok", [targetUUID]); } [About("Reads a value from the KeyValue storage (temp unless SQL is enabled)")] @@ -88,11 +84,11 @@ namespace SecondBotEvents.Commands { if (SecondbotHelpers.isempty(Key) == false) { - return Failure("Key is empty", new[] { Key, Value }); + return Failure("Key is empty", [Key, Value]); } if (SecondbotHelpers.isempty(Value) == false) { - return Failure("Value is empty", new[] { Key, Value }); + return Failure("Value is empty", [Key, Value]); } master.DataStoreService.SetKeyValue(Key, Value); return BasicReply("ok"); @@ -106,7 +102,7 @@ namespace SecondBotEvents.Commands { if (SecondbotHelpers.isempty(Key) == false) { - return Failure("Key is empty", new[] { Key }); + return Failure("Key is empty", [Key]); } master.DataStoreService.ClearKeyValue(Key); return BasicReply("ok"); @@ -121,14 +117,14 @@ namespace SecondBotEvents.Commands if ((target == "ground") || (target == UUID.Zero.ToString())) { GetClient().Self.SitOnGround(); - return BasicReply("ok", new [] { target }); + return BasicReply("ok", [target]); } if(UUID.TryParse(target,out UUID objectuuid) == false) { return Failure("Invaild object uuid and not ground"); } GetClient().Self.RequestSit(objectuuid, Vector3.Zero); - return BasicReply("ok", new [] { target }); + return BasicReply("ok", [target]); } [About("Makes the bot stand up if sitting (also resets animations)")] @@ -150,7 +146,7 @@ namespace SecondBotEvents.Commands { if (UUID.TryParse(target, out UUID objectuuid) == false) { - return Failure("Invaild object UUID", new [] { target }); + return Failure("Invaild object UUID", [target]); } GetClient().Self.PointAtEffect(GetClient().Self.AgentID, objectuuid, new Vector3d(0, 0, 0), PointAtType.Select, new UUID("1df9eb92-62fa-15e5-4bfb-5931f1525274")); @@ -167,7 +163,7 @@ namespace SecondBotEvents.Commands break; } } - return BasicReply(found_object.ToString(), new [] { target }); + return BasicReply(found_object.ToString(), [target]); } [About("Makes the bot kill itself you monster")] @@ -183,7 +179,7 @@ namespace SecondBotEvents.Commands [ReturnHints("list of commands")] public object GetLastCommands() { - List reply = new List(); + List reply = []; foreach(CommandHistory A in master.DataStoreService.GetCommandHistory()) { reply.Add(JsonConvert.SerializeObject(A)); @@ -192,7 +188,7 @@ namespace SecondBotEvents.Commands break; } } - return BasicReply("ok", reply.ToArray()); + return BasicReply("ok", [.. reply]); } [About("Sets the bot to accept a request type from the avatar (or a object owned by the avatar)\n " + @@ -215,30 +211,28 @@ namespace SecondBotEvents.Commands ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { - return Failure("avatar lookup", new [] { avatar, flag, state, sticky }); + return Failure("avatar lookup", [avatar, flag, state, sticky]); } - bool stateflag = false; - bool stickyflag = false; - if(bool.TryParse(state,out stateflag) == false) + if (bool.TryParse(state, out bool stateflag) == false) { - return Failure("Invaild state", new [] { avatar, flag, state, sticky }); + return Failure("Invaild state", [avatar, flag, state, sticky]); } - if (bool.TryParse(sticky, out stickyflag) == false) + if (bool.TryParse(sticky, out bool stickyflag) == false) { - return Failure("Invaild sticky", new [] { avatar, flag, state, sticky }); + return Failure("Invaild sticky", [avatar, flag, state, sticky]); } - string[] AcceptedFlags = new [] { "friend", "group", "animation", "teleport", "command", "inventory" }; + string[] AcceptedFlags = ["friend", "group", "animation", "teleport", "command", "inventory"]; if (AcceptedFlags.Contains(flag) == false) { - return Failure("Invaild flag", new [] { avatar, flag, state, sticky }); + return Failure("Invaild flag", [avatar, flag, state, sticky]); } if (stateflag == true) { // @todo add stick/normal accept dynamic actions - return BasicReply("Added perm: " + flag + " Sticky: " + stickyflag.ToString(), new [] { avatar, flag, state, sticky }); + return BasicReply("Added perm: " + flag + " Sticky: " + stickyflag.ToString(), [avatar, flag, state, sticky]); } // @todo remove stick/normal accept dynamic actions - return BasicReply("Removed perm: " + flag + " Sticky: " + stickyflag.ToString(), new [] { avatar, flag, state, sticky }); + return BasicReply("Removed perm: " + flag + " Sticky: " + stickyflag.ToString(), [avatar, flag, state, sticky]); } diff --git a/SecondBotEvents/Commands/Services.cs b/SecondBotEvents/Commands/Services.cs index 884b3fe..69456e6 100644 --- a/SecondBotEvents/Commands/Services.cs +++ b/SecondBotEvents/Commands/Services.cs @@ -19,13 +19,9 @@ namespace SecondBotEvents.Commands "TriggerOnEventService
" + "RelayService
" + "ChatGptService")] - public class Services : CommandsAPI + public class Services(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public Services(EventsSecondBot setmaster) : base(setmaster) - { - } - - protected List controlable = new List { + protected List controlable = [ "BotClientService", "RLVService", "HttpService", @@ -37,7 +33,7 @@ namespace SecondBotEvents.Commands "TriggerOnEventService", "RelayService", "ChatGptService" - }; + ]; [About("Marks a service as enabled and starts it")] [ReturnHints("ok")] diff --git a/SecondBotEvents/Commands/StreamAdmin.cs b/SecondBotEvents/Commands/StreamAdmin.cs index a916859..4937a61 100644 --- a/SecondBotEvents/Commands/StreamAdmin.cs +++ b/SecondBotEvents/Commands/StreamAdmin.cs @@ -7,13 +7,8 @@ using System; namespace SecondBotEvents.Commands { [ClassInfo("Interface for streamadmin to create notecards, you will prob never need this")] - public class StreamAdmin : CommandsAPI + public class StreamAdmin(EventsSecondBot setmaster) : CommandsAPI(setmaster) { - public StreamAdmin(EventsSecondBot setmaster) : base(setmaster) - { - } - - [About("A streamadin command")] [ReturnHints("True|False")] [ReturnHintsFailure("Bad reply: ...")] @@ -28,11 +23,11 @@ namespace SecondBotEvents.Commands { if (SecondbotHelpers.notempty(endpoint) == false) { - return Failure("Endpoint is empty", new [] { endpoint, endpointcode }); + return Failure("Endpoint is empty", [endpoint, endpointcode]); } if (SecondbotHelpers.notempty(endpointcode) == false) { - return Failure("Endpointcode is empty", new [] { endpoint, endpointcode }); + return Failure("Endpointcode is empty", [endpoint, endpointcode]); } string attempt_endpoint = endpoint + "sys.php"; @@ -48,34 +43,34 @@ namespace SecondBotEvents.Commands RestResponse endpoint_checks = client.ExecutePostAsync(request).Result; if (endpoint_checks.StatusCode != System.Net.HttpStatusCode.OK) { - return Failure("HTTP status code: " + endpoint_checks.StatusCode.ToString(), new [] { endpoint, endpointcode }); + return Failure("HTTP status code: " + endpoint_checks.StatusCode.ToString(), [endpoint, endpointcode]); } try { NotecardEndpoint server_reply = JsonConvert.DeserializeObject(endpoint_checks.Content); if (server_reply.status == false) { - return Failure("Bad reply: " + server_reply.message, new [] { endpoint, endpointcode }); + return Failure("Bad reply: " + server_reply.message, [endpoint, endpointcode]); } if (server_reply.NotecardTitle.Length < 3) { - return Failure("Notecard title is to short", new [] { endpoint, endpointcode }); + return Failure("Notecard title is to short", [endpoint, endpointcode]); } ProcessAvatar(server_reply.AvatarUUID); if(avataruuid == UUID.Zero) { - return Failure("Unable to unpack avatar", new[] { endpoint, endpointcode }); + return Failure("Unable to unpack avatar", [endpoint, endpointcode]); } bool result = master.BotClient.SendNotecard(server_reply.NotecardTitle, server_reply.NotecardContent, avataruuid); if (result == false) { - return Failure("Failed to create/send notecard", new[] { endpoint, endpointcode }); + return Failure("Failed to create/send notecard", [endpoint, endpointcode]); } return BasicReply("ok"); } catch (Exception e) { - return Failure("Error: " + e.Message + "", new [] { endpoint, endpointcode }); + return Failure("Error: " + e.Message + "", [endpoint, endpointcode]); } } diff --git a/SecondBotEvents/Config/BasicConfig.cs b/SecondBotEvents/Config/BasicConfig.cs index 6bb6c25..d1c6e7d 100644 --- a/SecondBotEvents/Config/BasicConfig.cs +++ b/SecondBotEvents/Config/BasicConfig.cs @@ -4,9 +4,8 @@ using System.Text; namespace SecondBotEvents.Config { - public class BasicConfig : Config + public class BasicConfig(bool fromENV, string fromFolder = "") : Config(fromENV, fromFolder) { - public BasicConfig(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } protected override void MakeSettings() { filename = "basic"; diff --git a/SecondBotEvents/Config/ChatGptConfig.cs b/SecondBotEvents/Config/ChatGptConfig.cs index dbe61c8..1163d3e 100644 --- a/SecondBotEvents/Config/ChatGptConfig.cs +++ b/SecondBotEvents/Config/ChatGptConfig.cs @@ -5,9 +5,8 @@ using System.Text; namespace SecondBotEvents.Config { - public class ChatGptConfig : Config + public class ChatGptConfig(bool fromENV, string fromFolder = "") : Config(fromENV, fromFolder) { - public ChatGptConfig(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } protected override void MakeSettings() { filename = "chatgpt"; diff --git a/SecondBotEvents/Config/CommandsConfig.cs b/SecondBotEvents/Config/CommandsConfig.cs index 0e21a6b..9abd88f 100644 --- a/SecondBotEvents/Config/CommandsConfig.cs +++ b/SecondBotEvents/Config/CommandsConfig.cs @@ -5,9 +5,8 @@ using System.Linq; namespace SecondBotEvents.Config { - public class CommandsConfig : Config + public class CommandsConfig(bool fromENV, string fromFolder = "") : Config(fromENV, fromFolder) { - public CommandsConfig(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } protected override void MakeSettings() { filename = "commands"; @@ -22,8 +21,15 @@ namespace SecondBotEvents.Config settings.Add("Enabled"); settings.Add("ObjectMasterOptout"); settings.Add("AllowServiceControl"); + settings.Add("CommandHistoryLogResults"); settings.Add("HideStatusOutput"); } + + + public bool GetCommandHistoryLogResults() + { + return ReadSettingAsBool("CommandHistoryLogResults", false); + } public bool GetAllowServiceControl() { return ReadSettingAsBool("AllowServiceControl", false); diff --git a/SecondBotEvents/Config/CustomCommandsConfig.cs b/SecondBotEvents/Config/CustomCommandsConfig.cs index e820c0b..325059a 100644 --- a/SecondBotEvents/Config/CustomCommandsConfig.cs +++ b/SecondBotEvents/Config/CustomCommandsConfig.cs @@ -4,10 +4,8 @@ using System.Text; namespace SecondBotEvents.Config { - public class CustomCommandsConfig : Config + public class CustomCommandsConfig(bool fromENV, string fromFolder = "") : Config(fromENV, fromFolder) { - public CustomCommandsConfig(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } - protected override void MakeSettings() { filename = "customcommands"; diff --git a/SecondBotEvents/Config/DataStoreConfig.cs b/SecondBotEvents/Config/DataStoreConfig.cs index 248b754..fbdfb9e 100644 --- a/SecondBotEvents/Config/DataStoreConfig.cs +++ b/SecondBotEvents/Config/DataStoreConfig.cs @@ -4,9 +4,8 @@ using System.Text; namespace SecondBotEvents.Config { - public class DataStoreConfig : Config + public class DataStoreConfig(bool fromENV, string fromFolder = "") : Config(fromENV, fromFolder) { - public DataStoreConfig(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } protected override void MakeSettings() { filename = "datastore"; @@ -24,6 +23,7 @@ namespace SecondBotEvents.Config settings.Add("HideStatusOutput"); } + public int GetCommandHistoryLimit() { return ReadSettingAsInt("CommandHistoryLimit", 30); diff --git a/SecondBotEvents/Config/DialogRelayConfig.cs b/SecondBotEvents/Config/DialogRelayConfig.cs index 4b8bf14..725925e 100644 --- a/SecondBotEvents/Config/DialogRelayConfig.cs +++ b/SecondBotEvents/Config/DialogRelayConfig.cs @@ -5,9 +5,8 @@ using System.Text; namespace SecondBotEvents.Config { - public class DialogRelayConfig : Config + public class DialogRelayConfig(bool fromENV, string fromFolder = "") : Config(fromENV, fromFolder) { - public DialogRelayConfig(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } protected override void MakeSettings() { filename = "dialogrelay"; diff --git a/SecondBotEvents/Config/DiscordConfig.cs b/SecondBotEvents/Config/DiscordConfig.cs index 31efe0b..5e92d7b 100644 --- a/SecondBotEvents/Config/DiscordConfig.cs +++ b/SecondBotEvents/Config/DiscordConfig.cs @@ -4,9 +4,8 @@ using System.Text; namespace SecondBotEvents.Config { - public class DiscordConfig : Config + public class DiscordConfig(bool fromENV, string fromFolder = "") : Config(fromENV, fromFolder) { - public DiscordConfig(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } protected override void MakeSettings() { filename = "discord"; diff --git a/SecondBotEvents/Config/EventsConfig.cs b/SecondBotEvents/Config/EventsConfig.cs index bd7a9f6..46b4bea 100644 --- a/SecondBotEvents/Config/EventsConfig.cs +++ b/SecondBotEvents/Config/EventsConfig.cs @@ -5,9 +5,8 @@ using System.Text; namespace SecondBotEvents.Config { - public class EventsConfig : Config + public class EventsConfig(bool fromENV, string fromFolder = "") : Config(fromENV, fromFolder) { - public EventsConfig(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } protected override void MakeSettings() { filename = "events"; diff --git a/SecondBotEvents/Config/HomeboundConfig.cs b/SecondBotEvents/Config/HomeboundConfig.cs index d697d75..26ba1f2 100644 --- a/SecondBotEvents/Config/HomeboundConfig.cs +++ b/SecondBotEvents/Config/HomeboundConfig.cs @@ -5,9 +5,8 @@ using System.Text; namespace SecondBotEvents.Config { - public class HomeboundConfig : Config + public class HomeboundConfig(bool fromENV, string fromFolder = "") : Config(fromENV, fromFolder) { - public HomeboundConfig(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } protected override void MakeSettings() { filename = "homebound"; diff --git a/SecondBotEvents/Config/HttpConfig.cs b/SecondBotEvents/Config/HttpConfig.cs index a85af31..0843c4e 100644 --- a/SecondBotEvents/Config/HttpConfig.cs +++ b/SecondBotEvents/Config/HttpConfig.cs @@ -4,9 +4,8 @@ using System.Text; namespace SecondBotEvents.Config { - public class HttpConfig: Config + public class HttpConfig(bool fromENV, string fromFolder = "") : Config(fromENV, fromFolder) { - public HttpConfig(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } protected override void MakeSettings() { filename = "http"; diff --git a/SecondBotEvents/Config/InteractionConfig.cs b/SecondBotEvents/Config/InteractionConfig.cs index 9612224..792c728 100644 --- a/SecondBotEvents/Config/InteractionConfig.cs +++ b/SecondBotEvents/Config/InteractionConfig.cs @@ -4,9 +4,8 @@ using System.Text; namespace SecondBotEvents.Config { - public class InteractionConfig : Config + public class InteractionConfig(bool fromENV, string fromFolder = "") : Config(fromENV, fromFolder) { - public InteractionConfig(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } protected override void MakeSettings() { filename = "interaction"; diff --git a/SecondBotEvents/Config/OnEventConfig.cs b/SecondBotEvents/Config/OnEventConfig.cs index eab78a8..e5ab388 100644 --- a/SecondBotEvents/Config/OnEventConfig.cs +++ b/SecondBotEvents/Config/OnEventConfig.cs @@ -6,9 +6,8 @@ using System.Text; namespace SecondBotEvents.Config { - public class OnEventConfig : Config + public class OnEventConfig(bool fromENV, string fromFolder = "") : Config(fromENV, fromFolder) { - public OnEventConfig(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } protected override void MakeSettings() { filename = "onevent"; diff --git a/SecondBotEvents/Config/RelayConfig.cs b/SecondBotEvents/Config/RelayConfig.cs index b02772f..b5ad5ec 100644 --- a/SecondBotEvents/Config/RelayConfig.cs +++ b/SecondBotEvents/Config/RelayConfig.cs @@ -5,10 +5,8 @@ using System.Text; namespace SecondBotEvents.Config { - public class RelayConfig : Config + public class RelayConfig(bool fromENV, string fromFolder = "") : Config(fromENV, fromFolder) { - public RelayConfig(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } - protected override void MakeSettings() { filename = "relay"; @@ -100,13 +98,13 @@ namespace SecondBotEvents.Config } // config not unpacked from string lets unpack it string config = ReadSettingAsString(relayID.ToString() + "_RelayConfig", ""); - UnpackedConfigs.Add(relayID, new Dictionary()); + UnpackedConfigs.Add(relayID, []); if (config == "") { return UnpackedConfigs[relayID]; } string[] bits = config.Split("{}", StringSplitOptions.RemoveEmptyEntries); - Dictionary data = new Dictionary(); + Dictionary data = []; foreach(string A in bits) { string[] B = A.Split("::", StringSplitOptions.RemoveEmptyEntries); @@ -122,7 +120,7 @@ namespace SecondBotEvents.Config { return UnpackedConfigs[relayID]; } - List checks = new List() { "sType", "sFilter", "tType", "tConfig" }; + List checks = ["sType", "sFilter", "tType", "tConfig"]; bool allfound = true; foreach (string A in checks) { @@ -139,7 +137,7 @@ namespace SecondBotEvents.Config return UnpackedConfigs[relayID]; } - protected Dictionary> UnpackedConfigs = new Dictionary>(); + protected Dictionary> UnpackedConfigs = []; } diff --git a/SecondBotEvents/Config/RlvConfig.cs b/SecondBotEvents/Config/RlvConfig.cs index 14c97b1..b5b8ac2 100644 --- a/SecondBotEvents/Config/RlvConfig.cs +++ b/SecondBotEvents/Config/RlvConfig.cs @@ -4,9 +4,8 @@ using System.Text; namespace SecondBotEvents.Config { - public class RlvConfig : Config + public class RlvConfig(bool fromENV, string fromFolder = "") : Config(fromENV, fromFolder) { - public RlvConfig(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } protected override void MakeSettings() { filename = "rlv"; diff --git a/SecondBotEvents/Config/SmtpConfig.cs b/SecondBotEvents/Config/SmtpConfig.cs index c7e8907..95a574f 100644 --- a/SecondBotEvents/Config/SmtpConfig.cs +++ b/SecondBotEvents/Config/SmtpConfig.cs @@ -4,9 +4,8 @@ using System.Text; namespace SecondBotEvents.Config { - public class SmtpConfig : Config + public class SmtpConfig(bool fromENV, string fromFolder = "") : Config(fromENV, fromFolder) { - public SmtpConfig(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } protected override void MakeSettings() { filename = "smtp"; diff --git a/SecondBotEvents/Config/config.cs b/SecondBotEvents/Config/config.cs index cb81c84..e8ae4bc 100644 --- a/SecondBotEvents/Config/config.cs +++ b/SecondBotEvents/Config/config.cs @@ -12,8 +12,8 @@ namespace SecondBotEvents.Config { public abstract class Config { - protected Dictionary mysettings = new Dictionary(); - protected List settings = new List(); + protected Dictionary mysettings = []; + protected List settings = []; protected string filename = "config"; protected bool loaded = false; protected bool tryLoadfromEnv = false; @@ -60,7 +60,7 @@ namespace SecondBotEvents.Config protected void MakeSettingsFile(string fromFolder) { - Dictionary saveMe = new Dictionary(); + Dictionary saveMe = []; Type thisType = this.GetType(); foreach (string setting in settings) { @@ -73,7 +73,7 @@ namespace SecondBotEvents.Config string value = theMethod.Invoke(this, null).ToString(); saveMe.Add(setting, value); } - SimpleIO IO = new SimpleIO(); + SimpleIO IO = new(); IO.ChangeRoot(fromFolder); string writeFile = filename + ".json"; IO.WriteFile(writeFile, JsonConvert.SerializeObject(saveMe)); @@ -81,7 +81,7 @@ namespace SecondBotEvents.Config } protected void LoadSettingsFromFile(string fromFolder) { - SimpleIO IO = new SimpleIO(); + SimpleIO IO = new(); IO.ChangeRoot(fromFolder); string readfile = filename + ".json"; if (IO.Exists(readfile) == false) diff --git a/SecondBotEvents/EventsSecondBot.cs b/SecondBotEvents/EventsSecondBot.cs index 79060e3..91294b2 100644 --- a/SecondBotEvents/EventsSecondBot.cs +++ b/SecondBotEvents/EventsSecondBot.cs @@ -15,7 +15,7 @@ namespace SecondBotEvents new WikiMake(); #endif LogFormater.Info("Welcome to Secondbot [Events build] version: " + AssemblyInfo.GetGitHash()); - EventsSecondBot worker = new EventsSecondBot(args); + EventsSecondBot worker = new(args); while (worker.Exit() == false) { @@ -62,7 +62,7 @@ namespace SecondBotEvents remove { lock (SystemStatusMessagesEventsLockable) { SystemStatusMessages -= value; } } } - private readonly object SystemStatusMessagesEventsLockable = new object(); + private readonly object SystemStatusMessagesEventsLockable = new(); public void TriggerSystemStatusMessageEvent(bool change, string message) { @@ -76,7 +76,7 @@ namespace SecondBotEvents add { lock (BotclientEventNoticesLockable) { BotclientEventNotices += value; } } remove { lock (BotclientEventNoticesLockable) { BotclientEventNotices -= value; } } } - private readonly object BotclientEventNoticesLockable = new object(); + private readonly object BotclientEventNoticesLockable = new(); public void TriggerBotClientEvent(bool asRestart,bool asDC) { @@ -118,7 +118,7 @@ namespace SecondBotEvents StartServices(); } - protected Dictionary services = new Dictionary(); + protected Dictionary services = []; public BotServices GetService(string classname) { @@ -157,8 +157,8 @@ namespace SecondBotEvents public void StartServices() { Ready = false; - services = new Dictionary(); - lastStatus = new Dictionary(); + services = []; + lastStatus = []; StopService("RecoveryService"); // kill the recovery service if its still running RegisterService("BotClientService", false); RegisterService("DataStoreService"); @@ -187,7 +187,7 @@ namespace SecondBotEvents Ready = true; } - Dictionary lastStatus = new Dictionary(); + Dictionary lastStatus = []; public void Status() { string Output = ""; @@ -277,14 +277,9 @@ namespace SecondBotEvents } } - public class SystemStatusMessage + public class SystemStatusMessage(bool setChanged, string setMessage) { - public bool changed = false; - public string message = ""; - public SystemStatusMessage(bool setChanged, string setMessage) - { - changed = setChanged; - message = setMessage; - } + public bool changed = setChanged; + public string message = setMessage; } } diff --git a/SecondBotEvents/RLV/RLVEventArgs.cs b/SecondBotEvents/RLV/RLVEventArgs.cs index 92124df..1d5d13a 100644 --- a/SecondBotEvents/RLV/RLVEventArgs.cs +++ b/SecondBotEvents/RLV/RLVEventArgs.cs @@ -22,13 +22,8 @@ using System; namespace SecondBotEvents.RLV { - public class RLVEventArgs : EventArgs + public class RLVEventArgs(RLVRule rule) : EventArgs { - public RLVRule Rule { set; get; } - - public RLVEventArgs(RLVRule rule) - { - Rule = rule; - } + public RLVRule Rule { set; get; } = rule; } } \ No newline at end of file diff --git a/SecondBotEvents/Services/BotClientService.cs b/SecondBotEvents/Services/BotClientService.cs index 12261d4..e125e39 100644 --- a/SecondBotEvents/Services/BotClientService.cs +++ b/SecondBotEvents/Services/BotClientService.cs @@ -60,9 +60,11 @@ namespace SecondBotEvents.Services { running = true; LogFormater.Info("Client service [Starting]"); - AutoRestartLoginTimer = new Timer(); - AutoRestartLoginTimer.Interval = 30 * 1000; - AutoRestartLoginTimer.AutoReset = false; + AutoRestartLoginTimer = new Timer + { + Interval = 30 * 1000, + AutoReset = false + }; AutoRestartLoginTimer.Elapsed += RestartTimer; Login(); } @@ -137,7 +139,7 @@ namespace SecondBotEvents.Services { if (Success) { - AssetNotecard empty = new AssetNotecard { BodyText = "\n" }; + AssetNotecard empty = new() { BodyText = "\n" }; empty.Encode(); client.Inventory.RequestUploadNotecardAsset(empty.AssetData, item.UUID, (bool emptySuccess, string emptyStatus, UUID emptyItemID, UUID emptyAssetID) => @@ -195,7 +197,7 @@ namespace SecondBotEvents.Services ResetClient(); goodticks = 0; master.TriggerBotClientEvent(false, false); - LoginParams loginParams = new LoginParams( + LoginParams loginParams = new( client, basicCfg.GetFirstName(), basicCfg.GetLastName(), diff --git a/SecondBotEvents/Services/ChatGptService.cs b/SecondBotEvents/Services/ChatGptService.cs index 60fe3fd..5c1101e 100644 --- a/SecondBotEvents/Services/ChatGptService.cs +++ b/SecondBotEvents/Services/ChatGptService.cs @@ -49,7 +49,7 @@ namespace SecondBotEvents.Services { try { - ConfigurationOptions configRedis = new ConfigurationOptions() + ConfigurationOptions configRedis = new() { EndPoints = { myConfig.GetRedisSource() } }; @@ -120,7 +120,7 @@ namespace SecondBotEvents.Services return "Enabled No chat history"; } - readonly string[] hard_blocked_agents = new[] { "secondlife", "second life" }; + readonly string[] hard_blocked_agents = ["secondlife", "second life"]; protected void BotLocalchat(object o, ChatEventArgs e) { if (e.SourceID == GetClient().Self.AgentID) @@ -220,9 +220,9 @@ namespace SecondBotEvents.Services } } - Dictionary>> chatHistoryAI = new Dictionary>>(); - Dictionary ChatHistoryLastAccessed = new Dictionary(); - Dictionary ChatRateLimiter = new Dictionary(); + Dictionary>> chatHistoryAI = []; + Dictionary ChatHistoryLastAccessed = []; + Dictionary ChatRateLimiter = []; protected long lastUpkeep = 0; protected void upkeep() @@ -236,7 +236,7 @@ namespace SecondBotEvents.Services // check for expired chat windows (longer than 2 mins from last message) lock (ChatHistoryLastAccessed) lock (chatHistoryAI) lock (ChatRateLimiter) { - List needcleaning = new List(); + List needcleaning = []; long now = SecondbotHelpers.UnixTimeNow(); foreach (KeyValuePair entry in ChatHistoryLastAccessed) { @@ -292,7 +292,7 @@ namespace SecondBotEvents.Services // are we using redis? if (RedisLive() == false) { - return new List>(); + return []; } // is redis enabled for this message type? if ((myConfig.GetRedisImchat() == true) && (avatarchat == true)) @@ -311,7 +311,7 @@ namespace SecondBotEvents.Services return ReadChatFromRedis(store); } // Redis is not enabled for this message type, use local storage - return new List>(); + return []; } @@ -319,7 +319,7 @@ namespace SecondBotEvents.Services { try { - RedisKey readkey = new RedisKey(myConfig.GetRedisPrefix() + store.Guid.ToString()); + RedisKey readkey = new(myConfig.GetRedisPrefix() + store.Guid.ToString()); if (redisDb.KeyExists(readkey) == false) { string rawstring = redisDb.StringGet(readkey); @@ -343,7 +343,7 @@ namespace SecondBotEvents.Services { if (chatHistoryAI.ContainsKey(store) == false) { - return new List>(); + return []; } return chatHistoryAI[store]; } @@ -363,7 +363,7 @@ namespace SecondBotEvents.Services if (chatHistoryAI.ContainsKey(store) == false) { // totaly new chat build it out - chatHistoryAI.Add(store, new List>()); + chatHistoryAI.Add(store, []); string yourname = GetClient().Self.FirstName; if (myConfig.GetCustomName() != "") { @@ -437,7 +437,7 @@ namespace SecondBotEvents.Services { history.RemoveAt(1); } - RedisKey writekey = new RedisKey(myConfig.GetRedisPrefix() + store.Guid.ToString()); + RedisKey writekey = new(myConfig.GetRedisPrefix() + store.Guid.ToString()); try { string savestring = JsonConvert.SerializeObject(history); @@ -446,7 +446,7 @@ namespace SecondBotEvents.Services LogFormater.Warn("Redis failed to convert history into savable format"); return false; } - RedisValue storeme = new RedisValue(savestring); + RedisValue storeme = new(savestring); if(redisDb.StringSet(writekey, storeme) == true) { return redisDb.KeyExpire(writekey, TimeSpan.FromMinutes(myConfig.GetRedisMaxageMins())); @@ -506,7 +506,7 @@ namespace SecondBotEvents.Services { ChatRateLimiter[user] = SecondbotHelpers.UnixTimeNow() + 1; } - List messages = new List(); + List messages = []; lock (chatHistoryAI) lock (ChatHistoryLastAccessed) { // convert history into the AI format while adding the new message @@ -646,7 +646,7 @@ namespace SecondBotEvents.Services } } - private static readonly Random _random = new Random(); + private static readonly Random _random = new(); public static double EstimateTypingTime(string input, double randomizationFactor) { diff --git a/SecondBotEvents/Services/CommandsService.cs b/SecondBotEvents/Services/CommandsService.cs index d46c158..37107f8 100644 --- a/SecondBotEvents/Services/CommandsService.cs +++ b/SecondBotEvents/Services/CommandsService.cs @@ -13,19 +13,13 @@ using System.ComponentModel.DataAnnotations; namespace SecondBotEvents.Services { - public class BotCommandNotice + public class BotCommandNotice(string Setcommand, string Setargs, string Setsource, bool Setaccepted, string Setresults) { - public string command; - public string args; - public string source; - public bool accepted; - public BotCommandNotice(string Setcommand, string Setargs, string Setsource, bool Setaccepted) - { - command = Setcommand; - args = Setargs; - source = Setsource; - accepted = Setaccepted; - } + public string command = Setcommand; + public string args = Setargs; + public string source = Setsource; + public bool accepted = Setaccepted; + public string results = Setresults; } public class CommandsService : BotServices { @@ -35,10 +29,10 @@ namespace SecondBotEvents.Services add { lock (BotCommandNoticeLockable) { BotclientCommandEventNotices += value; } } remove { lock (BotCommandNoticeLockable) { BotclientCommandEventNotices -= value; } } } - private readonly object BotCommandNoticeLockable = new object(); + private readonly object BotCommandNoticeLockable = new(); - public CommandsConfig myConfig = null; + public new CommandsConfig myConfig = null; public bool acceptNewCommands = false; public CommandsService(EventsSecondBot setMaster) : base(setMaster) { @@ -66,7 +60,7 @@ namespace SecondBotEvents.Services protected virtual void LoadCommandEndpoint(Type endpointtype) { - CommandsAPI controler = (CommandsAPI)Activator.CreateInstance(endpointtype, args: new object[] { master }); + CommandsAPI controler = (CommandsAPI)Activator.CreateInstance(endpointtype, args: [master]); commandEndpoints.Add(endpointtype.Name, controler); foreach (MethodInfo M in endpointtype.GetMethods()) { @@ -221,7 +215,7 @@ namespace SecondBotEvents.Services { source = "customcommand"; } - SignedCommand C = new SignedCommand(this,source,message,requireSigning,myConfig.GetEnforceTimeWindow(),myConfig.GetTimeWindowSecs(),myConfig.GetSharedSecret()); + SignedCommand C = new(this,source,message,requireSigning,myConfig.GetEnforceTimeWindow(),myConfig.GetTimeWindowSecs(),myConfig.GetSharedSecret()); if (C.accepted == false) { return new KeyValuePair(false, "Not accepted via signing"); @@ -276,8 +270,8 @@ namespace SecondBotEvents.Services } else if (mode == "HTTP") { - Dictionary values = new Dictionary - { + Dictionary values = new() + { { "reply", output }, { "command", command }, }; @@ -301,7 +295,7 @@ namespace SecondBotEvents.Services } } } - protected HttpClient HTTPclient = new HttpClient(); + protected HttpClient HTTPclient = new(); protected KeyValuePair RunBaseCommand(SignedCommand C, string source) { @@ -311,10 +305,10 @@ namespace SecondBotEvents.Services MethodInfo theMethod = Endpoint.GetType().GetMethod(C.command); if (theMethod != null) { - List argsList = C.args.ToList(); - string reply = "Inconnect number of args expected: " + theMethod.GetParameters().Count().ToString() + " but got: " + argsList.Count.ToString(); + List argsList = [.. C.args]; + string reply = "Inconnect number of args expected: " + theMethod.GetParameters().Length.ToString() + " but got: " + argsList.Count.ToString(); bool status = false; - if (argsList.Count == theMethod.GetParameters().Count()) + if (argsList.Count == theMethod.GetParameters().Length) { status = true; try @@ -323,23 +317,23 @@ namespace SecondBotEvents.Services { return new KeyValuePair(false, "Endpoint is null"); } - object[] argsWorker = argsList.ToArray(); + object[] argsWorker = [.. argsList]; object processed = theMethod.Invoke(Endpoint, argsWorker); reply = "Error"; if (processed != null) { reply = JsonConvert.SerializeObject(processed); } - CommandNotice(C.command, source, String.Join("@@@", C.args), true); + CommandNotice(C.command, source, String.Join("@@@", C.args), true, reply); return new KeyValuePair(status, reply); } catch (Exception e) { - CommandNotice(C.command, source+" ~~ Failure: "+e.Message, String.Join("@@@", C.args), false); + CommandNotice(C.command, source+" ~~ Failure: "+e.Message, String.Join("@@@", C.args), false, e.Message); return new KeyValuePair(false, e.Message); } } - CommandNotice(C.command, source + " ~~ Failure: incorrect number of args expected: "+ theMethod.GetParameters().Count().ToString()+" but got "+ argsList.Count.ToString()+"", String.Join("@@@", C.args), false); + CommandNotice(C.command, source + " ~~ Failure: incorrect number of args expected: "+ theMethod.GetParameters().Length.ToString()+" but got "+ argsList.Count.ToString()+"", String.Join("@@@", C.args), false, "no results"); return new KeyValuePair(status, reply); } return new KeyValuePair(false, "theMethod is null"); @@ -392,17 +386,17 @@ namespace SecondBotEvents.Services public string[] GetFullListOfCommands() { - List output = new List(); + List output = []; foreach (string A in endpointcommandmap.Keys) { output.Add(A.ToLowerInvariant()); } - return output.ToArray(); + return [.. output]; } - protected Dictionary commandEndpoints = new Dictionary(); - protected Dictionary endpointcommandmap = new Dictionary(); // command = endpoint - protected Dictionary commandnameLowerToReal = new Dictionary(); + protected Dictionary commandEndpoints = []; + protected Dictionary endpointcommandmap = []; // command = endpoint + protected Dictionary commandnameLowerToReal = []; protected void BotClientRestart(object o, BotClientNotice e) { @@ -440,9 +434,13 @@ namespace SecondBotEvents.Services LogFormater.Info("Commands service [accepting IM commands]"); } - public void CommandNotice(string command,string source, string args,bool accepted) + public void CommandNotice(string command,string source, string args,bool accepted, string results) { - BotCommandNotice e = new BotCommandNotice(command, args, source, accepted); + if(myConfig.GetCommandHistoryLogResults() == false) + { + results = ""; + } + BotCommandNotice e = new(command, args, source, accepted, results); EventHandler handler = BotclientCommandEventNotices; handler?.Invoke(this, e); if(master.BotClient.basicCfg.GetLogCommands() == true) @@ -561,7 +559,7 @@ namespace SecondBotEvents.Services command = bits[0]; // command // args~#~args~#~args - args = new string[] { }; + args = []; if(bits.Length == 2) { args = bits[1].Split("~#~"); diff --git a/SecondBotEvents/Services/CurrentOutfitFolder.cs b/SecondBotEvents/Services/CurrentOutfitFolder.cs index e0ca856..adb974b 100644 --- a/SecondBotEvents/Services/CurrentOutfitFolder.cs +++ b/SecondBotEvents/Services/CurrentOutfitFolder.cs @@ -12,23 +12,19 @@ using static SecondBotEvents.Services.RLVService; namespace SecondBotEvents.Services { - public class CurrentOutfitFolder : BotServices + public class CurrentOutfitFolder(EventsSecondBot setMaster) : BotServices(setMaster) { #region Fields private bool InitiCOF = false; private bool AppearanceSent = false; private bool COFReady = false; private bool InitialUpdateDone = false; - public Dictionary Content = new Dictionary(); + public Dictionary Content = []; public InventoryFolder COF; protected bool botConnected = false; #endregion Fields - #region Construction and disposal - public CurrentOutfitFolder(EventsSecondBot setMaster) : base(setMaster) - { - } public override string Status() { @@ -156,7 +152,7 @@ namespace SecondBotEvents.Services } } - private readonly object FolderSync = new object(); + private readonly object FolderSync = new(); private void Inventory_FolderUpdated(object sender, FolderUpdatedEventArgs e) { @@ -170,8 +166,8 @@ namespace SecondBotEvents.Services lock (Content) Content.Clear(); - List items = new List(); - List owners = new List(); + List items = []; + List owners = []; foreach (var link in ContentLinks()) { @@ -198,8 +194,7 @@ namespace SecondBotEvents.Services { if (GetClient().Network.CurrentSim != e.Simulator) return; - Primitive prim = null; - if (GetClient().Network.CurrentSim.ObjectsPrimitives.TryGetValue(e.ObjectLocalID, out prim)) + if (GetClient().Network.CurrentSim.ObjectsPrimitives.TryGetValue(e.ObjectLocalID, out Primitive prim)) { UUID invItem = GetAttachmentItem(prim); if (invItem != UUID.Zero) @@ -417,7 +412,7 @@ namespace SecondBotEvents.Services /// ID of the target inventory item for which we want link to be removed public void RemoveLink(UUID itemID) { - RemoveLink(new List(1) { itemID }); + RemoveLink([itemID]); } /// @@ -539,7 +534,7 @@ namespace SecondBotEvents.Services /// Should existing wearable of the same type be removed public void AddToOutfit(InventoryItem item, bool replace) { - AddToOutfit(new List(1) { item }, replace); + AddToOutfit([item], replace); } /// @@ -607,7 +602,7 @@ namespace SecondBotEvents.Services /// Item to remove public void RemoveFromOutfit(InventoryItem item) { - RemoveFromOutfit(new List(1) { item }); + RemoveFromOutfit([item]); } /// diff --git a/SecondBotEvents/Services/CustomCommandsService.cs b/SecondBotEvents/Services/CustomCommandsService.cs index d18c916..5aba8c3 100644 --- a/SecondBotEvents/Services/CustomCommandsService.cs +++ b/SecondBotEvents/Services/CustomCommandsService.cs @@ -13,7 +13,7 @@ namespace SecondBotEvents.Services { protected new CustomCommandsConfig myConfig; protected bool botConnected = false; - protected Dictionary commands = new Dictionary(); + protected Dictionary commands = []; public bool HasCommand(string C) { return commands.ContainsKey(C); @@ -57,9 +57,11 @@ namespace SecondBotEvents.Services int loop = 1; while(loop <= myConfig.GetCount()) { - CustomCommand C = new CustomCommand(); - C.trigger = myConfig.GetCommandTrigger(loop); - C.args = myConfig.GetCommandArgs(loop); + CustomCommand C = new() + { + trigger = myConfig.GetCommandTrigger(loop), + args = myConfig.GetCommandArgs(loop) + }; int loop2 = 1; while(loop2 <= myConfig.GetCommandSteps(loop)) { @@ -127,6 +129,6 @@ namespace SecondBotEvents.Services { public string trigger = ""; public int args = 0; - public List steps = new List(); + public List steps = []; } } diff --git a/SecondBotEvents/Services/DataStoreService.cs b/SecondBotEvents/Services/DataStoreService.cs index 82e3963..5f9ad14 100644 --- a/SecondBotEvents/Services/DataStoreService.cs +++ b/SecondBotEvents/Services/DataStoreService.cs @@ -21,25 +21,25 @@ namespace SecondBotEvents.Services myConfig = new DataStoreConfig(master.fromEnv,master.fromFolder); } - protected Dictionary avatarsName2Key = new(); - protected Dictionary avatarLastUsed = new(); + protected Dictionary avatarsName2Key = []; + protected Dictionary avatarLastUsed = []; - protected Dictionary groupsKey2Name = new(); + protected Dictionary groupsKey2Name = []; - protected Dictionary> groupMembers = new(); - protected Dictionary> groupRoles = new(); + protected Dictionary> groupMembers = []; + protected Dictionary> groupRoles = []; - protected List localChatHistory = new(); + protected List localChatHistory = []; - protected Dictionary> chatWindows = new(); // sess, list chat - protected Dictionary chatWindowsUnread = new(); // sess, bool - protected Dictionary chatWindowsIsGroup = new(); // sess, bool - protected Dictionary chatWindowsOwner = new(); // sess, owner id + protected Dictionary> chatWindows = []; // sess, list chat + protected Dictionary chatWindowsUnread = []; // sess, bool + protected Dictionary chatWindowsIsGroup = []; // sess, bool + protected Dictionary chatWindowsOwner = []; // sess, owner id - protected Dictionary KeyValueStore = new(); - protected Dictionary KeyValueStoreLastUsed = new(); + protected Dictionary KeyValueStore = []; + protected Dictionary KeyValueStoreLastUsed = []; - protected List commandHistories = new(); + protected List commandHistories = []; @@ -47,8 +47,8 @@ namespace SecondBotEvents.Services protected long lastCleanupKeyValueStore = 0; protected long lastCleanupAvatarStore = 0; - protected List acceptedStores = new List() { "FriendRequest", "InventoryOffer", "GroupInvite", "Teleport" }; - protected Dictionary> AcceptNextStore = new Dictionary>(); + protected List acceptedStores = ["FriendRequest", "InventoryOffer", "GroupInvite", "Teleport"]; + protected Dictionary> AcceptNextStore = []; public bool KnownStoreType(string storeType) { return acceptedStores.Contains(storeType); @@ -82,7 +82,7 @@ namespace SecondBotEvents.Services } if(AcceptNextStore.ContainsKey(store) == false) { - AcceptNextStore.Add(store, new List()); + AcceptNextStore.Add(store, []); } if(AcceptNextStore[store].Contains(avatar) == true) { @@ -155,7 +155,7 @@ namespace SecondBotEvents.Services if (dif > 125) { lastCleanupKeyValueStore = unixtime; - List clearentrys = new(); + List clearentrys = []; foreach (KeyValuePair entry in KeyValueStoreLastUsed) { dif = unixtime - entry.Value; @@ -185,7 +185,7 @@ namespace SecondBotEvents.Services if (dif > 75) { lastCleanupAvatarStore = unixtime; - Dictionary clearLinks = new(); + Dictionary clearLinks = []; foreach (KeyValuePair entry in avatarsName2Key) { dif = unixtime - avatarLastUsed[entry.Value]; @@ -212,11 +212,11 @@ namespace SecondBotEvents.Services return sum.ToString(); } - public void AddCommandToHistory(bool status, string command, string[] args) + public void AddCommandToHistory(bool status, string command, string[] args, string results=null) { lock (commandHistories) { - CommandHistory A = new(status, command, args, SecondbotHelpers.UnixTimeNow()); + CommandHistory A = new(status, command, args, SecondbotHelpers.UnixTimeNow(), results); commandHistories.Add(A); int c = commandHistories.Count; while (c > myConfig.GetCommandHistoryLimit()) @@ -290,7 +290,7 @@ namespace SecondBotEvents.Services public List GetAllGroupsChatWithUnread() { - List reply = new(); + List reply = []; foreach(KeyValuePair windowState in chatWindowsUnread) { if(windowState.Value == false) @@ -338,7 +338,7 @@ namespace SecondBotEvents.Services { if(chatWindows.ContainsKey(group) == false) { - return new List(); + return []; } chatWindowsUnread[group] = false; return chatWindows[group]; @@ -364,7 +364,7 @@ namespace SecondBotEvents.Services public Dictionary GetGroupRoles(UUID group) { - Dictionary reply = new(); + Dictionary reply = []; if (groupRoles.ContainsKey(group) == false) { @@ -401,7 +401,7 @@ namespace SecondBotEvents.Services { if (groupMembers.ContainsKey(group) == false) { - groupMembers.Add(group, new List()); + groupMembers.Add(group, []); } if (groupMembers[group].Contains(avatar) == false) { @@ -439,7 +439,7 @@ namespace SecondBotEvents.Services { if (groupMembers.ContainsKey(Group) == false) { - groupMembers.Add(Group, new List()); + groupMembers.Add(Group, []); } } return groupMembers[Group]; @@ -544,7 +544,7 @@ namespace SecondBotEvents.Services } return; // chat recovered } - chatWindows.Add(sessionID, new List()); + chatWindows.Add(sessionID, []); chatWindowsUnread.Add(sessionID, false); chatWindowsIsGroup.Add(sessionID, group); chatWindowsOwner.Add(sessionID, ownerID); @@ -553,7 +553,7 @@ namespace SecondBotEvents.Services } - protected Dictionary> notecardDataStore = new(); + protected Dictionary> notecardDataStore = []; public List GetLocalChat() { @@ -593,7 +593,7 @@ namespace SecondBotEvents.Services if (currentHash != ObjectsAvatarsHash) { ObjectsAvatarsHash = currentHash; - List avs = GetClient().Network.CurrentSim.ObjectsAvatars.Copy().Values.ToList(); + List avs = [.. GetClient().Network.CurrentSim.ObjectsAvatars.Copy().Values]; foreach (Avatar A in avs) { AddAvatar(A.ID, A.Name); @@ -662,7 +662,7 @@ namespace SecondBotEvents.Services public void GetAvatarNames(List avatars) { - List lookup = new(); + List lookup = []; foreach (UUID id in avatars) { if (avatarsName2Key.ContainsValue(id) == false) @@ -715,7 +715,7 @@ namespace SecondBotEvents.Services public Dictionary GetAvatarImWindows() { - Dictionary windows = new(); + Dictionary windows = []; foreach (KeyValuePair links in chatWindowsIsGroup) { if(links.Value == true) @@ -735,7 +735,7 @@ namespace SecondBotEvents.Services { if (chatWindowsOwner.ContainsValue(avatarId) == false) { - return new List(); + return []; } UUID sessionID = UUID.Zero; foreach (KeyValuePair links in chatWindowsOwner) @@ -748,7 +748,7 @@ namespace SecondBotEvents.Services } if(chatWindowsIsGroup[sessionID] == true) { - return new List(); + return []; } chatWindowsUnread[sessionID] = false; return chatWindows[sessionID]; @@ -780,7 +780,7 @@ namespace SecondBotEvents.Services public List GetAvatarImWindowsUnread() { - List windows = new(); + List windows = []; foreach (KeyValuePair links in chatWindowsIsGroup) { if (links.Value == true) @@ -819,23 +819,23 @@ namespace SecondBotEvents.Services { lastCleanupKeyValueStore = 0; - avatarsName2Key = new Dictionary(); + avatarsName2Key = []; - groupsKey2Name = new Dictionary(); + groupsKey2Name = []; - groupMembers = new Dictionary>(); - groupRoles = new Dictionary>(); + groupMembers = []; + groupRoles = []; - localChatHistory = new List(); + localChatHistory = []; - notecardDataStore = new Dictionary>(); + notecardDataStore = []; - chatWindows = new Dictionary>(); // sess, list chat - chatWindowsUnread = new Dictionary(); // sess, bool - chatWindowsIsGroup = new Dictionary(); // sess, bool - chatWindowsOwner = new Dictionary(); // sess, owner id + chatWindows = []; // sess, list chat + chatWindowsUnread = []; // sess, bool + chatWindowsIsGroup = []; // sess, bool + chatWindowsOwner = []; // sess, owner id - estateBanlist = new List(); + estateBanlist = []; } @@ -864,7 +864,7 @@ namespace SecondBotEvents.Services { if (groupRoles.ContainsKey(e.GroupID) == false) { - groupRoles.Add(e.GroupID, new Dictionary()); + groupRoles.Add(e.GroupID, []); } groupRoles[e.GroupID] = e.Roles; } @@ -878,7 +878,7 @@ namespace SecondBotEvents.Services { groupMembers.Remove(e.GroupID); } - groupMembers.Add(e.GroupID, new List()); + groupMembers.Add(e.GroupID, []); foreach (KeyValuePair a in e.Members) { groupMembers[e.GroupID].Add(a.Value.ID); @@ -890,7 +890,7 @@ namespace SecondBotEvents.Services { if (estateBanlist == null) { - List reply = new(); + List reply = []; AutoResetEvent fetchEvent = new(false); void callback(object sender, EstateBansReplyEventArgs e) { @@ -907,8 +907,8 @@ namespace SecondBotEvents.Services return estateBanlist; } - List estateBanlist = null; - Dictionary FriendMapLocations = new Dictionary(); + protected List estateBanlist = null; + protected Dictionary FriendMapLocations = []; public FriendLocations GetFriendMap(UUID id) { @@ -921,8 +921,7 @@ namespace SecondBotEvents.Services protected void FindFriendReply(object o, FriendFoundReplyEventArgs e) { - uint x, y; - Utils.LongToUInts(e.RegionHandle, out x, out y); + Utils.LongToUInts(e.RegionHandle, out uint x, out uint y); x /= 256; y /= 256; Dictionary FriendListCopy = GetClient().Friends.FriendList.Copy(); @@ -930,7 +929,7 @@ namespace SecondBotEvents.Services { return; } - FriendLocations NewEntry = new FriendLocations(FriendListCopy[e.AgentID].Name, e.Location, new Vector3(x,y,10)); + FriendLocations NewEntry = new(FriendListCopy[e.AgentID].Name, e.Location, new Vector3(x,y,10)); if(FriendMapLocations.ContainsKey(e.AgentID) == false) { FriendMapLocations.Add(e.AgentID, NewEntry); @@ -955,12 +954,12 @@ namespace SecondBotEvents.Services Task.Factory.StartNew(() => { Thread.Sleep(2000); - attachEventsAfterDelay(); + AttachEventsAfterDelay(); }); } - Dictionary avprops = new Dictionary(); + Dictionary avprops = []; public KeyValuePair GetAvatarAvatarProperties(UUID agentID) { if (avprops.ContainsKey(agentID) == false) @@ -980,7 +979,7 @@ namespace SecondBotEvents.Services avprops[e.AvatarID] = e.Properties; } - protected void attachEventsAfterDelay() + protected void AttachEventsAfterDelay() { GetClient().Groups.CurrentGroups += GroupCurrent; GetClient().Groups.GroupJoinedReply += GroupJoin; @@ -996,9 +995,9 @@ namespace SecondBotEvents.Services GetClient().Friends.FriendFoundReply += FindFriendReply; GetClient().Avatars.AvatarPropertiesReply += AvatarDetailsReply; GetClient().Groups.RequestCurrentGroups(); - GetClient().Self.RetrieveInstantMessages(); + _ = GetClient().Self.RetrieveInstantMessages(); } - readonly string[] hard_blocked_agents = new[] { "secondlife", "second life" }; + readonly string[] hard_blocked_agents = ["secondlife", "second life"]; protected void ChatFromSim(object o, ChatEventArgs e) { switch(e.Type) @@ -1046,7 +1045,7 @@ namespace SecondBotEvents.Services { lock (groupsKey2Name) { - List missingGroups = groupsKey2Name.Keys.ToList(); + List missingGroups = [.. groupsKey2Name.Keys]; foreach (Group G in e.Groups.Values) { missingGroups.Remove(G.ID); @@ -1217,35 +1216,21 @@ namespace SecondBotEvents.Services } } - public class CommandHistory + public class CommandHistory(bool setStatus, string setCommand, string[] setArgs, long setUnixtime, string Setresults) { - public string Command = ""; - public string[] Args = Array.Empty(); - public long Unixtime = 0; - public bool status = false; - - public CommandHistory(bool setStatus, string setCommand, string[] setArgs, long setUnixtime) - { - status = setStatus; - Command = setCommand; - Args = setArgs; - Unixtime = setUnixtime; - } + public string Command = setCommand; + public string[] Args = setArgs; + public long Unixtime = setUnixtime; + public bool status = setStatus; + public string results = Setresults; } - public class FriendLocations + public class FriendLocations(string SetName, Vector3 setPos, Vector3 setRegionPos) { - public string Name; - public Vector3 Pos; - public Vector3 RegionPos; - public long time; - public FriendLocations(string SetName, Vector3 setPos, Vector3 setRegionPos) - { - time = SecondbotHelpers.UnixTimeNow(); - Name = SetName; - Pos = setPos; - RegionPos = setRegionPos; - } + public string Name = SetName; + public Vector3 Pos = setPos; + public Vector3 RegionPos = setRegionPos; + public long time = SecondbotHelpers.UnixTimeNow(); } } diff --git a/SecondBotEvents/Services/DialogService.cs b/SecondBotEvents/Services/DialogService.cs index 7fd804a..878b14b 100644 --- a/SecondBotEvents/Services/DialogService.cs +++ b/SecondBotEvents/Services/DialogService.cs @@ -138,7 +138,7 @@ namespace SecondBotEvents.Services lock(DialogWindows) { long unixtime = SecondbotHelpers.UnixTimeNow(); - List removeids = new List(); + List removeids = []; foreach(KeyValuePair a in DialogWindowsExpire) { if(a.Value > unixtime) @@ -157,12 +157,12 @@ namespace SecondBotEvents.Services - protected Dictionary DialogWindows = new Dictionary(); - protected Dictionary DialogWindowsExpire = new Dictionary(); + protected Dictionary DialogWindows = []; + protected Dictionary DialogWindowsExpire = []; protected int nextDialogWindow = 1; - protected List DialogRelayChannels = new List(); - protected List DialogRelayAvatars = new List(); - protected List DialogRelayHTTP = new List(); + protected List DialogRelayChannels = []; + protected List DialogRelayAvatars = []; + protected List DialogRelayHTTP = []; protected UUID objectOwnerOnly = UUID.Zero; protected void DialogWindowEvent(object sender, ScriptDialogEventArgs e) @@ -182,12 +182,14 @@ namespace SecondBotEvents.Services DialogWindows.Add(windowid, e); long expiresAt = SecondbotHelpers.UnixTimeNow() + 440; DialogWindowsExpire.Add(windowid, expiresAt); - DialogWindow window = new DialogWindow(); - window.buttons = e.ButtonLabels.ToArray(); - window.dialogid = windowid; - window.message = e.Message; - window.objectname = e.ObjectName; - window.expires = expiresAt; + DialogWindow window = new() + { + buttons = [.. e.ButtonLabels], + dialogid = windowid, + message = e.Message, + objectname = e.ObjectName, + expires = expiresAt + }; string eventMessage = JsonConvert.SerializeObject(window); foreach(int a in DialogRelayChannels) { diff --git a/SecondBotEvents/Services/DiscordService.cs b/SecondBotEvents/Services/DiscordService.cs index d6eb68d..c09046a 100644 --- a/SecondBotEvents/Services/DiscordService.cs +++ b/SecondBotEvents/Services/DiscordService.cs @@ -89,7 +89,7 @@ namespace SecondBotEvents.Services return Task.CompletedTask; } - private readonly object m_discordEventChatLock = new object(); + private readonly object m_discordEventChatLock = new(); private EventHandler m_discordChatEvent; /// Raised when a scripted object or agent within range sends a public message @@ -104,27 +104,27 @@ namespace SecondBotEvents.Services if (GetReadyForDiscordActions() == false) { // bot is not ready this message should not have got here yet. - return new KeyValuePair>(false, new List() { "not ready" }); + return new KeyValuePair>(false, ["not ready"]); } if (ulong.TryParse(givenserverid, out ulong serverid) == false) { - return new KeyValuePair>(false, new List() { "invaild server" }); + return new KeyValuePair>(false, ["invaild server"]); } if (ulong.TryParse(givenmemberid, out ulong memberid) == false) { - return new KeyValuePair>(false, new List() { "invaild member" }); + return new KeyValuePair>(false, ["invaild member"]); } SocketGuild server = DiscordClient.GetGuild(serverid); if (server == null) { - return new KeyValuePair>(false, new List() { "Cant get server" }); + return new KeyValuePair>(false, ["Cant get server"]); } SocketGuildUser user = server.GetUser(memberid); if (user == null) { - return new KeyValuePair>(false, new List() { "Cant get user" }); + return new KeyValuePair>(false, ["Cant get user"]); } - List roleids = new List(); + List roleids = []; foreach (SocketRole role in user.Roles) { roleids.Add(role.Id.ToString()); @@ -132,7 +132,7 @@ namespace SecondBotEvents.Services return new KeyValuePair>(true, roleids); } - protected HttpClient HTTPclient = new HttpClient(); + protected HttpClient HTTPclient = new(); protected bool MessageInteractionEvent(SocketMessage message, SocketChannel socketChannel) { if (myConfig.GetInteractionEnabled() != true) @@ -155,8 +155,8 @@ namespace SecondBotEvents.Services string getmessage = message.Content.Replace(myConfig.GetInteractionCommandName(), ""); long unixtime = SecondbotHelpers.UnixTimeNow(); string hash = SecondbotHelpers.GetSHA1(unixtime.ToString() + getmessage + master.CommandsService.myConfig.GetSharedSecret()); - Dictionary values = new Dictionary - { + Dictionary values = new() + { { "message", getmessage }, { "username", message.Author.Username }, { "userid", message.Author.Id.ToString() }, @@ -310,8 +310,7 @@ namespace SecondBotEvents.Services { // handle group notice // !notice {Title}@@@{Message}[@@@{Inventory UUID}] - List args = new List(); - args.Add(groupuuid.ToString()); + List args = [groupuuid.ToString()]; cleaned = cleaned.Replace("!notice ", ""); bits = cleaned.Split("@@@", StringSplitOptions.RemoveEmptyEntries); args.AddRange(bits); @@ -321,10 +320,10 @@ namespace SecondBotEvents.Services ReplyToMessage(message, "Notices require title and a message split with @@@!"); return; } - SignedCommand C = new SignedCommand( + SignedCommand C = new( master.CommandsService, "discordapi", - "Groupnotice", null, args.ToArray(), 0, "none", false, 0, "", false); + "Groupnotice", null, [.. args], 0, "none", false, 0, "", false); if (bits.Length == 3) { C.command = "GroupnoticeWithAttachment"; @@ -336,35 +335,27 @@ namespace SecondBotEvents.Services { // handle group eject cleaned = cleaned.Replace("!eject ", ""); - List args = new List(); - args.Add(groupuuid.ToString()); - args.Add(cleaned); + List args = [groupuuid.ToString(), cleaned]; RunCommandFromMessage(new SignedCommand(master.CommandsService, - "discordapi", "GroupEject", null, args.ToArray(), 0, "none", false, 0, "", false), message); + "discordapi", "GroupEject", null, [.. args], 0, "none", false, 0, "", false), message); return; } else if(cleaned.StartsWith("!invite") == true) { // hangle group invite cleaned = cleaned.Replace("!invite ", ""); - List args = new List(); - args.Add(groupuuid.ToString()); - args.Add(cleaned); - args.Add("everyone"); + List args = [groupuuid.ToString(), cleaned, "everyone"]; RunCommandFromMessage(new SignedCommand(master.CommandsService, - "discordapi", "GroupInvite", null, args.ToArray(), 0, "none", false, 0, "", false), message); + "discordapi", "GroupInvite", null, [.. args], 0, "none", false, 0, "", false), message); return; } else if(cleaned.StartsWith("!ban") == true) { // hangle group ban cleaned = cleaned.Replace("!ban ", ""); - List args = new List(); - args.Add(groupuuid.ToString()); - args.Add(cleaned); - args.Add("true"); + List args = [groupuuid.ToString(), cleaned, "true"]; RunCommandFromMessage(new SignedCommand(master.CommandsService, - "discordapi", "GroupBan", null, args.ToArray(), 0, "none", false, 0, "", false), message); + "discordapi", "GroupBan", null, [.. args], 0, "none", false, 0, "", false), message); return; } if (myConfig.GethideChatterName() == false) @@ -713,20 +704,20 @@ namespace SecondBotEvents.Services return "group=" + groupuuid.ToString() + "||| !clear !notice {Title}@@@{Message}[@@@{Inventory UUID}] !eject {Avatar} !invite {Avatar} !ban {Avatar}"; } - protected Dictionary ChannelMap = new Dictionary(); - protected Dictionary CategoryMap = new Dictionary(); + protected Dictionary ChannelMap = []; + protected Dictionary CategoryMap = []; protected async void DoServerChannelSetup() { LogFormater.Info("Setting up channels"); LoginEvents(); - Dictionary WantedTextChannels = new Dictionary + Dictionary WantedTextChannels = new() { { "status", StatusPrefill() }, { "commands", "Send a command to the bot as if you are a master" }, { "localchat", LocalChatPrefill() } }; - ChannelMap = new Dictionary(); + ChannelMap = []; SocketGuild server = DiscordClient.GetGuild(myConfig.GetServerID()); foreach (ITextChannel channel in server.TextChannels) @@ -750,12 +741,12 @@ namespace SecondBotEvents.Services } - List WantedCategoryChannels = new List - { + List WantedCategoryChannels = + [ "bot", "im", "group" - }; + ]; foreach (ICategoryChannel category in server.CategoryChannels) { if (WantedCategoryChannels.Contains(category.Name) == false) @@ -834,7 +825,7 @@ namespace SecondBotEvents.Services SendMessageToChannel("localchat", LocalChatPrefill(), ":white_small_square: "+ objectName + ": " + message, "bot"); } - readonly string[] hard_blocked_agents = new[] { "secondlife", "second life" }; + readonly string[] hard_blocked_agents = ["secondlife", "second life"]; protected void LocalChat(object o, ChatEventArgs e) { switch (e.Type) @@ -1093,10 +1084,10 @@ namespace SecondBotEvents.Services { if (ulong.TryParse(givenserverid, out ulong serverid) == true) { - return new KeyValuePair>(false, new Dictionary()); + return new KeyValuePair>(false, []); } SocketGuild server = DiscordClient.GetGuild(serverid); - Dictionary textChannels = new Dictionary(); + Dictionary textChannels = []; foreach (SocketTextChannel channel in server.TextChannels) { textChannels.Add(channel.Id.ToString(), channel.Name); @@ -1124,10 +1115,10 @@ namespace SecondBotEvents.Services { if (ulong.TryParse(givenserverid, out ulong serverid) == false) { - return new KeyValuePair>(false, new Dictionary()); + return new KeyValuePair>(false, []); } SocketGuild server = DiscordClient.GetGuild(serverid); - Dictionary rolesList = new Dictionary(); + Dictionary rolesList = []; foreach (SocketRole role in server.Roles) { rolesList.Add(role.Id.ToString(), role.Name); @@ -1282,17 +1273,17 @@ namespace SecondBotEvents.Services { if (ulong.TryParse(givenserverid, out ulong serverid) == false) { - return new KeyValuePair>(false, new Dictionary()); + return new KeyValuePair>(false, []); } if (ulong.TryParse(givenroleid, out ulong roleid) == false) { - return new KeyValuePair>(false, new Dictionary()); + return new KeyValuePair>(false, []); } SocketGuild server = DiscordClient.GetGuild(serverid); SocketRole role = server.GetRole(roleid); - Dictionary settings = new Dictionary + Dictionary settings = new() { - { "Config|Color", String.Join(",", new byte[3] { role.Color.R, role.Color.G, role.Color.B }) }, + { "Config|Color", String.Join(",", [role.Color.R, role.Color.G, role.Color.B]) }, { "Config|Name", role.Name }, { "Info|AssignedCount", role.Members.ToString() }, { "Perm|AttachFiles", role.Permissions.AttachFiles.ToString() }, @@ -1388,11 +1379,11 @@ namespace SecondBotEvents.Services { if (ulong.TryParse(givenserverid, out ulong serverid) == false) { - return new KeyValuePair>(false, new Dictionary()); + return new KeyValuePair>(false, []); } SocketGuild server = DiscordClient.GetGuild(serverid); IEnumerable users = await server.GetUsersAsync().FlattenAsync().ConfigureAwait(true); - Dictionary membersList = new Dictionary(); + Dictionary membersList = []; foreach (IGuildUser user in users) { @@ -1454,13 +1445,13 @@ namespace SecondBotEvents.Services } SocketGuild server = DiscordClient.GetGuild(serverid); SocketGuildUser user = server.GetUser(memberid); - TimeSpan somedays = new TimeSpan(13, 22, 59, 59, 0); + TimeSpan somedays = new(13, 22, 59, 59, 0); DateTimeOffset justundertwosweeks = DateTimeOffset.Now; justundertwosweeks = justundertwosweeks.Subtract(somedays); long unixtimelimit = justundertwosweeks.ToUnixTimeSeconds(); foreach (SocketTextChannel channel in server.TextChannels) { - List DeleteMessages = new List(); + List DeleteMessages = []; IEnumerable messages = await channel.GetMessagesAsync(100).FlattenAsync(); foreach (IMessage message in messages) { diff --git a/SecondBotEvents/Services/EventsService.cs b/SecondBotEvents/Services/EventsService.cs index 008f167..a30557b 100644 --- a/SecondBotEvents/Services/EventsService.cs +++ b/SecondBotEvents/Services/EventsService.cs @@ -17,9 +17,9 @@ namespace SecondBotEvents.Services protected bool botConnected = false; protected string lastSimName = ""; protected UUID TrackGroupUUID = UUID.Zero; - protected List GroupMembers = new List(); + protected List GroupMembers = []; protected bool GroupLoaded = false; - protected List AvatarsOnSim = new List(); + protected List AvatarsOnSim = []; protected bool GuestListLoaded = false; protected string lastparcelname = ""; protected UUID OutputAvatar = UUID.Zero; @@ -67,12 +67,12 @@ namespace SecondBotEvents.Services } } - Dictionary> InventoryEvents = new Dictionary>(); + Dictionary> InventoryEvents = []; public void AddInventoryEvent(string inventoryType, string outputTarget) { if(InventoryEvents.ContainsKey(inventoryType) == false) { - InventoryEvents.Add(inventoryType, new List()); + InventoryEvents.Add(inventoryType, []); } if (InventoryEvents[inventoryType].Contains(outputTarget) == false) { @@ -154,7 +154,7 @@ namespace SecondBotEvents.Services { if ((myConfig.GetGuestTrackingSimname() != GetClient().Network.CurrentSim.Name) || (myConfig.GetGuestTrackingParcelname() != lastparcelname)) { - AvatarsOnSim = new List(); + AvatarsOnSim = []; GuestListLoaded = false; return; } @@ -167,7 +167,7 @@ namespace SecondBotEvents.Services lastAvUpdate = SecondbotHelpers.UnixTimeNow(); string hashstring = ""; - List avs = new List(); + List avs = []; foreach(Avatar A in GetClient().Network.CurrentSim.ObjectsAvatars.Copy().Values) { avs.Add(A.ID); @@ -182,12 +182,8 @@ namespace SecondBotEvents.Services if (GuestListLoaded == true) { - List joined = new List(); - List tracked = new List(); - foreach (UUID a in AvatarsOnSim) - { - tracked.Add(a); - } + List joined = []; + List tracked = [.. AvatarsOnSim]; foreach (UUID a in avs) { if (tracked.Contains(a) == true) @@ -256,7 +252,7 @@ namespace SecondBotEvents.Services protected void PushEvent(string eventname, Dictionary args) { - OnEvent e = new OnEvent( + OnEvent e = new( GetClient().Self.AgentID.ToString(), eventname, args, @@ -295,9 +291,11 @@ namespace SecondBotEvents.Services { return; } - Dictionary args = new Dictionary(); - args.Add("Message", e.Message); - args.Add("NotificationId", e.NotificationId); + Dictionary args = new() + { + { "Message", e.Message }, + { "NotificationId", e.NotificationId } + }; PushEvent("AlertMessage", args); } @@ -307,9 +305,11 @@ namespace SecondBotEvents.Services { return; } - Dictionary args = new Dictionary(); - args.Add("oldparcel", lastparcelname); - args.Add("newparcel", newparcelname); + Dictionary args = new() + { + { "oldparcel", lastparcelname }, + { "newparcel", newparcelname } + }; lastparcelname = newparcelname; PushEvent("ChangedParcel", args); } @@ -320,8 +320,10 @@ namespace SecondBotEvents.Services { return; } - Dictionary args = new Dictionary(); - args.Add("Message", e.message); + Dictionary args = new() + { + { "Message", e.message } + }; PushEvent("StatusMessage", args); } @@ -333,12 +335,8 @@ namespace SecondBotEvents.Services } if(GroupLoaded == true) { - List joined = new List(); - List tracked = new List(); - foreach (UUID a in GroupMembers) - { - tracked.Add(a); - } + List joined = []; + List tracked = [.. GroupMembers]; master.DataStoreService.GetAvatarNames(tracked); foreach (UUID a in e.Members.Keys) { @@ -365,29 +363,29 @@ namespace SecondBotEvents.Services } } - GroupMembers = new List(); - foreach (UUID a in e.Members.Keys) - { - GroupMembers.Add(a); - } + GroupMembers = [.. e.Members.Keys]; GroupLoaded = true; } protected void GroupMembershipEvent(UUID avatar, string action) { - Dictionary args = new Dictionary(); - args.Add("uuid", avatar.ToString()); - args.Add("name", master.DataStoreService.GetAvatarName(avatar)); - args.Add("action", action); + Dictionary args = new() + { + { "uuid", avatar.ToString() }, + { "name", master.DataStoreService.GetAvatarName(avatar) }, + { "action", action } + }; PushEvent("GroupMembership", args); } protected void GuestTrackingEvent(UUID avatar, string action) { - Dictionary args = new Dictionary(); - args.Add("uuid", avatar.ToString()); - args.Add("name", master.DataStoreService.GetAvatarName(avatar)); - args.Add("action", action); + Dictionary args = new() + { + { "uuid", avatar.ToString() }, + { "name", master.DataStoreService.GetAvatarName(avatar) }, + { "action", action } + }; PushEvent("GuestTracking", args); } @@ -397,9 +395,11 @@ namespace SecondBotEvents.Services { return; } - Dictionary args = new Dictionary(); - args.Add("lastsim", lastSimName); - args.Add("newsim", GetClient().Network.CurrentSim.Name); + Dictionary args = new() + { + { "lastsim", lastSimName }, + { "newsim", GetClient().Network.CurrentSim.Name } + }; PushEvent("ChangedSim", args); lastSimName = e.PreviousSimulator.Name; } @@ -410,14 +410,16 @@ namespace SecondBotEvents.Services { return; } - Dictionary args = new Dictionary(); - args.Add("fromuuid", e.TransactionInfo.SourceID.ToString()); - args.Add("touuid", e.TransactionInfo.DestID.ToString()); - args.Add("amount", e.TransactionInfo.Amount.ToString()); - args.Add("balance", e.Balance.ToString()); - args.Add("fromname", master.DataStoreService.GetAvatarName(e.TransactionInfo.SourceID)); - args.Add("toname", master.DataStoreService.GetAvatarName(e.TransactionInfo.DestID)); - args.Add("transactionid", e.TransactionID.ToString()); + Dictionary args = new() + { + { "fromuuid", e.TransactionInfo.SourceID.ToString() }, + { "touuid", e.TransactionInfo.DestID.ToString() }, + { "amount", e.TransactionInfo.Amount.ToString() }, + { "balance", e.Balance.ToString() }, + { "fromname", master.DataStoreService.GetAvatarName(e.TransactionInfo.SourceID) }, + { "toname", master.DataStoreService.GetAvatarName(e.TransactionInfo.DestID) }, + { "transactionid", e.TransactionID.ToString() } + }; PushEvent("MoneyEvent", args); } @@ -456,7 +458,7 @@ namespace SecondBotEvents.Services public class OnEvent { public string EventName = ""; - public Dictionary Data = new Dictionary(); + public Dictionary Data = []; public string Hash = ""; public long Unixtime = 0; public string BotUUID = ""; diff --git a/SecondBotEvents/Services/HomeboundService.cs b/SecondBotEvents/Services/HomeboundService.cs index 198ecbb..e5d8fd8 100644 --- a/SecondBotEvents/Services/HomeboundService.cs +++ b/SecondBotEvents/Services/HomeboundService.cs @@ -77,7 +77,7 @@ namespace SecondBotEvents.Services { if (evacWanted == true) { - BotAlertMessage(null, new AlertMessageEventArgs("restart", "999", new OpenMetaverse.StructuredData.OSDMap())); + BotAlertMessage(null, new AlertMessageEventArgs("restart", "999", [])); } if (GetClient().Network.CurrentSim.Name == home.name) { diff --git a/SecondBotEvents/Services/HttpService.cs b/SecondBotEvents/Services/HttpService.cs index 6bbf998..5769dfa 100644 --- a/SecondBotEvents/Services/HttpService.cs +++ b/SecondBotEvents/Services/HttpService.cs @@ -145,14 +145,9 @@ namespace SecondBotEvents.Services } } - public abstract class CommandsAPI + public abstract class CommandsAPI(EventsSecondBot setmaster) { - protected EventsSecondBot master; - public CommandsAPI(EventsSecondBot setmaster) - { - master = setmaster; - } - + protected EventsSecondBot master = setmaster; protected UUID avataruuid = UUID.Zero; protected Parcel targetparcel = null; @@ -241,72 +236,44 @@ namespace SecondBotEvents.Services } [AttributeUsage(AttributeTargets.Class)] - public class ClassInfo : Attribute + public class ClassInfo(string classinfo) : Attribute { - public string classinfo = ""; - public ClassInfo(string classinfo) - { - this.classinfo = classinfo; - } + public string classinfo = classinfo; } [AttributeUsage(AttributeTargets.Method)] - public class About : Attribute + public class About(string about) : Attribute { - public string about = ""; - public About(string about) - { - this.about = about; - } + public string about = about; } [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - public class ReturnHints : Attribute + public class ReturnHints(string hint) : Attribute { - public string hint = ""; - public ReturnHints(string hint) - { - this.hint = hint; - } + public string hint = hint; } [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - public class ReturnHintsFailure : Attribute + public class ReturnHintsFailure(string hint) : Attribute { - public string hint = ""; - public ReturnHintsFailure(string hint) - { - this.hint = hint; - } + public string hint = hint; } [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - public class ArgHints : Attribute + public class ArgHints(string name, string about) : Attribute { - public string name = ""; - public string about = ""; - - public ArgHints(string name, string about) - { - this.name = name; - this.about = about; - } + public string name = name; + public string about = about; } - public class SecondbotWebApi : WebApiController + public class SecondbotWebApi(EventsSecondBot setmaster) : WebApiController { - protected EventsSecondBot master; - public SecondbotWebApi(EventsSecondBot setmaster) - { - master = setmaster; - } + protected EventsSecondBot master = setmaster; } - public class HttpWebBot : SecondbotWebApi + public class HttpWebBot(EventsSecondBot setmaster) : SecondbotWebApi(setmaster) { - public HttpWebBot(EventsSecondBot setmaster) : base(setmaster) { } - [About("Runs a command on the bot")] [ReturnHints("command reply")] [ReturnHintsFailure("Bad token signing")] diff --git a/SecondBotEvents/Services/InteractionService.cs b/SecondBotEvents/Services/InteractionService.cs index 0c9e0ba..ebda904 100644 --- a/SecondBotEvents/Services/InteractionService.cs +++ b/SecondBotEvents/Services/InteractionService.cs @@ -48,7 +48,7 @@ namespace SecondBotEvents.Services { if (misc == null) { - misc = new Dictionary(); + misc = []; } if (myConfig.GetEnabled() == false) { @@ -160,8 +160,10 @@ namespace SecondBotEvents.Services protected void JsonOuputCleaner(string misc, string source) { - Dictionary reply = new Dictionary(); - reply.Add("value", misc); + Dictionary reply = new() + { + { "value", misc } + }; JsonOuputCleaner(reply, source); } @@ -198,8 +200,10 @@ namespace SecondBotEvents.Services mode = "Teleport Av to Bot"; markTeleport = false; } - Dictionary misc = new Dictionary(); - misc.Add("mode", mode); + Dictionary misc = new() + { + { "mode", mode } + }; if (ProcessRequest(myConfig.GetAcceptTeleports(),myConfig.GetTeleportRequestLevel(), e.IM.FromAgentName, "Teleport", e.IM.FromAgentID, misc) == false) { // rejected requests @@ -226,9 +230,11 @@ namespace SecondBotEvents.Services protected void BotGroupInviteOffer(object o, GroupInvitationEventArgs e) { - Dictionary reply = new Dictionary(); - reply.Add("message", e.Message); - reply.Add("fromuuid", e.AgentID.ToString()); + Dictionary reply = new() + { + { "message", e.Message }, + { "fromuuid", e.AgentID.ToString() } + }; if (ProcessRequest(myConfig.GetAcceptGroupInvites(),myConfig.GetGroupInviteLevel(), e.FromName, "GroupInvite", e.AgentID, reply) == false) { return; @@ -240,7 +246,7 @@ namespace SecondBotEvents.Services protected void BotInventoryAdd(object o, InventoryObjectAddedEventArgs e) { InventoryItem F = (InventoryItem)e.Obj; - Dictionary details = new Dictionary + Dictionary details = new() { { "itemname", e.Obj.Name }, { "itemuuid", e.Obj.UUID.ToString() }, @@ -255,7 +261,7 @@ namespace SecondBotEvents.Services protected void BotInventoryOffer(object o, InventoryObjectOfferedEventArgs e) { - Dictionary details = new Dictionary + Dictionary details = new() { { "transactionid", e.Offer.IMSessionID.ToString() }, { "itemtype", e.AssetType.ToString() }, @@ -285,8 +291,10 @@ namespace SecondBotEvents.Services protected void BotFriendRequested(object o, FriendshipOfferedEventArgs e) { - Dictionary misc = new Dictionary(); - misc.Add("fromName", e.AgentName); + Dictionary misc = new() + { + { "fromName", e.AgentName } + }; if (ProcessRequest(myConfig.GetAcceptFriendRequests(),myConfig.GetFriendRequestLevel(), e.AgentName, "FriendRequest", e.AgentID, misc) == false) { return; @@ -370,7 +378,7 @@ namespace SecondBotEvents.Services public string eventType = "?"; public bool accepted = false; public string info = ""; - public Dictionary misc = new Dictionary(); + public Dictionary misc = []; public InteractionEvent(string setFrom, string setType, bool setAccepted, string setInfo, Dictionary setMisc = null) { accepted = setAccepted; diff --git a/SecondBotEvents/Services/RLVService.cs b/SecondBotEvents/Services/RLVService.cs index 6f537a2..2835add 100644 --- a/SecondBotEvents/Services/RLVService.cs +++ b/SecondBotEvents/Services/RLVService.cs @@ -17,7 +17,7 @@ namespace SecondBotEvents.Services { public class RLVService : BotServices { - protected RlvConfig myConfig; + protected new RlvConfig myConfig; protected bool botConnected = false; protected CurrentOutfitFolder CurrentOutfitFolder = null; @@ -77,11 +77,11 @@ namespace SecondBotEvents.Services CurrentOutfitFolder = master.CurrentOutfitFolder; botConnected = true; // attach events - RLVWearables = new List(); - RLVAttachments = new List - { + RLVWearables = []; + RLVAttachments = + [ new RLVAttachment() {Name = "none", Point = AttachmentPoint.Default} - }; + ]; foreach (WearableType wear in Enum.GetValues(typeof(WearableType))) { if (wear.Equals(WearableType.Invalid)) continue; @@ -178,7 +178,7 @@ namespace SecondBotEvents.Services } /// Thread sync lock object - private readonly object m_RLVRuleChangedLock = new object(); + private readonly object m_RLVRuleChangedLock = new(); /// Triggered when an RLVRuleChangedUpdate packet is received, /// telling us what our avatar is currently wearing @@ -239,8 +239,8 @@ namespace SecondBotEvents.Services GridClient client => instance.BotClient.GetClient(); EventsSecondBot instance = null; - readonly Regex rlv_regex = new Regex(@"(?[^:=]+)(:(?