groupchat / im chat fixs and improvements to discord-v
This commit is contained in:
parent
cd19b71011
commit
c0d2203099
13 changed files with 138 additions and 18 deletions
|
|
@ -124,7 +124,7 @@ namespace BetterSecondBotShared.bottypes
|
||||||
public bool GetAllowFunds { get { return myconfig.Setting_AllowFunds; } }
|
public bool GetAllowFunds { get { return myconfig.Setting_AllowFunds; } }
|
||||||
public string LastStatusMessage { get; set; }
|
public string LastStatusMessage { get; set; }
|
||||||
|
|
||||||
public bool KillMe { get { return killMe; } }
|
public virtual bool KillMe { get { return killMe; } }
|
||||||
|
|
||||||
protected bool teleported;
|
protected bool teleported;
|
||||||
public void SetTeleported()
|
public void SetTeleported()
|
||||||
|
|
|
||||||
|
|
@ -213,6 +213,8 @@ namespace BetterSecondBot.DiscordSupervisor
|
||||||
List<string> required_cats = new List<string>() { "bot", "group", "im" };
|
List<string> required_cats = new List<string>() { "bot", "group", "im" };
|
||||||
IReadOnlyCollection<ICategoryChannel> found_cats = await DiscordServer.GetCategoriesAsync(CacheMode.AllowDownload);
|
IReadOnlyCollection<ICategoryChannel> found_cats = await DiscordServer.GetCategoriesAsync(CacheMode.AllowDownload);
|
||||||
foreach (ICategoryChannel fcat in found_cats)
|
foreach (ICategoryChannel fcat in found_cats)
|
||||||
|
{
|
||||||
|
if (catmap.ContainsKey(fcat.Name) == false)
|
||||||
{
|
{
|
||||||
if (required_cats.Contains(fcat.Name) == true)
|
if (required_cats.Contains(fcat.Name) == true)
|
||||||
{
|
{
|
||||||
|
|
@ -220,6 +222,11 @@ namespace BetterSecondBot.DiscordSupervisor
|
||||||
catmap.Add(fcat.Name, fcat);
|
catmap.Add(fcat.Name, fcat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
required_cats.Remove(fcat.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
foreach (string A in required_cats)
|
foreach (string A in required_cats)
|
||||||
{
|
{
|
||||||
ICategoryChannel newcat = await DiscordServer.CreateCategoryAsync(A).ConfigureAwait(true);
|
ICategoryChannel newcat = await DiscordServer.CreateCategoryAsync(A).ConfigureAwait(true);
|
||||||
|
|
@ -235,6 +242,8 @@ namespace BetterSecondBot.DiscordSupervisor
|
||||||
required_channels.Remove(chan.Name);
|
required_channels.Remove(chan.Name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (GroupChannels.Contains(chan.Name) == false)
|
||||||
{
|
{
|
||||||
if (chan.CategoryId == catmap["group"].Id)
|
if (chan.CategoryId == catmap["group"].Id)
|
||||||
{
|
{
|
||||||
|
|
@ -242,6 +251,7 @@ namespace BetterSecondBot.DiscordSupervisor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
foreach (string A in required_channels)
|
foreach (string A in required_channels)
|
||||||
{
|
{
|
||||||
_ = await FindTextChannel(A, catmap["bot"], UUID.Zero, "bot").ConfigureAwait(false);
|
_ = await FindTextChannel(A, catmap["bot"], UUID.Zero, "bot").ConfigureAwait(false);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,10 @@ namespace BetterSecondBot.DiscordSupervisor
|
||||||
{
|
{
|
||||||
while (exit_super == false)
|
while (exit_super == false)
|
||||||
{
|
{
|
||||||
|
if (HasBasicBot() == false)
|
||||||
|
{
|
||||||
|
StatusMessageHandler(null, new BSB.bottypes.StatusMessageEvent(false, "None"));
|
||||||
|
}
|
||||||
string NewStatusMessage = GetStatus();
|
string NewStatusMessage = GetStatus();
|
||||||
if (NewStatusMessage != LastStatusMessage)
|
if (NewStatusMessage != LastStatusMessage)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ namespace BetterSecondBot.DiscordSupervisor
|
||||||
|
|
||||||
protected virtual async Task<Task> DiscordClientReady()
|
protected virtual async Task<Task> DiscordClientReady()
|
||||||
{
|
{
|
||||||
|
await DiscordClient.SetStatusAsync(Discord.UserStatus.Idle);
|
||||||
|
await DiscordClient.SetGameAsync("Not connected", null, ActivityType.CustomStatus);
|
||||||
DiscordServer = DiscordClient.GetGuild(myconfig.DiscordFull_ServerID);
|
DiscordServer = DiscordClient.GetGuild(myconfig.DiscordFull_ServerID);
|
||||||
if (DiscordServer != null)
|
if (DiscordServer != null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,49 @@ namespace BetterSecondBot.DiscordSupervisor
|
||||||
{
|
{
|
||||||
public class DiscordEvents : DiscordBot
|
public class DiscordEvents : DiscordBot
|
||||||
{
|
{
|
||||||
|
protected StatusMessageEvent LastNetworkEventArgs = null;
|
||||||
protected void attach_events()
|
protected void attach_events()
|
||||||
{
|
{
|
||||||
controler.Bot.MessageEvent += BotChatControlerHandler;
|
controler.Bot.MessageEvent += BotChatControlerHandler;
|
||||||
|
controler.Bot.StatusMessageEvent += StatusMessageHandler;
|
||||||
|
controler.Bot.GroupsReadyEvent += GroupsReady;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async void GroupsReady(object sender, GroupEventArgs e)
|
||||||
|
{
|
||||||
|
await DiscordRebuildChannels();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void BotChatControlerHandler(object sender, MessageEventArgs e)
|
protected void BotChatControlerHandler(object sender, MessageEventArgs e)
|
||||||
{
|
{
|
||||||
BotChatControler(e.message, e.sender_name, e.sender_uuid, e.avatar, e.group, e.group_uuid, e.localchat, e.fromme);
|
BotChatControler(e.message, e.sender_name, e.sender_uuid, e.avatar, e.group, e.group_uuid, e.localchat, e.fromme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected async void StatusMessageHandler(object sender, StatusMessageEvent e)
|
||||||
|
{
|
||||||
|
bool apply_update = true;
|
||||||
|
if(LastNetworkEventArgs != null)
|
||||||
|
{
|
||||||
|
if((LastNetworkEventArgs.sim == e.sim) && (LastNetworkEventArgs.connected == e.connected))
|
||||||
|
{
|
||||||
|
apply_update = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (apply_update == true)
|
||||||
|
{
|
||||||
|
LastNetworkEventArgs = e;
|
||||||
|
if (e.connected == true)
|
||||||
|
{
|
||||||
|
await DiscordClient.SetGameAsync("Sim:" + e.sim);
|
||||||
|
await DiscordClient.SetStatusAsync(Discord.UserStatus.Online);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await DiscordClient.SetGameAsync("Logged out");
|
||||||
|
await DiscordClient.SetStatusAsync(Discord.UserStatus.Idle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,15 @@ namespace BetterSecondBot.DiscordSupervisor
|
||||||
await TTSchannel.SendMessageAsync(message, true);
|
await TTSchannel.SendMessageAsync(message, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
await base.DiscordIMMessage(sender_uuid, sender_name, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await base.DiscordIMMessage(sender_uuid, sender_name, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace BetterSecondBot.DiscordSupervisor
|
namespace BetterSecondBot.DiscordSupervisor
|
||||||
{
|
{
|
||||||
|
|
@ -67,6 +68,5 @@ namespace BetterSecondBot.DiscordSupervisor
|
||||||
}
|
}
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@ namespace BSB.bottypes
|
||||||
|
|
||||||
protected override void AfterBotLoginHandler()
|
protected override void AfterBotLoginHandler()
|
||||||
{
|
{
|
||||||
base.AfterBotLoginHandler();
|
|
||||||
if (reconnect == false)
|
if (reconnect == false)
|
||||||
{
|
{
|
||||||
Client.Avatars.AvatarAnimation += AvatarAnimationHandler;
|
Client.Avatars.AvatarAnimation += AvatarAnimationHandler;
|
||||||
}
|
}
|
||||||
|
base.AfterBotLoginHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ResetAnimations()
|
public override void ResetAnimations()
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ namespace BSB.bottypes
|
||||||
|
|
||||||
protected override void AfterBotLoginHandler()
|
protected override void AfterBotLoginHandler()
|
||||||
{
|
{
|
||||||
base.AfterBotLoginHandler();
|
|
||||||
if (reconnect == false)
|
if (reconnect == false)
|
||||||
{
|
{
|
||||||
Client.Groups.GroupRoleDataReply += GroupRolesData;
|
Client.Groups.GroupRoleDataReply += GroupRolesData;
|
||||||
|
|
@ -20,6 +19,7 @@ namespace BSB.bottypes
|
||||||
Client.Groups.GroupMembersReply += GroupMembersReplyHandler;
|
Client.Groups.GroupMembersReply += GroupMembersReplyHandler;
|
||||||
Client.Parcels.ParcelObjectOwnersReply += ObjectOwnersHandler;
|
Client.Parcels.ParcelObjectOwnersReply += ObjectOwnersHandler;
|
||||||
}
|
}
|
||||||
|
base.AfterBotLoginHandler();
|
||||||
}
|
}
|
||||||
protected override void GroupMembersReplyHandler(object sender, GroupMembersReplyEventArgs e)
|
protected override void GroupMembersReplyHandler(object sender, GroupMembersReplyEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -191,12 +191,12 @@ namespace BSB.bottypes
|
||||||
|
|
||||||
protected override void AfterBotLoginHandler()
|
protected override void AfterBotLoginHandler()
|
||||||
{
|
{
|
||||||
base.AfterBotLoginHandler();
|
|
||||||
if (reconnect == false)
|
if (reconnect == false)
|
||||||
{
|
{
|
||||||
CommandsInterface = new Commands.CoreCommandsInterface(this);
|
CommandsInterface = new Commands.CoreCommandsInterface(this);
|
||||||
}
|
}
|
||||||
Client.Self.RequestBalance();
|
Client.Self.RequestBalance();
|
||||||
|
base.AfterBotLoginHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void CoreCommandLib(UUID fromUUID, bool from_accepted_avatar, string command, string arg, string signing_code, string signed_with)
|
protected override void CoreCommandLib(UUID fromUUID, bool from_accepted_avatar, string command, string arg, string signing_code, string signed_with)
|
||||||
|
|
|
||||||
|
|
@ -45,12 +45,12 @@ namespace BSB.bottypes
|
||||||
|
|
||||||
protected override void AfterBotLoginHandler()
|
protected override void AfterBotLoginHandler()
|
||||||
{
|
{
|
||||||
base.AfterBotLoginHandler();
|
|
||||||
if (reconnect == false)
|
if (reconnect == false)
|
||||||
{
|
{
|
||||||
Client.Network.RegisterCallback(PacketType.SetFollowCamProperties, SetFollowCamPropertiesPacketHandler);
|
Client.Network.RegisterCallback(PacketType.SetFollowCamProperties, SetFollowCamPropertiesPacketHandler);
|
||||||
}
|
}
|
||||||
delay_appearence_update = 0; // reset Appearance helper
|
delay_appearence_update = 0; // reset Appearance helper
|
||||||
|
base.AfterBotLoginHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void SetFollowCamPropertiesPacketHandler(object sender, PacketReceivedEventArgs e)
|
protected void SetFollowCamPropertiesPacketHandler(object sender, PacketReceivedEventArgs e)
|
||||||
|
|
@ -60,6 +60,26 @@ namespace BSB.bottypes
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public class StatusMessageEvent : EventArgs
|
||||||
|
{
|
||||||
|
public bool connected { get; }
|
||||||
|
public string sim { get; }
|
||||||
|
|
||||||
|
public StatusMessageEvent(bool connected,string sim)
|
||||||
|
{
|
||||||
|
this.connected = connected;
|
||||||
|
this.sim = sim;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class GroupEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public bool ready { get; }
|
||||||
|
|
||||||
|
public GroupEventArgs(bool ready)
|
||||||
|
{
|
||||||
|
this.ready = ready;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class MessageEventArgs : EventArgs
|
public class MessageEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
|
|
@ -88,15 +108,28 @@ namespace BSB.bottypes
|
||||||
public class EventsBot : VoidEventBot
|
public class EventsBot : VoidEventBot
|
||||||
{
|
{
|
||||||
private EventHandler<MessageEventArgs> _MessageEvent;
|
private EventHandler<MessageEventArgs> _MessageEvent;
|
||||||
|
private EventHandler<StatusMessageEvent> _StatusMessageEvent;
|
||||||
|
private EventHandler<GroupEventArgs> _GroupsEvent;
|
||||||
|
|
||||||
private readonly object _MessageEventLock = new object();
|
private readonly object _MessageEventLock = new object();
|
||||||
|
private readonly object _StatusMessageEventlock = new object();
|
||||||
|
private readonly object _GroupsEventLock = new object();
|
||||||
|
|
||||||
/// <summary>Raised when a request we sent to friend another agent is accepted or declined</summary>
|
|
||||||
public event EventHandler<MessageEventArgs> MessageEvent
|
public event EventHandler<MessageEventArgs> MessageEvent
|
||||||
{
|
{
|
||||||
add { lock (_MessageEventLock) { _MessageEvent += value; } }
|
add { lock (_MessageEventLock) { _MessageEvent += value; } }
|
||||||
remove { lock (_MessageEventLock) { _MessageEvent -= value; } }
|
remove { lock (_MessageEventLock) { _MessageEvent -= value; } }
|
||||||
}
|
}
|
||||||
|
public event EventHandler<StatusMessageEvent> StatusMessageEvent
|
||||||
|
{
|
||||||
|
add { lock (_StatusMessageEventlock) { _StatusMessageEvent += value; } }
|
||||||
|
remove { lock (_StatusMessageEventlock) { _StatusMessageEvent -= value; } }
|
||||||
|
}
|
||||||
|
public event EventHandler<GroupEventArgs> GroupsReadyEvent
|
||||||
|
{
|
||||||
|
add { lock (_GroupsEventLock) { _GroupsEvent += value; } }
|
||||||
|
remove { lock (_GroupsEventLock) { _GroupsEvent -= value; } }
|
||||||
|
}
|
||||||
|
|
||||||
protected void On_MessageEvent(MessageEventArgs e)
|
protected void On_MessageEvent(MessageEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
@ -104,6 +137,18 @@ namespace BSB.bottypes
|
||||||
handler?.Invoke(this, e);
|
handler?.Invoke(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void On_StatusMessageEvent(StatusMessageEvent e)
|
||||||
|
{
|
||||||
|
EventHandler<StatusMessageEvent> handler = _StatusMessageEvent;
|
||||||
|
handler?.Invoke(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void On_GroupsReadyEvent(GroupEventArgs e)
|
||||||
|
{
|
||||||
|
EventHandler<GroupEventArgs> handler = _GroupsEvent;
|
||||||
|
handler?.Invoke(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void BotChatControler(string message, string sender_name, UUID sender_uuid, bool avatar, bool group, UUID group_uuid, bool localchat, bool fromme)
|
protected virtual void BotChatControler(string message, string sender_name, UUID sender_uuid, bool avatar, bool group, UUID group_uuid, bool localchat, bool fromme)
|
||||||
{
|
{
|
||||||
if (_MessageEvent != null)
|
if (_MessageEvent != null)
|
||||||
|
|
@ -201,8 +246,22 @@ namespace BSB.bottypes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Client.Network.CurrentSim != null)
|
||||||
|
{
|
||||||
|
On_StatusMessageEvent(new StatusMessageEvent(true, Client.Network.CurrentSim.Name));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
On_StatusMessageEvent(new StatusMessageEvent(true, "None"));
|
||||||
|
}
|
||||||
return base.GetStatus();
|
return base.GetStatus();
|
||||||
}
|
}
|
||||||
|
public override void KillMePlease()
|
||||||
|
{
|
||||||
|
On_StatusMessageEvent(new StatusMessageEvent(false, "None"));
|
||||||
|
base.KillMePlease();
|
||||||
|
}
|
||||||
|
|
||||||
protected string login_status = "Waiting to login";
|
protected string login_status = "Waiting to login";
|
||||||
protected override void LoginHandler(object o, LoginProgressEventArgs e)
|
protected override void LoginHandler(object o, LoginProgressEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
@ -252,11 +311,12 @@ namespace BSB.bottypes
|
||||||
{
|
{
|
||||||
Client.Self.RequestJoinGroupChat(entry.Value.ID);
|
Client.Self.RequestJoinGroupChat(entry.Value.ID);
|
||||||
}
|
}
|
||||||
|
On_GroupsReadyEvent(new GroupEventArgs(true));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void AfterBotLoginHandler()
|
protected override void AfterBotLoginHandler()
|
||||||
{
|
{
|
||||||
base.AfterBotLoginHandler();
|
|
||||||
if (reconnect == false)
|
if (reconnect == false)
|
||||||
{
|
{
|
||||||
Client.Self.ChatFromSimulator += ChatInputHandler;
|
Client.Self.ChatFromSimulator += ChatInputHandler;
|
||||||
|
|
@ -266,6 +326,7 @@ namespace BSB.bottypes
|
||||||
Client.Friends.FriendshipResponse += FriendshipResponse;
|
Client.Friends.FriendshipResponse += FriendshipResponse;
|
||||||
delay_group_fetch = helpers.UnixTimeNow() + 10;
|
delay_group_fetch = helpers.UnixTimeNow() + 10;
|
||||||
}
|
}
|
||||||
|
base.AfterBotLoginHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void FriendshipResponse(object o, FriendshipResponseEventArgs E)
|
protected virtual void FriendshipResponse(object o, FriendshipResponseEventArgs E)
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ namespace BSB.bottypes
|
||||||
|
|
||||||
protected override void AfterBotLoginHandler()
|
protected override void AfterBotLoginHandler()
|
||||||
{
|
{
|
||||||
base.AfterBotLoginHandler();
|
|
||||||
connected_to_groups = false;
|
connected_to_groups = false;
|
||||||
|
base.AfterBotLoginHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly string[] hard_blocked_agents = new string[] { "secondlife", "second life"};
|
readonly string[] hard_blocked_agents = new string[] { "secondlife", "second life"};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue