(purple) Register per-protocol commands
This commit is contained in:
parent
d9051766d9
commit
91c7e44b44
|
@ -109,6 +109,8 @@ PurpleApp::MessageReceived(BMessage* msg)
|
|||
|| msg->FindInt64("thread_id", &thread) != B_OK)
|
||||
break;
|
||||
fAccountThreads.AddItem(username, thread);
|
||||
|
||||
SendMessage(thread, _GetCommands(_AccountFromMessage(msg)));
|
||||
break;
|
||||
}
|
||||
case PURPLE_REQUEST_DISCONNECT:
|
||||
|
@ -563,6 +565,42 @@ PurpleApp::_GetRoomTemplate(PurplePluginProtocolInfo* info)
|
|||
}
|
||||
|
||||
|
||||
BMessage
|
||||
PurpleApp::_GetCommands(PurpleAccount* account)
|
||||
{
|
||||
PurpleConversation* conv = purple_conversation_new(PURPLE_CONV_TYPE_ANY,
|
||||
account, NULL);
|
||||
|
||||
BMessage cmdMsgs(PURPLE_REGISTER_COMMANDS);
|
||||
GList* cmds = purple_cmd_list(conv);
|
||||
|
||||
for (int i = 0; cmds != NULL; cmds = cmds->next) {
|
||||
const char* cmd_name = (const char*)cmds->data;
|
||||
if (cmd_name == NULL) break;;
|
||||
|
||||
BMessage cmdMsg;
|
||||
cmdMsg.AddString("class", "ChatCommand");
|
||||
cmdMsg.AddString("_name", cmd_name);
|
||||
cmdMsg.AddBool("_proto", true);
|
||||
cmdMsg.AddInt32("_argtype", 0);
|
||||
|
||||
BString helpString;
|
||||
GList* helps = purple_cmd_help(NULL, cmd_name);
|
||||
for (int j = 0; helps != NULL; helps = helps->next)
|
||||
helpString << (const char*)helps->data;
|
||||
cmdMsg.AddString("_desc", helpString);
|
||||
|
||||
BMessage cmdActionMsg(IM_MESSAGE);
|
||||
cmdActionMsg.AddInt32("im_what", PURPLE_CHAT_COMMAND);
|
||||
cmdActionMsg.AddString("cmd_name", cmd_name);
|
||||
cmdMsg.AddMessage("_msg", &cmdActionMsg);
|
||||
|
||||
cmdMsgs.AddMessage("command", &cmdMsg);
|
||||
}
|
||||
return cmdMsgs;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PurpleApp::_ParseAccountTemplate(BMessage* settings)
|
||||
{
|
||||
|
|
|
@ -89,6 +89,7 @@ private:
|
|||
|
||||
BMessage _GetAccountTemplate(PurplePluginProtocolInfo* info);
|
||||
BMessage _GetRoomTemplate(PurplePluginProtocolInfo* info);
|
||||
BMessage _GetCommands(PurpleAccount* account);
|
||||
|
||||
void _ParseAccountTemplate(BMessage* settings);
|
||||
GHashTable* _ParseRoomTemplate(BMessage* msg);
|
||||
|
|
|
@ -56,7 +56,15 @@ enum purple_message {
|
|||
|
||||
/*! Disconnect add-on's account →Server
|
||||
Requires: String account_name */
|
||||
PURPLE_REQUEST_DISCONNECT = 'Axwx'
|
||||
PURPLE_REQUEST_DISCONNECT = 'Axwx',
|
||||
|
||||
/*! Register chat commands with proto →Protocol */
|
||||
PURPLE_REGISTER_COMMANDS = 'Scmd',
|
||||
|
||||
/*! User has typed a command, process! →Server
|
||||
Forwarded from Cardie.
|
||||
Requires: String chat_id, String cmd_name, String misc_str */
|
||||
PURPLE_CHAT_COMMAND = 'Pcmd'
|
||||
};
|
||||
|
||||
#endif // _PURPLE_MESSAGES_H
|
||||
|
|
|
@ -121,8 +121,16 @@ status_t
|
|||
connect_thread(void* data)
|
||||
{
|
||||
PurpleProtocol* protocol = (PurpleProtocol*)data;
|
||||
while (true)
|
||||
protocol->SendMessage(new BMessage(receive_message()));
|
||||
while (true) {
|
||||
BMessage* msg = new BMessage(receive_message());
|
||||
switch (msg->what) {
|
||||
case PURPLE_REGISTER_COMMANDS:
|
||||
protocol->Process(msg);
|
||||
break;
|
||||
default:
|
||||
protocol->SendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -172,13 +180,25 @@ PurpleProtocol::Shutdown()
|
|||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PurpleProtocol::Process(BMessage* msg)
|
||||
{
|
||||
if (msg->what == IM_MESSAGE) {
|
||||
_SendPrplMessage(msg);
|
||||
return B_OK;
|
||||
switch(msg->what)
|
||||
{
|
||||
case IM_MESSAGE:
|
||||
_SendPrplMessage(msg);
|
||||
return B_OK;
|
||||
case PURPLE_REGISTER_COMMANDS:
|
||||
{
|
||||
BMessage cmd;
|
||||
for (int i = 0; msg->FindMessage("command", i, &cmd) == B_OK; i++)
|
||||
fCommands.AddItem(new BMessage(cmd));
|
||||
|
||||
BMessage* reload = new BMessage(IM_MESSAGE);
|
||||
reload->AddInt32("im_what", IM_PROTOCOL_RELOAD_COMMANDS);
|
||||
SendMessage(reload);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return B_ERROR;
|
||||
}
|
||||
|
@ -192,7 +212,7 @@ PurpleProtocol::UpdateSettings(BMessage* msg)
|
|||
msg->what = PURPLE_CONNECT_ACCOUNT;
|
||||
_SendPrplMessage(msg);
|
||||
|
||||
thread_id thread = spawn_thread(connect_thread, "bird_superiority",
|
||||
thread_id thread = spawn_thread(connect_thread, "fly_away_little_bird",
|
||||
B_NORMAL_PRIORITY, (void*)this);
|
||||
|
||||
if (thread < B_OK)
|
||||
|
@ -225,7 +245,7 @@ PurpleProtocol::SettingsTemplate(const char* name)
|
|||
BObjectList<BMessage>
|
||||
PurpleProtocol::Commands()
|
||||
{
|
||||
return BObjectList<BMessage>();
|
||||
return fCommands;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@ private:
|
|||
BString fSignature;
|
||||
BString fFriendlySignature;
|
||||
BMessage fTemplates;
|
||||
BObjectList<BMessage> fCommands;
|
||||
};
|
||||
|
||||
|
||||
|
|
Ŝarĝante…
Reference in New Issue