diff --git a/Core/bottypes/SecondBot.cs b/Core/bottypes/SecondBot.cs index 83a5584..ed5cba9 100644 --- a/Core/bottypes/SecondBot.cs +++ b/Core/bottypes/SecondBot.cs @@ -11,20 +11,54 @@ namespace BSB.bottypes { public class SecondBot : DialogsBot { - protected override void AfterBotLoginHandler() + protected bool friendslist_ready = false; + protected bool masteruuid_ready = false; + protected bool started_friendship_hug = false; + + protected virtual void friendsListReady(object sender,FriendsReadyEventArgs e) { - base.AfterBotLoginHandler(); - if (helpers.notempty(myconfig.master) == true) + friendslist_ready = true; + TryHugMaster(); + } + + protected void TryHugMaster() + { + if ((masteruuid_ready == true) && (friendslist_ready == true) && (started_friendship_hug == false)) { + started_friendship_hug = true; if (myconfig.OnStartLinkupWithMaster == true) { - CommandsInterface.Call("IM", String.Join("~#~", new string[] { myconfig.master, "Hello master I am now online and ready to accept teleport offers" })); - CommandsInterface.Call("FriendRequest", myconfig.master, Client.Self.AgentID); - CommandsInterface.Call("FriendFullPerms", String.Join("~#~", new string[] { myconfig.master, "true" }), Client.Self.AgentID); + if (Client.Friends.FriendList.ContainsKey(master_uuid) == false) + { + CommandsInterface.Call("IM", String.Join("~#~", new string[] { myconfig.master, "Hello master, I am sending you a friend request now!" })); + CommandsInterface.Call("FriendRequest", myconfig.master, Client.Self.AgentID); + } + else + { + CommandsInterface.Call("FriendFullPerms", String.Join("~#~", new string[] { myconfig.master, "true" }), Client.Self.AgentID); + } } } } + protected override void BotStartHandler() + { + base.BotStartHandler(); + friendslist_ready = false; + if (reconnect == false) + { + Client.Friends.friendsListReady += friendsListReady; + } + } + protected override void FoundMasterAvatar() + { + if (helpers.notempty(myconfig.master) == true) + { + masteruuid_ready = true; + TryHugMaster(); + } + } + protected override void FriendshipResponse(object o,FriendshipResponseEventArgs E) { base.FriendshipResponse(o, E);