summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--degesch.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/degesch.c b/degesch.c
index 95350ae..628c9d3 100644
--- a/degesch.c
+++ b/degesch.c
@@ -112,6 +112,12 @@ isdigit_ascii (int c)
return c >= '0' && c <= '9';
}
+static int
+toupper_ascii (int c)
+{
+ return c >= 'A' && c <= 'Z' ? c : c - ('a' - 'A');
+}
+
/// Shorthand to set an error and return failure from the function
#define FAIL(...) \
BLOCK_START \
@@ -3313,6 +3319,42 @@ handle_command_notice (struct app_context *ctx, char *arguments)
}
static bool
+handle_command_ctcp (struct app_context *ctx, char *arguments)
+{
+ if (!server_command_check (ctx, "send messages"))
+ return true;
+ if (!*arguments)
+ return false;
+
+ char *target = cut_word (&arguments);
+ if (!*arguments)
+ return false;
+
+ char *tag = cut_word (&arguments);
+ for (char *p = tag; *p; p++)
+ *p = toupper_ascii (*p);
+
+ if (*arguments)
+ irc_send (ctx, "PRIVMSG %s :\x01%s %s\x01", target, tag, arguments);
+ else
+ irc_send (ctx, "PRIVMSG %s :\x01%s\x01", target, tag);
+
+ buffer_send_status (ctx, ctx->server_buffer,
+ "CTCP query to %s: %s", target, tag);
+ return true;
+}
+
+static bool
+handle_command_me (struct app_context *ctx, char *arguments)
+{
+ if (!server_command_check (ctx, "send messages"))
+ return true;
+
+ // TODO
+ return true;
+}
+
+static bool
handle_command_quit (struct app_context *ctx, char *arguments)
{
if (ctx->irc_fd != -1)
@@ -3412,10 +3454,10 @@ g_command_handlers[] =
"<nick> <message>" },
{ "notice", handle_command_notice, "Send notice to a nick or channel",
"<target> <message>" },
-#if 0
- { "ctcp", NULL, "", "" },
- { "me", NULL, "", "" },
-#endif
+ { "ctcp", handle_command_ctcp, "Send a CTCP query",
+ "<target> <tag>" },
+ { "me", handle_command_me, "Send a CTCP action",
+ "<message>" },
{ "join", handle_command_join, "Join channels",
"[channel...]" },