aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-06-17 21:34:04 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-06-17 21:34:56 +0200
commit9027889002741af359d6f1fcc8d95409734121cc (patch)
tree0383761c56f2dad877b290ef5f976232744fd1f3
parent178c1b072ad41f7d67ee14be924c45c7d23f5fc5 (diff)
downloadxK-9027889002741af359d6f1fcc8d95409734121cc.tar.gz
xK-9027889002741af359d6f1fcc8d95409734121cc.tar.xz
xK-9027889002741af359d6f1fcc8d95409734121cc.zip
degesch: add /op, /deop, /voice, /devoice
-rw-r--r--degesch.c66
1 files changed, 65 insertions, 1 deletions
diff --git a/degesch.c b/degesch.c
index 4e47a1d..560cd37 100644
--- a/degesch.c
+++ b/degesch.c
@@ -6254,6 +6254,63 @@ handle_command_cycle (struct app_context *ctx, char *arguments)
}
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)
{
if (!server_command_check (ctx, "mode", true))
@@ -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>...]",