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:
parent
cbf6dd0709
commit
8f59ba4bb7
22 changed files with 122 additions and 90 deletions
|
|
@ -7,20 +7,14 @@ namespace BSB.Commands.Group
|
||||||
{
|
{
|
||||||
public class GetGroupList : CoreGroupCommand_SmartReply_auto
|
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()
|
protected override string RunFunction()
|
||||||
{
|
{
|
||||||
StringBuilder reply = new StringBuilder();
|
|
||||||
string addon = "";
|
|
||||||
foreach (KeyValuePair<UUID, OpenMetaverse.Group> groupdata in bot.MyGroups)
|
foreach (KeyValuePair<UUID, OpenMetaverse.Group> groupdata in bot.MyGroups)
|
||||||
{
|
{
|
||||||
reply.Append(addon);
|
collection.Add(groupdata.Value.Name, groupdata.Key.ToString());
|
||||||
addon = ",";
|
|
||||||
reply.Append(groupdata.Value.Name);
|
|
||||||
reply.Append("=");
|
|
||||||
reply.Append(groupdata.Key);
|
|
||||||
}
|
}
|
||||||
return reply.ToString();
|
return "grouplist=loaded";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ namespace BSB.Commands.Group
|
||||||
{
|
{
|
||||||
public class GetGroupRoles : CoreGroupCommand_SmartReply_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)
|
public override bool CallFunction(string[] args)
|
||||||
{
|
{
|
||||||
if (base.CallFunction(args) == true)
|
if (base.CallFunction(args) == true)
|
||||||
|
|
@ -36,23 +36,14 @@ namespace BSB.Commands.Group
|
||||||
public override void Callback(string[] args, EventArgs e)
|
public override void Callback(string[] args, EventArgs e)
|
||||||
{
|
{
|
||||||
GroupRolesDataReplyEventArgs rolesData = (GroupRolesDataReplyEventArgs)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)
|
foreach(KeyValuePair<UUID,GroupRole> data in rolesData.Roles)
|
||||||
{
|
{
|
||||||
if (data.Key != UUID.Zero)
|
if (data.Key != UUID.Zero)
|
||||||
{
|
{
|
||||||
reply.Append(addon);
|
collection.Add(data.Value.Name, data.Key.ToString());
|
||||||
addon = ",";
|
|
||||||
reply.Append(data.Value.Name);
|
|
||||||
reply.Append("=");
|
|
||||||
reply.Append(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);
|
base.Callback(args, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace BSB.Commands.Group
|
namespace BSB.Commands.Group
|
||||||
{
|
{
|
||||||
|
|
@ -12,14 +13,15 @@ namespace BSB.Commands.Group
|
||||||
{
|
{
|
||||||
if (base.CallFunction(args) == true)
|
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
|
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[] ArgTypes { get { return new[] { "Mixed", "UUID" }; } }
|
||||||
public override string[] ArgHints { get { return new[] { "Smart reply [Channel|IM uuid|http url]", "Group" }; } }
|
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)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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"; } }
|
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()
|
protected override string RunFunction()
|
||||||
{
|
{
|
||||||
return bot.HasUnreadGroupchats().ToString();
|
return "groupchatunread="+bot.HasUnreadGroupchats().ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ namespace BSB.Commands.Group
|
||||||
|
|
||||||
protected override string RunFunction(UUID targetgroup)
|
protected override string RunFunction(UUID targetgroup)
|
||||||
{
|
{
|
||||||
return bot.GroupHasUnread(targetgroup).ToString();
|
return ""+targetgroup.ToString()+"=" + bot.GroupHasUnread(targetgroup).ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.VisualBasic.CompilerServices;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
|
|
||||||
namespace BSB.Commands.Group
|
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]"; } }
|
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)
|
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()+"";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,19 +5,17 @@ namespace BSB.Commands.Group
|
||||||
{
|
{
|
||||||
public class GroupchatListAllUnreadGroups : CoreGroupCommand_SmartReply_auto
|
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()
|
protected override string RunFunction()
|
||||||
{
|
{
|
||||||
StringBuilder reply = new StringBuilder();
|
int entry = 1;
|
||||||
string addon = "";
|
|
||||||
foreach (UUID group in bot.UnreadGroupchatGroups())
|
foreach (UUID group in bot.UnreadGroupchatGroups())
|
||||||
{
|
{
|
||||||
reply.Append(addon);
|
collection.Add(entry.ToString(),group.ToString());
|
||||||
addon = ",";
|
entry++;
|
||||||
reply.Append(group);
|
|
||||||
}
|
}
|
||||||
return reply.ToString();
|
return "count="+collection.Count.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,11 @@
|
||||||
{
|
{
|
||||||
if (bot.GetAllowFunds == true)
|
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();
|
bot.GetClient.Self.RequestBalance();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
return bot.GetCommandsInterface.SmartCommandReply(args[0], "0", CommandName);
|
return bot.GetCommandsInterface.SmartCommandReply(false,args[0], "0", CommandName);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
{
|
{
|
||||||
if (base.CallFunction(args) == true)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
{
|
{
|
||||||
if (base.CallFunction(args) == true)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
{
|
{
|
||||||
if (base.CallFunction(args) == true)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace BSB.Commands.Info
|
||||||
{
|
{
|
||||||
if (base.CallFunction(args) == true)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ namespace BSB.Commands.Inventory
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return bot.GetCommandsInterface.SmartCommandReply(args[0], String.Join("~|~", content), CommandName);
|
return bot.GetCommandsInterface.SmartCommandReply(true, args[0], String.Join("~|~", content), CommandName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace BSB.Commands.Inventory
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string reply = HelperInventory.MapFolder(bot, true);
|
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;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
{
|
{
|
||||||
if (base.CallFunction(args) == true)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,20 +56,15 @@ namespace BSB.Commands.CMD_Parcel
|
||||||
if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true)
|
if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true)
|
||||||
{
|
{
|
||||||
Parcel p = bot.GetClient.Network.CurrentSim.Parcels[localid];
|
Parcel p = bot.GetClient.Network.CurrentSim.Parcels[localid];
|
||||||
StringBuilder reply = new StringBuilder();
|
Dictionary<string, string> collection = new Dictionary<string, string>();
|
||||||
string addon = "";
|
|
||||||
foreach (string cfg in get_flags)
|
foreach (string cfg in get_flags)
|
||||||
{
|
{
|
||||||
if (flags.ContainsKey(cfg) == true)
|
if (flags.ContainsKey(cfg) == true)
|
||||||
{
|
{
|
||||||
reply.Append(addon);
|
collection.Add(cfg, p.Flags.HasFlag(flags[cfg]).ToString());
|
||||||
reply.Append(cfg);
|
|
||||||
reply.Append("=");
|
|
||||||
reply.Append(p.Flags.HasFlag(flags[cfg]).ToString());
|
|
||||||
addon = ",";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bot.GetCommandsInterface.SmartCommandReply(target, reply.ToString(), CommandName);
|
return bot.GetCommandsInterface.SmartCommandReply(true,target, p.Name, CommandName, collection);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ using System.Text;
|
||||||
|
|
||||||
namespace BSB.Commands.CMD_Parcel
|
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[] 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" }; } }
|
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)
|
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);
|
int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition);
|
||||||
reply.Append("DATA=");
|
collection.Add("sim", bot.GetClient.Network.CurrentSim.Name);
|
||||||
reply.Append(bot.GetClient.Network.CurrentSim.Name);
|
|
||||||
reply.Append(",");
|
|
||||||
reply.Append(localid.ToString());
|
|
||||||
reply.Append(",");
|
|
||||||
reply.Append(avatar.ToString());
|
|
||||||
reply.Append(",");
|
|
||||||
if (owner_uuids.Contains(avatar) == true)
|
if (owner_uuids.Contains(avatar) == true)
|
||||||
{
|
{
|
||||||
int owner_count = owner_counts[owner_uuids.IndexOf(avatar)];
|
int owner_count = owner_counts[owner_uuids.IndexOf(avatar)];
|
||||||
reply.Append(owner_count.ToString());
|
collection.Add("count", owner_count.ToString());
|
||||||
}
|
}
|
||||||
else
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,8 @@ using System.Text;
|
||||||
|
|
||||||
namespace BSB.Commands.CMD_Parcel
|
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 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)
|
public override void Callback(string[] args, EventArgs e)
|
||||||
|
|
@ -18,15 +16,11 @@ namespace BSB.Commands.CMD_Parcel
|
||||||
{
|
{
|
||||||
total_count += owner.Count;
|
total_count += owner.Count;
|
||||||
}
|
}
|
||||||
StringBuilder reply = new StringBuilder();
|
|
||||||
int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition);
|
int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition);
|
||||||
reply.Append("DATA=");
|
collection.Add("sim", bot.GetClient.Network.CurrentSim.Name);
|
||||||
reply.Append(bot.GetClient.Network.CurrentSim.Name);
|
collection.Add("parcelid", localid.ToString());
|
||||||
reply.Append(",");
|
collection.Add("count", total_count.ToString());
|
||||||
reply.Append(localid.ToString());
|
base.Callback(args, e, bot.GetCommandsInterface.SmartCommandReply(true,args[0], "ok", CommandName,collection));
|
||||||
reply.Append(",");
|
|
||||||
reply.Append(total_count.ToString());
|
|
||||||
base.Callback(args, e, bot.GetCommandsInterface.SmartCommandReply(args[0], reply.ToString(), CommandName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CallFunction(string[] args)
|
public override bool CallFunction(string[] args)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,13 @@ namespace BSB.Commands.Self
|
||||||
{
|
{
|
||||||
if (base.CallFunction(args) == true)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
{
|
{
|
||||||
if (base.CallFunction(args) == true)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using BSB.bottypes;
|
||||||
using BetterSecondBotShared.API;
|
using BetterSecondBotShared.API;
|
||||||
using BetterSecondBotShared.Static;
|
using BetterSecondBotShared.Static;
|
||||||
using BetterSecondBotShared.logs;
|
using BetterSecondBotShared.logs;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace BSB.Commands
|
namespace BSB.Commands
|
||||||
{
|
{
|
||||||
|
|
@ -132,11 +133,13 @@ namespace BSB.Commands
|
||||||
}
|
}
|
||||||
protected HttpClient HTTPclient = new HttpClient();
|
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";
|
string mode = "CHAT";
|
||||||
UUID target_avatar = UUID.Zero;
|
UUID target_avatar = UUID.Zero;
|
||||||
|
|
@ -151,12 +154,41 @@ namespace BSB.Commands
|
||||||
}
|
}
|
||||||
else
|
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")
|
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")
|
else if (mode == "IM")
|
||||||
{
|
{
|
||||||
|
|
@ -167,13 +199,8 @@ namespace BSB.Commands
|
||||||
Dictionary<string, string> values = new Dictionary<string, string>
|
Dictionary<string, string> values = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "reply", output },
|
{ "reply", output },
|
||||||
{ "unixtime", helpers.UnixTimeNow().ToString() }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (command != "")
|
|
||||||
{
|
|
||||||
values.Add("command", command);
|
|
||||||
}
|
|
||||||
var content = new FormUrlEncodedContent(values);
|
var content = new FormUrlEncodedContent(values);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -181,14 +208,16 @@ namespace BSB.Commands
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
run_status = false;
|
||||||
ConsoleLog.Crit("[SmartReply] HTTP failed: " + e.Message + "");
|
ConsoleLog.Crit("[SmartReply] HTTP failed: " + e.Message + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
ConsoleLog.Crit("[SmartReply] Unsupported output target");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return run_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<string> suppress_warnings = new List<string>();
|
protected List<string> suppress_warnings = new List<string>();
|
||||||
|
|
@ -266,6 +295,17 @@ namespace BSB.Commands
|
||||||
return new KeyValuePair<bool, string>(false, "--");
|
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
|
public abstract class CoreCommand_1arg : CoreCommand
|
||||||
{
|
{
|
||||||
|
|
@ -283,11 +323,22 @@ namespace BSB.Commands
|
||||||
{
|
{
|
||||||
public override int Min_Required_args { get { return 4; } }
|
public override int Min_Required_args { get { return 4; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class CoreCommand_SmartReply_1arg : CoreCommand_1arg
|
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[] ArgTypes { get { return new[] { "Smart" }; } }
|
||||||
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]" }; } }
|
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
|
public abstract class CoreCommand : API_interface
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -97,17 +97,17 @@ namespace BSB.bottypes
|
||||||
string DialogMessage = "NewDialog###" + dialogID.ToString() + "###"+ Dmess + "###" + String.Join("~|~",e.ButtonLabels) + "";
|
string DialogMessage = "NewDialog###" + dialogID.ToString() + "###"+ Dmess + "###" + String.Join("~|~",e.ButtonLabels) + "";
|
||||||
if (RelayDialogsToChannel != 0)
|
if (RelayDialogsToChannel != 0)
|
||||||
{
|
{
|
||||||
CommandsInterface.SmartCommandReply(RelayDialogsToChannel.ToString(), DialogMessage,"NewDialogNotice");
|
CommandsInterface.SmartCommandReply(true,RelayDialogsToChannel.ToString(), DialogMessage,"NewDialogNotice");
|
||||||
}
|
}
|
||||||
if(RelayDialogsToAvatar != UUID.Zero)
|
if(RelayDialogsToAvatar != UUID.Zero)
|
||||||
{
|
{
|
||||||
CommandsInterface.SmartCommandReply(RelayDialogsToAvatar.ToString(), DialogMessage, "NewDialogNotice");
|
CommandsInterface.SmartCommandReply(true, RelayDialogsToAvatar.ToString(), DialogMessage, "NewDialogNotice");
|
||||||
}
|
}
|
||||||
if(RelayDialogsToHttp != null)
|
if(RelayDialogsToHttp != null)
|
||||||
{
|
{
|
||||||
if (RelayDialogsToHttp.StartsWith("http") == true)
|
if (RelayDialogsToHttp.StartsWith("http") == true)
|
||||||
{
|
{
|
||||||
CommandsInterface.SmartCommandReply(RelayDialogsToAvatar.ToString(), DialogMessage, "NewDialogNotice");
|
CommandsInterface.SmartCommandReply(true, RelayDialogsToAvatar.ToString(), DialogMessage, "NewDialogNotice");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue