Add '/help' command

This commit is contained in:
Jaidyn Ann 2021-06-15 00:45:51 -05:00
parent 46d6d0a0b0
commit 7d72b5152c
4 changed files with 52 additions and 5 deletions

View File

@ -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

View File

@ -61,8 +61,9 @@ BString
CommandArgs(BString line)
{
BString remove("/");
remove << CommandName(line) << " ";
return line.RemoveFirst(remove);
remove << CommandName(line) << "";
line.RemoveFirst(remove);
return line.Trim();
}

View File

@ -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;

View File

@ -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);
}