degesch: further cleanups

This commit is contained in:
Přemysl Eric Janouch 2015-06-19 23:09:46 +02:00
parent 5be1cad4da
commit b55494c68f
1 changed files with 46 additions and 55 deletions

101
degesch.c
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)
{
struct str_vector v;
str_vector_init (&v);
split_str_ignore_empty (arguments, ' ', &v);
mass_channel_mode (s, channel_name, adding, mode_char, &v);
str_vector_free (&v);
}
else
return false; return false;
struct str_vector v;
str_vector_init (&v);
split_str_ignore_empty (arguments, ' ', &v);
mass_channel_mode (s, channel_name, adding, mode_char, &v);
str_vector_free (&v);
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)
{
char *target = cut_word (&arguments);
if (*arguments)
irc_send (s, "KICK %s %s :%s", channel_name, target, arguments);
else
irc_send (s, "KICK %s %s", channel_name, target);
}
else
return false; return false;
char *target = cut_word (&arguments);
if (*arguments)
irc_send (s, "KICK %s %s :%s", channel_name, target, arguments);
else
irc_send (s, "KICK %s %s", channel_name, target);
return true; return true;
} }
@ -6409,38 +6405,44 @@ handle_command_kickban (struct app_context *ctx, char *arguments)
{ {
CHANNEL_COMMAND ("kickban", true) CHANNEL_COMMAND ("kickban", true)
if (*arguments) if (!*arguments)
{
char *target = cut_word (&arguments);
if (strpbrk (target, "!@*?"))
return false;
// XXX: how about other masks?
irc_send (s, "MODE %s +b %s!*@*", channel_name, target);
if (*arguments)
irc_send (s, "KICK %s %s :%s", channel_name, target, arguments);
else
irc_send (s, "KICK %s %s", channel_name, target);
}
else
return false; return false;
char *target = cut_word (&arguments);
if (strpbrk (target, "!@*?"))
return false;
// XXX: how about other masks?
irc_send (s, "MODE %s +b %s!*@*", channel_name, target);
if (*arguments)
irc_send (s, "KICK %s %s :%s", channel_name, target, arguments);
else
irc_send (s, "KICK %s %s", channel_name, target);
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,17 +6450,13 @@ 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;
}
mass_channel_mode_mask_list (s, channel_name, true, 'b', arguments);
return true; return true;
} }
@ -6467,17 +6465,10 @@ 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;
} }