clean up and moving functions out of basic into events

This commit is contained in:
Madpeter 2020-10-26 04:15:42 +00:00
parent 36bd3f69d1
commit a92a62a92d
2 changed files with 144 additions and 77 deletions

View file

@ -51,8 +51,10 @@ namespace BetterSecondBotShared.bottypes
else
{
// search for file called "commands.cmd"
JsonCommandsfile LoadedCommands = new JsonCommandsfile();
LoadedCommands.CustomCommands = new string[] { "sayexample!!!say|||Hello{-}delay|||2500{-}say|||Bye" };
JsonCommandsfile LoadedCommands = new JsonCommandsfile
{
CustomCommands = new string[] { "sayexample!!!say|||Hello{-}delay|||2500{-}say|||Bye" }
};
string CommandsFile = "custom_commands.json";
SimpleIO io = new SimpleIO();
if (SimpleIO.FileType(CommandsFile, "json") == true)
@ -280,34 +282,17 @@ namespace BetterSecondBotShared.bottypes
protected virtual void AfterBotLoginHandler()
{
Debug("AfterBotLoginHandler proc not overridden");
}
protected virtual void GroupInvite(InstantMessageEventArgs e)
{
string[] stage1 = e.IM.FromAgentName.ToLowerInvariant().Split('.');
string name = "" + stage1[0].FirstCharToUpper() + "";
if (stage1.Length == 1)
{
name = " Resident";
}
else
{
name = "" + name + " " + stage1[1].FirstCharToUpper() + "";
}
if(Is_avatar_master(name) == true)
{
GroupInvitationEventArgs G = new GroupInvitationEventArgs(e.Simulator, e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message);
Client.Self.GroupInviteRespond(G.AgentID, e.IM.IMSessionID, true);
Client.Groups.RequestCurrentGroups();
}
Debug("GroupInvite proc not overridden");
}
protected virtual void FriendshipOffer(UUID IMSessionID, string FromAgentName, UUID FromAgentID)
{
if (Is_avatar_master(FromAgentName) == true)
{
Client.Friends.AcceptFriendship(FromAgentID, IMSessionID);
}
Debug("FriendshipOffer proc not overridden");
}
protected virtual void RequestLure(UUID IMSessionID, string FromAgentName, UUID FromAgentID)
@ -329,22 +314,7 @@ namespace BetterSecondBotShared.bottypes
protected virtual void RequestTeleport(UUID IMSessionID, string FromAgentName, UUID FromAgentID)
{
bool allow = false;
if (Is_avatar_master(FromAgentName) == true)
{
allow = true;
}
else if(accept_next_teleport_from.Contains(FromAgentID) == true)
{
allow = true;
accept_next_teleport_from.Remove(FromAgentID);
}
if(allow == true)
{
ResetAnimations();
SetTeleported();
Client.Self.TeleportLureRespond(FromAgentID, IMSessionID, true);
}
Debug("RequestTeleport proc not overridden");
}
protected virtual void ChatInputHandler(object sender, ChatEventArgs e)

View file

@ -64,7 +64,6 @@ namespace BSB.bottypes
}
public class EventsBot : VoidEventBot
{
protected List<string> accept_animation_request_from_users = new List<string>();
protected bool login_auto_logout;
protected long delay_group_fetch;
protected Dictionary<UUID, KeyValuePair<long, List<UUID>>> group_members_storage = new Dictionary<UUID, KeyValuePair<long, List<UUID>>>();
@ -101,7 +100,7 @@ namespace BSB.bottypes
return result;
}
protected void cleanup_group_member_storage()
protected void Cleanup_group_member_storage()
{
lock (group_members_storage)
{
@ -121,18 +120,6 @@ namespace BSB.bottypes
}
}
public void ToggleAutoAcceptAnimations(string userName)
{
if(accept_animation_request_from_users.Contains(userName) == true)
{
accept_animation_request_from_users.Remove(userName);
}
else
{
accept_animation_request_from_users.Add(userName);
}
}
protected override void BotStartHandler()
{
Client.Network.LoginProgress += LoginHandler;
@ -150,8 +137,8 @@ namespace BSB.bottypes
if (dif > 30)
{
last_cleanup = helpers.UnixTimeNow();
cleanup_await_events();
cleanup_group_member_storage();
Cleanup_await_events();
Cleanup_group_member_storage();
}
if (delay_group_fetch > 0)
{
@ -236,36 +223,146 @@ namespace BSB.bottypes
protected override void PermissionsHandler(object sender, ScriptQuestionEventArgs e)
{
if(e.ObjectOwnerName == Client.Self.Name)
if (e.Questions == ScriptPermission.TriggerAnimation)
{
Client.Self.ScriptQuestionReply(Client.Network.CurrentSim, e.ItemID, e.TaskID, e.Questions);
}
else if(accept_animation_request_from_users.Contains(e.ObjectOwnerName) == true)
{
Client.Self.ScriptQuestionReply(Client.Network.CurrentSim, e.ItemID, e.TaskID, ScriptPermission.TriggerAnimation);
}
else if((e.ObjectOwnerName == myconfig.Security_MasterUsername) && (myconfig.Security_MasterUsername != ""))
{
Client.Self.ScriptQuestionReply(Client.Network.CurrentSim, e.ItemID, e.TaskID, e.Questions);
}
else if(Client.Self.SittingOn > 0)
{
if(Client.Network.CurrentSim.ObjectsPrimitives.ContainsKey(Client.Self.SittingOn))
{
Primitive obj = GetClient.Network.CurrentSim.ObjectsPrimitives[Client.Self.SittingOn];
if(obj.ID == e.ItemID)
{
Client.Self.ScriptQuestionReply(Client.Network.CurrentSim, e.ItemID, e.TaskID, ScriptPermission.TriggerAnimation);
}
}
TriggerAnimation(e);
}
else
{
Client.Self.ScriptQuestionReply(Client.Network.CurrentSim, e.ItemID, e.TaskID, ScriptPermission.None);
if (e.ObjectOwnerName == Client.Self.Name)
{
Client.Self.ScriptQuestionReply(Client.Network.CurrentSim, e.ItemID, e.TaskID, e.Questions);
}
else
{
Client.Self.ScriptQuestionReply(Client.Network.CurrentSim, e.ItemID, e.TaskID, ScriptPermission.None);
}
}
}
protected void cleanup_await_events()
public bool IsSittingOnUUID(UUID id)
{
if (Client.Self.SittingOn > 0)
{
if (Client.Network.CurrentSim.ObjectsPrimitives.ContainsKey(Client.Self.SittingOn))
{
Primitive obj = GetClient.Network.CurrentSim.ObjectsPrimitives[Client.Self.SittingOn];
if (obj.ID == id)
{
return true;
}
}
}
return false;
}
protected virtual void TriggerAnimation(ScriptQuestionEventArgs e)
{
bool accept_invite;
if (Is_avatar_master(e.ObjectOwnerName) == true)
{
accept_invite = true;
}
else if (e.ObjectOwnerName == Client.Self.Name)
{
accept_invite = true;
}
else if(IsSittingOnUUID(e.ItemID) == true)
{
accept_invite = true;
}
else
{
accept_invite = Accept_action_from("animation", e.ItemID);
if (accept_invite == true)
{
Remove_action_from("animation", e.ItemID);
}
}
if (accept_invite == true)
{
Client.Self.ScriptQuestionReply(Client.Network.CurrentSim, e.ItemID, e.TaskID, ScriptPermission.TriggerAnimation);
}
}
protected override void FriendshipOffer(UUID IMSessionID, string FromAgentName, UUID FromAgentID)
{
bool accept_invite;
if (Is_avatar_master(FromAgentName) == true)
{
accept_invite = true;
}
else
{
accept_invite = Accept_action_from("friend", FromAgentID);
if (accept_invite == true)
{
Remove_action_from("friend", FromAgentID);
}
}
if (accept_invite == true)
{
Client.Friends.AcceptFriendship(FromAgentID, IMSessionID);
}
}
protected override void RequestTeleport(UUID IMSessionID, string FromAgentName, UUID FromAgentID)
{
bool accept_invite;
if (Is_avatar_master(FromAgentName) == true)
{
accept_invite = true;
}
else
{
accept_invite = Accept_action_from("teleport", FromAgentID);
if (accept_invite == true)
{
Remove_action_from("teleport", FromAgentID);
}
}
if (accept_invite == true)
{
ResetAnimations();
SetTeleported();
Client.Self.TeleportLureRespond(FromAgentID, IMSessionID, true);
}
}
protected override void GroupInvite(InstantMessageEventArgs e)
{
string[] stage1 = e.IM.FromAgentName.ToLowerInvariant().Split('.');
string name = "" + stage1[0].FirstCharToUpper() + "";
if (stage1.Length == 1)
{
name = " Resident";
}
else
{
name = "" + name + " " + stage1[1].FirstCharToUpper() + "";
}
bool accept_invite;
if (Is_avatar_master(name) == true)
{
accept_invite = true;
}
else
{
accept_invite = Accept_action_from("group", e.IM.FromAgentID);
if(accept_invite == true)
{
Remove_action_from("group", e.IM.FromAgentID);
}
}
if (accept_invite == true)
{
GroupInvitationEventArgs G = new GroupInvitationEventArgs(e.Simulator, e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message);
Client.Self.GroupInviteRespond(G.AgentID, e.IM.IMSessionID, true);
Client.Groups.RequestCurrentGroups();
}
}
protected void Cleanup_await_events()
{
long dif;
List<string> purge_event_ids = new List<string>();