From 54262e2d206b21be2dffb11c2bdd2914b03675f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Sun, 26 Apr 2015 22:53:38 +0200 Subject: [PATCH] degesch: implement /ctcp, stubplement /me --- degesch.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file 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 \ @@ -3312,6 +3318,42 @@ handle_command_notice (struct app_context *ctx, char *arguments) return true; } +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) { @@ -3412,10 +3454,10 @@ g_command_handlers[] = " " }, { "notice", handle_command_notice, "Send notice to a nick or channel", " " }, -#if 0 - { "ctcp", NULL, "", "" }, - { "me", NULL, "", "" }, -#endif + { "ctcp", handle_command_ctcp, "Send a CTCP query", + " " }, + { "me", handle_command_me, "Send a CTCP action", + "" }, { "join", handle_command_join, "Join channels", "[channel...]" },