Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * xchat-rainbow - insert color codes in messages to make rainbows
- * Copyright (C) 2012 Jakob Kramer <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
- #include <wchar.h>
- #include <string.h>
- #include <stdlib.h>
- #include "xchat-plugin.h"
- #define COLORS_NUM 6
- #define STEPSIZE 9
- xchat_plugin *ph;
- const unsigned short COLORS[] = {
- 4, 7, 8, 3, 2, 6
- };
- int rainbow(char *word[], char *word_eol[], void *userdata) {
- size_t length = mbstowcs(NULL, word_eol[2], 0);
- if (!length) {
- xchat_print(ph, "You must specify a message.\n");
- return XCHAT_EAT_ALL;
- }
- size_t stepsize = length / COLORS_NUM + 1;
- size_t end_length = length + 3 * (length / stepsize +
- (length % stepsize ? 1 : 0)) + 1;
- wchar_t *message = malloc(sizeof(wchar_t[length+1]));
- mbstowcs(message, word_eol[2], length+1);
- wchar_t *formatted = malloc(sizeof(wchar_t[end_length]));
- for (size_t i = 0, j = 0, color = COLORS[0]; i < length; i++, j++,
- color = COLORS[(i+1) / stepsize % COLORS_NUM]) {
- if ((i+1) % stepsize == 0 || i == 0) {
- formatted[j] = L'\003';
- formatted[j+1] = L'0';
- formatted[j+2] = L'0' + color;
- j += 3;
- }
- formatted[j] = message[i];
- }
- formatted[end_length-1] = '\0';
- xchat_commandf(ph, "SAY %ls", formatted);
- free(formatted);
- free(message);
- return XCHAT_EAT_ALL;
- }
- int xchat_plugin_init(xchat_plugin *plugin_handle, char **plugin_name,
- char **plugin_desc, char **plugin_version, char *arg) {
- ph = plugin_handle;
- *plugin_name = "Rainbows";
- *plugin_desc = "Make good-looking rainbows.";
- *plugin_version = "0.1.dev";
- xchat_hook_command(ph, "RAINBOW", XCHAT_PRI_NORM, &rainbow,
- "Usage: /RAINBOW MESSAGE, Gives MESSAGE a colorful "
- "look.", NULL);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment