rendered paste body#include "xchat-plugin.h"
static xchat_plugin *ph;
static int enable;
static xchat_hook *privmsg_cb_hook;
static xchat_hook *notice_cb_hook;
static void set_context(void)
{
xchat_set_context(ph,xchat_find_context(ph,xchat_get_info(ph,"server"),"-garbage-"));
}
static int privmsg_cb(char **word,char **word_eol,void *userdata)
{
if((word[3]!=NULL)&&(word[3][0]!='#')&&((word[3][0])!=0))
{
set_context();
xchat_printf(ph,"private message from %s: %s\n",word[1],word_eol[4]);
return XCHAT_EAT_XCHAT;
}
return XCHAT_EAT_NONE;
}
static int notice_cb(char **word,char **word_eol,void *userdata)
{
if((word[3]!=NULL)&&(word[3][0]!='#')&&(word[3][0]!=0))
{
set_context();
xchat_printf(ph,"notice from %s: %s\n",word[1],word_eol[4]);
return XCHAT_EAT_XCHAT;
}
return XCHAT_EAT_NONE;
}
static int garbagetoggle_cb(char **word,char **word_eol,void *userdata)
{
if(!enable)
{
enable=1;
xchat_command(ph,"query -garbage-");
privmsg_cb_hook=xchat_hook_server(ph,"PRIVMSG",XCHAT_PRI_NORM,privmsg_cb,NULL);
notice_cb_hook=xchat_hook_server(ph,"NOTICE",XCHAT_PRI_NORM,notice_cb,NULL);
xchat_print(ph,"\0034garbage filter enabled");
}
else
{
enable=0;
xchat_unhook(ph,privmsg_cb_hook);
xchat_unhook(ph,notice_cb_hook);
xchat_print(ph,"\0034garbage filter disabled");
}
return XCHAT_EAT_ALL;
}
void xchat_plugin_get_info(char **name, char **desc, char **version, void **reserved)
{
*name = "Garbage";
*desc = "Sends private and notice garbage to server tab";
*version = "0.1";
if (reserved)
*reserved = NULL;
}
int xchat_plugin_init(xchat_plugin *plugin_handle,
char **plugin_name,
char **plugin_desc,
char **plugin_version,
char **arg)
{
ph=plugin_handle;
xchat_plugin_get_info(
plugin_name,
plugin_desc,
plugin_version,
NULL);
enable=0;
xchat_hook_command(
ph,
"GARBAGE",
XCHAT_PRI_NORM,
garbagetoggle_cb,
"Usage: GARBAGE, turns OFF/ON garbage filter",
0);
xchat_print(ph,"garbage filter plugin loaded successfully\n");
return 1;
}