degesch: implement /join and /part
This commit is contained in:
parent
392c2e7a5f
commit
c946c46f1f
79
degesch.c
79
degesch.c
|
@ -1987,6 +1987,77 @@ handle_command_quit (struct app_context *ctx, char *arguments)
|
||||||
initiate_quit (ctx);
|
initiate_quit (ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
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)* key(,key)*"
|
||||||
|
irc_send (ctx, "JOIN %s", arguments);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ctx->current_buffer->type != BUFFER_CHANNEL)
|
||||||
|
buffer_send_error (ctx, ctx->current_buffer,
|
||||||
|
"%s: %s", "Can't join",
|
||||||
|
"no argument given and this buffer is not a channel");
|
||||||
|
// TODO: have a better way of checking if we're on the channel
|
||||||
|
else if (ctx->current_buffer->channel->users)
|
||||||
|
buffer_send_error (ctx, ctx->current_buffer,
|
||||||
|
"%s: %s", "Can't join",
|
||||||
|
"you already are on the channel");
|
||||||
|
else
|
||||||
|
// TODO: send the key if known
|
||||||
|
irc_send (ctx, "JOIN %s", ctx->current_buffer->channel->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
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)*"
|
||||||
|
irc_send (ctx, "PART %s", arguments);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ctx->current_buffer->type != BUFFER_CHANNEL)
|
||||||
|
buffer_send_error (ctx, ctx->current_buffer,
|
||||||
|
"%s: %s", "Can't part",
|
||||||
|
"no argument given and this buffer is not a channel");
|
||||||
|
// TODO: have a better way of checking if we're on the channel
|
||||||
|
else if (!ctx->current_buffer->channel->users)
|
||||||
|
buffer_send_error (ctx, ctx->current_buffer,
|
||||||
|
"%s: %s", "Can't join", "you're not on the channel");
|
||||||
|
else
|
||||||
|
irc_send (ctx, "PART %s", ctx->current_buffer->channel->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_command_quote (struct app_context *ctx, char *arguments)
|
handle_command_quote (struct app_context *ctx, char *arguments)
|
||||||
{
|
{
|
||||||
|
@ -2014,9 +2085,13 @@ g_command_handlers[] =
|
||||||
{ "notice", NULL, "", "" },
|
{ "notice", NULL, "", "" },
|
||||||
{ "ctcp", NULL, "", "" },
|
{ "ctcp", NULL, "", "" },
|
||||||
{ "me", NULL, "", "" },
|
{ "me", NULL, "", "" },
|
||||||
|
#endif
|
||||||
|
|
||||||
{ "join", NULL, "", "" },
|
{ "join", handle_command_join, "Join channels",
|
||||||
{ "part", NULL, "", "" },
|
"[channel...]" },
|
||||||
|
{ "part", handle_command_part, "Leave channels",
|
||||||
|
"[channel...]" },
|
||||||
|
#if 0
|
||||||
{ "cycle", NULL, "", "" },
|
{ "cycle", NULL, "", "" },
|
||||||
|
|
||||||
{ "mode", NULL, "", "" },
|
{ "mode", NULL, "", "" },
|
||||||
|
|
Loading…
Reference in New Issue