Make InventoryUpdateEvent asynchronous
Wraps InventoryUpdateEvent logic in a Task to run asynchronously, improving responsiveness and preventing blocking of the main thread during event processing.
This commit is contained in:
parent
050ef3c133
commit
04b4e872a8
1 changed files with 40 additions and 35 deletions
|
|
@ -8,6 +8,7 @@ using System.Text.Json;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Swan;
|
using Swan;
|
||||||
using RestSharp;
|
using RestSharp;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SecondBotEvents.Services
|
namespace SecondBotEvents.Services
|
||||||
{
|
{
|
||||||
|
|
@ -28,13 +29,16 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
public void InventoryUpdateEvent(Dictionary<string, string> detail)
|
public void InventoryUpdateEvent(Dictionary<string, string> detail)
|
||||||
{
|
{
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
|
||||||
detail["itemtype"] = detail["itemtype"].ToLower().FirstCharToUpper();
|
detail["itemtype"] = detail["itemtype"].ToLower().FirstCharToUpper();
|
||||||
if (InventoryEvents.ContainsKey(detail["itemtype"]) == true)
|
if (InventoryEvents.ContainsKey(detail["itemtype"]) == true)
|
||||||
{
|
{
|
||||||
foreach(string A in InventoryEvents[detail["itemtype"]])
|
foreach (string A in InventoryEvents[detail["itemtype"]])
|
||||||
{
|
{
|
||||||
string output = JsonSerializer.Serialize(detail);
|
string output = JsonSerializer.Serialize(detail);
|
||||||
if(UUID.TryParse(A, out UUID OutputAvatar) == true)
|
if (UUID.TryParse(A, out UUID OutputAvatar) == true)
|
||||||
{
|
{
|
||||||
if (OutputAvatar != UUID.Zero)
|
if (OutputAvatar != UUID.Zero)
|
||||||
{
|
{
|
||||||
|
|
@ -44,7 +48,7 @@ namespace SecondBotEvents.Services
|
||||||
else if (A.StartsWith("http") == true)
|
else if (A.StartsWith("http") == true)
|
||||||
{
|
{
|
||||||
long unixtime = SecondbotHelpers.UnixTimeNow();
|
long unixtime = SecondbotHelpers.UnixTimeNow();
|
||||||
string token = SecondbotHelpers.GetSHA1(unixtime.ToString() + "EventService" + GetClient().Self.AgentID + output+master.CommandsService.myConfig.GetSharedSecret());
|
string token = SecondbotHelpers.GetSHA1(unixtime.ToString() + "EventService" + GetClient().Self.AgentID + output + master.CommandsService.myConfig.GetSharedSecret());
|
||||||
var client = new RestClient(A);
|
var client = new RestClient(A);
|
||||||
var request = new RestRequest("Inventory/Update", Method.Post);
|
var request = new RestRequest("Inventory/Update", Method.Post);
|
||||||
request.AddParameter("token", token);
|
request.AddParameter("token", token);
|
||||||
|
|
@ -66,6 +70,7 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<string, List<string>> InventoryEvents = [];
|
Dictionary<string, List<string>> InventoryEvents = [];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue