group role storage and more

adds new http namespace parcelestate
adds grouprole metadata storage

adds the following http commands:
parcelestate/parcelbanlist
groups/ismember
groups/listgrouproles

Adds new core command
getparcelbanlist
This commit is contained in:
Madpeterz 2021-02-07 19:03:33 +00:00
parent 29c326f842
commit 92bc9dceb9
10 changed files with 209 additions and 8 deletions

View file

@ -133,8 +133,10 @@ namespace BetterSecondBotShared.bottypes
}
protected Dictionary<UUID, Group> mygroups = new Dictionary<UUID, Group>();
protected Dictionary<UUID, KeyValuePair<long, List<GroupRole>>> mygrouprolesstorage = new Dictionary<UUID, KeyValuePair<long, List<GroupRole>>>();
public Dictionary<UUID, Group> MyGroups { get { return mygroups; } }
public Dictionary<UUID, KeyValuePair<long, List<GroupRole>>> MyGroupRolesStorage { get { return mygrouprolesstorage; } }
protected GridClient Client;
public GridClient GetClient { get { return Client; } }

View file

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Text;
using OpenMetaverse;
using Newtonsoft.Json;
using BetterSecondBotShared.Static;
namespace BetterSecondBot.HttpService
{
@ -15,6 +16,47 @@ namespace BetterSecondBot.HttpService
{
public HttpApiGroup(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { }
[About("Checks if the given UUID is in the given group<br/>Note: if group membership data is more than 60 secs old this will return Updating<br/>Please wait and retry later")]
[ReturnHints("True|False")]
[ReturnHints("Updating")]
[ReturnHints("Unknown group")]
[ReturnHints("Invaild group UUID")]
[ReturnHints("Unable to find avatar UUID")]
[Route(HttpVerbs.Get, "/ismember/{group}/{avatar}/{token}")]
public object ismember(string group,string avatar,string token)
{
if (tokens.Allow(token, getClientIP()) == true)
{
if (UUID.TryParse(group, out UUID groupuuid) == true)
{
if (bot.MyGroups.ContainsKey(groupuuid) == true)
{
if (bot.NeedReloadGroupData(groupuuid) == false)
{
UUID avataruuid = UUID.Zero;
if(UUID.TryParse(avatar,out avataruuid) == false)
{
string lookup = bot.FindAvatarName2Key(avatar);
if (UUID.TryParse(lookup, out avataruuid) == false)
{
return BasicReply("Unable to find avatar UUID");
}
}
bool status = bot.FastCheckInGroup(groupuuid, avataruuid);
return BasicReply(status.ToString());
}
bot.GetClient.Groups.RequestGroupMembers(groupuuid);
return BasicReply("Updating");
}
return BasicReply("Unknown group");
}
return BasicReply("Invaild group UUID");
}
return BasicReply("Token not accepted");
}
[About("fetchs a list of all groups known to the bot")]
[ReturnHints("array UUID=name")]
[Route(HttpVerbs.Get, "/listgroups/{token}")]
@ -32,10 +74,62 @@ namespace BetterSecondBot.HttpService
return BasicReply("Token not accepted");
}
[About("Requests the roles for the selected group<br/>Replys with GroupRoleDetails object formated as follows <ul><li>UpdateUnderway (Bool)</li><li>RoleDataAge (Int) [default -1]</li><li>Roles (KeyPair array of UUID=Name)</li></ul><br/>")]
[ArgHints("group", "URLARG", "UUID of the group")]
[ReturnHints("GroupRoleDetails object")]
[ReturnHints("Group is not currently known")]
[ReturnHints("Invaild group UUID")]
[ReturnHints("Updating")]
[Route(HttpVerbs.Get, "/listgrouproles/{group}/{token}")]
public object listgrouproles(string group, string token)
{
if (tokens.Allow(token, getClientIP()) == true)
{
if (UUID.TryParse(group, out UUID groupuuid) == true)
{
if (bot.MyGroups.ContainsKey(groupuuid) == true)
{
GroupRoleDetails reply = new GroupRoleDetails();
reply.UpdateUnderway = false;
reply.RoleDataAge = -1;
reply.Roles = new Dictionary<string, string>();
if (bot.MyGroupRolesStorage.ContainsKey(groupuuid) == false)
{
reply.UpdateUnderway = true;
}
else
{
long dif = helpers.UnixTimeNow() - bot.MyGroupRolesStorage[groupuuid].Key;
if(dif >= 120)
{
reply.UpdateUnderway = true;
reply.RoleDataAge = dif;
}
foreach(GroupRole gr in bot.MyGroupRolesStorage[groupuuid].Value)
{
reply.Roles.Add(gr.ID.ToString(), gr.Name);
}
}
if(reply.UpdateUnderway == true)
{
if(reply.Roles.Count == 0)
{
return BasicReply("Updating");
}
}
return BasicReply(JsonConvert.SerializeObject(reply));
}
return BasicReply("Group is not currently known");
}
return BasicReply("Invaild group UUID");
}
return BasicReply("Token not accepted");
}
[About("fetchs a list of all groups with unread messages")]
[ReturnHints("array UUID")]
[Route(HttpVerbs.Get, "/listgroupswithunread/{token}")]
public object listgroupswithunread(string group, string token)
public object listgroupswithunread(string token)
{
if (tokens.Allow(token, getClientIP()) == true)
{
@ -93,7 +187,12 @@ namespace BetterSecondBot.HttpService
}
return BasicReply("Token not accepted");
}
}
public class GroupRoleDetails
{
public bool UpdateUnderway { get; set; }
public Dictionary<string,string> Roles { get; set; }
public long RoleDataAge = 0;
}
}

View file

@ -61,8 +61,11 @@ namespace BetterSecondBot.HttpService
.WithController(() => new HttpApiIM(Bot, Tokens))
)
.WithWebApi("/core", m => m
.WithController(() => new HttpApiCore(Config, Bot, Tokens)))
.WithController(() => new HttpApiCore(Config, Bot, Tokens))
)
.WithWebApi("/parcelestate", m => m
.WithController(() => new HttpApiParcelEstate(Bot,Tokens))
)
.WithModule(new ActionModule("/", HttpVerbs.Any, ctx => ctx.SendDataAsync(new { Message = "Error" })));
return server;
}

View file

@ -0,0 +1,50 @@
using BSB.bottypes;
using BSB.Static;
using EmbedIO;
using EmbedIO.Routing;
using EmbedIO.WebApi;
using System;
using System.Collections.Generic;
using System.Text;
using OpenMetaverse;
using Newtonsoft.Json;
using static OpenMetaverse.ParcelManager;
namespace BetterSecondBot.HttpService
{
class HttpApiParcelEstate: WebApiControllerWithTokens
{
public HttpApiParcelEstate(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { }
[About("Fetchs the parcel ban list of the parcel the bot is currently on<br/>If the name returned is lookup the bot is currently requesting the avatar name")]
[ReturnHints("array of UUID=Name")]
[ReturnHints("Error not in a sim")]
[ReturnHints("Parcel data not ready")]
[Route(HttpVerbs.Get, "/parcelbanlist/{token}")]
public object parcelbanlist(string token)
{
if (tokens.Allow(token, getClientIP()) == true)
{
if (bot.GetClient.Network.CurrentSim != null)
{
int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition);
Parcel targetparcel = null;
if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true)
{
targetparcel = bot.GetClient.Network.CurrentSim.Parcels[localid];
Dictionary<string, string> reply = new Dictionary<string, string>();
foreach (ParcelAccessEntry e in targetparcel.AccessBlackList)
{
string name = bot.FindAvatarKey2Name(e.AgentID);
reply.Add(e.AgentID.ToString(), name);
}
return BasicReply(JsonConvert.SerializeObject(reply));
}
return BasicReply("Parcel data not ready");
}
return BasicReply("Error not in a sim");
}
return BasicReply("Token not accepted");
}
}
}

View file

@ -566,6 +566,7 @@ namespace BetterSecondBot.WikiMake
createEndpoint("im", typeof(HttpApiIM));
createEndpoint("groups", typeof(HttpApiGroup));
createEndpoint("chat", typeof(HttpApiLocalchat));
createEndpoint("parcelestate", typeof(HttpApiParcelEstate));
}
public string getCommandMethod(string endpoint, string command)

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;
using static OpenMetaverse.ParcelManager;
namespace BSB.Commands.Parcel
{
class GetParcelBanlist : ParcelCommand_CheckParcel_1arg_smart
{
public override string Helpfile { get { return "Fetchs the current parcels banlist and sends it to the smart reply target on [ARG 1]"; } }
public override bool CallFunction(string[] args)
{
if (base.CallFunction(args) == true)
{
Dictionary<string, string> reply = new Dictionary<string, string>();
foreach(ParcelAccessEntry e in targetparcel.AccessBlackList)
{
string name = bot.FindAvatarKey2Name(e.AgentID);
reply.Add(e.AgentID.ToString(), name);
}
return bot.GetCommandsInterface.SmartCommandReply(true, args[0], targetparcel.Name, CommandName, reply);
}
return false;
}
}
}

View file

@ -55,7 +55,7 @@ namespace BSB.Commands.CMD_Parcel
int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition);
if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true)
{
Parcel p = bot.GetClient.Network.CurrentSim.Parcels[localid];
OpenMetaverse.Parcel p = bot.GetClient.Network.CurrentSim.Parcels[localid];
Dictionary<string, string> collection = new Dictionary<string, string>();
foreach (string cfg in get_flags)
{

View file

@ -19,7 +19,7 @@ namespace BSB.Commands.CMD_Parcel
if (owner_uuids.Count > 0)
{
int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition);
Parcel p = bot.GetClient.Network.CurrentSim.Parcels[localid];
OpenMetaverse.Parcel p = bot.GetClient.Network.CurrentSim.Parcels[localid];
if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true)
{
if (parcel_static.has_parcel_perm(p, bot) == true)

View file

@ -55,7 +55,7 @@ namespace BSB.Commands.CMD_Parcel
int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition);
if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true)
{
Parcel p = bot.GetClient.Network.CurrentSim.Parcels[localid];
OpenMetaverse.Parcel p = bot.GetClient.Network.CurrentSim.Parcels[localid];
if (parcel_static.has_parcel_perm(p, bot) == true)
{
foreach (KeyValuePair<string, bool> cfg in setflags)

View file

@ -3,7 +3,8 @@ using System;
using System.Collections.Generic;
using System.Text;
using OpenMetaverse;
using BetterSecondBotShared.Static;
namespace BSB.bottypes
{
public abstract class AwaitReplyEventBot : CommandsBot
@ -111,6 +112,24 @@ namespace BSB.bottypes
{
if(await_events.ContainsKey("grouproles") == true)
{
// update group role storage
List<GroupRole> entrys = new List<GroupRole>();
foreach(GroupRole gr in e.Roles.Values)
{
entrys.Add(gr);
}
KeyValuePair<long, List<GroupRole>> storage = new KeyValuePair<long, List<GroupRole>>(helpers.UnixTimeNow(), entrys);
if (mygrouprolesstorage.ContainsKey(e.GroupID) == false)
{
mygrouprolesstorage.Add(e.GroupID, storage);
}
else
{
mygrouprolesstorage[e.GroupID] = storage;
}
List<string> PurgeAwaiters = new List<string>();
foreach(KeyValuePair<string, KeyValuePair<CoreCommand, string[]>> await_reply in await_events["grouproles"])
{