degesch: add /op, /deop, /voice, /devoice

This commit is contained in:
Přemysl Eric Janouch 2015-06-17 21:34:04 +02:00
parent 178c1b072a
commit 9027889002

View File

@ -6253,6 +6253,63 @@ handle_command_cycle (struct app_context *ctx, char *arguments)
return true;
}
static bool
handle_command_channel_mode (struct app_context *ctx, char *arguments,
const char *command_name, bool adding, char mode_char)
{
if (!server_command_check (ctx, command_name, true))
return true;
struct server *s = ctx->current_buffer->server;
char *channel_name = try_get_channel (ctx, &arguments);
if (!channel_name)
{
buffer_send_error (ctx, ctx->current_buffer,
"%s: %s", "Can't set mode",
"no channel name given and this buffer is not a channel");
return true;
}
if (!*arguments)
return false;
struct str_vector v;
str_vector_init (&v);
split_str_ignore_empty (arguments, ' ', &v);
size_t n;
for (size_t i = 0; i < v.len; i += n)
{
struct str modes; str_init (&modes);
struct str params; str_init (&params);
n = MIN (v.len - i, s->irc_max_modes);
str_append_printf (&modes, "MODE %s %c", channel_name, "-+"[adding]);
for (size_t k = 0; k < n; k++)
{
str_append_c (&modes, mode_char);
str_append_printf (&params, " %s", v.vector[i + k]);
}
irc_send (s, "%s%s", modes.str, params.str);
str_free (&modes);
str_free (&params);
}
str_vector_free (&v);
return true;
}
#define CHANMODE_HANDLER(name, adding, mode_char) \
static bool \
handle_command_ ## name (struct app_context *ctx, char *arguments) \
{ \
return handle_command_channel_mode \
(ctx, arguments, (#name), (adding), (mode_char)); \
}
CHANMODE_HANDLER (op, true, 'o') CHANMODE_HANDLER (deop, false, 'o')
CHANMODE_HANDLER (voice, true, 'v') CHANMODE_HANDLER (devoice, false, 'v')
static bool
handle_command_mode (struct app_context *ctx, char *arguments)
{
@ -6631,7 +6688,14 @@ g_command_handlers[] =
"[<channel>[,<channel>...]] [<reason>]",
handle_command_cycle },
// TODO: /op, /voice, /hop
{ "op", "Give channel operator status",
"<nick>...", handle_command_op },
{ "deop", "Remove channel operator status",
"<nick>...", handle_command_deop },
{ "voice", "Give voice",
"<nick>...", handle_command_voice },
{ "devoice", "Remove voice",
"<nick>...", handle_command_devoice },
{ "mode", "Change mode",
"[<channel>] [<mode>...]",