From 4016c387f805f7d5bf9917837d6ac6f3261bf358 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Tue, 19 May 2015 21:02:49 +0200
Subject: degesch: naively implement the unimplemented
---
degesch.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 111 insertions(+), 12 deletions(-)
diff --git a/degesch.c b/degesch.c
index 52414de..b5fc556 100644
--- a/degesch.c
+++ b/degesch.c
@@ -4794,6 +4794,8 @@ server_command_check (struct app_context *ctx, const char *action,
// as they may want to log buffer lines and use our current nickname
if (ctx->current_buffer->type == BUFFER_GLOBAL)
+ // XXX: couldn't we just pass the name of the user command here?
+ // That doesn't actually concern the function but rather its callers.
buffer_send_error (ctx, ctx->current_buffer,
"Can't do this from a global buffer (%s)", action);
else
@@ -5498,6 +5500,91 @@ handle_command_list (struct app_context *ctx, char *arguments)
return true;
}
+static bool
+handle_command_names (struct app_context *ctx, char *arguments)
+{
+ if (!server_command_check (ctx, "names", true))
+ return true;
+
+ struct server *s = ctx->current_buffer->server;
+ char *channel_name = try_get_channel (ctx, &arguments);
+ if (!channel_name)
+ irc_send (s, "NAMES");
+ else
+ irc_send (s, "NAMES %s", channel_name);
+ return true;
+}
+
+static bool
+handle_command_who (struct app_context *ctx, char *arguments)
+{
+ if (!server_command_check (ctx, "who", true))
+ return true;
+
+ struct server *s = ctx->current_buffer->server;
+ if (*arguments)
+ irc_send (s, "WHO %s", arguments);
+ else
+ irc_send (s, "WHO");
+ return true;
+}
+
+static bool
+handle_command_whois (struct app_context *ctx, char *arguments)
+{
+ if (!server_command_check (ctx, "whois", true))
+ return true;
+
+ struct server *s = ctx->current_buffer->server;
+ if (*arguments)
+ irc_send (s, "WHOIS %s", arguments);
+ else
+ irc_send (s, "WHOIS");
+ return true;
+}
+
+static bool
+handle_command_whowas (struct app_context *ctx, char *arguments)
+{
+ if (!server_command_check (ctx, "whowas", true))
+ return true;
+
+ struct server *s = ctx->current_buffer->server;
+ if (*arguments)
+ irc_send (s, "WHOWAS %s", arguments);
+ else
+ irc_send (s, "WHOWAS");
+ return true;
+}
+
+static bool
+handle_command_motd (struct app_context *ctx, char *arguments)
+{
+ if (!server_command_check (ctx, "motd", true))
+ return true;
+
+ struct server *s = ctx->current_buffer->server;
+ if (*arguments)
+ irc_send (s, "MOTD %s", arguments);
+ else
+ irc_send (s, "MOTD");
+ return true;
+}
+
+static bool
+handle_command_away (struct app_context *ctx, char *arguments)
+{
+ if (!server_command_check (ctx, "away", true))
+ return true;
+
+ struct server *s = ctx->current_buffer->server;
+ if (*arguments)
+ irc_send (s, "AWAY %s", arguments);
+ else
+ irc_send (s, "AWAY");
+ return true;
+}
+
static bool
handle_command_nick (struct app_context *ctx, char *arguments)
{
@@ -5526,8 +5613,6 @@ handle_command_quote (struct app_context *ctx, char *arguments)
static bool handle_command_help (struct app_context *, char *);
-#define NOT_IMPLEMENTED(name) { #name, "(Not implemented)", NULL, NULL },
-
static struct command_handler
{
const char *name;
@@ -5579,6 +5664,8 @@ g_command_handlers[] =
"[[,...]] []",
handle_command_cycle },
+ // TODO: /op, /voice, /hop
+
{ "mode", "Change mode",
"[] [...]",
handle_command_mode },
@@ -5607,12 +5694,28 @@ g_command_handlers[] =
{ "list", "List channels and their topic",
"[[,...]] []",
handle_command_list },
- NOT_IMPLEMENTED (names)
- NOT_IMPLEMENTED (who)
- NOT_IMPLEMENTED (whois)
-
- NOT_IMPLEMENTED (motd)
- NOT_IMPLEMENTED (away)
+ // XXX: for NAMES with no arguments, how do we tell the end of it all?
+ // Maybe we just surf through all channels and process the lists
+ // as they are.
+ { "names", "List users on channel",
+ "[[,...]]",
+ handle_command_names },
+ { "who", "List users",
+ "[]",
+ handle_command_who },
+ { "whois", "Get user information",
+ "",
+ handle_command_whois },
+ { "whowas", "Get user information",
+ "",
+ handle_command_whowas },
+
+ { "motd", "Get the Message of The Day",
+ NULL,
+ handle_command_motd },
+ { "away", "Set away status",
+ "[]",
+ handle_command_away },
{ "nick", "Change current nick",
"",
handle_command_nick },
@@ -5754,10 +5857,6 @@ process_user_command (struct app_context *ctx, char *command)
if (!handler)
buffer_send_error (ctx, ctx->global_buffer,
"%s: %s", "No such command", name);
- // TODO: remove once everything is implemented
- else if (!handler->handler)
- buffer_send_error (ctx, ctx->global_buffer,
- "%s: %s", "Not implemented", name);
else if (!handler->handler (ctx, command))
buffer_send_error (ctx, ctx->global_buffer,
"%s: /%s %s", "Usage", handler->name, handler->usage);
--
cgit v1.2.3-70-g09d2