Finish revising messaging API
This commit is contained in:
parent
59c62e62e2
commit
4b07283a3d
8 changed files with 137 additions and 143 deletions
|
@ -6,7 +6,7 @@ using System.Reflection;
|
||||||
[assembly: AssemblyCompany("ZNI")]
|
[assembly: AssemblyCompany("ZNI")]
|
||||||
[assembly: AssemblyAlgorithmId(System.Configuration.Assemblies.AssemblyHashAlgorithm.MD5)]
|
[assembly: AssemblyAlgorithmId(System.Configuration.Assemblies.AssemblyHashAlgorithm.MD5)]
|
||||||
[assembly: AssemblyCopyright("© 2020 Tara Piccari")]
|
[assembly: AssemblyCopyright("© 2020 Tara Piccari")]
|
||||||
[assembly: AssemblyFileVersion("5.3.091")]
|
[assembly: AssemblyFileVersion("5.3.912")]
|
||||||
[assembly: AssemblyDescription("Second Life Bot - BotCore5")]
|
[assembly: AssemblyDescription("Second Life Bot - BotCore5")]
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ namespace Bot.Assemble
|
||||||
public class ASMInfo
|
public class ASMInfo
|
||||||
{
|
{
|
||||||
public static string BotName = "ZBotCore";
|
public static string BotName = "ZBotCore";
|
||||||
public static string BotVer = "5.3.091";
|
public static string BotVer = "5.3.912";
|
||||||
public static string GitPassword
|
public static string GitPassword
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
@ -46,5 +46,7 @@ namespace Bot
|
||||||
public DateTime LaunchTime { get; set; } = DateTime.Now;
|
public DateTime LaunchTime { get; set; } = DateTime.Now;
|
||||||
public bool WaitForFiveMinutes = false;
|
public bool WaitForFiveMinutes = false;
|
||||||
public MessageService MSGSVC { get; set; } = new MessageService();
|
public MessageService MSGSVC { get; set; } = new MessageService();
|
||||||
|
public bool EnqueueExit = false;
|
||||||
|
public bool EnqueueGroupRefresh = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,8 +94,8 @@ namespace Bot.CommandSystem
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[CommandGroup("show_level", 0, 0, "This command shows your current auth level if any.", Destinations.DEST_AGENT | Destinations.DEST_LOCAL | Destinations.DEST_GROUP)]
|
[CommandGroup("show_level", 0, 0, "This command shows your current auth level if any.", Destinations.DEST_AGENT | Destinations.DEST_DISCORD | Destinations.DEST_LOCAL | Destinations.DEST_GROUP)]
|
||||||
public void show_level(UUID client, int level, GridClient grid, string[] additionalArgs,
|
public void show_level(UUID client, int level, string[] additionalArgs,
|
||||||
Destinations source,
|
Destinations source,
|
||||||
UUID agentKey, string agentName)
|
UUID agentKey, string agentName)
|
||||||
{
|
{
|
||||||
|
@ -128,7 +128,7 @@ namespace Bot.CommandSystem
|
||||||
public void PerformExit(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
|
public void PerformExit(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
|
||||||
{
|
{
|
||||||
MHE(source, client, "Bot exit initiated.");
|
MHE(source, client, "Bot exit initiated.");
|
||||||
BotSession.Instance.LaunchTime = new DateTime(); // zero out date time to force a relog
|
BotSession.Instance.EnqueueExit = true;
|
||||||
}
|
}
|
||||||
// !!help
|
// !!help
|
||||||
[CommandGroup("!help", 1, 0, "Prints the entire help registry", Destinations.DEST_AGENT |Destinations.DEST_LOCAL | Destinations.DEST_GROUP)]
|
[CommandGroup("!help", 1, 0, "Prints the entire help registry", Destinations.DEST_AGENT |Destinations.DEST_LOCAL | Destinations.DEST_GROUP)]
|
||||||
|
|
|
@ -239,8 +239,23 @@ namespace Bot.CommandSystem
|
||||||
//(UUID client, int level, string[] additionalArgs,
|
//(UUID client, int level, string[] additionalArgs,
|
||||||
//Destinations source,
|
//Destinations source,
|
||||||
//UUID agentKey, string agentName)
|
//UUID agentKey, string agentName)
|
||||||
Thread CommandThread = new Thread(() => cgX.AssignedMethod.Invoke(ovj, new object[] { user, level, additionalArgs, source, agentKey, agentName }));
|
try
|
||||||
CommandThread.Start();
|
{
|
||||||
|
Thread CMDThread = new Thread(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
cgX.AssignedMethod.Invoke(ovj, new object[] { user,level,additionalArgs, source,agentKey, agentName });
|
||||||
|
}catch(Exception e)
|
||||||
|
{
|
||||||
|
MessageFactory.Post(Destinations.DEST_LOCAL, "Exception caught when executing a command\n" + e.Message + "\nStacktrace: " + e.StackTrace, UUID.Zero);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
CMDThread.Start();
|
||||||
|
}catch(Exception e)
|
||||||
|
{
|
||||||
|
MessageFactory.Post(Destinations.DEST_LOCAL, "EXCEPTION CAUGHT WHEN EXECUTING COMMAND\n\n" + e.Message + "\nSTACK\n" + e.StackTrace, UUID.Zero);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace Bot
|
||||||
{
|
{
|
||||||
void run(); // Define the run command since a thread needs a entry point
|
void run(); // Define the run command since a thread needs a entry point
|
||||||
|
|
||||||
string getTick(); // Run every second to check for queued data. If queue exists, then it will be returned as a JSON string.
|
void getTick(); // Run every second to check for queued data. If queue exists, then it will be returned as a JSON string.
|
||||||
// getTick can reply with data for the serializer for instance.
|
// getTick can reply with data for the serializer for instance.
|
||||||
|
|
||||||
void passArguments(string data); // json!!
|
void passArguments(string data); // json!!
|
||||||
|
|
|
@ -7,7 +7,7 @@ using OpenMetaverse;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Microsoft.VisualBasic;
|
||||||
|
|
||||||
namespace Bot
|
namespace Bot
|
||||||
{
|
{
|
||||||
|
@ -114,11 +114,72 @@ namespace Bot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class DiscordMessage : Message
|
||||||
|
{
|
||||||
|
private string Msg;
|
||||||
|
public string ServerName;
|
||||||
|
public string ChannelName;
|
||||||
|
private UUID SenderID;
|
||||||
|
|
||||||
|
public override int GetChannel()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string GetMessage()
|
||||||
|
{
|
||||||
|
return Msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Destinations GetMessageSource()
|
||||||
|
{
|
||||||
|
return Destinations.DEST_DISCORD;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override UUID GetSender()
|
||||||
|
{
|
||||||
|
// This is always UUID.Zero with the bot's discord plugin
|
||||||
|
return SenderID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string GetSenderName()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override UUID GetTarget()
|
||||||
|
{
|
||||||
|
return UUID.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void set(Destinations dest, string msg, UUID agentID, string senderName, int channel)
|
||||||
|
{
|
||||||
|
Msg = msg;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DiscordMessage(string Msg, UUID Sender)
|
||||||
|
{
|
||||||
|
this.Msg = Msg;
|
||||||
|
ServerName = "MAP_NOT_KNOWN";
|
||||||
|
ChannelName = "MAP_NOT_KNOWN";
|
||||||
|
SenderID = Sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DiscordMessage(string Msg, string Server, string Channel, UUID Sender)
|
||||||
|
{
|
||||||
|
this.Msg = Msg;
|
||||||
|
ServerName = Server;
|
||||||
|
ChannelName = Channel;
|
||||||
|
SenderID = Sender;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class MessageFactory
|
public class MessageFactory
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Post(Destinations dest, string Msg, UUID destID, int chn = 0)
|
public static void Post(Destinations dest, string Msg, UUID destID, int chn = 0,string ServerName="MAP_NOT_KNOWN", string ChannelName="MAP_NOT_KNOWN")
|
||||||
{
|
{
|
||||||
|
|
||||||
Message m = null;
|
Message m = null;
|
||||||
|
@ -129,7 +190,7 @@ namespace Bot
|
||||||
m = new GroupMessage(destID);
|
m = new GroupMessage(destID);
|
||||||
break;
|
break;
|
||||||
case Destinations.DEST_DISCORD:
|
case Destinations.DEST_DISCORD:
|
||||||
m = new ChatMessage(UUID.Zero);
|
m = new DiscordMessage(Msg,ServerName, ChannelName,destID);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
m = new ChatMessage(destID);
|
m = new ChatMessage(destID);
|
||||||
|
@ -148,18 +209,26 @@ namespace Bot
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MessageService
|
public class MessageService
|
||||||
{
|
{
|
||||||
|
public List<MessageEventArgs> QUEUE = new List<MessageEventArgs>();
|
||||||
public MessageService()
|
public MessageService()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DoSend(MessageEventArgs args)
|
||||||
|
{
|
||||||
|
OnMessageEvent(args);
|
||||||
|
}
|
||||||
|
|
||||||
public static void Dispatch(Message M)
|
public static void Dispatch(Message M)
|
||||||
{
|
{
|
||||||
MessageEventArgs MEA = new MessageEventArgs();
|
MessageEventArgs MEA = new MessageEventArgs();
|
||||||
MEA.Timestamp = DateTime.Now;
|
MEA.Timestamp = DateTime.Now;
|
||||||
MEA.Msg = M;
|
MEA.Msg = M;
|
||||||
|
|
||||||
BotSession.Instance.MSGSVC.OnMessageEvent(MEA);
|
|
||||||
|
BotSession.Instance.MSGSVC.QUEUE.Add(MEA);
|
||||||
|
//BotSession.Instance.MSGSVC.OnMessageEvent(MEA);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnMessageEvent(MessageEventArgs e)
|
protected virtual void OnMessageEvent(MessageEventArgs e)
|
||||||
|
@ -171,6 +240,15 @@ namespace Bot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public event EventHandler<MessageEventArgs> MessageEvent;
|
public event EventHandler<MessageEventArgs> MessageEvent;
|
||||||
|
|
||||||
|
|
||||||
|
public void PopMessage()
|
||||||
|
{
|
||||||
|
if (QUEUE.Count == 0) return;
|
||||||
|
|
||||||
|
DoSend(QUEUE.First());
|
||||||
|
QUEUE.Remove(QUEUE.First());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -182,122 +260,4 @@ namespace Bot
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class MessageHandler_old // keep the old structure for now
|
|
||||||
{
|
|
||||||
private List<MessageQueuePacket> MSGQueue = new List<MessageQueuePacket>();
|
|
||||||
private List<ActionPacket> ActionQueue = new List<ActionPacket>();
|
|
||||||
private List<DiscordAction> DiscordQueue = new List<DiscordAction>();
|
|
||||||
public ManualResetEvent GroupJoinWaiter = new ManualResetEvent(false);
|
|
||||||
private Logger Log = BotSession.Instance.Logger;
|
|
||||||
|
|
||||||
|
|
||||||
public struct MessageQueuePacket
|
|
||||||
{
|
|
||||||
public Destinations Dest;
|
|
||||||
public UUID DestID;
|
|
||||||
public string Msg;
|
|
||||||
public int channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct ActionPacket
|
|
||||||
{
|
|
||||||
public Destinations Dest;
|
|
||||||
public string ActionStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct DiscordAction
|
|
||||||
{
|
|
||||||
public string Action;
|
|
||||||
}
|
|
||||||
|
|
||||||
public delegate void MessageHandleEvent(Destinations DType, UUID AgentOrSession, string MSG, int channel = 0);
|
|
||||||
public volatile MessageHandleEvent callbacks;
|
|
||||||
public void MessageHandle(Destinations DType, UUID AgentOrSession, string MSG, int channel = 0)
|
|
||||||
{
|
|
||||||
if (DType == Destinations.DEST_DISCORD)
|
|
||||||
{
|
|
||||||
DiscordAction DA = new DiscordAction();
|
|
||||||
DA.Action = MSG;
|
|
||||||
DiscordQueue.Add(DA);
|
|
||||||
return; // Do nothing
|
|
||||||
}
|
|
||||||
MessageQueuePacket pkt = new MessageQueuePacket();
|
|
||||||
pkt.channel = channel;
|
|
||||||
pkt.Dest = DType;
|
|
||||||
pkt.DestID = AgentOrSession;
|
|
||||||
pkt.Msg = MSG;
|
|
||||||
|
|
||||||
if (MSGQueue != null)
|
|
||||||
MSGQueue.Add(pkt);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void ClearQueues()
|
|
||||||
{
|
|
||||||
MSGQueue = new List<MessageQueuePacket>();
|
|
||||||
DiscordQueue = new List<DiscordAction>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run(GridClient client)
|
|
||||||
{
|
|
||||||
// Execute one queue item
|
|
||||||
if (MSGQueue.Count == 0) return;
|
|
||||||
MessageQueuePacket pkt = MSGQueue.First();
|
|
||||||
MSGQueue.RemoveAt(MSGQueue.IndexOf(pkt));
|
|
||||||
if (pkt.Dest == Destinations.DEST_AGENT)
|
|
||||||
{
|
|
||||||
client.Self.InstantMessage(pkt.DestID, "[" + MSGQueue.Count.ToString() + "] " + pkt.Msg);
|
|
||||||
}
|
|
||||||
else if (pkt.Dest == Destinations.DEST_GROUP)
|
|
||||||
{
|
|
||||||
if (client.Self.GroupChatSessions.ContainsKey(pkt.DestID))
|
|
||||||
client.Self.InstantMessageGroup(pkt.DestID, "[" + MSGQueue.Count.ToString() + "] " + pkt.Msg);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GroupJoinWaiter.Reset();
|
|
||||||
client.Groups.ActivateGroup(pkt.DestID);
|
|
||||||
client.Self.RequestJoinGroupChat(pkt.DestID);
|
|
||||||
//callbacks(Destinations.DEST_LOCAL, UUID.Zero, "Attempting to join group chat for secondlife:///app/group/" + pkt.DestID.ToString() + "/about");
|
|
||||||
|
|
||||||
if (GroupJoinWaiter.WaitOne(TimeSpan.FromSeconds(20), false))
|
|
||||||
{
|
|
||||||
|
|
||||||
client.Self.InstantMessageGroup(pkt.DestID, "[" + MSGQueue.Count.ToString() + "] " + pkt.Msg);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MSGQueue.Add(pkt); // Because we failed to join the group chat we'll tack this onto the end of the queue and try again
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (pkt.Dest == Destinations.DEST_LOCAL)
|
|
||||||
{
|
|
||||||
client.Self.Chat("[" + MSGQueue.Count.ToString() + "] " + pkt.Msg, pkt.channel, ChatType.Normal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string CheckActions()
|
|
||||||
{
|
|
||||||
string RETURNStr = "";
|
|
||||||
if (ActionQueue.Count == 0) return "NONE";
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RETURNStr = ActionQueue.First().ActionStr;
|
|
||||||
ActionQueue.Remove(ActionQueue.First());
|
|
||||||
return RETURNStr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string CheckDiscordActions()
|
|
||||||
{
|
|
||||||
if (DiscordQueue.Count == 0) return "NONE";
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string RET = DiscordQueue.First().Action;
|
|
||||||
DiscordQueue.Remove(DiscordQueue.First());
|
|
||||||
return RET;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
38
Program.cs
38
Program.cs
|
@ -241,9 +241,6 @@ namespace Bot
|
||||||
{
|
{
|
||||||
Console.WriteLine("Check Creds:\n \nFirst Name: '" + fna + "'\nLast Name: '" + lna + "'\nPWD: '" + pwd + "'\nBotStr: '" + BotStr + "'\nBotVer: " + BotVer.ToString()+"\n \nLogin Message: "+client.Network.LoginMessage);
|
Console.WriteLine("Check Creds:\n \nFirst Name: '" + fna + "'\nLast Name: '" + lna + "'\nPWD: '" + pwd + "'\nBotStr: '" + BotStr + "'\nBotVer: " + BotVer.ToString()+"\n \nLogin Message: "+client.Network.LoginMessage);
|
||||||
|
|
||||||
|
|
||||||
if(args[0] == "-x") // debug launch
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
}
|
||||||
if (LoggedIn)
|
if (LoggedIn)
|
||||||
{
|
{
|
||||||
|
@ -339,7 +336,7 @@ namespace Bot
|
||||||
|
|
||||||
client.Self.RetrieveInstantMessages();
|
client.Self.RetrieveInstantMessages();
|
||||||
if (client.Network.Connected == false) g_iIsRunning = false; // Quit the program and restart immediately!
|
if (client.Network.Connected == false) g_iIsRunning = false; // Quit the program and restart immediately!
|
||||||
Thread.Sleep(2000);
|
Thread.Sleep(1000);
|
||||||
|
|
||||||
|
|
||||||
if (conf.ConfigFor == "Main")
|
if (conf.ConfigFor == "Main")
|
||||||
|
@ -434,6 +431,16 @@ namespace Bot
|
||||||
|
|
||||||
// onSimChange(null, new SimChangedEventArgs(client.Network.CurrentSim));
|
// onSimChange(null, new SimChangedEventArgs(client.Network.CurrentSim));
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
if (BotSession.Instance.EnqueueExit) g_iIsRunning = false;
|
||||||
|
|
||||||
|
if (BotSession.Instance.EnqueueGroupRefresh)
|
||||||
|
{
|
||||||
|
BotSession.Instance.EnqueueGroupRefresh = false;
|
||||||
|
ReloadGroupsCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
BotSession.Instance.MSGSVC.PopMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
prompter.Interrupt();
|
prompter.Interrupt();
|
||||||
|
@ -454,22 +461,33 @@ namespace Bot
|
||||||
private static ManualResetEvent GroupJoinWaiter = new ManualResetEvent(false);
|
private static ManualResetEvent GroupJoinWaiter = new ManualResetEvent(false);
|
||||||
private static void MSGSVC_onGroupMessage(object sender, MessageEventArgs e)
|
private static void MSGSVC_onGroupMessage(object sender, MessageEventArgs e)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
// not implemented, yet, but do not throw error
|
||||||
|
switch (e.Msg.GetMessageSource())
|
||||||
|
{
|
||||||
|
case Destinations.DEST_GROUP:
|
||||||
|
BotSession.Instance.grid.Self.InstantMessageGroup(e.Msg.GetTarget(), e.Msg.GetMessage());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void MSGSVC_onIM(object sender, MessageEventArgs e)
|
private static void MSGSVC_onIM(object sender, MessageEventArgs e)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
switch (e.Msg.GetMessageSource())
|
||||||
|
{
|
||||||
|
case Destinations.DEST_AGENT:
|
||||||
|
BotSession.Instance.grid.Self.InstantMessage(e.Msg.GetTarget(), e.Msg.GetMessage());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void MSGSVC_onChat(object sender, MessageEventArgs e)
|
private static void MSGSVC_onChat(object sender, MessageEventArgs e)
|
||||||
{
|
{
|
||||||
switch (e.Msg.GetMessageSource())
|
switch (e.Msg.GetMessageSource())
|
||||||
{
|
{
|
||||||
case Destinations.DEST_AGENT:
|
|
||||||
// send as IM
|
|
||||||
BotSession.Instance.grid.Self.InstantMessage(e.Msg.GetTarget(), e.Msg.GetMessage());
|
|
||||||
break;
|
|
||||||
case Destinations.DEST_LOCAL:
|
case Destinations.DEST_LOCAL:
|
||||||
BotSession.Instance.grid.Self.Chat(e.Msg.GetMessage(), e.Msg.GetChannel(), ChatType.Normal);
|
BotSession.Instance.grid.Self.Chat(e.Msg.GetMessage(), e.Msg.GetChannel(), ChatType.Normal);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -35,10 +35,9 @@ namespace Bot.WebHookServer
|
||||||
get { return 1.7f; }
|
get { return 1.7f; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string getTick()
|
public void getTick()
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void passArguments(string data)
|
public void passArguments(string data)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue