From a30abf4ec4942eefc869875016187a294a65eaae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Pettersson?= Date: Sat, 4 Oct 2014 23:51:17 +0200 Subject: [PATCH] Added /nospam command. --- src/twc-commands.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/twc-commands.c b/src/twc-commands.c index cfda050..977635e 100644 --- a/src/twc-commands.c +++ b/src/twc-commands.c @@ -575,6 +575,54 @@ twc_cmd_name(void *data, struct t_gui_buffer *buffer, return WEECHAT_RC_OK; } +/** + * Command /nospam callback. + */ +int +twc_cmd_nospam(void *data, struct t_gui_buffer *buffer, + int argc, char **argv, char **argv_eol) +{ + if (argc > 2) + return WEECHAT_RC_ERROR; + + struct t_twc_profile *profile = twc_profile_search_buffer(buffer); + TWC_CHECK_PROFILE(profile); + TWC_CHECK_PROFILE_LOADED(profile); + + uint32_t new_nospam; + if (argc == 2) + { + char *endptr; + unsigned long value = strtoul(argv[1], &endptr, 16); + if (endptr == argv[1] || value > UINT32_MAX) + { + weechat_printf(profile->buffer, + "%snospam must be a hexadecimal value between " + "0x00000000 and 0xFFFFFFFF", + weechat_prefix("error")); + + return WEECHAT_RC_OK; + } + + // reverse the value bytes so it's displayed as entered in the Tox ID + new_nospam = twc_uint32_reverse_bytes(value); + } + else + { + new_nospam = random(); + } + + uint32_t old_nospam = tox_get_nospam(profile->tox); + tox_set_nospam(profile->tox, new_nospam); + + weechat_printf(profile->buffer, + "%snew nospam has been set; this changes your Tox ID! To " + "revert, run \"/nospam %x\"", + weechat_prefix("network"), twc_uint32_reverse_bytes(old_nospam)); + + return WEECHAT_RC_OK; +} + /** * Command /status callback. */ @@ -846,6 +894,15 @@ twc_commands_init() "name: your new name", NULL, twc_cmd_name, NULL); + weechat_hook_command("nospam", + "change nospam value", + "[]", + "hex value: new nospam value; when omitted, a random " + "new value is used\n\n" + "Warning: changing your nospam value will alter your " + "Tox ID!", + NULL, twc_cmd_nospam, NULL); + weechat_hook_command("status", "change your Tox status", "online|busy|away",