From 9027889002741af359d6f1fcc8d95409734121cc Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Wed, 17 Jun 2015 21:34:04 +0200
Subject: degesch: add /op, /deop, /voice, /devoice
---
degesch.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 65 insertions(+), 1 deletion(-)
diff --git a/degesch.c b/degesch.c
index 4e47a1d..560cd37 100644
--- a/degesch.c
+++ b/degesch.c
@@ -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 (¶ms);
+
+ 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 (¶ms, " %s", v.vector[i + k]);
+ }
+
+ irc_send (s, "%s%s", modes.str, params.str);
+
+ str_free (&modes);
+ str_free (¶ms);
+ }
+ 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[] =
"[[,...]] []",
handle_command_cycle },
- // TODO: /op, /voice, /hop
+ { "op", "Give channel operator status",
+ "...", handle_command_op },
+ { "deop", "Remove channel operator status",
+ "...", handle_command_deop },
+ { "voice", "Give voice",
+ "...", handle_command_voice },
+ { "devoice", "Remove voice",
+ "...", handle_command_devoice },
{ "mode", "Change mode",
"[] [...]",
--
cgit v1.2.3-70-g09d2