Add '/help' command
This commit is contained in:
parent
46d6d0a0b0
commit
7d72b5152c
|
@ -44,7 +44,10 @@ const uint32 CAYA_MOVE_UP = 'CYmu';
|
|||
//! Select the downward conversation
|
||||
const uint32 CAYA_MOVE_DOWN = 'CYmd';
|
||||
|
||||
//! Select the downward conversation
|
||||
//! Disable a given account
|
||||
const uint32 CAYA_DISABLE_ACCOUNT = 'CYda';
|
||||
|
||||
//! Request a "help" message
|
||||
const uint32 CAYA_REQUEST_HELP = 'CYhm';
|
||||
|
||||
#endif // _CAYA_MESSAGES_H
|
||||
|
|
|
@ -62,7 +62,8 @@ CommandArgs(BString line)
|
|||
{
|
||||
BString remove("/");
|
||||
remove << CommandName(line) << "";
|
||||
return line.RemoveFirst(remove);
|
||||
line.RemoveFirst(remove);
|
||||
return line.Trim();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ Conversation::ImMessage(BMessage* msg)
|
|||
ChatCommand* cmd = _GetServer()->CommandById(name);
|
||||
|
||||
if (cmd == NULL) {
|
||||
_WarnUser(BString("That isn't a valid command."));
|
||||
_WarnUser(BString("That isn't a valid command. Try /help for a list."));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -370,6 +370,9 @@ Conversation::_LogChatMessage(BMessage* msg)
|
|||
BString id = msg->FindString("user_id");
|
||||
BString body = msg->FindString("body");
|
||||
|
||||
if (id.IsEmpty() == true)
|
||||
return;
|
||||
|
||||
// Binary logs
|
||||
// TODO: Don't hardcode 21, expose maximum as a setting
|
||||
BStringList users, bodies;
|
||||
|
|
|
@ -109,11 +109,46 @@ Server::Filter(BMessage* message, BHandler **target)
|
|||
result = B_SKIP_MESSAGE;
|
||||
break;
|
||||
}
|
||||
|
||||
RemoveProtocolLooper(instance);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAYA_REQUEST_HELP:
|
||||
{
|
||||
BString body;
|
||||
BString cmd_name = message->FindString("misc_str");
|
||||
Conversation* chat = _EnsureConversation(message);
|
||||
|
||||
if (chat == NULL)
|
||||
break;
|
||||
|
||||
if (cmd_name.IsEmpty() == false) {
|
||||
ChatCommand* cmd = CommandById(cmd_name);
|
||||
if (cmd == NULL)
|
||||
body = "-- That command doesn't exist. Try '/help' for a "
|
||||
"list.\n";
|
||||
else {
|
||||
body = "** ";
|
||||
body << cmd->GetName() << " ― " << cmd->GetDesc() << "\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
body << "** Commands: ";
|
||||
for (int i = 0; i < fCommands.CountItems(); i++) {
|
||||
ChatCommand* cmd = fCommands.ValueAt(i);
|
||||
if (i > 0) body << ", ";
|
||||
body << cmd->GetName();
|
||||
}
|
||||
body << "\n";
|
||||
}
|
||||
BMessage* help = new BMessage(IM_MESSAGE);
|
||||
help->AddInt32("im_what", IM_MESSAGE_RECEIVED);
|
||||
help->AddString("body", body);
|
||||
help->AddInt64("when", 0);
|
||||
chat->ImMessage(help);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
// Dispatch not handled messages to main window
|
||||
break;
|
||||
|
@ -911,6 +946,11 @@ Server::_InitDefaultCommands()
|
|||
ChatCommand* invite = new ChatCommand("invite", inviteMsg, true, knownUser);
|
||||
invite->SetDesc("Invite a user to the current room.");
|
||||
fCommands.AddItem("invite", invite);
|
||||
|
||||
BMessage helpMsg(CAYA_REQUEST_HELP);
|
||||
ChatCommand* help = new ChatCommand("help", helpMsg, false, List<int>());
|
||||
help->SetDesc("List all current commands, or get help for certain command.");
|
||||
fCommands.AddItem("help", help);
|
||||
}
|
||||
|
||||
|
||||
|
|
Ŝarĝante…
Reference in New Issue