This commit is contained in:
Madpeter 2023-07-25 20:43:16 +01:00
parent 1ebf6725d4
commit 45fdca1896
15 changed files with 132 additions and 66 deletions

View file

@ -278,6 +278,34 @@ namespace SecondBotEvents.Commands
return BasicReply(reply.ToString(), new [] { item });
}
[About("sends a item to an avatar via a path")]
[ReturnHints("ok")]
[ReturnHints("Failed")]
[ReturnHints("Invaild avatar uuid")]
[ReturnHints("Unable to find item")]
[ArgHints("path", "item name and path example: Notecard/sendme or Objects/DemoItem")]
[ArgHints("avatar", "a UUID or Firstname Lastname")]
public object SendItemByPath(string path, string avatar)
{
ProcessAvatar(avatar);
if (avataruuid == UUID.Zero)
{
return Failure("Invaild avatar uuid", new[] { path, avatar });
}
UUID targetitem = GetClient().Inventory.FindObjectByPath(GetClient().Inventory.Store.RootFolder.UUID, GetClient().Self.AgentID, path, (3 * 1000));
if(targetitem == UUID.Zero)
{
return Failure("Unable to find item via path", new[] { path, avatar });
}
InventoryItem itm = GetClient().Inventory.FetchItem(targetitem, GetClient().Self.AgentID, (3 * 1000));
if (itm == null)
{
return Failure("Unable to find item with found uuid", new[] { path, avatar });
}
GetClient().Inventory.GiveItem(itm.UUID, itm.Name, itm.AssetType, avataruuid, false);
return BasicReply("ok", new[] { path, avatar });
}
[About("sends a item to an avatar")]
[ReturnHints("ok")]
[ReturnHints("Failed")]
@ -321,7 +349,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild avatar uuid", new [] { folder, avatar });
}
if (UUID.TryParse(folder, out UUID targetfolder) == true)
if (UUID.TryParse(folder, out UUID targetfolder) == false)
{
return Failure("Invaild folder uuid", new [] { folder, avatar });
}

View file

@ -106,6 +106,7 @@ namespace SecondBotEvents.Commands
[ReturnHints("ok")]
public object Stand()
{
master.HomeboundService.MarkStandup();
GetClient().Self.Stand();
return BasicReply("ok");
}

View file

@ -26,7 +26,7 @@ namespace SecondBotEvents.Config
public int GetRelayCount()
{
return ReadSettingAsInt("count", 1);
return ReadSettingAsInt("count", 0);
}
public bool GetRelayEnabled(int relayID)

View file

@ -155,7 +155,7 @@ namespace SecondBotEvents
RegisterService("CustomCommandsService");
if (BotClient.IsLoaded() == false)
{
Console.WriteLine("Config is not loaded :(");
LogFormater.Info("Config is not loaded :(");
exitNow = true;
return;
}

View file

@ -36,7 +36,7 @@ namespace SecondBotEvents.Services
public override void Start()
{
running = true;
Console.WriteLine("Client service [Starting]");
LogFormater.Info("Client service [Starting]");
AutoRestartLoginTimer = new Timer();
AutoRestartLoginTimer.Interval = 30 * 1000;
AutoRestartLoginTimer.AutoReset = false;
@ -47,7 +47,7 @@ namespace SecondBotEvents.Services
{
if(running == true)
{
Console.WriteLine("Client service [Stopping]");
LogFormater.Info("Client service [Stopping]");
}
running = false;
AutoRestartLoginTimer.Stop();
@ -56,35 +56,35 @@ namespace SecondBotEvents.Services
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
{
Console.WriteLine("Client service ~ Logged out");
LogFormater.Info("Client service ~ Logged out");
}
protected void BotSimConnected(object o, SimConnectedEventArgs e)
{
AutoRestartLoginTimer.Stop();
Console.WriteLine("Client service ~ Connected to sim: "+e.Simulator.Name);
LogFormater.Info("Client service ~ Connected to sim: "+e.Simulator.Name);
}
protected void BotSimDisconnected(object o, SimDisconnectedEventArgs e)
{
Console.WriteLine("Client service ~ Disconnected from sim: " + e.Simulator.Name);
LogFormater.Info("Client service ~ Disconnected from sim: " + e.Simulator.Name);
}
protected void BotDisconnected(object o, DisconnectedEventArgs e)
{
Console.WriteLine("Client service ~ Network disconnected: " + e.Message);
LogFormater.Info("Client service ~ Network disconnected: " + e.Message);
}
protected void BotLoginStatus(object o, LoginProgressEventArgs e)
{
if(e.FailReason != "")
{
Console.WriteLine("Client service ~ {FAILED} Login status: " + e.FailReason.ToString());
LogFormater.Info("Client service ~ {FAILED} Login status: " + e.FailReason.ToString());
client.Network.Logout();
ResetClient();
return;
}
Console.WriteLine("Client service ~ Login status: " + e.Status.ToString());
LogFormater.Info("Client service ~ Login status: " + e.Status.ToString());
}
public void SendIM(UUID avatar, string message)
{

View file

@ -309,7 +309,7 @@ namespace SecondBotEvents.Services
protected void BotClientRestart(object o, BotClientNotice e)
{
acceptNewCommands = false;
Console.WriteLine("Commands service [Attached to new client]");
LogFormater.Info("Commands service [Attached to new client]");
GetClient().Network.LoggedOut += BotLoggedOut;
GetClient().Network.SimConnected += BotLoggedIn;
}
@ -317,7 +317,7 @@ namespace SecondBotEvents.Services
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
{
GetClient().Network.SimConnected += BotLoggedIn;
Console.WriteLine("Commands service [Waiting for connect]");
LogFormater.Info("Commands service [Waiting for connect]");
}
protected void BotLoggedIn(object o, SimConnectedEventArgs e)
@ -332,7 +332,7 @@ namespace SecondBotEvents.Services
}
}
acceptNewCommands = true;
Console.WriteLine("Commands service [accepting IM commands]");
LogFormater.Info("Commands service [accepting IM commands]");
}
}

View file

@ -85,7 +85,7 @@ namespace SecondBotEvents.Services
protected void BotClientRestart(object o, BotClientNotice e)
{
Console.WriteLine("CustomCommands service [Attached to new client]");
LogFormater.Info("CustomCommands service [Attached to new client]");
GetClient().Network.LoggedOut += BotLoggedOut;
GetClient().Network.SimConnected += BotLoggedIn;
}
@ -93,7 +93,7 @@ namespace SecondBotEvents.Services
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
{
GetClient().Network.SimConnected += BotLoggedIn;
Console.WriteLine("CustomCommands service [waiting for new client]");
LogFormater.Info("CustomCommands service [waiting for new client]");
}
protected void BotLoggedIn(object o, SimConnectedEventArgs e)

View file

@ -790,7 +790,7 @@ namespace SecondBotEvents.Services
protected void BotClientRestart(object o, BotClientNotice e)
{
botConnected = false;
Console.WriteLine("DataStore Service [Attached to new client]");
LogFormater.Info("DataStore Service [Attached to new client]");
GetClient().Network.LoggedOut += BotLoggedOut;
GetClient().Network.SimConnected += BotLoggedIn;
}
@ -799,7 +799,7 @@ namespace SecondBotEvents.Services
{
botConnected = false;
GetClient().Network.SimConnected += BotLoggedIn;
Console.WriteLine("DataStore Service [Standby]");
LogFormater.Info("DataStore Service [Standby]");
}
protected void GroupRoles(object o, GroupRolesDataReplyEventArgs e)
@ -877,7 +877,7 @@ namespace SecondBotEvents.Services
GetClient().Estate.EstateBansReply += EstateBans;
GetClient().Groups.RequestCurrentGroups();
botConnected = true;
Console.WriteLine("DataStore Service [Active]");
LogFormater.Info("DataStore Service [Active]");
GetAvatarName(GetClient().Self.AgentID);
}
readonly string[] hard_blocked_agents = new[] { "secondlife", "second life" };
@ -1045,14 +1045,14 @@ namespace SecondBotEvents.Services
Stop();
running = true;
master.BotClientNoticeEvent += BotClientRestart;
Console.WriteLine("DataStore Service [Starting]");
LogFormater.Info("DataStore Service [Starting]");
}
public override void Stop()
{
if(running == true)
{
Console.WriteLine("DataStore Service [Stopping]");
LogFormater.Info("DataStore Service [Stopping]");
}
running = false;
Reset();

View file

@ -194,7 +194,7 @@ namespace SecondBotEvents.Services
protected void BotClientRestart(object o, BotClientNotice e)
{
Console.WriteLine("Dialog service [Attached to new client]");
LogFormater.Info("Dialog service [Attached to new client]");
GetClient().Network.LoggedOut += BotLoggedOut;
GetClient().Network.SimConnected += BotLoggedIn;
}
@ -202,7 +202,7 @@ namespace SecondBotEvents.Services
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
{
GetClient().Network.SimConnected += BotLoggedIn;
Console.WriteLine("Dialog service [waiting for new client]");
LogFormater.Info("Dialog service [waiting for new client]");
if (GetClient() != null)
{
GetClient().Self.ScriptDialog -= DialogWindowEvent;

View file

@ -58,14 +58,14 @@ namespace SecondBotEvents.Services
protected Task DiscordClientLoggedOut()
{
Console.WriteLine("Discord service [Logged out]");
LogFormater.Info("Discord service [Logged out]");
DiscordIsReady = false;
return Task.CompletedTask;
}
protected Task DicordClientLoggedin()
{
Console.WriteLine("Discord service [Logged in]");
LogFormater.Info("Discord service [Logged in]");
DiscordDoingLogin = false;
_ = DiscordClient.StartAsync();
return Task.CompletedTask;
@ -73,7 +73,7 @@ namespace SecondBotEvents.Services
protected Task DiscordClientReady()
{
Console.WriteLine("Discord service [Ready]");
LogFormater.Info("Discord service [Ready]");
DiscordIsReady = true;
DoServerChannelSetup();
return Task.CompletedTask;
@ -358,7 +358,7 @@ namespace SecondBotEvents.Services
}
if (message.Author.Id != DiscordClient.CurrentUser.Id)
{
GetClient().Self.Chat(message.Author.Username + ": " + message.CleanContent, 0, ChatType.Normal);
GetClient().Self.Chat(message.CleanContent, 0, ChatType.Normal);
_ = message.DeleteAsync();
}
}
@ -380,7 +380,7 @@ namespace SecondBotEvents.Services
protected Task DiscordDisconnected(Exception e)
{
Console.WriteLine("Discord service [Disconnected: "+e.Message+"]");
LogFormater.Info("Discord service [Disconnected: "+e.Message+"]");
DiscordIsReady = false;
if(DiscordDisconnectExpected == false)
{
@ -407,21 +407,25 @@ namespace SecondBotEvents.Services
running = true;
if (myConfig.GetEnabled() == false)
{
Console.WriteLine("Discord service [Disabled]");
LogFormater.Info("Discord service [Disabled]");
return;
}
if(myConfig.GetServerID() == 0)
{
Console.WriteLine("Discord service [Invaild server id]");
LogFormater.Info("Discord service [Invaild server id]");
return;
}
DiscordServerChannelsSetup = false;
DiscordDisconnectExpected = false;
DiscordIsReady = false;
Console.WriteLine("Discord service [Starting]");
LogFormater.Info("Discord service [Starting]");
master.SystemStatusMessagesEvent += SystemStatusEvent;
master.BotClientNoticeEvent += BotClientRestart;
DiscordClient = new DiscordSocketClient();
var config = new DiscordSocketConfig()
{
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.GuildIntegrations | GatewayIntents.MessageContent
};
DiscordClient = new DiscordSocketClient(config);
DiscordClient.Ready += DiscordClientReady;
DiscordClient.LoggedOut += DiscordClientLoggedOut;
DiscordClient.LoggedIn += DicordClientLoggedin;
@ -434,7 +438,7 @@ namespace SecondBotEvents.Services
{
if(running == true)
{
Console.WriteLine("Discord service [Stopping]");
LogFormater.Info("Discord service [Stopping]");
}
running = false;
@ -473,7 +477,7 @@ namespace SecondBotEvents.Services
{
if (e.isRestart == false)
{
Console.WriteLine("Discord service [Avi link]");
LogFormater.Info("Discord service [Avi link]");
AcceptEventsFromSL = false;
GetClient().Network.LoggedOut += BotLoggedOut;
GetClient().Self.ChatFromSimulator -= LocalChat;
@ -491,7 +495,7 @@ namespace SecondBotEvents.Services
GetClient().Self.IM -= BotImMessage;
GetClient().Groups.CurrentGroups -= GroupCurrent;
AcceptEventsFromSL = false;
Console.WriteLine("Discord service [Avi link - standby]");
LogFormater.Info("Discord service [Avi link - standby]");
}
protected void BotImMessage(object o, InstantMessageEventArgs e)
@ -536,6 +540,7 @@ namespace SecondBotEvents.Services
protected async void DoServerChannelSetup()
{
LogFormater.Info("Setting up channels");
LoginEvents();
Dictionary<string, string> WantedTextChannels = new Dictionary<string, string>
{
{ "status", StatusPrefill() },
@ -830,10 +835,33 @@ namespace SecondBotEvents.Services
{
AcceptEventsFromSL = true;
GetClient().Network.SimConnected -= BotLoggedIn;
GetClient().Self.IM += BotImMessage;
GetClient().Self.ChatFromSimulator += LocalChat;
GetClient().Groups.CurrentGroups += GroupCurrent;
Console.WriteLine("Discord service [Avi link - Active]");
LogFormater.Info("Discord service [Avi link - Active]");
LoginEvents();
BotCurrentSim(o, e);
}
protected void BotCurrentSim(object o, SimConnectedEventArgs e)
{
if (DiscordIsReady == true)
{
DiscordClient.SetGameAsync(e.Simulator.Name, null, ActivityType.Playing);
}
}
protected void LoginEvents()
{
if((AcceptEventsFromSL == true) && (DiscordIsReady == true))
{
GetClient().Self.IM += BotImMessage;
GetClient().Network.SimConnected -= BotCurrentSim;
GetClient().Self.ChatFromSimulator += LocalChat;
GetClient().Groups.CurrentGroups += GroupCurrent;
GetClient().Groups.RequestCurrentGroups();
}
else if(DiscordIsReady == true)
{
DiscordClient.SetGameAsync("Waiting for login", null, ActivityType.Listening);
}
}
#region discord helper functions

View file

@ -60,7 +60,7 @@ namespace SecondBotEvents.Services
protected void BotClientRestart(object o, BotClientNotice e)
{
Console.WriteLine("Events service [Attached to new client]");
LogFormater.Info("Events service [Attached to new client]");
GetClient().Network.LoggedOut += BotLoggedOut;
GetClient().Network.SimConnected += BotLoggedIn;
}
@ -68,7 +68,7 @@ namespace SecondBotEvents.Services
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
{
GetClient().Network.SimConnected += BotLoggedIn;
Console.WriteLine("Events service [Bot commands disabled]");
LogFormater.Info("Events service [Bot commands disabled]");
removeEvents();
}
@ -340,7 +340,7 @@ namespace SecondBotEvents.Services
{
if (myConfig.GetEnabled() == false)
{
Console.WriteLine("Events service [Disabled]");
LogFormater.Info("Events service [Disabled]");
return;
}
Stop();

View file

@ -20,12 +20,18 @@ namespace SecondBotEvents.Services
protected long lastGotoAction = 0;
protected bool softDisable = false;
protected bool closeToHome = false;
protected bool softDisableSit = false;
public void MarkTeleport()
{
softDisable = true;
}
public void MarkStandup()
{
softDisableSit = true;
}
public HomeboundService(EventsSecondBot setMaster) : base(setMaster)
{
myConfig = new HomeboundConfig(master.fromEnv, master.fromFolder);
@ -65,7 +71,10 @@ namespace SecondBotEvents.Services
{
if (GetClient().Self.SittingOn == 0)
{
GetClient().Self.RequestSit(sitTarget, Vector3.Zero);
if (softDisableSit == false)
{
GetClient().Self.RequestSit(sitTarget, Vector3.Zero);
}
}
}
if (myConfig.GetAtHomeSeekLocation() == true)
@ -246,7 +255,7 @@ namespace SecondBotEvents.Services
protected void BotClientRestart(object o, BotClientNotice e)
{
botConnected = false;
Console.WriteLine("Homebound Service [Attached to new client]");
LogFormater.Info("Homebound Service [Attached to new client]");
GetClient().Network.LoggedOut += BotLoggedOut;
GetClient().Network.SimConnected += BotLoggedIn;
GetClient().Self.AlertMessage += BotAlertMessage;
@ -264,12 +273,12 @@ namespace SecondBotEvents.Services
softDisable = false;
closeToHome = false;
lastGotoAction = SecondbotHelpers.UnixTimeNow();
Console.WriteLine("Homebound Service [Standby]");
LogFormater.Info("Homebound Service [Standby]");
}
protected void BotLoggedIn(object o, SimConnectedEventArgs e)
{
botConnected = true;
Console.WriteLine("Homebound Service [Active]");
LogFormater.Info("Homebound Service [Active]");
}
public override void Start()
@ -281,14 +290,14 @@ namespace SecondBotEvents.Services
Stop();
running = true;
master.BotClientNoticeEvent += BotClientRestart;
Console.WriteLine("Homebound Service [Starting]");
LogFormater.Info("Homebound Service [Starting]");
}
public override void Stop()
{
if(running == true)
{
Console.WriteLine("Homebound Service [Stopping]");
LogFormater.Info("Homebound Service [Stopping]");
}
running = false;
master.BotClientNoticeEvent -= BotClientRestart;

View file

@ -22,7 +22,7 @@ namespace SecondBotEvents.Services
myConfig = new HttpConfig(master.fromEnv, master.fromFolder);
if (myConfig.GetEnabled() == false)
{
Console.WriteLine(Status());
LogFormater.Info(Status());
return;
}
}
@ -57,7 +57,7 @@ namespace SecondBotEvents.Services
protected void BotClientRestart(object o, BotClientNotice e)
{
acceptBotCommands = false;
Console.WriteLine("HTTP service [Attached to new client]");
LogFormater.Info("HTTP service [Attached to new client]");
GetClient().Network.LoggedOut += BotLoggedOut;
GetClient().Network.SimConnected += BotLoggedIn;
}
@ -66,7 +66,7 @@ namespace SecondBotEvents.Services
{
acceptBotCommands = false;
GetClient().Network.SimConnected += BotLoggedIn;
Console.WriteLine("HTTP service [Bot commands disabled]");
LogFormater.Info("HTTP service [Bot commands disabled]");
}
protected void BotLoggedIn(object o, SimConnectedEventArgs e)
@ -80,7 +80,7 @@ namespace SecondBotEvents.Services
{
if (myConfig.GetEnabled() == false)
{
Console.WriteLine("HTTP service [Disabled]");
LogFormater.Info("HTTP service [Disabled]");
return;
}
Stop();
@ -92,7 +92,7 @@ namespace SecondBotEvents.Services
{
if(running == true)
{
Console.WriteLine("HTTP service [Stopping]");
LogFormater.Info("HTTP service [Stopping]");
}
running = false;
if (myConfig.GetEnabled() == false)
@ -119,7 +119,7 @@ namespace SecondBotEvents.Services
.WithModule(new ActionModule("/", HttpVerbs.Any, ctx => ctx.SendDataAsync(new { Message = "Error" }))
);
HTTPendpoint.RunAsync();
Console.WriteLine("HTTP service [Enabled] on port "+ myConfig.GetPort().ToString());
LogFormater.Info("HTTP service [Enabled] on port "+ myConfig.GetPort().ToString());
}
}

View file

@ -17,7 +17,7 @@ namespace SecondBotEvents.Services
myConfig = new InteractionConfig(master.fromEnv,master.fromFolder);
if (myConfig.GetEnabled() == false)
{
Console.WriteLine(Status());
LogFormater.Info(Status());
return;
}
}
@ -68,7 +68,7 @@ namespace SecondBotEvents.Services
protected void BotClientRestart(object o, BotClientNotice e)
{
botConnected = false;
Console.WriteLine("Interaction Service [Attached to new client]");
LogFormater.Info("Interaction Service [Attached to new client]");
GetClient().Network.LoggedOut += BotLoggedOut;
GetClient().Network.SimConnected += BotLoggedIn;
}
@ -168,7 +168,7 @@ namespace SecondBotEvents.Services
{
botConnected = false;
GetClient().Network.SimConnected += BotLoggedIn;
Console.WriteLine("Interaction Service [Standby]");
LogFormater.Info("Interaction Service [Standby]");
}
protected void BotLoggedIn(object o, SimConnectedEventArgs e)
@ -179,27 +179,27 @@ namespace SecondBotEvents.Services
GetClient().Groups.GroupInvitation += BotGroupInviteOffer;
GetClient().Self.IM += BotTeleportOffer;
botConnected = true;
Console.WriteLine("Interaction Service [Active]");
LogFormater.Info("Interaction Service [Active]");
}
public override void Start()
{
if (myConfig.GetEnabled() == false)
{
Console.WriteLine("Interaction Service [- Not requested -]");
LogFormater.Info("Interaction Service [- Not requested -]");
return;
}
Stop();
running = true;
master.BotClientNoticeEvent += BotClientRestart;
Console.WriteLine("Interaction Service [Starting]");
LogFormater.Info("Interaction Service [Starting]");
}
public override void Stop()
{
if(running == true)
{
Console.WriteLine("Interaction Service [Stopping]");
LogFormater.Info("Interaction Service [Stopping]");
}
running = false;
if (myConfig.GetEnabled() == false)

View file

@ -35,7 +35,7 @@ namespace SecondBotEvents.Services
protected void BotClientRestart(object o, BotClientNotice e)
{
botConnected = false;
Console.WriteLine("Relay Service [Attached to new client]");
LogFormater.Info("Relay Service [Attached to new client]");
GetClient().Network.LoggedOut += BotLoggedOut;
GetClient().Network.SimConnected += BotLoggedIn;
}
@ -44,7 +44,7 @@ namespace SecondBotEvents.Services
{
botConnected = false;
GetClient().Network.SimConnected += BotLoggedIn;
Console.WriteLine("Relay Service [Standby]");
LogFormater.Info("Relay Service [Standby]");
}
protected void BotLoggedIn(object o, SimConnectedEventArgs e)
@ -53,7 +53,7 @@ namespace SecondBotEvents.Services
GetClient().Self.IM += BotImMessage;
GetClient().Self.ChatFromSimulator += LocalChat;
botConnected = true;
Console.WriteLine("Relay Service [Active]");
LogFormater.Info("Relay Service [Active]");
}
readonly string[] hard_blocked_agents = new[] { "secondlife", "second life" };
@ -132,14 +132,14 @@ namespace SecondBotEvents.Services
Stop();
running = true;
master.BotClientNoticeEvent += BotClientRestart;
Console.WriteLine("Relay Service [Starting]");
LogFormater.Info("Relay Service [Starting]");
}
public override void Stop()
{
if(running == true)
{
Console.WriteLine("Relay Service [Stopping]");
LogFormater.Info("Relay Service [Stopping]");
}
running = false;
master.BotClientNoticeEvent -= BotClientRestart;