smart reply update to use json encoding and collections, most commands help info updated but i might have missed some

This commit is contained in:
Madpeter 2020-05-11 15:01:23 +01:00
parent cbf6dd0709
commit 8f59ba4bb7
22 changed files with 122 additions and 90 deletions

View file

@ -7,20 +7,14 @@ namespace BSB.Commands.Group
{
public class GetGroupList : CoreGroupCommand_SmartReply_auto
{
public override string Helpfile { get { return "Returns a csv of known groups NAME=UUID,NAME=UUID... "; } }
public override string Helpfile { get { return "Gets a list of groups Json encoded"; } }
protected override string RunFunction()
{
StringBuilder reply = new StringBuilder();
string addon = "";
foreach (KeyValuePair<UUID, OpenMetaverse.Group> groupdata in bot.MyGroups)
{
reply.Append(addon);
addon = ",";
reply.Append(groupdata.Value.Name);
reply.Append("=");
reply.Append(groupdata.Key);
collection.Add(groupdata.Value.Name, groupdata.Key.ToString());
}
return reply.ToString();
return "grouplist=loaded";
}
}
}

View file

@ -7,7 +7,7 @@ namespace BSB.Commands.Group
{
public class GetGroupRoles : CoreGroupCommand_SmartReply_Group
{
public override string Helpfile { get { return "Returns group=UUID@@@rolename=UUID,rolename=UUID ... "; } }
public override string Helpfile { get { return "Gets a list of group roles Json encoded "; } }
public override bool CallFunction(string[] args)
{
if (base.CallFunction(args) == true)
@ -36,23 +36,14 @@ namespace BSB.Commands.Group
public override void Callback(string[] args, EventArgs e)
{
GroupRolesDataReplyEventArgs rolesData = (GroupRolesDataReplyEventArgs)e;
StringBuilder reply = new StringBuilder();
reply.Append("group=");
reply.Append(args[1]);
reply.Append("@@@");
string addon = "";
foreach(KeyValuePair<UUID,GroupRole> data in rolesData.Roles)
{
if (data.Key != UUID.Zero)
{
reply.Append(addon);
addon = ",";
reply.Append(data.Value.Name);
reply.Append("=");
reply.Append(data.Key.ToString());
collection.Add(data.Value.Name, data.Key.ToString());
}
}
bot.GetCommandsInterface.SmartCommandReply(args[0], reply.ToString(), CommandName);
bot.GetCommandsInterface.SmartCommandReply(true,args[0], "group=" + args[1], CommandName,collection);
base.Callback(args, e);
}
}

View file

@ -1,4 +1,5 @@
using OpenMetaverse;
using System.Collections.Generic;
namespace BSB.Commands.Group
{
@ -12,14 +13,15 @@ namespace BSB.Commands.Group
{
if (base.CallFunction(args) == true)
{
return bot.GetCommandsInterface.SmartCommandReply(args[0], RunFunction(), CommandName);
return bot.GetCommandsInterface.SmartCommandReply(true, args[0], RunFunction(), CommandName, collection);
}
return false;
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "", CommandName);
}
}
public abstract class CoreGroupCommand_SmartReply_Group : CoreCommand_2arg
{
protected Dictionary<string, string> collection = new Dictionary<string, string>();
public override string[] ArgTypes { get { return new[] { "Mixed", "UUID" }; } }
public override string[] ArgHints { get { return new[] { "Smart reply [Channel|IM uuid|http url]", "Group" }; } }
}
@ -38,7 +40,7 @@ namespace BSB.Commands.Group
{
if (bot.MyGroups.ContainsKey(targetgroup) == true)
{
return bot.GetCommandsInterface.SmartCommandReply(args[0], RunFunction(targetgroup), CommandName);
return bot.GetCommandsInterface.SmartCommandReply(true,args[0], RunFunction(targetgroup), CommandName);
}
else
{

View file

@ -5,7 +5,7 @@
public override string Helpfile { get { return "Returns True|False via the smart reply target if there are any unread group ims"; } }
protected override string RunFunction()
{
return bot.HasUnreadGroupchats().ToString();
return "groupchatunread="+bot.HasUnreadGroupchats().ToString();
}
}
}

View file

@ -8,7 +8,7 @@ namespace BSB.Commands.Group
protected override string RunFunction(UUID targetgroup)
{
return bot.GroupHasUnread(targetgroup).ToString();
return ""+targetgroup.ToString()+"=" + bot.GroupHasUnread(targetgroup).ToString();
}
}

View file

@ -1,4 +1,6 @@
using System;
using System.Linq;
using Microsoft.VisualBasic.CompilerServices;
using OpenMetaverse;
namespace BSB.Commands.Group
@ -8,7 +10,13 @@ namespace BSB.Commands.Group
public override string Helpfile { get { return "Returns the chat history for the selected group [ARG 2] via smart reply [ARG 1]"; } }
protected override string RunFunction(UUID targetgroup)
{
return String.Join("###", bot.GetGroupchat(targetgroup));
int entry = 1;
foreach(string A in bot.GetGroupchat(targetgroup))
{
collection.Add(entry.ToString(),A);
entry++;
}
return "group="+targetgroup.ToString()+"";
}
}
}

View file

@ -5,19 +5,17 @@ namespace BSB.Commands.Group
{
public class GroupchatListAllUnreadGroups : CoreGroupCommand_SmartReply_auto
{
public override string Helpfile { get { return "Returns a csv of groups with unread messages: UUID,UUID... "; } }
public override string Helpfile { get { return "Returns what groups have unread messages "; } }
protected override string RunFunction()
{
StringBuilder reply = new StringBuilder();
string addon = "";
int entry = 1;
foreach (UUID group in bot.UnreadGroupchatGroups())
{
reply.Append(addon);
addon = ",";
reply.Append(group);
collection.Add(entry.ToString(),group.ToString());
entry++;
}
return reply.ToString();
return "count="+collection.Count.ToString();
}
}
}

View file

@ -9,11 +9,11 @@
{
if (bot.GetAllowFunds == true)
{
bool status = bot.GetCommandsInterface.SmartCommandReply(args[0], bot.GetClient.Self.Balance.ToString(), CommandName);
bool status = bot.GetCommandsInterface.SmartCommandReply(true,args[0], bot.GetClient.Self.Balance.ToString(), CommandName);
bot.GetClient.Self.RequestBalance();
return status;
}
return bot.GetCommandsInterface.SmartCommandReply(args[0], "0", CommandName);
return bot.GetCommandsInterface.SmartCommandReply(false,args[0], "0", CommandName);
}
return false;
}

View file

@ -7,7 +7,7 @@
{
if (base.CallFunction(args) == true)
{
return bot.GetCommandsInterface.SmartCommandReply(args[0], bot.GetClient.Self.RelativePosition.ToString(), CommandName);
return bot.GetCommandsInterface.SmartCommandReply(true,args[0], bot.GetClient.Self.RelativePosition.ToString(), CommandName);
}
return false;
}

View file

@ -8,7 +8,7 @@
{
if (base.CallFunction(args) == true)
{
return bot.GetCommandsInterface.SmartCommandReply(args[0], targetparcel.Name, CommandName);
return bot.GetCommandsInterface.SmartCommandReply(true,args[0], targetparcel.Name, CommandName);
}
return false;
}

View file

@ -7,7 +7,7 @@
{
if (base.CallFunction(args) == true)
{
return bot.GetCommandsInterface.SmartCommandReply(args[0], bot.GetClient.Network.CurrentSim.Name, CommandName);
return bot.GetCommandsInterface.SmartCommandReply(true,args[0], bot.GetClient.Network.CurrentSim.Name, CommandName);
}
return false;
}

View file

@ -9,7 +9,7 @@ namespace BSB.Commands.Info
{
if (base.CallFunction(args) == true)
{
return bot.GetCommandsInterface.SmartCommandReply(args[0], helpers.UnixTimeNow().ToString(), CommandName);
return bot.GetCommandsInterface.SmartCommandReply(true,args[0], helpers.UnixTimeNow().ToString(), CommandName);
}
return false;
}

View file

@ -37,7 +37,7 @@ namespace BSB.Commands.Inventory
}
else
{
return bot.GetCommandsInterface.SmartCommandReply(args[0], String.Join("~|~", content), CommandName);
return bot.GetCommandsInterface.SmartCommandReply(true, args[0], String.Join("~|~", content), CommandName);
}
}
else

View file

@ -27,7 +27,7 @@ namespace BSB.Commands.Inventory
else
{
string reply = HelperInventory.MapFolder(bot, true);
return bot.GetCommandsInterface.SmartCommandReply(args[0], reply, CommandName);
return bot.GetCommandsInterface.SmartCommandReply(true,args[0], reply, CommandName);
}
}
return false;

View file

@ -8,7 +8,7 @@
{
if (base.CallFunction(args) == true)
{
return bot.GetCommandsInterface.SmartCommandReply(args[0], targetparcel.Desc, CommandName);
return bot.GetCommandsInterface.SmartCommandReply(true, args[0], targetparcel.Desc, CommandName);
}
return false;
}

View file

@ -56,20 +56,15 @@ namespace BSB.Commands.CMD_Parcel
if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true)
{
Parcel p = bot.GetClient.Network.CurrentSim.Parcels[localid];
StringBuilder reply = new StringBuilder();
string addon = "";
Dictionary<string, string> collection = new Dictionary<string, string>();
foreach (string cfg in get_flags)
{
if (flags.ContainsKey(cfg) == true)
{
reply.Append(addon);
reply.Append(cfg);
reply.Append("=");
reply.Append(p.Flags.HasFlag(flags[cfg]).ToString());
addon = ",";
collection.Add(cfg, p.Flags.HasFlag(flags[cfg]).ToString());
}
}
return bot.GetCommandsInterface.SmartCommandReply(target, reply.ToString(), CommandName);
return bot.GetCommandsInterface.SmartCommandReply(true,target, p.Name, CommandName, collection);
}
else
{

View file

@ -5,7 +5,7 @@ using System.Text;
namespace BSB.Commands.CMD_Parcel
{
class ParcelPrimCountAvatar : CoreCommand_2arg
class ParcelPrimCountAvatar : CoreCommand_SmartReply_2arg
{
public override string[] ArgTypes { get { return new[] { "Smart","Avatar" }; } }
public override string[] ArgHints { get { return new[] { "Smart reply target: Channel,Avatar,HTTP url","the avatar (UUID or Firstname Lastname) we want the count of back" }; } }
@ -25,25 +25,18 @@ namespace BSB.Commands.CMD_Parcel
{
if (UUID.TryParse(args[1], out UUID avatar) == true)
{
StringBuilder reply = new StringBuilder();
int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition);
reply.Append("DATA=");
reply.Append(bot.GetClient.Network.CurrentSim.Name);
reply.Append(",");
reply.Append(localid.ToString());
reply.Append(",");
reply.Append(avatar.ToString());
reply.Append(",");
collection.Add("sim", bot.GetClient.Network.CurrentSim.Name);
if (owner_uuids.Contains(avatar) == true)
{
int owner_count = owner_counts[owner_uuids.IndexOf(avatar)];
reply.Append(owner_count.ToString());
collection.Add("count", owner_count.ToString());
}
else
{
reply.Append("0");
collection.Add("count", "0");
}
base.Callback(args, e, bot.GetCommandsInterface.SmartCommandReply(args[0], reply.ToString(), CommandName));
base.Callback(args, e, bot.GetCommandsInterface.SmartCommandReply(true,args[0], "avatar="+ avatar.ToString(), CommandName,collection));
}
else
{

View file

@ -4,10 +4,8 @@ using System.Text;
namespace BSB.Commands.CMD_Parcel
{
class ParcelPrimCountTotal : CoreCommand_1arg
class ParcelPrimCountTotal : CoreCommand_SmartReply_1arg
{
public override string[] ArgTypes { get { return new[] { "Smart" }; } }
public override string[] ArgHints { get { return new[] { "Smart reply target: Channel,Avatar,HTTP url" }; } }
public override string Helpfile { get { return "Returns the total number of prims on the current parcel as follows: DATA=SIMNAME,PARCELID,COUNT"; } }
public override void Callback(string[] args, EventArgs e)
@ -18,15 +16,11 @@ namespace BSB.Commands.CMD_Parcel
{
total_count += owner.Count;
}
StringBuilder reply = new StringBuilder();
int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition);
reply.Append("DATA=");
reply.Append(bot.GetClient.Network.CurrentSim.Name);
reply.Append(",");
reply.Append(localid.ToString());
reply.Append(",");
reply.Append(total_count.ToString());
base.Callback(args, e, bot.GetCommandsInterface.SmartCommandReply(args[0], reply.ToString(), CommandName));
collection.Add("sim", bot.GetClient.Network.CurrentSim.Name);
collection.Add("parcelid", localid.ToString());
collection.Add("count", total_count.ToString());
base.Callback(args, e, bot.GetCommandsInterface.SmartCommandReply(true,args[0], "ok", CommandName,collection));
}
public override bool CallFunction(string[] args)

View file

@ -10,7 +10,13 @@ namespace BSB.Commands.Self
{
if (base.CallFunction(args) == true)
{
return bot.GetCommandsInterface.SmartCommandReply(args[0], String.Join(',',bot.GetLastCommands(5)), CommandName);
int entry = 1;
foreach(string a in bot.GetLastCommands(5))
{
collection.Add(entry.ToString(), a);
entry++;
}
return bot.GetCommandsInterface.SmartCommandReply(true,args[0], "last=5", CommandName,collection);
}
return false;
}

View file

@ -7,7 +7,7 @@
{
if (base.CallFunction(args) == true)
{
return bot.GetCommandsInterface.SmartCommandReply(args[0], bot.MyVersion, CommandName);
return bot.GetCommandsInterface.SmartCommandReply(true,args[0], bot.MyVersion, CommandName);
}
return false;
}

View file

@ -8,6 +8,7 @@ using BSB.bottypes;
using BetterSecondBotShared.API;
using BetterSecondBotShared.Static;
using BetterSecondBotShared.logs;
using Newtonsoft.Json;
namespace BSB.Commands
{
@ -132,11 +133,13 @@ namespace BSB.Commands
}
protected HttpClient HTTPclient = new HttpClient();
public bool SmartCommandReply(string target, string output)
public bool SmartCommandReply(bool run_status, string target, string output, string command)
{
return SmartCommandReply(target, output, "");
return SmartCommandReply(run_status, target, output, command, null);
}
public bool SmartCommandReply(string target, string output, string command)
public bool SmartCommandReply(bool run_status, string target, string output, string command, Dictionary<string,string> collection)
{
string mode = "CHAT";
UUID target_avatar = UUID.Zero;
@ -151,12 +154,41 @@ namespace BSB.Commands
}
else
{
int.TryParse(target, out target_channel);
if (int.TryParse(target, out target_channel) == false)
{
run_status = false;
}
}
if (collection != null)
{
var reply_object = new CoreCommand_json_reply_wit_collection();
reply_object.status = run_status;
reply_object.command = command;
reply_object.output = output;
reply_object.collection = collection;
output = JsonConvert.SerializeObject(reply_object);
}
else
{
var reply_object = new CoreCommand_json_reply();
reply_object.status = run_status;
reply_object.command = command;
reply_object.output = output;
output = JsonConvert.SerializeObject(reply_object);
}
if (mode == "CHAT")
{
bot.GetClient.Self.Chat(output, target_channel, ChatType.Normal);
if (target_channel >= 0)
{
bot.GetClient.Self.Chat(output, target_channel, ChatType.Normal);
}
else
{
run_status = false;
ConsoleLog.Crit("[SmartReply] output Channel must be zero or higher");
}
}
else if (mode == "IM")
{
@ -167,13 +199,8 @@ namespace BSB.Commands
Dictionary<string, string> values = new Dictionary<string, string>
{
{ "reply", output },
{ "unixtime", helpers.UnixTimeNow().ToString() }
};
if (command != "")
{
values.Add("command", command);
}
var content = new FormUrlEncodedContent(values);
try
{
@ -181,14 +208,16 @@ namespace BSB.Commands
}
catch (Exception e)
{
run_status = false;
ConsoleLog.Crit("[SmartReply] HTTP failed: " + e.Message + "");
}
}
else
{
ConsoleLog.Crit("[SmartReply] Unsupported output target");
return false;
}
return true;
return run_status;
}
protected List<string> suppress_warnings = new List<string>();
@ -266,6 +295,17 @@ namespace BSB.Commands
return new KeyValuePair<bool, string>(false, "--");
}
}
class CoreCommand_json_reply_wit_collection : CoreCommand_json_reply
{
public Dictionary<string, string> collection = new Dictionary<string, string>();
}
class CoreCommand_json_reply
{
public bool status;
public string command;
public string output;
}
public abstract class CoreCommand_1arg : CoreCommand
{
@ -283,11 +323,22 @@ namespace BSB.Commands
{
public override int Min_Required_args { get { return 4; } }
}
public abstract class CoreCommand_SmartReply_1arg : CoreCommand_1arg
{
protected Dictionary<string, string> collection = new Dictionary<string, string>();
public override string[] ArgTypes { get { return new[] { "Smart" }; } }
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]" }; } }
}
public abstract class CoreCommand_SmartReply_2arg : CoreCommand_SmartReply_1arg
{
public override int Min_Required_args { get { return 2; } }
}
public abstract class CoreCommand_SmartReply_3arg : CoreCommand_SmartReply_1arg
{
public override int Min_Required_args { get { return 3; } }
}
public abstract class CoreCommand : API_interface
{

View file

@ -97,17 +97,17 @@ namespace BSB.bottypes
string DialogMessage = "NewDialog###" + dialogID.ToString() + "###"+ Dmess + "###" + String.Join("~|~",e.ButtonLabels) + "";
if (RelayDialogsToChannel != 0)
{
CommandsInterface.SmartCommandReply(RelayDialogsToChannel.ToString(), DialogMessage,"NewDialogNotice");
CommandsInterface.SmartCommandReply(true,RelayDialogsToChannel.ToString(), DialogMessage,"NewDialogNotice");
}
if(RelayDialogsToAvatar != UUID.Zero)
{
CommandsInterface.SmartCommandReply(RelayDialogsToAvatar.ToString(), DialogMessage, "NewDialogNotice");
CommandsInterface.SmartCommandReply(true, RelayDialogsToAvatar.ToString(), DialogMessage, "NewDialogNotice");
}
if(RelayDialogsToHttp != null)
{
if (RelayDialogsToHttp.StartsWith("http") == true)
{
CommandsInterface.SmartCommandReply(RelayDialogsToAvatar.ToString(), DialogMessage, "NewDialogNotice");
CommandsInterface.SmartCommandReply(true, RelayDialogsToAvatar.ToString(), DialogMessage, "NewDialogNotice");
}
}
}