Anope IRC Services

Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: Assistance Request: spam_module.c  (Read 3420 times)

0 Members and 1 Guest are viewing this topic.

mmx

  • Guest
Assistance Request: spam_module.c
« on: February 26, 2007, 12:15:20 AM »

Hello folks, awhile back I created a watered-down module for our SAs who weren't familiar with the /spamfilter command.  Provided it can be confusing...  While this module does work I can't get it to apply custom reasons. IE: !spam regex REASON

Currently it only supports the syntax: !spam regex
The reason is set by default via fprintf.

Below is the complete spam_module.c file.  It's probably pretty jerky but it indeed *does* work on our network.  If someone could take a look at it and tell me how I can fix it to allow custom reasons I'd greatly appreciate it.

Ex: !spam some-web-link Potential virus link. Please do not spam.


Code: [Select]

/* spam_module written for use on ParanoiaNet.com
   Author retains all original rights to work.
   You may modify/redistribute this code under
   the GPL agreement provided you maintain
   Author's credit.
*/

#include "module.h"
#include <stdio.h>

#define AUTHOR "David Chafin"
#define VERSION "v1.0a"

/*Function Declaration */
int spamadd(int argc, char **argv);


int AnopeInit(int argc, char **argv)
{
    EvtHook *hook;
    int status;

    hook = createEventHook(EVENT_BOT_FANTASY, spamadd);
    status = moduleAddEventHook(hook);

    if (status != MOD_ERR_OK) {
        alog("Error binding to event EVENT_BOT_FANTASY [%d]", status);
        return MOD_STOP;
    }

        hook = createEventHook(EVENT_BOT_FANTASY_NO_ACCESS, spamadd);
        status = moduleAddEventHook(hook);
    if (status != MOD_ERR_OK) {
        alog("Error binding to event EVENT_BOT_FANTASY [%d]", status);
        return MOD_STOP;
    }

    moduleAddAuthor(AUTHOR);       /* Add the author information  */
    moduleAddVersion(VERSION);     /* Add the version information */
    moduleSetType(THIRD);          /* Flag as Third party module  */

    /* Loading Success! */
    alog("spamadd successfully loaded");
    return MOD_CONT;
}

/*************************************************************************/

void AnopeFini(void)
{
 /* A message about unload */
 alog("spamadd unloaded");
}

/*************************************************************************/

int spamadd(int argc, char **argv)
{
    User *u;
    ChannelInfo *ci;
    FILE * pFile;
    /* Set below to actual allow.conf file to be used */


    pFile = fopen ("/path/to/included/spam.conf","a");


    /* Check that we got at least 3 parameters */
    if (argc < 3) {
      /* return now */
      return MOD_CONT;
    }

    /* Get the user struct */
    u = finduser(argv[1]);
    /* Get the channel info struct */
    ci = cs_findchan(argv[2]);

    /* Make sure they aren't null */
    if (!u || !ci) {
       return MOD_CONT;
    }

    if (!stricmp("spam", argv[0])) {
     if (is_services_admin(u)) {
       if ( argc == 4 ) {
           if ( pFile != NULL )
               {

                fprintf(pFile, "#Added by %s\n", u->nick);
                fprintf(pFile, "spamfilter {\n");
                fprintf(pFile, "      regex     \"%s\";\n", argv[3]);
                fprintf(pFile, "      target    { private; channel; private-notice; channel-notice; part; quit
                fprintf(pFile, "      action    block;\n");
                fprintf(pFile, "      reason    \"Spam is bad\";\n");
                fprintf(pFile, "};\n");
                fclose (pFile);
                notice(whosends(ci), ci->name, "!spam used by %s: adding: %s",
                       u->nick, argv[3]);
                return MOD_CONT;
               }
            else {
               alog("Could not open file! Aborting!");
               notice(whosends(ci), u->nick, "No such file exists!");
               return MOD_STOP;
            }

           }
       else {
           notice(whosends(ci), u->nick, "You must supply an expression.");
           return MOD_STOP;
           }
    }
     else {
           notice(whosends(ci), u->nick, "Permission denied.");
           return MOD_STOP;
      }
     }


    /* All Done */
    return MOD_CONT;
}



Logged
Pages: [1]   Go Up