2021-06-15 00:19:52 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
|
|
|
* All rights reserved. Distributed under the terms of the MIT license.
|
|
|
|
*/
|
|
|
|
#ifndef CHAT_COMMAND_H
|
|
|
|
#define CHAT_COMMAND_H
|
|
|
|
|
2021-06-15 22:03:11 -05:00
|
|
|
#include <Archivable.h>
|
2021-06-15 00:19:52 -05:00
|
|
|
#include <Message.h>
|
|
|
|
#include <String.h>
|
|
|
|
|
|
|
|
#include <libsupport/KeyMap.h>
|
2021-06-30 11:12:57 -05:00
|
|
|
#include <libsupport/List.h>
|
2021-06-15 00:19:52 -05:00
|
|
|
|
|
|
|
class Conversation;
|
2021-08-18 15:15:56 -05:00
|
|
|
class User;
|
|
|
|
|
|
|
|
typedef KeyMap<BString, User*> UserMap;
|
2021-06-15 00:19:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
enum cmd_arg_type
|
|
|
|
{
|
|
|
|
CMD_ROOM_PARTICIPANT = 'CArp', // "user_id" in message
|
|
|
|
CMD_KNOWN_USER = 'CAku', // "user_id" in message
|
|
|
|
CMD_ANY_USER = 'CAau', // "user_id" in message
|
|
|
|
CMD_BODY_STRING = 'CAbs', // "body" in message
|
|
|
|
CMD_MISC_STRING = 'CAms' // "misc_str" in message
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-06-15 22:03:11 -05:00
|
|
|
class ChatCommand : public BArchivable {
|
2021-06-15 00:19:52 -05:00
|
|
|
public:
|
|
|
|
ChatCommand(const char* name, BMessage msg, bool toProtocol,
|
|
|
|
List<int32> argTypes);
|
2021-06-15 22:03:11 -05:00
|
|
|
ChatCommand(BMessage* data);
|
|
|
|
|
|
|
|
status_t Archive(BMessage* data, bool deep=true);
|
|
|
|
ChatCommand* Instantiate(BMessage* data);
|
|
|
|
|
2021-06-15 00:19:52 -05:00
|
|
|
|
|
|
|
const char* GetName() { return fName.String(); }
|
|
|
|
|
|
|
|
void SetDesc(const char* description);
|
|
|
|
const char* GetDesc() { return fDescription.String(); }
|
|
|
|
|
|
|
|
bool Parse(BString args, BString* errorMsg, Conversation* chat);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool _ProcessArgs(BString args, BMessage* msg, BString* errorMsg,
|
|
|
|
Conversation* chat);
|
|
|
|
|
2021-08-18 15:15:56 -05:00
|
|
|
User* _FindUser(BString idOrName, UserMap users);
|
|
|
|
|
2021-06-15 00:19:52 -05:00
|
|
|
bool _Send(BMessage* msg, Conversation* chat);
|
|
|
|
|
|
|
|
BString fName;
|
|
|
|
BString fDescription;
|
|
|
|
BMessage fMessage;
|
|
|
|
|
|
|
|
bool fToProto;
|
|
|
|
List<int32> fArgTypes;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef KeyMap<BString, ChatCommand*> CommandMap;
|
|
|
|
|
|
|
|
#endif // CHAT_COMMAND_H
|