SecondBot/SecondBotEvents/Commands/Chat.cs
2022-05-30 05:30:15 +01:00

102 lines
3.7 KiB
C#

using Newtonsoft.Json;
using OpenMetaverse;
using SecondBotEvents.Services;
namespace SecondBotEvents.Commands
{
public class Chat : CommandsAPI
{
public Chat(EventsSecondBot setmaster) : base(setmaster)
{
}
[About("fetchs the last localchat messages")]
[ReturnHints("json encoded array")]
public object LocalChatHistory()
{
return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.getLocalChat()));
}
[About("sends a message to localchat")]
[ArgHints("channel", "the channel to output on (>=0)")]
[ArgHints("message", "the message to send")]
[ReturnHints("array string")]
[ReturnHintsFailure("Message empty")]
[ReturnHintsFailure("Invaild channel")]
public object Say(string channel, string message)
{
if (SecondbotHelpers.isempty(message) == true)
{
return Failure("Message empty", "Say", new [] { channel, message });
}
if(int.TryParse(channel,out int channelnum) == false)
{
return Failure("Invaild channel", "Say", new [] { channel, message });
}
if(channelnum < 0)
{
return Failure("Invaild channel", "Say", new [] { channel, message });
}
getClient().Self.Chat(message, channelnum, ChatType.Normal);
return BasicReply("ok");
}
[About("sends a im to the selected avatar")]
[ArgHints("avatar", "a UUID or Firstname Lastname")]
[ArgHints("message", "the message to send")]
[ReturnHints("ok")]
[ReturnHintsFailure("Message empty")]
[ReturnHintsFailure("avatar lookup")]
public object IM(string avatar, string message)
{
ProcessAvatar(avatar);
if(avataruuid == UUID.Zero)
{
return Failure("avatar lookup", "IM", new [] { avatar, message });
}
if (SecondbotHelpers.isempty(message) == true)
{
return Failure("Message empty", "IM", new [] { avatar, message });
}
master.botClient.SendIM(avataruuid, message);
return BasicReply("ok", "IM", new [] { avatar, message });
}
[About("gets a full list of all avatar chat windows")]
[ReturnHints("array UUID = Name")]
public object chatwindows()
{
return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.getAvatarImWindows()));
}
[About("gets a list of chat windows from avatars with unread messages")]
[ReturnHints("array of UUID")]
public object listwithunread()
{
return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.getAvatarImWindowsUnread()));
}
[About("gets if there are any unread im messages from avatars at all")]
[ReturnHints("True|False")]
public object haveunreadims()
{
return BasicReply(master.DataStoreService.getAvatarImWindowsUnreadAny().ToString());
}
[About("gets the chat from the selected window for avatar")]
[ArgHints("window", "the UUID of the avatar you wish to view the chat from")]
[ReturnHintsFailure("avatar UUID invaild")]
[ReturnHints("Array of text")]
public object getimchat(string avatarid)
{
UUID avatarUUID = UUID.Zero;
if (UUID.TryParse(avatarid, out avatarUUID) == false)
{
return Failure("avatar UUID invaild");
}
return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.getAvatarImWindow(avatarUUID)));
}
}
}