inventory uodate
This commit is contained in:
parent
a91e221171
commit
5d4d3b8420
9 changed files with 231 additions and 14 deletions
|
|
@ -43,11 +43,11 @@
|
||||||
<Optimize>True</Optimize>
|
<Optimize>True</Optimize>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="log4net" Version="2.0.15" />
|
<PackageReference Include="log4net" Version="2.0.17" />
|
||||||
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="8.0.6" />
|
||||||
<PackageReference Include="OggVorbisEncoder" Version="1.2.2" />
|
<PackageReference Include="OggVorbisEncoder" Version="1.2.2" />
|
||||||
<PackageReference Include="OpenJpegDotNet-LMV" Version="2.4.0.5" />
|
<PackageReference Include="OpenJpegDotNet-LMV" Version="2.4.0.5" />
|
||||||
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="8.0.6" />
|
||||||
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||||
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
|
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
|
||||||
<PackageReference Include="System.Threading.Channels" Version="8.0.0" />
|
<PackageReference Include="System.Threading.Channels" Version="8.0.0" />
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
using SecondBotEvents.Services;
|
using Newtonsoft.Json;
|
||||||
|
using SecondBotEvents.Services;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace SecondBotEvents.Commands
|
namespace SecondBotEvents.Commands
|
||||||
{
|
{
|
||||||
|
|
@ -42,6 +45,20 @@ namespace SecondBotEvents.Commands
|
||||||
return BasicReply(master.DiscordService.BanMember(serverid, memberid, why).Result.ToString(), new [] { serverid, memberid, why });
|
return BasicReply(master.DiscordService.BanMember(serverid, memberid, why).Result.ToString(), new [] { serverid, memberid, why });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object Discord_GetMemberRoles(string serverid, string memberid)
|
||||||
|
{
|
||||||
|
if (master.DiscordService.DiscordReady() == false)
|
||||||
|
{
|
||||||
|
return Failure("Discord client not ready");
|
||||||
|
}
|
||||||
|
KeyValuePair<bool, List<string>> reply = master.DiscordService.DiscordMemerRoles(serverid, memberid);
|
||||||
|
if(reply.Key == false)
|
||||||
|
{
|
||||||
|
return Failure(reply.Value.First());
|
||||||
|
}
|
||||||
|
return BasicReply(JsonConvert.SerializeObject(reply.Value));
|
||||||
|
}
|
||||||
|
|
||||||
[About("Clears messages on the server sent by the member in the last 13 days, 22hours 59mins")]
|
[About("Clears messages on the server sent by the member in the last 13 days, 22hours 59mins")]
|
||||||
[ReturnHintsFailure("Discord client not ready")]
|
[ReturnHintsFailure("Discord client not ready")]
|
||||||
[ReturnHints("true|false")]
|
[ReturnHints("true|false")]
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,12 @@ namespace SecondBotEvents.Commands
|
||||||
[ArgHints("outputTarget", "HTTP url, channel, avatar UUID or clear to remove all events for the selected type")]
|
[ArgHints("outputTarget", "HTTP url, channel, avatar UUID or clear to remove all events for the selected type")]
|
||||||
public object SetInventoryUpdate(string inventoryType, string outputTarget)
|
public object SetInventoryUpdate(string inventoryType, string outputTarget)
|
||||||
{
|
{
|
||||||
return Failure("@todo inventory update events");
|
if (master.EventsService.isRunning() == true)
|
||||||
|
{
|
||||||
|
master.EventsService.AddInventoryEvent(inventoryType, outputTarget);
|
||||||
|
return BasicReply("Ok");
|
||||||
|
}
|
||||||
|
return Failure("Events service is not running");
|
||||||
}
|
}
|
||||||
|
|
||||||
[About("Uploads a new sound file to inventory")]
|
[About("Uploads a new sound file to inventory")]
|
||||||
|
|
@ -151,7 +156,7 @@ namespace SecondBotEvents.Commands
|
||||||
[ReturnHints("ok")]
|
[ReturnHints("ok")]
|
||||||
[ReturnHints("okMulti")]
|
[ReturnHints("okMulti")]
|
||||||
[ReturnHints("invaild item uuid pr invaild attach point")]
|
[ReturnHints("invaild item uuid pr invaild attach point")]
|
||||||
[ArgHints("item", "UUID of item, or the attach point")]
|
[ArgHints("item", "UUID of item, or the attach point, or * to remove everything")]
|
||||||
public object Detach(string item)
|
public object Detach(string item)
|
||||||
{
|
{
|
||||||
if (UUID.TryParse(item, out UUID itemuuid) == false)
|
if (UUID.TryParse(item, out UUID itemuuid) == false)
|
||||||
|
|
@ -159,7 +164,7 @@ namespace SecondBotEvents.Commands
|
||||||
List<InventoryItem> toBeRemoved = new List<InventoryItem>();
|
List<InventoryItem> toBeRemoved = new List<InventoryItem>();
|
||||||
foreach (KeyValuePair<UUID, AttachmentPoint> pair in GetClient().Appearance.GetAttachmentsByItemId())
|
foreach (KeyValuePair<UUID, AttachmentPoint> pair in GetClient().Appearance.GetAttachmentsByItemId())
|
||||||
{
|
{
|
||||||
if(pair.Value.ToString() != item)
|
if((pair.Value.ToString() != item) || (item == "*"))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -425,6 +430,15 @@ namespace SecondBotEvents.Commands
|
||||||
}
|
}
|
||||||
if (RealObject.Value == null)
|
if (RealObject.Value == null)
|
||||||
{
|
{
|
||||||
|
GetClient().Objects.RequestObjectMedia(objectUUID, GetClient().Network.CurrentSim, null);
|
||||||
|
foreach (KeyValuePair<uint, Primitive> Obj in objects_copy)
|
||||||
|
{
|
||||||
|
if (Obj.Value.ID == objectUUID)
|
||||||
|
{
|
||||||
|
RealObject = Obj;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
return Failure("Unable to find object", new [] { item, objectuuid, running });
|
return Failure("Unable to find object", new [] { item, objectuuid, running });
|
||||||
}
|
}
|
||||||
bool scriptState = runscript;
|
bool scriptState = runscript;
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,10 @@ namespace SecondBotEvents.Config
|
||||||
settings.Add("ServerID");
|
settings.Add("ServerID");
|
||||||
settings.Add("ClientToken");
|
settings.Add("ClientToken");
|
||||||
settings.Add("AllowDiscordCommands");
|
settings.Add("AllowDiscordCommands");
|
||||||
|
settings.Add("InteractionEnabled");
|
||||||
|
settings.Add("InteractionCommandName");
|
||||||
|
settings.Add("InteractionHttpTarget");
|
||||||
|
settings.Add("InteractionChannelNumber");
|
||||||
settings.Add("HideStatusOutput");
|
settings.Add("HideStatusOutput");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36,5 +40,30 @@ namespace SecondBotEvents.Config
|
||||||
{
|
{
|
||||||
return ReadSettingAsBool("AllowDiscordCommands");
|
return ReadSettingAsBool("AllowDiscordCommands");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool GetInteractionEnabled()
|
||||||
|
{
|
||||||
|
return ReadSettingAsBool("InteractionEnabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetInteractionHttpTarget()
|
||||||
|
{
|
||||||
|
return ReadSettingAsString("InteractionHttpTarget", "https://localhost/interaction.php");
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetInteractionCommandName()
|
||||||
|
{
|
||||||
|
return ReadSettingAsString("InteractionCommandName","Go");
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetInteractionChannelNumber()
|
||||||
|
{
|
||||||
|
return ReadSettingAsString("InteractionChannelNumber", "-1");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetInteractionEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
mysettings["InteractionEnabled"] = enabled.ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -10,17 +10,17 @@
|
||||||
<DockerfileRunEnvironmentFiles>settings.env</DockerfileRunEnvironmentFiles>
|
<DockerfileRunEnvironmentFiles>settings.env</DockerfileRunEnvironmentFiles>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Discord.Net" Version="3.13.0" />
|
<PackageReference Include="Discord.Net" Version="3.15.2" />
|
||||||
<PackageReference Include="Discord.Net.WebSocket" Version="3.13.0" />
|
<PackageReference Include="Discord.Net.WebSocket" Version="3.15.2" />
|
||||||
<PackageReference Include="EmbedIO" Version="3.4.3" />
|
<PackageReference Include="EmbedIO" Version="3.5.2" />
|
||||||
<PackageReference Include="Microsoft.NET.Build.Containers" Version="8.0.100" />
|
<PackageReference Include="Microsoft.NET.Build.Containers" Version="8.0.302" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
|
||||||
<PackageReference Include="MSBuildGitHash" Version="2.0.2">
|
<PackageReference Include="MSBuildGitHash" Version="2.0.2">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="RestSharp" Version="110.2.0" />
|
<PackageReference Include="RestSharp" Version="111.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\LibreMetaverse\LibreMetaverse.csproj" />
|
<ProjectReference Include="..\LibreMetaverse\LibreMetaverse.csproj" />
|
||||||
|
|
|
||||||
|
|
@ -298,7 +298,7 @@ namespace SecondBotEvents.Services
|
||||||
return new KeyValuePair<bool, string>(false, e.Message);
|
return new KeyValuePair<bool, string>(false, e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CommandNotice(C.command, source + " ~~ Failure: incorrect number of args", String.Join("@@@", C.args), false);
|
CommandNotice(C.command, source + " ~~ Failure: incorrect number of args expected: "+ theMethod.GetParameters().Count().ToString()+" but got "+ argsList.Count.ToString()+"", String.Join("@@@", C.args), false);
|
||||||
return new KeyValuePair<bool, string>(status, reply);
|
return new KeyValuePair<bool, string>(status, reply);
|
||||||
}
|
}
|
||||||
return new KeyValuePair<bool, string>(false, "theMethod is null");
|
return new KeyValuePair<bool, string>(false, "theMethod is null");
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ using SecondBotEvents.Commands;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -94,6 +95,86 @@ namespace SecondBotEvents.Services
|
||||||
remove { lock (m_discordEventChatLock) { m_discordChatEvent -= value; } }
|
remove { lock (m_discordEventChatLock) { m_discordChatEvent -= value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public KeyValuePair<bool, List<string>> DiscordMemerRoles(string givenserverid, string givenmemberid)
|
||||||
|
{
|
||||||
|
if (GetReadyForDiscordActions() == false)
|
||||||
|
{
|
||||||
|
// bot is not ready this message should not have got here yet.
|
||||||
|
return new KeyValuePair<bool, List<string>>(false,new List<string>() { "not ready"});
|
||||||
|
}
|
||||||
|
if (ulong.TryParse(givenserverid, out ulong serverid) == false)
|
||||||
|
{
|
||||||
|
return new KeyValuePair<bool, List<string>>(false, new List<string>() { "invaild server"});
|
||||||
|
}
|
||||||
|
if (ulong.TryParse(givenmemberid, out ulong memberid) == false)
|
||||||
|
{
|
||||||
|
return new KeyValuePair<bool, List<string>>(false, new List<string>() { "invaild member"});
|
||||||
|
}
|
||||||
|
SocketGuild server = DiscordClient.GetGuild(serverid);
|
||||||
|
if (server == null)
|
||||||
|
{
|
||||||
|
return new KeyValuePair<bool, List<string>>(false, new List<string>() { "Cant get server"});
|
||||||
|
}
|
||||||
|
SocketGuildUser user = server.GetUser(memberid);
|
||||||
|
if(user == null)
|
||||||
|
{
|
||||||
|
return new KeyValuePair<bool, List<string>>(false, new List<string>() { "Cant get user" });
|
||||||
|
}
|
||||||
|
List<string> roleids = new List<string>();
|
||||||
|
foreach(SocketRole role in user.Roles)
|
||||||
|
{
|
||||||
|
roleids.Add(role.Id.ToString());
|
||||||
|
}
|
||||||
|
return new KeyValuePair<bool, List<string>>(true, roleids);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected HttpClient HTTPclient = new HttpClient();
|
||||||
|
protected bool MessageInteractionEvent(SocketMessage message, SocketChannel socketChannel)
|
||||||
|
{
|
||||||
|
if (myConfig.GetInteractionEnabled() != true)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (myConfig.GetInteractionChannelNumber() != socketChannel.Id.ToString())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(message.Content.StartsWith(myConfig.GetInteractionCommandName()) == false)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(myConfig.GetInteractionHttpTarget().StartsWith("http") == false)
|
||||||
|
{
|
||||||
|
myConfig.SetInteractionEnabled(false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
string getmessage = message.Content.Replace(myConfig.GetInteractionCommandName(), "");
|
||||||
|
long unixtime = SecondbotHelpers.UnixTimeNow();
|
||||||
|
string hash = SecondbotHelpers.GetSHA1(unixtime.ToString()+getmessage + master.CommandsService.myConfig.GetSharedSecret());
|
||||||
|
Dictionary<string, string> values = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "message", getmessage },
|
||||||
|
{ "username", message.Author.Username },
|
||||||
|
{ "userid", message.Author.Id.ToString() },
|
||||||
|
{ "unixtime", unixtime.ToString() },
|
||||||
|
{ "hash", hash }
|
||||||
|
};
|
||||||
|
var content = new FormUrlEncodedContent(values);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HTTPclient.PostAsync(myConfig.GetInteractionHttpTarget(), content);
|
||||||
|
_ = MarkMessage((IUserMessage)message, "✅");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LogFormater.Crit("[MessageInteractionEvent] HTTP failed: " + e.Message + "");
|
||||||
|
_ = MarkMessage((IUserMessage)message, "❌");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected Task DiscordClientMessageReceived(SocketMessage message)
|
protected Task DiscordClientMessageReceived(SocketMessage message)
|
||||||
{
|
{
|
||||||
if(GetReadyForDiscordActions() == false)
|
if(GetReadyForDiscordActions() == false)
|
||||||
|
|
@ -102,6 +183,10 @@ namespace SecondBotEvents.Services
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
SocketChannel socketChannel = DiscordClient.GetChannel(message.Channel.Id);
|
SocketChannel socketChannel = DiscordClient.GetChannel(message.Channel.Id);
|
||||||
|
if(MessageInteractionEvent(message, socketChannel) == true)
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
if(socketChannel.GetChannelType() != Discord.ChannelType.Text)
|
if(socketChannel.GetChannelType() != Discord.ChannelType.Text)
|
||||||
{
|
{
|
||||||
// bot only does stuff on text channels.
|
// bot only does stuff on text channels.
|
||||||
|
|
@ -471,6 +556,20 @@ namespace SecondBotEvents.Services
|
||||||
_ = DiscordClient.LoginAsync(TokenType.Bot, myConfig.GetClientToken()).ConfigureAwait(false);
|
_ = DiscordClient.LoginAsync(TokenType.Bot, myConfig.GetClientToken()).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Task DiscordInteraction(SocketMessageCommand msg)
|
||||||
|
{
|
||||||
|
if (myConfig.GetInteractionEnabled() == false)
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
if (msg.CommandName != myConfig.GetInteractionCommandName())
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Stop()
|
public override void Stop()
|
||||||
{
|
{
|
||||||
if(running == true)
|
if(running == true)
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,60 @@ namespace SecondBotEvents.Services
|
||||||
protected UUID OutputAvatar = UUID.Zero;
|
protected UUID OutputAvatar = UUID.Zero;
|
||||||
protected long lastGroupMembershipUpdate = 0;
|
protected long lastGroupMembershipUpdate = 0;
|
||||||
|
|
||||||
|
public void InventoryUpdateEvent(Dictionary<string, string> detail)
|
||||||
|
{
|
||||||
|
if (InventoryEvents.ContainsKey(detail["itemtype"]) == true)
|
||||||
|
{
|
||||||
|
foreach(string A in InventoryEvents[detail["itemtype"]])
|
||||||
|
{
|
||||||
|
string output = JsonConvert.SerializeObject(detail);
|
||||||
|
if(UUID.TryParse(A, out UUID OutputAvatar) == true)
|
||||||
|
{
|
||||||
|
if (OutputAvatar != UUID.Zero)
|
||||||
|
{
|
||||||
|
GetClient().Self.InstantMessage(OutputAvatar, output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (A.StartsWith("http") == true)
|
||||||
|
{
|
||||||
|
long unixtime = SecondbotHelpers.UnixTimeNow();
|
||||||
|
string token = SecondbotHelpers.GetSHA1(unixtime.ToString() + "EventService" + GetClient().Self.AgentID + output);
|
||||||
|
var client = new RestClient(A);
|
||||||
|
var request = new RestRequest("Inventory/Update", Method.Post);
|
||||||
|
request.AddParameter("token", token);
|
||||||
|
request.AddParameter("unixtime", unixtime.ToString());
|
||||||
|
request.AddParameter("method", "Inventory");
|
||||||
|
request.AddParameter("action", "Update");
|
||||||
|
request.AddParameter("botname", GetClient().Self.Name);
|
||||||
|
request.AddParameter("event", output);
|
||||||
|
request.AddHeader("content-type", "application/x-www-form-urlencoded");
|
||||||
|
client.ExecutePostAsync(request);
|
||||||
|
}
|
||||||
|
else if (int.TryParse(A, out int chann) == true)
|
||||||
|
{
|
||||||
|
if (chann >= 0)
|
||||||
|
{
|
||||||
|
GetClient().Self.Chat(output, chann, ChatType.Normal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<string, List<string>> InventoryEvents = new Dictionary<string, List<string>>();
|
||||||
|
public void AddInventoryEvent(string inventoryType, string outputTarget)
|
||||||
|
{
|
||||||
|
if(InventoryEvents.ContainsKey(inventoryType) == false)
|
||||||
|
{
|
||||||
|
InventoryEvents.Add(inventoryType, new List<string>());
|
||||||
|
}
|
||||||
|
if (InventoryEvents[inventoryType].Contains(outputTarget) == false)
|
||||||
|
{
|
||||||
|
InventoryEvents[inventoryType].Add(outputTarget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public EventsService(EventsSecondBot setMaster) : base(setMaster)
|
public EventsService(EventsSecondBot setMaster) : base(setMaster)
|
||||||
{
|
{
|
||||||
myConfig = new EventsConfig(master.fromEnv, master.fromFolder);
|
myConfig = new EventsConfig(master.fromEnv, master.fromFolder);
|
||||||
|
|
|
||||||
|
|
@ -198,6 +198,10 @@ namespace SecondBotEvents.Services
|
||||||
details["itemname"] = itm.Name;
|
details["itemname"] = itm.Name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(master.EventsService.isRunning() == true)
|
||||||
|
{
|
||||||
|
master.EventsService.InventoryUpdateEvent(details);
|
||||||
|
}
|
||||||
JsonOuputCleaner(details, "InventoryOffer");
|
JsonOuputCleaner(details, "InventoryOffer");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue