diff options
| author | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-19 21:34:11 +0200 | 
|---|---|---|
| committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-19 21:34:11 +0200 | 
| commit | c946c46f1fd3c4b3c24136a111839577629823a2 (patch) | |
| tree | 1ffeb9b227ecf58f74db2ad5eb8a8aed0238130a | |
| parent | 392c2e7a5f93b26faf8a734a5df99aca8311caeb (diff) | |
| download | xK-c946c46f1fd3c4b3c24136a111839577629823a2.tar.gz xK-c946c46f1fd3c4b3c24136a111839577629823a2.tar.xz xK-c946c46f1fd3c4b3c24136a111839577629823a2.zip  | |
degesch: implement /join and /part
| -rw-r--r-- | degesch.c | 79 | 
1 files changed, 77 insertions, 2 deletions
@@ -1988,6 +1988,77 @@ 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"); +		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  handle_command_quote (struct app_context *ctx, char *arguments)  {  	irc_send (ctx, arguments); @@ -2014,9 +2085,13 @@ g_command_handlers[] =  	{ "notice",  NULL, "", "" },  	{ "ctcp",    NULL, "", "" },  	{ "me",      NULL, "", "" }, +#endif -	{ "join",    NULL, "", "" }, -	{ "part",    NULL, "", "" }, +	{ "join",    handle_command_join,   "Join channels", +	  "[channel...]" }, +	{ "part",    handle_command_part,   "Leave channels", +	  "[channel...]" }, +#if 0  	{ "cycle",   NULL, "", "" },  	{ "mode",    NULL, "", "" },  | 
