degesch: refactor command handlers
This commit is contained in:
parent
15032f9ce7
commit
cc6e9306e6
86
degesch.c
86
degesch.c
@ -2587,6 +2587,19 @@ try_decode_buffer (struct app_context *ctx, const char *word)
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static bool
|
||||
server_command_check (struct app_context *ctx, const char *action)
|
||||
{
|
||||
if (ctx->current_buffer->type == BUFFER_GLOBAL)
|
||||
buffer_send_error (ctx, ctx->current_buffer,
|
||||
"Can't do this from a global buffer (%s)", action);
|
||||
else if (ctx->irc_fd == -1)
|
||||
buffer_send_error (ctx, ctx->server_buffer, "Not connected");
|
||||
else
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_command_buffer (struct app_context *ctx, char *arguments)
|
||||
{
|
||||
@ -2657,18 +2670,8 @@ handle_command_buffer (struct app_context *ctx, char *arguments)
|
||||
static void
|
||||
handle_command_msg (struct app_context *ctx, char *arguments)
|
||||
{
|
||||
if (ctx->current_buffer->type == BUFFER_GLOBAL)
|
||||
{
|
||||
buffer_send_error (ctx, ctx->current_buffer,
|
||||
"Can't send messages from a global buffer");
|
||||
if (!server_command_check (ctx, "send messages"))
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->irc_fd == -1)
|
||||
{
|
||||
buffer_send_error (ctx, ctx->server_buffer, "Not connected");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!*arguments)
|
||||
{
|
||||
@ -2686,18 +2689,8 @@ handle_command_msg (struct app_context *ctx, char *arguments)
|
||||
static void
|
||||
handle_command_query (struct app_context *ctx, char *arguments)
|
||||
{
|
||||
if (ctx->current_buffer->type == BUFFER_GLOBAL)
|
||||
{
|
||||
buffer_send_error (ctx, ctx->current_buffer,
|
||||
"Can't send messages from a global buffer");
|
||||
if (!server_command_check (ctx, "send messages"))
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->irc_fd == -1)
|
||||
{
|
||||
buffer_send_error (ctx, ctx->server_buffer, "Not connected");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!*arguments)
|
||||
{
|
||||
@ -2707,12 +2700,8 @@ handle_command_query (struct app_context *ctx, char *arguments)
|
||||
|
||||
char *target = cut_word (&arguments);
|
||||
if (irc_is_channel (ctx, target))
|
||||
{
|
||||
buffer_send_error (ctx, ctx->server_buffer, "Cannot query a channel");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!*arguments)
|
||||
else if (!*arguments)
|
||||
buffer_send_error (ctx, ctx->server_buffer, "No text to send");
|
||||
else
|
||||
{
|
||||
@ -2724,18 +2713,8 @@ handle_command_query (struct app_context *ctx, char *arguments)
|
||||
static void
|
||||
handle_command_notice (struct app_context *ctx, char *arguments)
|
||||
{
|
||||
if (ctx->current_buffer->type == BUFFER_GLOBAL)
|
||||
{
|
||||
buffer_send_error (ctx, ctx->current_buffer,
|
||||
"Can't send messages from a global buffer");
|
||||
if (!server_command_check (ctx, "send messages"))
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->irc_fd == -1)
|
||||
{
|
||||
buffer_send_error (ctx, ctx->server_buffer, "Not connected");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!*arguments)
|
||||
{
|
||||
@ -2766,18 +2745,8 @@ handle_command_quit (struct app_context *ctx, char *arguments)
|
||||
static void
|
||||
handle_command_join (struct app_context *ctx, char *arguments)
|
||||
{
|
||||
if (ctx->current_buffer->type == BUFFER_GLOBAL)
|
||||
{
|
||||
buffer_send_error (ctx, ctx->current_buffer,
|
||||
"Can't join from a global buffer");
|
||||
if (!server_command_check (ctx, "join"))
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->irc_fd == -1)
|
||||
{
|
||||
buffer_send_error (ctx, ctx->server_buffer, "Not connected");
|
||||
return;
|
||||
}
|
||||
|
||||
if (*arguments)
|
||||
// TODO: check if the arguments are in the form of
|
||||
@ -2803,18 +2772,8 @@ handle_command_join (struct app_context *ctx, char *arguments)
|
||||
static void
|
||||
handle_command_part (struct app_context *ctx, char *arguments)
|
||||
{
|
||||
if (ctx->current_buffer->type == BUFFER_GLOBAL)
|
||||
{
|
||||
buffer_send_error (ctx, ctx->current_buffer,
|
||||
"Can't part from a global buffer");
|
||||
if (!server_command_check (ctx, "part"))
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->irc_fd == -1)
|
||||
{
|
||||
buffer_send_error (ctx, ctx->server_buffer, "Not connected");
|
||||
return;
|
||||
}
|
||||
|
||||
if (*arguments)
|
||||
// TODO: check if the arguments are in the form of "channel(,channel)*"
|
||||
@ -2838,10 +2797,9 @@ handle_command_part (struct app_context *ctx, char *arguments)
|
||||
static void
|
||||
handle_command_quote (struct app_context *ctx, char *arguments)
|
||||
{
|
||||
if (ctx->current_buffer->type == BUFFER_GLOBAL)
|
||||
buffer_send_error (ctx, ctx->current_buffer,
|
||||
"Can't do this from a global buffer");
|
||||
else
|
||||
if (!server_command_check (ctx, "quote"))
|
||||
return;
|
||||
|
||||
irc_send (ctx, arguments);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user