degesch: further cleanups

This commit is contained in:
Přemysl Eric Janouch 2015-06-19 23:09:46 +02:00
parent 5be1cad4da
commit b55494c68f

View File

@ -6314,16 +6314,14 @@ handle_command_channel_mode (struct app_context *ctx, char *arguments,
{ {
CHANNEL_COMMAND (command_name, true) CHANNEL_COMMAND (command_name, true)
if (*arguments) if (!*arguments)
{ return false;
struct str_vector v; struct str_vector v;
str_vector_init (&v); str_vector_init (&v);
split_str_ignore_empty (arguments, ' ', &v); split_str_ignore_empty (arguments, ' ', &v);
mass_channel_mode (s, channel_name, adding, mode_char, &v); mass_channel_mode (s, channel_name, adding, mode_char, &v);
str_vector_free (&v); str_vector_free (&v);
}
else
return false;
return true; return true;
} }
@ -6391,16 +6389,14 @@ handle_command_kick (struct app_context *ctx, char *arguments)
{ {
CHANNEL_COMMAND ("kick", true) CHANNEL_COMMAND ("kick", true)
if (*arguments) if (!*arguments)
{ return false;
char *target = cut_word (&arguments); char *target = cut_word (&arguments);
if (*arguments) if (*arguments)
irc_send (s, "KICK %s %s :%s", channel_name, target, arguments); irc_send (s, "KICK %s %s :%s", channel_name, target, arguments);
else else
irc_send (s, "KICK %s %s", channel_name, target); irc_send (s, "KICK %s %s", channel_name, target);
}
else
return false;
return true; return true;
} }
@ -6409,8 +6405,9 @@ handle_command_kickban (struct app_context *ctx, char *arguments)
{ {
CHANNEL_COMMAND ("kickban", true) CHANNEL_COMMAND ("kickban", true)
if (*arguments) if (!*arguments)
{ return false;
char *target = cut_word (&arguments); char *target = cut_word (&arguments);
if (strpbrk (target, "!@*?")) if (strpbrk (target, "!@*?"))
return false; return false;
@ -6421,26 +6418,31 @@ handle_command_kickban (struct app_context *ctx, char *arguments)
irc_send (s, "KICK %s %s :%s", channel_name, target, arguments); irc_send (s, "KICK %s %s :%s", channel_name, target, arguments);
else else
irc_send (s, "KICK %s %s", channel_name, target); irc_send (s, "KICK %s %s", channel_name, target);
}
else
return false;
return true; return true;
} }
static void static void
complete_user_masks (struct str_vector *v) mass_channel_mode_mask_list (struct server *s, const char *channel_name,
bool adding, char mode_char, const char *arguments)
{ {
struct str_vector v;
str_vector_init (&v);
split_str_ignore_empty (arguments, ' ', &v);
// XXX: this may be a bit too trivial; we could map also nicknames // XXX: this may be a bit too trivial; we could map also nicknames
// to information from WHO polling or userhost-in-names // to information from WHO polling or userhost-in-names
for (size_t i = 0; i < v->len; i++) for (size_t i = 0; i < v.len; i++)
{ {
char *target = v->vector[i]; char *target = v.vector[i];
if (strpbrk (target, "!@*?")) if (strpbrk (target, "!@*?"))
continue; continue;
v->vector[i] = xstrdup_printf ("%s!*@*", target); v.vector[i] = xstrdup_printf ("%s!*@*", target);
free (target); free (target);
} }
mass_channel_mode (s, channel_name, adding, mode_char, &v);
str_vector_free (&v);
} }
static bool static bool
@ -6448,36 +6450,25 @@ handle_command_ban (struct app_context *ctx, char *arguments)
{ {
CHANNEL_COMMAND ("ban", true) CHANNEL_COMMAND ("ban", true)
if (*arguments) if (!*arguments)
{ {
struct str_vector v;
str_vector_init (&v);
split_str_ignore_empty (arguments, ' ', &v);
complete_user_masks (&v);
mass_channel_mode (s, channel_name, true, 'b', &v);
str_vector_free (&v);
}
else
irc_send (s, "MODE %s +b", channel_name); irc_send (s, "MODE %s +b", channel_name);
return true; return true;
} }
mass_channel_mode_mask_list (s, channel_name, true, 'b', arguments);
return true;
}
static bool static bool
handle_command_unban (struct app_context *ctx, char *arguments) handle_command_unban (struct app_context *ctx, char *arguments)
{ {
CHANNEL_COMMAND ("unban", true) CHANNEL_COMMAND ("unban", true)
if (*arguments) if (!*arguments)
{
struct str_vector v;
str_vector_init (&v);
split_str_ignore_empty (arguments, ' ', &v);
complete_user_masks (&v);
mass_channel_mode (s, channel_name, false, 'b', &v);
str_vector_free (&v);
}
else
return false; return false;
mass_channel_mode_mask_list (s, channel_name, false, 'b', arguments);
return true; return true;
} }