Open sourced NatiBot

This commit is contained in:
2014-09-04 04:26:22 +01:00
parent 0c66d4a2ea
commit e4b4c631af
301 changed files with 84837 additions and 7 deletions

View File

@@ -0,0 +1,122 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : ActivateGroupCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
using OpenMetaverse.Packets;
using System;
using System.Collections.Generic;
using System.Threading;
public class ActivateGroupCommand : Command
{
ManualResetEvent GroupsEvent = new ManualResetEvent(false);
string activeGroup;
public ActivateGroupCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "activategroup";
base.Description = bot.Localization.clResourceManager.getText("Commands.ActivateGroup.Description") + " " + bot.Localization.clResourceManager.getText("Commands.ActivateGroup.Usage");
}
private void AgentDataUpdateHandler(object sender, PacketReceivedEventArgs e)
{
AgentDataUpdatePacket p = (AgentDataUpdatePacket)e.Packet;
if (p.AgentData.AgentID == Client.Self.AgentID)
{
activeGroup = Utils.BytesToString(p.AgentData.GroupName) + " ( " + Utils.BytesToString(p.AgentData.GroupTitle) + " )";
GroupsEvent.Set();
}
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
bool isGroupID = false;
if (args.Length < 1)
return Description;
activeGroup = string.Empty;
string groupName = String.Empty;
for (int i = 0; i < args.Length; i++)
groupName += args[i] + " ";
groupName = groupName.Trim();
Client.Groups.RequestCurrentGroups();
GroupsEvent.Reset();
string realGroupName = "";
UUID groupUUID = Client.GroupName2UUID(groupName);
if (UUID.Zero != groupUUID)
{
EventHandler<PacketReceivedEventArgs> pcallback = AgentDataUpdateHandler;
Client.Network.RegisterCallback(PacketType.AgentDataUpdate, pcallback);
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.ActivateGroup.Setting"), groupName);
Client.Groups.ActivateGroup(groupUUID);
GroupsEvent.WaitOne(30000, false);
Client.Network.UnregisterCallback(PacketType.AgentDataUpdate, pcallback);
GroupsEvent.Reset();
/* A.Biondi
* TODO: Handle titles choosing.
*/
Client.key2Name(groupUUID, out realGroupName, out isGroupID);
if (!isGroupID)
return String.Format(bot.Localization.clResourceManager.getText("Commands.GroupEject.AvatarID"), groupUUID);
if (realGroupName == "")
realGroupName = groupUUID.ToString();
if (String.IsNullOrEmpty(activeGroup))
return String.Format(bot.Localization.clResourceManager.getText("Commands.ActivateGroup.Failed"), Client.ToString(),
realGroupName);
return String.Format(bot.Localization.clResourceManager.getText("Commands.ActivateGroup.Active"), Client.ToString(),
realGroupName);
}
return String.Format(bot.Localization.clResourceManager.getText("Commands.ActivateGroup.NotInGroup"), Client.ToString(),
realGroupName);
return String.Format(bot.Localization.clResourceManager.getText("Commands.ActivateGroup.NoGroups"), Client.ToString());
}
}
}

View File

@@ -0,0 +1,126 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : ActivateRoleCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
using System;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Packets;
using System.Text;
namespace bot.Commands
{
public class ActivateRoleCommand : Command
{
private ManualResetEvent GroupsEvent = new ManualResetEvent(false);
private string GroupName;
private UUID GroupUUID;
private UUID RoleUUID;
private UUID GroupRequestID;
private Dictionary<UUID, GroupRole> GroupRoles;
public ActivateRoleCommand(SecondLifeBot secondLifeBot)
{
Name = "activaterole";
Description = bot.Localization.clResourceManager.getText("Commands.ActivateRole.Description") + " " + bot.Localization.clResourceManager.getText("Commands.ActivateRole.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
bool isGroupKey = false;
if (args.Length > 2 || args.Length < 1)
return bot.Localization.clResourceManager.getText("Commands.ActivateRole.Usage");
if (args.Length == 2)
{
if (!UUID.TryParse(args[1], out GroupUUID))
return bot.Localization.clResourceManager.getText("Commands.GroupEject.ExpectedGroupID");
}
else
{
if (Client.Self.ActiveGroup == UUID.Zero)
return bot.Localization.clResourceManager.getText("Commands.GroupEject.NoGroupActive");
GroupUUID = Client.Self.ActiveGroup;
}
if (!UUID.TryParse(args[0], out RoleUUID))
return bot.Localization.clResourceManager.getText("Commands.AddToRole.ExpectedRoleID");
if (!Client.key2Name(GroupUUID, out GroupName, out isGroupKey))
return bot.Localization.clResourceManager.getText("Commands.GroupEject.GroupNotFound");
if (!isGroupKey)
return bot.Localization.clResourceManager.getText("Commands.GroupEject.AvatarID");
Client.ReloadGroupsCache();
if (Client.GroupsCache == null)
return bot.Localization.clResourceManager.getText("Commands.Groups.CacheFailed");
if (Client.GroupsCache.Count == 0)
return bot.Localization.clResourceManager.getText("Commands.Groups.NoGroups");
if (!Client.GroupsCache.ContainsKey(GroupUUID))
return String.Format(bot.Localization.clResourceManager.getText("Commands.AddToRole.NotMemberSelf"), GroupName);
Client.Groups.GroupRoleDataReply += Groups_GroupRoles;
GroupRequestID = Client.Groups.RequestGroupRoles(GroupUUID);
if (!GroupsEvent.WaitOne(30000, false))
{
GroupsEvent.Reset();
Client.Groups.GroupRoleDataReply -= Groups_GroupRoles;
return bot.Localization.clResourceManager.getText("Commands.GroupInvite.CannotRoles");
}
else
{
GroupsEvent.Reset();
Client.Groups.GroupRoleDataReply -= Groups_GroupRoles;
}
GroupRole chosenRole;
if (!GroupRoles.TryGetValue(RoleUUID, out chosenRole))
return bot.Localization.clResourceManager.getText("Commands.GroupInvite.NotRole");
Client.Groups.ActivateTitle(GroupUUID, RoleUUID);
return String.Format(bot.Localization.clResourceManager.getText("Commands.ActivateRole.Activating"), chosenRole.Name, GroupName);
}
private void Groups_GroupRoles(object sender, GroupRolesDataReplyEventArgs e)
{
if (e.RequestID == GroupRequestID)
{
GroupRoles = e.Roles;
GroupsEvent.Set();
}
}
}
}

View File

@@ -0,0 +1,163 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : AddToRoleCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
using System;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Packets;
using System.Text;
namespace bot.Commands
{
public class AddToRoleCommand : Command
{
private ManualResetEvent GroupsEvent = new ManualResetEvent(false);
private string GroupName, AvatarName;
private UUID GroupUUID;
private UUID RoleUUID;
private UUID GroupRequestID;
private UUID AvatarUUID;
private Dictionary<UUID, GroupRole> GroupRoles;
private Dictionary<UUID, GroupMember> GroupMembers;
public AddToRoleCommand(SecondLifeBot secondLifeBot)
{
Name = "addtorole";
Description = bot.Localization.clResourceManager.getText("Commands.AddToRole.Description") + " " + bot.Localization.clResourceManager.getText("Commands.AddToRole.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
bool isGroupKey = false;
if (args.Length > 3 || args.Length < 2)
return bot.Localization.clResourceManager.getText("Commands.AddToRole.Usage");
if (args.Length == 3)
{
if (!UUID.TryParse(args[2], out GroupUUID))
return bot.Localization.clResourceManager.getText("Commands.GroupEject.ExpectedGroupID");
}
else
{
if (Client.Self.ActiveGroup == UUID.Zero)
return bot.Localization.clResourceManager.getText("Commands.GroupEject.NoGroupActive");
GroupUUID = Client.Self.ActiveGroup;
}
if (!UUID.TryParse(args[0], out RoleUUID))
return bot.Localization.clResourceManager.getText("Commands.AddToRole.ExpectedRoleID");
if (!UUID.TryParse(args[1], out AvatarUUID))
return bot.Localization.clResourceManager.getText("Commands.GroupEject.AvatarID");
if (!Client.key2Name(GroupUUID, out GroupName, out isGroupKey))
return bot.Localization.clResourceManager.getText("Commands.GroupEject.GroupNotFound");
if (!isGroupKey)
return bot.Localization.clResourceManager.getText("Commands.GroupEject.AvatarID");
if (!Client.key2Name(AvatarUUID, out AvatarName, out isGroupKey))
return bot.Localization.clResourceManager.getText("Commands.GroupEject.AvatarNotFound");
if (isGroupKey)
return bot.Localization.clResourceManager.getText("Commands.GroupEject.GroupID");
Client.ReloadGroupsCache();
if (Client.GroupsCache == null)
return bot.Localization.clResourceManager.getText("Commands.Groups.CacheFailed");
if (Client.GroupsCache.Count == 0)
return bot.Localization.clResourceManager.getText("Commands.Groups.NoGroups");
if (!Client.GroupsCache.ContainsKey(GroupUUID))
return String.Format(bot.Localization.clResourceManager.getText("Commands.AddToRole.NotMemberSelf"), GroupName);
Client.Groups.GroupMembersReply += GroupMembersHandler;
GroupRequestID = Client.Groups.RequestGroupMembers(GroupUUID);
if (!GroupsEvent.WaitOne(30000, false))
{
GroupsEvent.Reset();
Client.Groups.GroupMembersReply -= GroupMembersHandler;
return "Unable to get group members.";
}
else
{
GroupsEvent.Reset();
Client.Groups.GroupMembersReply -= GroupMembersHandler;
}
GroupMember chosenMember;
if (!GroupMembers.TryGetValue(AvatarUUID, out chosenMember))
return String.Format(bot.Localization.clResourceManager.getText("Commands.AddToRole.NotMember"), AvatarName, GroupName);
Client.Groups.GroupRoleDataReply += Groups_GroupRoles;
GroupRequestID = Client.Groups.RequestGroupRoles(GroupUUID);
if (!GroupsEvent.WaitOne(30000, false))
{
GroupsEvent.Reset();
Client.Groups.GroupRoleDataReply -= Groups_GroupRoles;
return bot.Localization.clResourceManager.getText("Commands.GroupInvite.CannotRoles");
}
else
{
GroupsEvent.Reset();
Client.Groups.GroupRoleDataReply -= Groups_GroupRoles;
}
GroupRole chosenRole;
if (!GroupRoles.TryGetValue(RoleUUID, out chosenRole))
return bot.Localization.clResourceManager.getText("Commands.GroupInvite.NotRole");
Client.Groups.AddToRole(GroupUUID, RoleUUID, AvatarUUID);
return String.Format(bot.Localization.clResourceManager.getText("Commands.AddToRole.Adding"), AvatarName, chosenRole.Name, GroupName);
}
private void GroupMembersHandler(object sender, GroupMembersReplyEventArgs e)
{
if (e.RequestID == GroupRequestID)
{
GroupMembers = e.Members;
GroupsEvent.Set();
}
}
private void Groups_GroupRoles(object sender, GroupRolesDataReplyEventArgs e)
{
if (e.RequestID == GroupRequestID)
{
GroupRoles = e.Roles;
GroupsEvent.Set();
}
}
}
}

View File

@@ -0,0 +1,119 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : GroupEjectCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
using System;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Packets;
using System.Text;
namespace bot.Commands
{
public class GroupEjectCommand : Command
{
private ManualResetEvent GroupsEvent = new ManualResetEvent(false);
private string GroupName;
private UUID GroupUUID;
private UUID GroupRequestID;
private Dictionary<UUID, GroupMember> GroupMembers;
public GroupEjectCommand(SecondLifeBot secondLifeBot)
{
Name = "groupeject";
Description = bot.Localization.clResourceManager.getText("Commands.GroupEject.Description") + " " + bot.Localization.clResourceManager.getText("Commands.GroupEject.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
UUID avatarID;
bool isGroupKey;
string avatarName;
GroupMembers = new Dictionary<UUID, GroupMember>();
GroupsEvent.Reset();
if (args.Length < 1)
return bot.Localization.clResourceManager.getText("Commands.GroupEject.Usage");
if (args.Length == 2)
{
if (!UUID.TryParse(args[1], out GroupUUID))
return bot.Localization.clResourceManager.getText("Commands.GroupEject.ExpectedGroupID");
if (!Client.key2Name(GroupUUID, out GroupName, out isGroupKey))
return bot.Localization.clResourceManager.getText("Commands.GroupEject.GroupNotFound");
if (!isGroupKey)
return bot.Localization.clResourceManager.getText("Commands.GroupEject.AvatarID");
}
else
{
if (Client.Self.ActiveGroup == UUID.Zero)
return bot.Localization.clResourceManager.getText("Commands.GroupEject.NoGroupActive");
GroupUUID = Client.Self.ActiveGroup;
}
if (!UUID.TryParse(args[0], out avatarID))
return bot.Localization.clResourceManager.getText("Commands.GroupEject.ExpectedAvatarID");
if (!Client.key2Name(avatarID, out avatarName, out isGroupKey))
return bot.Localization.clResourceManager.getText("Commands.GroupEject.AvatarNotFound");
if (isGroupKey)
return bot.Localization.clResourceManager.getText("Commands.GroupEject.GroupID");
Client.Groups.GroupMembersReply += GroupMembersHandler;
GroupRequestID = Client.Groups.RequestGroupMembers(GroupUUID);
if (!GroupsEvent.WaitOne(30000, false))
{
Client.Groups.GroupMembersReply -= GroupMembersHandler;
return bot.Localization.clResourceManager.getText("Commands.GroupEject.ErrorMembers");
}
Client.Groups.GroupMembersReply -= GroupMembersHandler;
if (!GroupMembers.ContainsKey(avatarID))
return String.Format(bot.Localization.clResourceManager.getText("Commands.GroupEject.NotMember"), avatarName, GroupName);
Client.Groups.EjectUser(GroupUUID, avatarID);
return String.Format(bot.Localization.clResourceManager.getText("Commands.GroupEject.Ejected"), avatarName, GroupName);
}
private void GroupMembersHandler(object sender, GroupMembersReplyEventArgs e)
{
if (e.RequestID == GroupRequestID)
{
GroupMembers = e.Members;
GroupsEvent.Set();
}
}
}
}

View File

@@ -0,0 +1,124 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : GroupInviteCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
using System;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Packets;
using System.Text;
namespace bot.Commands
{
public class GroupInviteCommand : Command
{
private ManualResetEvent GroupsEvent = new ManualResetEvent(false);
private UUID roleID;
private UUID GroupRequestID;
private Dictionary<UUID, GroupRole> Roles;
public GroupInviteCommand(SecondLifeBot secondLifeBot)
{
Name = "invitegroup";
Description = bot.Localization.clResourceManager.getText("Commands.GroupInvite.Description") + " " + bot.Localization.clResourceManager.getText("Commands.GroupInvite.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
if (args.Length < 1)
return bot.Localization.clResourceManager.getText("Commands.GroupInvite.Usage");
UUID avatarID;
string avatarName, groupName;
bool isGroupKey = false;
Roles = new Dictionary<UUID,GroupRole>();
if (!UUID.TryParse(args[0], out avatarID))
return Description;
roleID = UUID.Zero;
if (args.Length == 2)
if (!UUID.TryParse(args[1], out roleID))
return Description;
if (Client.Self.ActiveGroup == UUID.Zero)
return bot.Localization.clResourceManager.getText("Commands.GroupInvite.NoGroupActive");
if (!Client.key2Name(avatarID, out avatarName, out isGroupKey))
return bot.Localization.clResourceManager.getText("Commands.GroupInvite.AvNotFound");
if (isGroupKey)
return bot.Localization.clResourceManager.getText("Commands.GroupInvite.CannotGroup");
Client.key2Name(Client.Self.ActiveGroup, out groupName);
Client.Groups.GroupRoleDataReply += Groups_GroupRoles;
GroupRequestID = Client.Groups.RequestGroupRoles(Client.Self.ActiveGroup);
if (!GroupsEvent.WaitOne(30000, false))
{
GroupsEvent.Reset();
return bot.Localization.clResourceManager.getText("Commands.GroupInvite.CannotRoles");
}
else
{
GroupsEvent.Reset();
}
Client.Groups.GroupRoleDataReply -= Groups_GroupRoles;
if (!Roles.ContainsKey(roleID))
return String.Format(bot.Localization.clResourceManager.getText("Commands.GroupInvite.NotRole"), roleID);
List<UUID> inviteRoles = new List<UUID>();
inviteRoles.Add(roleID);
GroupRole role;
if (!Roles.TryGetValue(roleID, out role))
return bot.Localization.clResourceManager.getText("Commands.GroupInvite.ErrorRole");
Client.Groups.Invite(Client.Self.ActiveGroup, inviteRoles, avatarID);
return String.Format(bot.Localization.clResourceManager.getText("Commands.GroupInvite.Inviting"), avatarName, groupName, role.Name);
}
void Groups_GroupRoles(object sender, GroupRolesDataReplyEventArgs e)
{
if (e.RequestID == GroupRequestID)
{
Roles = e.Roles;
GroupsEvent.Set();
}
}
}
}

View File

@@ -0,0 +1,108 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : GroupMembersCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
using System;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Packets;
using System.Text;
namespace bot.Commands
{
public class GroupMembersCommand : Command
{
private ManualResetEvent GroupsEvent = new ManualResetEvent(false);
private string GroupName;
private UUID GroupUUID;
private UUID GroupRequestID;
StringBuilder sb;
public GroupMembersCommand(SecondLifeBot secondLifeBot)
{
Name = "groupmembers";
Description = bot.Localization.clResourceManager.getText("Commands.GroupMembers.Description") + " " + bot.Localization.clResourceManager.getText("Commands.GroupMembers.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
if (args.Length < 1)
return bot.Localization.clResourceManager.getText("Commands.GroupMembers.Usage");
sb = new StringBuilder();
GroupName = String.Empty;
for (int i = 0; i < args.Length; i++)
GroupName += args[i] + " ";
GroupName = GroupName.Trim();
GroupUUID = Client.GroupName2UUID(GroupName);
if (UUID.Zero != GroupUUID)
{
Client.Groups.GroupMembersReply += GroupMembersHandler;
GroupRequestID = Client.Groups.RequestGroupMembers(GroupUUID);
GroupsEvent.WaitOne(30000, false);
GroupsEvent.Reset();
Client.Groups.GroupMembersReply -= GroupMembersHandler;
return sb.ToString();
}
return String.Format(bot.Localization.clResourceManager.getText("Commands.GroupMembers.NotMember"), Client.ToString(), GroupName);
}
private void GroupMembersHandler(object sender, GroupMembersReplyEventArgs e)
{
if (e.RequestID == GroupRequestID)
{
sb.AppendLine();
sb.AppendFormat(bot.Localization.clResourceManager.getText("Commands.GroupMembers.GotMembers"), Client.ToString()).AppendLine();
sb.AppendFormat(bot.Localization.clResourceManager.getText("Commands.GroupRoles.RequestID"), e.RequestID).AppendLine();
sb.AppendFormat(bot.Localization.clResourceManager.getText("Commands.GroupRoles.GroupName"), GroupName).AppendLine();
sb.AppendFormat(bot.Localization.clResourceManager.getText("Commands.GroupRoles.GroupID"), GroupUUID).AppendLine();
if (e.Members.Count > 0)
foreach (KeyValuePair<UUID, GroupMember> member in e.Members)
{
string MemberName;
if (!Client.key2Name(member.Key, out MemberName))
MemberName = bot.Localization.clResourceManager.getText("Commands.PrimInfo.Unknown");
sb.AppendFormat(bot.Localization.clResourceManager.getText("Commands.GroupMembers.Member"), MemberName, member.Key.ToString()).AppendLine();
}
sb.AppendFormat(bot.Localization.clResourceManager.getText("Commands.GroupMembers.MemberCount"), e.Members.Count).AppendLine();
GroupsEvent.Set();
}
}
}
}

View File

@@ -0,0 +1,98 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : GroupRolesCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
using System;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Packets;
using System.Text;
namespace bot.Commands
{
public class GroupRolesCommand : Command
{
private ManualResetEvent GroupsEvent = new ManualResetEvent(false);
private string GroupName;
private UUID GroupUUID;
private UUID GroupRequestID;
StringBuilder sb;
public GroupRolesCommand(SecondLifeBot secondLifeBot)
{
Name = "grouproles";
Description = bot.Localization.clResourceManager.getText("Commands.GroupRoles.Description") + " " + bot.Localization.clResourceManager.getText("Commands.GroupRoles.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
if (args.Length < 1)
return bot.Localization.clResourceManager.getText("Commands.GroupRoles.Usage");
sb = new StringBuilder();
GroupName = String.Empty;
for (int i = 0; i < args.Length; i++)
GroupName += args[i] + " ";
GroupName = GroupName.Trim();
GroupUUID = Client.GroupName2UUID(GroupName);
if (UUID.Zero != GroupUUID)
{
Client.Groups.GroupRoleDataReply += Groups_GroupRoles;
GroupRequestID = Client.Groups.RequestGroupRoles(GroupUUID);
GroupsEvent.WaitOne(30000, false);
GroupsEvent.Reset();
Client.Groups.GroupRoleDataReply -= Groups_GroupRoles;
return sb.ToString();
}
return String.Format(bot.Localization.clResourceManager.getText("Commands.GroupRoles.NoRoles"), Client.ToString(), GroupName);
}
private void Groups_GroupRoles(object sender, GroupRolesDataReplyEventArgs e)
{
if (e.RequestID == GroupRequestID)
{
sb.AppendLine();
sb.AppendFormat(bot.Localization.clResourceManager.getText("Commands.GroupRoles.GotRoles"), Client.ToString()).AppendLine();
sb.AppendFormat(bot.Localization.clResourceManager.getText("Commands.GroupRoles.RequestID"), e.RequestID).AppendLine();
sb.AppendFormat(bot.Localization.clResourceManager.getText("Commands.GroupRoles.GroupName"), GroupName).AppendLine();
sb.AppendFormat(bot.Localization.clResourceManager.getText("Commands.GroupRoles.GroupID"), GroupUUID).AppendLine();
if (e.Roles.Count > 0)
foreach (KeyValuePair<UUID, GroupRole> role in e.Roles)
sb.AppendFormat(bot.Localization.clResourceManager.getText("Commands.GroupRoles.Role"), role.Value.ID, role.Value.Name, role.Value.Title).AppendLine();
sb.AppendFormat(bot.Localization.clResourceManager.getText("Commands.GroupRoles.RoleCount"), e.Roles.Count).AppendLine();
GroupsEvent.Set();
}
}
}
}

View File

@@ -0,0 +1,77 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : GroupsCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
public class GroupsCommand : Command
{
ManualResetEvent GetCurrentGroupsEvent = new ManualResetEvent(false);
Dictionary<UUID, Group> groups = new Dictionary<UUID, Group>();
public GroupsCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "groups";
base.Description = bot.Localization.clResourceManager.getText("Commands.Groups.Description");
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
Client.ReloadGroupsCache();
return getGroupsString();
}
string getGroupsString()
{
if (null == Client.GroupsCache)
return bot.Localization.clResourceManager.getText("Commands.Groups.CacheFailed");
if (0 == Client.GroupsCache.Count)
return bot.Localization.clResourceManager.getText("Commands.Groups.NoGroups");
StringBuilder sb = new StringBuilder();
sb.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Groups.GotGroups"), Client.GroupsCache.Count).AppendLine();
foreach (Group group in Client.GroupsCache.Values)
{
sb.AppendLine(group.ID + ", " + group.Name);
}
return sb.ToString();
}
}
}

View File

@@ -0,0 +1,110 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : ImGroupCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
using System;
using System.Threading;
public class ImGroupCommand : Command
{
UUID ToGroupID = UUID.Zero;
ManualResetEvent WaitForSessionStart = new ManualResetEvent(false);
public ImGroupCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "imgroup";
base.Description = bot.Localization.clResourceManager.getText("Commands.IMGroup.Description") + " " + bot.Localization.clResourceManager.getText("Commands.IMGroup.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
if (args.Length < 2)
return bot.Localization.clResourceManager.getText("Commands.IMGroup.Usage");
if (UUID.TryParse(args[0], out ToGroupID))
{
string message = String.Empty;
for (int ct = 1; ct < args.Length; ct++)
message += args[ct] + " ";
message = message.TrimEnd();
if (message.Length > 1023)
message = message.Remove(1023);
Client.Self.GroupChatJoined += Self_GroupChatJoined;
if (!Client.Self.GroupChatSessions.ContainsKey(ToGroupID))
{
WaitForSessionStart.Reset();
Client.Self.RequestJoinGroupChat(ToGroupID);
}
else
{
WaitForSessionStart.Set();
}
if (WaitForSessionStart.WaitOne(20000, false))
{
Client.Self.InstantMessageGroup(ToGroupID, message);
}
else
{
return bot.Localization.clResourceManager.getText("Commands.IMGroup.Timeout");
}
Client.Self.GroupChatJoined -= Self_GroupChatJoined;
return String.Format(bot.Localization.clResourceManager.getText("Commands.IMGroup.Success"), ToGroupID.ToString(), message);
}
else
{
return bot.Localization.clResourceManager.getText("Commands.IMGroup.Fail");
}
}
void Self_GroupChatJoined(object sender, GroupChatJoinedEventArgs e)
{
if (e.Success)
{
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.IMGroup.Joined"), e.SessionName);
WaitForSessionStart.Set();
}
else
{
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.IMGroup.JoinFail"));
}
}
}
}

View File

@@ -0,0 +1,169 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : JoinGroupCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
using System;
using System.Collections.Generic;
using System.Threading;
public class JoinGroupCommand : Command
{
ManualResetEvent GetGroupsSearchEvent = new ManualResetEvent(false);
private UUID queryID = UUID.Zero;
private UUID resolvedGroupID;
private string groupName;
private string resolvedGroupName;
private bool joinedGroup;
public JoinGroupCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "joingroup";
base.Description = bot.Localization.clResourceManager.getText("Commands.JoinGroup.Description") + " " + bot.Localization.clResourceManager.getText("Commands.JoinGroup.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
if (args.Length < 1)
return Description;
groupName = String.Empty;
resolvedGroupID = UUID.Zero;
resolvedGroupName = String.Empty;
if (args.Length < 2)
{
if (!UUID.TryParse((resolvedGroupName = groupName = args[0]), out resolvedGroupID))
return String.Format(bot.Localization.clResourceManager.getText("Commands.JoinGroup.InvalidUUID"), resolvedGroupName);
}
else
{
for (int i = 0; i < args.Length; i++)
groupName += args[i] + " ";
groupName = groupName.Trim();
Client.Directory.DirGroupsReply += Directory_DirGroups;
queryID = Client.Directory.StartGroupSearch(groupName, 0);
GetGroupsSearchEvent.WaitOne(60000, false);
Client.Directory.DirGroupsReply -= Directory_DirGroups;
GetGroupsSearchEvent.Reset();
}
if (resolvedGroupID == UUID.Zero)
{
if (string.IsNullOrEmpty(resolvedGroupName))
return String.Format(bot.Localization.clResourceManager.getText("Commands.JoinGroup.UUIDNotFound"), groupName);
else
return resolvedGroupName;
}
Client.Groups.GroupJoinedReply += Groups_OnGroupJoined;
Client.Groups.RequestJoinGroup(resolvedGroupID);
/* A.Biondi
* TODO: implement the pay to join procedure.
*/
GetGroupsSearchEvent.WaitOne(60000, false);
Client.Groups.GroupJoinedReply -= Groups_OnGroupJoined;
GetGroupsSearchEvent.Reset();
if (joinedGroup)
return String.Format(bot.Localization.clResourceManager.getText("Commands.JoinGroup.Joined"), resolvedGroupName);
return String.Format(bot.Localization.clResourceManager.getText("Commands.JoinGroup.Failed"), resolvedGroupName);
}
void Groups_OnGroupJoined(object sender, GroupOperationEventArgs e)
{
if (e.Success)
{
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.JoinGroup.Joined"), e.GroupID.ToString());
joinedGroup = true;
}
else
{
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.JoinGroup.Failed"), e.GroupID.ToString());
joinedGroup = false;
}
}
void Directory_DirGroups(object sender, DirGroupsReplyEventArgs e)
{
if (queryID == e.QueryID)
{
queryID = UUID.Zero;
if (e.MatchedGroups.Count < 1)
{
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.JoinGroup.Empty"));
}
else
{
if (e.MatchedGroups.Count > 1)
{
/* A.Biondi
* The Group search doesn't work as someone could expect...
* It'll give back to you a long list of groups even if the
* searchText (groupName) matches esactly one of the groups
* names present on the server, so we need to check each result.
* UUIDs of the matching groups are written on the console.
*/
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.JoinGroup.Matching") + System.Environment.NewLine);
foreach (DirectoryManager.GroupSearchData groupRetrieved in e.MatchedGroups)
{
bot.Console.WriteLine(groupRetrieved.GroupName + "\t\t\t(" +
Name + " UUID " + groupRetrieved.GroupID.ToString() + ")");
if (groupRetrieved.GroupName.ToLower() == groupName.ToLower())
{
resolvedGroupID = groupRetrieved.GroupID;
resolvedGroupName = groupRetrieved.GroupName;
break;
}
}
if (string.IsNullOrEmpty(resolvedGroupName))
resolvedGroupName = String.Format(bot.Localization.clResourceManager.getText("Commands.JoinGroup.Ambigous"), e.MatchedGroups.Count.ToString());
}
}
GetGroupsSearchEvent.Set();
}
}
}
}

View File

@@ -0,0 +1,96 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : LeaveGroupCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
using System;
using System.Collections.Generic;
using System.Threading;
public class LeaveGroupCommand : Command
{
ManualResetEvent GroupsEvent = new ManualResetEvent(false);
Dictionary<UUID, Group> groups = new Dictionary<UUID, Group>();
private bool leftGroup;
public LeaveGroupCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "leavegroup";
base.Description = bot.Localization.clResourceManager.getText("Commands.LeaveGroup.Description") + " " + bot.Localization.clResourceManager.getText("Commands.LeaveGroup.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
if (args.Length < 1)
return Description;
string groupName = String.Empty;
for (int i = 0; i < args.Length; i++)
groupName += args[i] + " ";
groupName = groupName.Trim();
UUID groupUUID = Client.GroupName2UUID(groupName);
if (UUID.Zero != groupUUID)
{
Client.Groups.GroupLeaveReply += Groups_GroupLeft;
Client.Groups.LeaveGroup(groupUUID);
GroupsEvent.WaitOne(30000, false);
Client.Groups.GroupLeaveReply -= Groups_GroupLeft;
GroupsEvent.Reset();
Client.ReloadGroupsCache();
if (leftGroup)
return String.Format(bot.Localization.clResourceManager.getText("Commands.LeaveGroup.Left"), Client.ToString(),
groupName);
return String.Format(bot.Localization.clResourceManager.getText("Commands.LeaveGroup.Failed"), Client.ToString(),
groupName);
}
return String.Format(bot.Localization.clResourceManager.getText("Commands.LeaveGroup.NotInGroup"), Client.ToString(), groupName);
}
void Groups_GroupLeft(object sender, GroupOperationEventArgs e)
{
if (e.Success)
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.LeaveGroup.Left"), Client.ToString(), e.GroupID.ToString());
else
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.LeaveGroup.Failed"), Client.ToString(), e.GroupID.ToString());
leftGroup = e.Success;
GroupsEvent.Set();
}
}
}