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 string LastStatusMessage { get; set; }
|
||||
|
||||
public bool KillMe { get { return killMe; } }
|
||||
public virtual bool KillMe { get { return killMe; } }
|
||||
|
||||
protected bool teleported;
|
||||
public void SetTeleported()
|
||||
|
|
|
|||
|
|
@ -214,10 +214,17 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
IReadOnlyCollection<ICategoryChannel> found_cats = await DiscordServer.GetCategoriesAsync(CacheMode.AllowDownload);
|
||||
foreach (ICategoryChannel fcat in found_cats)
|
||||
{
|
||||
if (required_cats.Contains(fcat.Name) == true)
|
||||
{
|
||||
required_cats.Remove(fcat.Name);
|
||||
catmap.Add(fcat.Name, fcat);
|
||||
if (catmap.ContainsKey(fcat.Name) == false)
|
||||
{
|
||||
if (required_cats.Contains(fcat.Name) == true)
|
||||
{
|
||||
required_cats.Remove(fcat.Name);
|
||||
catmap.Add(fcat.Name, fcat);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
required_cats.Remove(fcat.Name);
|
||||
}
|
||||
}
|
||||
foreach (string A in required_cats)
|
||||
|
|
@ -236,9 +243,12 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
}
|
||||
else
|
||||
{
|
||||
if (chan.CategoryId == catmap["group"].Id)
|
||||
{
|
||||
GroupChannels.Add(chan.Name);
|
||||
if (GroupChannels.Contains(chan.Name) == false)
|
||||
{
|
||||
if (chan.CategoryId == catmap["group"].Id)
|
||||
{
|
||||
GroupChannels.Add(chan.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,10 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
{
|
||||
while (exit_super == false)
|
||||
{
|
||||
if (HasBasicBot() == false)
|
||||
{
|
||||
StatusMessageHandler(null, new BSB.bottypes.StatusMessageEvent(false, "None"));
|
||||
}
|
||||
string NewStatusMessage = GetStatus();
|
||||
if (NewStatusMessage != LastStatusMessage)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
|
||||
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);
|
||||
if (DiscordServer != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,14 +7,49 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
{
|
||||
public class DiscordEvents : DiscordBot
|
||||
{
|
||||
protected StatusMessageEvent LastNetworkEventArgs = null;
|
||||
protected void attach_events()
|
||||
{
|
||||
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)
|
||||
{
|
||||
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,8 +62,16 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
await TTSchannel.SendMessageAsync(message, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await base.DiscordIMMessage(sender_uuid, sender_name, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await base.DiscordIMMessage(sender_uuid, sender_name, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using OpenMetaverse;
|
||||
|
||||
using System;
|
||||
|
||||
namespace BetterSecondBot.DiscordSupervisor
|
||||
{
|
||||
public abstract class DiscordStatus : DiscordChannelControl
|
||||
|
|
@ -67,6 +68,5 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
}
|
||||
return reply;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@ namespace BSB.bottypes
|
|||
|
||||
protected override void AfterBotLoginHandler()
|
||||
{
|
||||
base.AfterBotLoginHandler();
|
||||
if (reconnect == false)
|
||||
{
|
||||
Client.Avatars.AvatarAnimation += AvatarAnimationHandler;
|
||||
}
|
||||
base.AfterBotLoginHandler();
|
||||
}
|
||||
|
||||
public override void ResetAnimations()
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ namespace BSB.bottypes
|
|||
|
||||
protected override void AfterBotLoginHandler()
|
||||
{
|
||||
base.AfterBotLoginHandler();
|
||||
if (reconnect == false)
|
||||
{
|
||||
Client.Groups.GroupRoleDataReply += GroupRolesData;
|
||||
|
|
@ -20,6 +19,7 @@ namespace BSB.bottypes
|
|||
Client.Groups.GroupMembersReply += GroupMembersReplyHandler;
|
||||
Client.Parcels.ParcelObjectOwnersReply += ObjectOwnersHandler;
|
||||
}
|
||||
base.AfterBotLoginHandler();
|
||||
}
|
||||
protected override void GroupMembersReplyHandler(object sender, GroupMembersReplyEventArgs e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -191,12 +191,12 @@ namespace BSB.bottypes
|
|||
|
||||
protected override void AfterBotLoginHandler()
|
||||
{
|
||||
base.AfterBotLoginHandler();
|
||||
if (reconnect == false)
|
||||
{
|
||||
CommandsInterface = new Commands.CoreCommandsInterface(this);
|
||||
}
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -45,12 +45,12 @@ namespace BSB.bottypes
|
|||
|
||||
protected override void AfterBotLoginHandler()
|
||||
{
|
||||
base.AfterBotLoginHandler();
|
||||
if (reconnect == false)
|
||||
{
|
||||
Client.Network.RegisterCallback(PacketType.SetFollowCamProperties, SetFollowCamPropertiesPacketHandler);
|
||||
}
|
||||
delay_appearence_update = 0; // reset Appearance helper
|
||||
base.AfterBotLoginHandler();
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
|
|
@ -88,15 +108,28 @@ namespace BSB.bottypes
|
|||
public class EventsBot : VoidEventBot
|
||||
{
|
||||
private EventHandler<MessageEventArgs> _MessageEvent;
|
||||
private EventHandler<StatusMessageEvent> _StatusMessageEvent;
|
||||
private EventHandler<GroupEventArgs> _GroupsEvent;
|
||||
|
||||
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
|
||||
{
|
||||
add { 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)
|
||||
{
|
||||
|
|
@ -104,6 +137,18 @@ namespace BSB.bottypes
|
|||
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)
|
||||
{
|
||||
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();
|
||||
}
|
||||
public override void KillMePlease()
|
||||
{
|
||||
On_StatusMessageEvent(new StatusMessageEvent(false, "None"));
|
||||
base.KillMePlease();
|
||||
}
|
||||
|
||||
protected string login_status = "Waiting to login";
|
||||
protected override void LoginHandler(object o, LoginProgressEventArgs e)
|
||||
{
|
||||
|
|
@ -252,11 +311,12 @@ namespace BSB.bottypes
|
|||
{
|
||||
Client.Self.RequestJoinGroupChat(entry.Value.ID);
|
||||
}
|
||||
On_GroupsReadyEvent(new GroupEventArgs(true));
|
||||
|
||||
}
|
||||
|
||||
protected override void AfterBotLoginHandler()
|
||||
{
|
||||
base.AfterBotLoginHandler();
|
||||
if (reconnect == false)
|
||||
{
|
||||
Client.Self.ChatFromSimulator += ChatInputHandler;
|
||||
|
|
@ -266,6 +326,7 @@ namespace BSB.bottypes
|
|||
Client.Friends.FriendshipResponse += FriendshipResponse;
|
||||
delay_group_fetch = helpers.UnixTimeNow() + 10;
|
||||
}
|
||||
base.AfterBotLoginHandler();
|
||||
}
|
||||
|
||||
protected virtual void FriendshipResponse(object o, FriendshipResponseEventArgs E)
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ namespace BSB.bottypes
|
|||
|
||||
protected override void AfterBotLoginHandler()
|
||||
{
|
||||
base.AfterBotLoginHandler();
|
||||
connected_to_groups = false;
|
||||
base.AfterBotLoginHandler();
|
||||
}
|
||||
|
||||
readonly string[] hard_blocked_agents = new string[] { "secondlife", "second life"};
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace BSB.bottypes
|
|||
|
||||
protected override void AfterBotLoginHandler()
|
||||
{
|
||||
base.AfterBotLoginHandler();
|
||||
base.AfterBotLoginHandler();
|
||||
last_tested_home_id = -1;
|
||||
last_tp_attempt_unixtime = helpers.UnixTimeNow() + 30;
|
||||
if (after_login_fired == false)
|
||||
|
|
|
|||
Loading…
Reference in a new issue