Advertisement
Guest User

hoxily/xchat colorize text plugin

a guest
May 1st, 2012
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include "xchat-plugin.h"
  5.  
  6. #define PNAME "ColorfulText"
  7. #define PDESC "Colorize your sending text"
  8. #define PVERSION "0.1.2"
  9.  
  10. static char *color_names[]={"DEFAULT","BLACK","DARKBLUE","DARKGREEN","PINK","RED","DARKPURPLE","BROWN","YELLOW","LIGHTGREEN","DARKCYAN","LIGHTCYAN","LIGHTBLUE","LIGHTPURPLE","DARKGRAY","LIGHTGRAY"};
  11.  
  12. static xchat_plugin *ph;   /* plugin handle */
  13. static int color_index = 6;
  14. static int enable = 1;
  15. static char buffer[2048];
  16.  
  17. static int your_message_callback(char *word[], char *userdata)
  18. {
  19.     if(enable)
  20.     {
  21.         sprintf(buffer,"\003%02d%s",color_index,word[2]);
  22.        
  23.         strcpy(word[2],buffer);
  24.         //hope word[2] is long enough to
  25.         //add 3 bytes!
  26.     }
  27.     return XCHAT_EAT_NONE;  /* don't eat this event, xchat needs to see it! */
  28. }
  29.  
  30. static int colorfultext_cb(char *word[], char *word_eol[], void *userdata)
  31. {
  32.         int i;
  33.         if(word[2][0]=='\0')
  34.         {
  35.             xchat_print(ph,"Usage: colorfultext <ColorName | toggle >, change text color to specified ColorName, or toggle on/off of colorfultext. All available color are: \nDEFAULT BLACK DARKBLUE DARKGREEN PINK RED DARKPURPLE BROWN YELLOW LIGHTGREEN DARKCYAN LIGHTCYAN LIGHTBLUE LIGHTPURPLE DARKGRAY LIGHTGRAY\n");
  36.             xchat_printf(ph, "Current color for text is %s\n",color_names[color_index]);
  37.             xchat_printf(ph, "Currently ColorfulText is %s\n",(enable)?"enabled":"disabled");
  38.         }
  39.         else
  40.         {
  41.             for(i=0;word[2][i]!='\0';i++)
  42.             {
  43.                 word[2][i]=toupper(word[2][i]);
  44.             }
  45.             for(i=0; i< 16; i++)
  46.             {
  47.                 if(strcmp(color_names[i],word[2])== 0)
  48.                 {
  49.                     break;
  50.                 }
  51.             }
  52.             if(i<16)
  53.             {
  54.                 color_index=i;
  55.                 xchat_printf(ph, "You have changed Colorful Text's color to %s\n",color_names[color_index]);
  56.             }
  57.             else if(strcmp(word[2], "TOGGLE") == 0)
  58.             {
  59.                 if(enable)
  60.                 {
  61.                     enable = 0;
  62.                     xchat_print(ph, "Colorful Text is disabled.\n");
  63.                 }
  64.                 else
  65.                 {
  66.                     enable = 1;
  67.                     xchat_print(ph, "Colorful Text is enabled.\n");
  68.                 }
  69.             }
  70.             else
  71.             {
  72.                 xchat_print(ph, "Unsupported color name.\n");
  73.                 xchat_printf(ph, "Current color for text is %s\n",color_names[color_index]);
  74.             }
  75.         }
  76.         return XCHAT_EAT_ALL;   /* eat this command so xchat and other plugins can't process it */
  77. }
  78.  
  79. void xchat_plugin_get_info(char **name, char **desc, char **version, void **reserved)
  80. {
  81.        *name = PNAME;
  82.           *desc = PDESC;
  83.              *version = PVERSION;
  84. }
  85.  
  86. int xchat_plugin_init(xchat_plugin *plugin_handle,
  87.                               char **plugin_name,
  88.                                             char **plugin_desc,
  89.                                                       char **plugin_version,
  90.                                                                 char *arg)
  91. {
  92.        /* we need to save this for use with any xchat_* functions */
  93.        ph = plugin_handle;
  94.  
  95.           /* tell xchat our info */
  96.           *plugin_name = PNAME;
  97.              *plugin_desc = PDESC;
  98.             *plugin_version = PVERSION;
  99.  
  100.                xchat_hook_command(ph, "colorfultext", XCHAT_PRI_NORM, colorfultext_cb, "Usage: colorfultext <ColorName>, change text color to specified ColorName. All available color are: \nDEFAULT BLACK DARKBLUE DARKGREEN PINK RED DARKPURPLE BROWN YELLOW LIGHTGREEN DARKCYAN LIGHTCYAN LIGHTBLUE LIGHTPURPLE DARKGRAY LIGHTGRAY\n", 0);
  101.                   xchat_hook_print(ph, "Your Message", XCHAT_PRI_NORM, your_message_callback, 0);
  102.  
  103.                  xchat_print(ph, "Colorful Text Plugin loaded successfully!\n");
  104.  
  105.                     return 1;       /* return 1 for success */
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement