Added script creation from http
Will fetch github link, and send compiled contents to avatar
This commit is contained in:
parent
63968b705e
commit
d2d504c8cb
3 changed files with 218 additions and 0 deletions
81
Core/Commands/Script/scriptHttp.cs
Normal file
81
Core/Commands/Script/scriptHttp.cs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using BetterSecondBotShared.Static;
|
||||
using OpenMetaverse;
|
||||
using RestSharp;
|
||||
|
||||
namespace BSB.Commands.script
|
||||
{
|
||||
public class ScriptHttp : CoreCommand_2arg
|
||||
{
|
||||
public override string[] ArgTypes { get { return new[] { "TEXT", "Avatar" }; } }
|
||||
public override string[] ArgHints { get { return new[] { "File endpoint", "Avatar Name/UUID to recive script" }; } }
|
||||
public override string Helpfile { get { return "[StreamAdmin]\nThis command is part of the streamadmin commands set\n No end user support will be given."; } }
|
||||
public override bool CallFunction(string[] args)
|
||||
{
|
||||
if (base.CallFunction(args) == true)
|
||||
{
|
||||
string attempt_endpoint = args[0];
|
||||
|
||||
if(attempt_endpoint.Contains("https://github.com/"))
|
||||
{
|
||||
attempt_endpoint.Replace("https://github.com/", "https://raw.githubusercontent.com/");
|
||||
}
|
||||
|
||||
var client = new RestClient(attempt_endpoint);
|
||||
var request = new RestRequest("", Method.GET);
|
||||
request.AddHeader("content-type", "application/x-www-form-urlencoded");
|
||||
IRestResponse endpoint_checks = client.Get(request);
|
||||
if (endpoint_checks.StatusCode == System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (endpoint_checks.IsSuccessful == true)
|
||||
{
|
||||
if (endpoint_checks.Content.Length > 3)
|
||||
{
|
||||
if (UUID.TryParse(args[1], out UUID Avatar))
|
||||
{
|
||||
return bot.SendScript(attempt_endpoint.Split('/').LastOrDefault(), endpoint_checks.Content, Avatar);
|
||||
}
|
||||
else
|
||||
{
|
||||
Failed("Avatar UUID not valid");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Failed("script title is to short");
|
||||
}
|
||||
}
|
||||
return Failed(endpoint_checks.ErrorMessage);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return Failed("Error: " + e.Message + "");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Failed("HTTP error DataObject broken Status:" + endpoint_checks.StatusCode.ToString() + " @ " + attempt_endpoint + "");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class scriptendpoint : endpoint
|
||||
{
|
||||
public string AvatarUUID { get; set; }
|
||||
public string scriptTitle { get; set; }
|
||||
public string scriptContent { get; set; }
|
||||
}
|
||||
|
||||
public class endpoint
|
||||
{
|
||||
public bool status { get; set; }
|
||||
public string message { get; set; }
|
||||
}
|
||||
}
|
||||
48
Core/Commands/Script/scriptSend.cs
Normal file
48
Core/Commands/Script/scriptSend.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using BetterSecondBotShared.Static;
|
||||
using OpenMetaverse;
|
||||
|
||||
namespace BSB.Commands.Script
|
||||
{
|
||||
class ScriptSend : CoreCommand_2arg
|
||||
{
|
||||
public override string[] ArgTypes { get { return new[] { "Avatar","Text","Text" }; } }
|
||||
public override string[] ArgHints { get { return new[] { "Avatar [UUID or Firstname Lastname]", "Collection","Script name" }; } }
|
||||
public override string Helpfile { get { return "Creats and send a Script to [ARG 1]<br/>" +
|
||||
" using the collection [ARG 2] as the content <br/>" +
|
||||
" Optional: You can name the Script using [ARG 3]"; } }
|
||||
|
||||
public override bool CallFunction(string[] args)
|
||||
{
|
||||
if (base.CallFunction(args) == true)
|
||||
{
|
||||
// target UUID,Script storage id,["Script title" <unixtime> or defaults to: New Script for <UUID> <unixtime>]
|
||||
if (UUID.TryParse(args[0], out UUID target) == true)
|
||||
{
|
||||
string content = bot.GetScriptContent(args[1]);
|
||||
if (content != null)
|
||||
{
|
||||
bot.ClearScriptStorage(args[1]);
|
||||
string Script_name = "New Script for " + args[0] + " " + helpers.UnixTimeNow().ToString() + "";
|
||||
if (args.Length == 3)
|
||||
{
|
||||
Script_name = args[2] + " " + helpers.UnixTimeNow().ToString() + "";
|
||||
}
|
||||
return bot.SendScript(Script_name, content, target);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Failed("No content in Script storage " + args[1]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Failed("Arg 0 not a UUID");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -82,6 +82,7 @@ namespace BSB.bottypes
|
|||
public Commands.CoreCommandsInterface GetCommandsInterface { get { return CommandsInterface; } }
|
||||
protected Commands.CoreCommandsInterface CommandsInterface;
|
||||
|
||||
protected Dictionary<string, string> Scripts_content = new Dictionary<string, string>();
|
||||
protected Dictionary<string, string> notecards_content = new Dictionary<string, string>();
|
||||
protected Dictionary<UUID, long> group_invite_lockout_timer = new Dictionary<UUID, long>();
|
||||
protected long last_cleanup_commands;
|
||||
|
|
@ -254,5 +255,93 @@ namespace BSB.bottypes
|
|||
);
|
||||
return returnstatus;
|
||||
}
|
||||
public void ScriptAddContent(string target_Script_storage_id, string content)
|
||||
{
|
||||
ScriptAddContent(target_Script_storage_id, content, true, "\n\r");
|
||||
}
|
||||
public void ScriptAddContent(string target_Script_storage_id, string content, bool add_newline)
|
||||
{
|
||||
ScriptAddContent(target_Script_storage_id, content, add_newline, "\n\r");
|
||||
}
|
||||
public void ScriptAddContent(string target_Script_storage_id, string content, bool add_newline, string newlinevalue)
|
||||
{
|
||||
if (Scripts_content.ContainsKey(target_Script_storage_id) == false)
|
||||
{
|
||||
Scripts_content.Add(target_Script_storage_id, "");
|
||||
}
|
||||
if (add_newline == true)
|
||||
{
|
||||
content = "" + newlinevalue + "" + content;
|
||||
}
|
||||
Scripts_content[target_Script_storage_id] = Scripts_content[target_Script_storage_id] + "" + content;
|
||||
}
|
||||
public string GetScriptContent(string target_Script_storage_id)
|
||||
{
|
||||
if (Scripts_content.ContainsKey(target_Script_storage_id) == true)
|
||||
{
|
||||
return Scripts_content[target_Script_storage_id];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ClearScriptStorage(string target_Script_storage_id)
|
||||
{
|
||||
if (Scripts_content.ContainsKey(target_Script_storage_id) == true)
|
||||
{
|
||||
Scripts_content.Remove(target_Script_storage_id);
|
||||
}
|
||||
}
|
||||
|
||||
public bool SendScript(string name, string content, UUID sendToUUID)
|
||||
{
|
||||
bool returnstatus = true;
|
||||
name = name + " " + DateTime.Now;
|
||||
Client.Inventory.RequestCreateItem(
|
||||
Client.Inventory.FindFolderForType(AssetType.LSLText),
|
||||
name,
|
||||
name + " Created via SecondBot Script API",
|
||||
AssetType.LSLText,
|
||||
UUID.Random(),
|
||||
InventoryType.LSL,
|
||||
PermissionMask.All,
|
||||
(bool Success, InventoryItem item) =>
|
||||
{
|
||||
if (Success)
|
||||
{
|
||||
AssetScriptText empty = new AssetScriptText { Source = "\n" };
|
||||
empty.Encode();
|
||||
Client.Inventory.RequestUpdateScriptAgentInventory(new byte[] { }, item.UUID, true,
|
||||
(bool uploadSuccess, string uploadStatus, bool compileSuccess, List<string> compileMessages, UUID itemID, UUID assetID) =>
|
||||
{
|
||||
if (uploadSuccess)
|
||||
{
|
||||
empty.AssetData = Encoding.ASCII.GetBytes(content);
|
||||
Client.Inventory.RequestUpdateScriptAgentInventory(empty.AssetData, itemID,true,
|
||||
(bool finaluploadSuccess, string finaluploadStatus, bool finalcompileSuccess, List<string> finalcompileMessages, UUID finalitemID, UUID finalassetID) =>
|
||||
{
|
||||
if (finalcompileSuccess == false)
|
||||
{
|
||||
ConsoleLog.Warn("Script failed to compile, sending anyway.");
|
||||
}
|
||||
Client.Inventory.GiveItem(finalitemID, name, AssetType.LSLText, sendToUUID, false);
|
||||
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Crit("The fuck empty success Script create");
|
||||
returnstatus = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Warn("Unable to find default Scripts folder");
|
||||
returnstatus = false;
|
||||
}
|
||||
}
|
||||
);
|
||||
return returnstatus;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue