diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-26 22:53:38 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-26 22:53:38 +0200 |
commit | 54262e2d206b21be2dffb11c2bdd2914b03675f2 (patch) | |
tree | 645d091e44c59c0aad19db14ee5b925716206d8a /degesch.c | |
parent | a66bf15e672f51315147a334238a4df2b00d5318 (diff) | |
download | xK-54262e2d206b21be2dffb11c2bdd2914b03675f2.tar.gz xK-54262e2d206b21be2dffb11c2bdd2914b03675f2.tar.xz xK-54262e2d206b21be2dffb11c2bdd2914b03675f2.zip |
degesch: implement /ctcp, stubplement /me
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 50 |
1 files changed, 46 insertions, 4 deletions
@@ -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...]" }, |