Localchat history (Required for webUI)

This commit is contained in:
Madpeter 2020-05-15 23:23:43 +01:00
parent 0958430471
commit 375a85667b
6 changed files with 166 additions and 18 deletions

View file

@ -0,0 +1,19 @@
using System.Linq;
using Newtonsoft.Json;
using OpenMetaverse;
namespace BSB.Commands.Chat
{
class LocalChatHistory : CoreCommand_SmartReply_1arg
{
public override string Helpfile { get { return "Gets the last 20 localchat messages the bot has."; } }
public override bool CallFunction(string[] args)
{
if(base.CallFunction(args) == true)
{
return bot.GetCommandsInterface.SmartCommandReply(true, args[0], JsonConvert.SerializeObject(bot.getLocalChatHistory()), CommandName);
}
return false;
}
}
}

View file

@ -31,6 +31,10 @@ namespace BSB.Commands.Chat
}
}
}
if (channel == 0)
{
bot.AddToLocalChat(bot.GetClient.Self.Name, message);
}
bot.GetClient.Self.Chat(message, channel, ChatLevel);
return true;
}

View file

@ -77,6 +77,7 @@ namespace BSB.bottypes
}
public virtual void SendIM(UUID avatar,string message)
{
AddToIMchat(avatar, GetClient.Self.Name, message);
Client.Self.InstantMessage(avatar, message);
}

View file

@ -24,7 +24,10 @@ namespace BSB.bottypes
{
av = true;
}
BotChatControler(e.Message, e.FromName, e.SourceID, av, false, UUID.Zero, true, fromme);
if (e.Message != "")
{
BotChatControler(e.Message, e.FromName, e.SourceID, av, false, UUID.Zero, true, fromme);
}
}
}
}

View file

@ -9,10 +9,42 @@ namespace BSB.bottypes
{
public abstract class VirtualsBot : BasicBot
{
public virtual Dictionary<UUID, string> GetIMChatWindowKeyNames()
{
return new Dictionary<UUID, string>();
}
public virtual void AddToLocalChat(string name, string message)
{
}
#region IMchat
public virtual List<UUID> IMChatWindows()
{
return new List<UUID>();
}
public virtual bool ImChatWindowHasUnread(UUID chat_window)
{
return false;
}
public virtual List<string> GetIMChatWindow(UUID chat_window)
{
return new List<string>();
}
public virtual void AddToIMchat(UUID avatar, string name, string message)
{
}
#endregion
#region group
protected List<UUID> active_group_chat_sessions = new List<UUID>();
public virtual List<UUID> GetActiveGroupchatSessions { get { return new List<UUID>(); } }
#endregion
public virtual List<string> getLocalChatHistory()
{
return new List<string>() { };
}
#region GroupIMs
public virtual bool HasUnreadGroupchats()
{
@ -22,11 +54,11 @@ namespace BSB.bottypes
{
return new UUID[] { };
}
public virtual string[] GetGroupchat(UUID group)
public virtual List<string> GetGroupchat(UUID group)
{
return new string[] { };
return new List<string>();
}
protected virtual void AddToGroupchat(UUID group, string name, string message)
public virtual void AddToGroupchat(UUID group, string name, string message)
{
}

View file

@ -1,24 +1,117 @@
using OpenMetaverse;
using Newtonsoft.Json;
using OpenMetaverse;
using System;
using System.Collections.Generic;
using System.Linq;
namespace BSB.bottypes
{
public abstract class ChatRelay : RLVbot
{
#region GroupIMs
protected int localchatlimit = 20;
protected int groupchatlimit = 10;
protected int imchatlimit = 20;
protected Dictionary<UUID, List<string>> group_chat_history = new Dictionary<UUID, List<string>>();
protected Dictionary<UUID, bool> group_chat_unread = new Dictionary<UUID, bool>();
protected bool unread_groupchats;
public override bool HasUnreadGroupchats()
protected Dictionary<UUID, List<string>> im_chat_history = new Dictionary<UUID, List<string>>();
protected Dictionary<UUID, bool> im_chat_unread = new Dictionary<UUID, bool>();
protected Dictionary<UUID, string> im_chat_history_to_name = new Dictionary<UUID, string>();
public override Dictionary<UUID, string> GetIMChatWindowKeyNames()
{
return unread_groupchats;
return im_chat_history_to_name;
}
protected void CheckUnreadGroupchat()
public override List<UUID> IMChatWindows()
{
unread_groupchats = group_chat_unread.ContainsValue(true);
return im_chat_history.Keys.ToList();
}
public override bool ImChatWindowHasUnread(UUID chat_window)
{
if(im_chat_unread.ContainsKey(chat_window) == true)
{
return im_chat_unread[chat_window];
}
return false;
}
public override List<string> GetIMChatWindow(UUID chat_window)
{
if(im_chat_history.ContainsKey(chat_window) == true)
{
im_chat_unread[chat_window] = false;
return im_chat_history[chat_window];
}
else
{
return new List<string>();
}
}
public override void AddToIMchat(UUID avatar, string name, string message)
{
if (im_chat_history.ContainsKey(avatar) == false)
{
im_chat_history.Add(avatar, new List<string>());
im_chat_unread.Add(avatar, false);
}
var date = DateTime.Now;
im_chat_history[avatar].Add("[" + date.Hour.ToString() + ":" + date.Minute.ToString() + "] " + name + ":" + message + "");
if (im_chat_history[avatar].Count > imchatlimit)
{
im_chat_history[avatar].RemoveAt(0);
}
if (name != GetClient.Self.Name)
{
im_chat_unread[avatar] = true;
}
}
public override void AddToLocalChat(string name, string message)
{
var date = DateTime.Now;
LocalChat_history.Add("[" + date.Hour.ToString() + ":" + date.Minute.ToString() + "] " + name + ":" + message + "");
if (LocalChat_history.Count > localchatlimit)
{
LocalChat_history.RemoveAt(0);
}
}
protected List<string> LocalChat_history = new List<string>();
public override List<string> getLocalChatHistory()
{
return LocalChat_history;
}
protected override void BotChatControler(string message, string sender_name, UUID sender_uuid, bool avatar, bool group, UUID group_uuid, bool localchat, bool fromme)
{
base.BotChatControler(message, sender_name, sender_uuid, avatar, group, group_uuid, localchat, fromme);
if(localchat == true)
{
if (avatar == true)
{
if (fromme == false)
{
AddToLocalChat(sender_name, message);
}
}
}
else
{
if (avatar == true)
{
if(group == false)
{
if (fromme == false)
{
AddToIMchat(sender_uuid, sender_name, message);
}
}
}
}
}
public override bool GroupHasUnread(UUID group)
{
if (group_chat_unread.ContainsKey(group) == true)
@ -39,17 +132,16 @@ namespace BSB.bottypes
}
return reply.ToArray();
}
public override string[] GetGroupchat(UUID group)
public override List<string> GetGroupchat(UUID group)
{
if (group_chat_history.ContainsKey(group) == true)
{
group_chat_unread[group] = false;
CheckUnreadGroupchat();
return group_chat_history[group].ToArray();
return group_chat_history[group];
}
return new string[] { };
return new List<string>();
}
protected override void AddToGroupchat(UUID group,string name,string message)
public override void AddToGroupchat(UUID group,string name,string message)
{
if (group_chat_history.ContainsKey(group) == false)
{
@ -64,7 +156,6 @@ namespace BSB.bottypes
}
if (name != GetClient.Self.Name)
{
unread_groupchats = true;
group_chat_unread[group] = true;
}
}
@ -74,14 +165,12 @@ namespace BSB.bottypes
{
group_chat_history.Remove(group);
group_chat_unread.Remove(group);
CheckUnreadGroupchat();
}
}
public override void ClearAllGroupchat()
{
group_chat_history = new Dictionary<UUID, List<string>>();
group_chat_unread = new Dictionary<UUID, bool>();
unread_groupchats = false;
}
#endregion
}