/*************************************************************************** ** bs_seen.c ********************* Author: GeniusDex ** Version: 0.5.0 ** *************************************************************************** * * * Service: BotServ * * Module: Improved !seen * * Version: 0.5.0 * * License: GPL [GNU Public License] * * Author: GeniusDex * * E-mail: geniusdex@twistification.net * * Description: Make the !seen command more general * * * * This module improves the BotServ !seen command by adding lookups for * * all registered users allover the network. It's not limited to people * * on your channel access list anymore, not the tracking, nor the usage. * * * *************************************************************************** * Languages: * * English GeniusDex * * Spanish DrStein * * Portugese MightyRaven * * French hexa * * Turkish guru * * Italian Hal9000 * * German Certus * * Catalan * * Greek * * Dutch GeniusDex * * Russian * * All open languages default to English * * TODO: Flood protection stuff * *************************************************************************** ** CHANGES ***************************************** VERSION HISTORY ** *************************************************************************** *** 0.5.0 ************************************************** 23/08/2004 *** * -Fixed compile errors for anope 1.7.6 * *** 0.4.1 ************************************************** 20/07/2004 *** * -Added French language * *** 0.4.0 ************************************************** 20/07/2004 *** * -Should now work on win32 * *** 0.3.1 ************************************************** 17/05/2004 *** * -Added Italian language * * -Fixed a bug causing incorrect searches due to some memory stuff blabla * *** 0.3.0 ************************************************** 17/04/2004 *** * -Made DeMiNi0 happy.... * * -Added Turkish language * *** 0.2.0 ************************************************** 11/04/2004 *** * -BS_UPDATE_LAST_VISIT_ON_PRIVMSG did effecitvely nothing, so removed * * -Implemented multilingual support. Some languages are still missing and * * thus default to English. Currently supported: English, Dutch, * * Spanish, German, Portugese. * * -Fixed a segfault when ommiting target * * -Fixed a bug with botserv handling his channel strings for kickers * *** 0.1.0 ************************************************** 08/04/2004 *** * -First testing release * *************************************************************************** *************************************************************************** ** CONFIGURATION ************************************* CONFIGURATION ** *************************************************************************** * Scaringly empty... * *************************************************************************** ** END OF CONFIGURATION *************************** END OF CONFIGURATION ** ****************** Don't change anything below this line ****************** **************************************************************************/ #include "module.h" #define AUTHOR "GeniusDex" #define VERSION "0.5.0" /* Win32 compatiblity stuff (it's a hack, but it works! thx heinz) */ #ifdef _WIN32 # define strtok_r(x,y,z) strtok(x,y) #endif /* Start of multi-lingual stuff... */ #define SEEN_BOT 0 #define SEEN_YOU 1 #define SEEN_ON_CHANNEL 2 #define SEEN_ON_CHANNEL_AS 3 #define SEEN_ONLINE 4 #define SEEN_ONLINE_AS 5 #define SEEN_WAS_ONLINE 6 #define SEEN_WAS_ONLINE_AS 7 #define SEEN_NEVER 8 #define SEEN_UNKNOWN 9 #define SEEN_FAILED 10 /* ENGLISH */ #define BS_SEEN_EN {"You found me, %s!", /* BOT */ \ "You might see yourself in the mirror, %s...", /* YOU */ \ "%s is on the channel right now!", /* ON CHANNEL */ \ "%s is on the channel right now (as %s) !", /* ON CHANNEL AS */ \ "%s is online right now!", /* ONLINE */ \ "%s is online right now (as %s) !", /* ONLINE AS */ \ "%s was last seen online %s ago.", /* WAS ONLINE */ \ "%s was last seen online %s ago (as %s) .", /* WAS ONLINE AS */ \ "I've never seen %s.", /* NEVER */ \ "I don't know who %s is.", /* UNKNOWN */ \ "Seen query failed."} /* FAILED */ /* /ENGLISH */ /* SPANISH */ #define BS_SEEN_ES {"%s me has encontrado!", /* BOT */ \ "Te podrias mirar en un espejo, %s...", /* YOU */ \ "%s esta en el canal ahora mismo!", /* ON CHANNEL */ \ "%s esta ahora en el canal (como %s) !", /* ON CHANNEL AS */ \ "%s esta ahora en linea!", /* ONLINE */ \ "%s esta ahora en linea (como %s) !", /* ONLINE AS */ \ "%s fue visto en linea %s atras.", /* WAS ONLINE */ \ "%s fue visto en linea %s atras (como %s) .", /* WAS ONLINE AS */ \ "Nunca he visto a %s.", /* NEVER */ \ "No se quien es %s.", /* UNKNOWN */ \ "La busqueda ha fallado."} /* FAILED */ /* /SPANISH */ /* PORTUGESE */ #define BS_SEEN_PT {"Voce me achou, %s!", /* BOT */ \ "Talves voce se veja no espelho, %s...", /* YOU */ \ "%s esta no canal agora!", /* ON CHANNEL */ \ "%s esta no canal agora (as %s) !", /* ON CHANNEL AS */ \ "%s é online agora!", /* ONLINE */ \ "%s é online agora (as %s) !", /* ONLINE AS */ \ "%s visto online para a ultima veis %s atrais.", /* WAS ONLINE */ \ "%s visto online para a ultima veis %s atrais (as %s) .", /* WAS ONLINE AS */ \ "Eu nunca viu %s.", /* NEVER */ \ "Eu não sei quen %s é.", /* UNKNOWN */ \ "Seen pergunta falhou."} /* FAILED */ /* /PORTUGESE */ /* FRENCH */ #define BS_SEEN_FR {"Tu m'as trouv!, %s!", /* BOT */ \ "Tu pourrais te regarder toi-mme dans le miroir, %s.", /* YOU */ \ "%s est dans le chatroom en ce moment.", /* ON CHANNEL */ \ "%s est dans le chatroom comme %s en ce moment.", /* ON CHANNEL AS */ \ "%s est en ligne", /* ONLINE */ \ "%s est en ligne (comme %s)", /* ONLINE AS */ \ "%s tait en ligne il y a %s.", /* WAS ONLINE */ \ "%s tait en ligne comme %s il y a %s.", /* WAS ONLINE AS */ \ "Je n'ai jamais vu %s.", /* NEVER */ \ "Je ne connais pas %s.", /* UNKNOWN */ \ "Demande choue."} /* FAILED */ /* /FRENCH \*/ /* TURKISH */ #define BS_SEEN_TR {"%s beni buldun!", /* BOT */ \ "%s kendini aynada da görebilirsin...", /* YOU */ \ "%s şu an zaten kanalda!", /* ON CHANNEL */ \ "%s şu an zaten kanalda (%s rumuzu ile) !", /* ON CHANNEL AS */ \ "%s şu an çevrimiçi!", /* ONLINE */ \ "%s şu an çevrimiçi (%s rumuzu ile) !", /* ONLINE AS */ \ "%s en son %s önce çevrimiçi görüldü.", /* WAS ONLINE */ \ "%s en son %s önce çevrimiçi görüldü (%s rumuzu ile) .", /* WAS ONLINE AS */ \ "%s rumuzlu kişiyi hiç görmedim.", /* NEVER */ \ "%s rumuzlu kişinin kim olduğunu bilmiyorum.", /* UNKNOWN */ \ "En son görülme sorgusu başarılamadı."} /* FAILED */ /* /TURKISH */ /* ITALIAN */ #define BS_SEEN_IT {"Mi hai trovato, %s!", /* BOT */ \ "Potresti vederti nello specchio, %s...", /* YOU */ \ "%s si trova nel canale ora!", /* ONCHANNEL */ \ "%s si trova nel canale ora (come %s) !", /* ONCHANNEL AS */ \ "%s è online ora!", /* ONLINE */ \ "%s è online ora (come %s) !", /* ONLINE AS */ \ "%s è stato visto online %s fa.", /* WASONLINE */ \ "%s è stato visto online %s fa (come %s) .", /* WASONLINE AS */ \ "Non ho mai visto %s.", /* NEVER */ \ "Non so chi sia %s.", /* UNKNOWN */ \ "La ricerca non ha avuto esito."} /* FAILED */ /* /ITALIAN */ /* GERMAN */ #define BS_SEEN_DE {"Du hast mich gefunden, %s!", /* BOT */ \ "Du könntest dich selbst im Spiegel sehen, %s...", /* YOU */ \ "%s ist gerade im Channel!", /* ON CHANNEL */ \ "%s ist gerade im Channel (als %s) !", /* ON CHANNEL AS */ \ "%s ist gerade online!", /* ONLINE */ \ "%s ist gerade online (als %s) !", /* ONLINE AS */ \ "%s wurde zuletzt vor %s online gesehen.", /* WAS ONLINE */ \ "%s wurde zuletzt vor %s online gesehen (als %s) .", /* WAS ONLINE AS */ \ "Ich habe %s nie gesehen.", /* NEVER */ \ "Ich kenne %s nicht.", /* UNKNOWN */ \ "Seen Anfrage fehlgeschlagen."} /* FAILED */ /* /GERMAN */ /* DUTCH */ #define BS_SEEN_NL {"Je hebt me gevonden, %s!", /* BOT */ \ "Een blik in de spiegel zou geen kwaad kunnen, %s...", /* YOU */ \ "%s is nu op het kanaal!", /* ON CHANNEL */ \ "%s is nu op het kanaal (als %s) !", /* ON CHANNEL AS */ \ "%s is nu online!", /* ONLINE */ \ "%s is nu online (als %s) !", /* ONLINE AS */ \ "%s is %s geleden voor het laatst online gezien.", /* WAS ONLINE */ \ "%s is %s geleden voor het laatst online gezien (als %s) .", /* WAS ONLINE AS */ \ "Ik heb %s nooit gezien.", /* NEVER */ \ "Ik weet niet wie %s is.", /* UNKNOWN */ \ "Zoekopdracht gefaald."} /* FAILED */ /* /DUTCH */ #define BS_NUM_LANGS 14 #define BS_NUM_STRINGS 11 char *langtable[BS_NUM_LANGS][BS_NUM_STRINGS] = { BS_SEEN_EN, /* LANG_EN_US * 0 * English (US) */ BS_SEEN_EN, /* LANG_JA_JIS * 1 * Japanese (JIS) */ BS_SEEN_EN, /* LANG_JA_EUC * 2 * Japanese (EUC) */ BS_SEEN_EN, /* LANG_JA_SJIS * 3 * Japanese (SJIS) */ BS_SEEN_ES, /* LANG_ES * 4 * Spanish */ BS_SEEN_PT, /* LANG_PT * 5 * Portugese */ BS_SEEN_FR, /* LANG_FR * 6 * French */ BS_SEEN_TR, /* LANG_TR * 7 * Turkish */ BS_SEEN_IT, /* LANG_IT * 8 * Italian */ BS_SEEN_DE, /* LANG_DE * 9 * German */ BS_SEEN_EN, /* LANG_CAT * 10 * Catalan */ BS_SEEN_EN, /* LANG_GR * 11 * Greek */ BS_SEEN_NL, /* LANG_NL * 12 * Dutch */ BS_SEEN_EN};/* LANG_RU * 13 * Russian */ /* /LANGSTUFF */ int msg_privmsg(char *source, int ac, char **av); void do_seen(User *u, ChannelInfo *ci, char *target); char *lang_get_string(uint16 lang, uint16 string); int AnopeInit(int argc, char **argv) { int i; Message *m; m = createMessage("privmsg", msg_privmsg); if ((i = moduleAddMessage(m, MOD_HEAD))) { alog("[bs_seen] Unable to hook to 'privmsg' (%d)", i); return MOD_STOP; } moduleAddAuthor(AUTHOR); moduleAddVersion(VERSION); alog("[bs_seen] Up and running..."); return MOD_CONT; } /* PRIVMSG handler for !seen on channels */ int msg_privmsg(char *source, int ac, char **av) { char *s; char *ctx; char *t; ChannelInfo *ci; User *u; if ((ac != 2) || !(u = finduser(source))) return MOD_CONT; ctx = NULL; if ((*av[0] == '#') && s_BotServ && (ci = cs_findchan(av[0])) && !(ci->flags & CI_VERBOTEN) && ci->c && ci->bi) { t = sstrdup(av[1]); s = strtok_r(t, " ", &ctx); if (s && !stricmp(s, "!seen")) { s = strtok_r(NULL, " ", &ctx); /* DeMiNi0 wanted me to code, i refused to. Therefore i completed this today and not yesterday */ if (s) do_seen(u, ci, s); free(t); return MOD_STOP; } free(t); } return MOD_CONT; } void do_seen(User *u, ChannelInfo *ci, char *target) { char buf[BUFSIZE]; char durastr[192]; char *nick; int i; time_t lastseen; uint16 lang; User *u2; NickAlias *na; NickAlias *na2; NickAlias *na3; NickCore *nc; buf[0] = 0; if (u && u->na && u->na->nc) lang = u->na->nc->language; else lang = NSDefLanguage; if (!stricmp(ci->bi->nick, target)) { snprintf(buf, sizeof(buf), lang_get_string(lang, SEEN_BOT), u->nick); } else if (!(na = findnick(target)) || (na->status & NS_VERBOTEN)) { snprintf(buf, sizeof(buf), lang_get_string(lang, SEEN_UNKNOWN), target); } else if ((u2 = nc_on_chan(ci->c, na->nc))) { if (u == u2 || (u->na && (u->na->nc == na->nc))) snprintf(buf, sizeof(buf), lang_get_string(lang, SEEN_YOU), u->nick); else if (!stricmp(u2->nick, target)) snprintf(buf, sizeof(buf), lang_get_string(lang, SEEN_ON_CHANNEL), u2->nick); else snprintf(buf, sizeof(buf), lang_get_string(lang, SEEN_ON_CHANNEL_AS), target, u2->nick); } else if (na->u) { snprintf(buf, sizeof(buf), lang_get_string(lang, SEEN_ONLINE), na->u->nick); } else { nc = na->nc; for (i = 0; i < nc->aliases.count; i++) { if ((u2 = ((NickAlias *)nc->aliases.list[i])->u)) snprintf(buf, sizeof(buf), lang_get_string(lang, SEEN_ONLINE_AS), target, u2->nick); } if (!buf[0]) { na3 = NULL; nick = NULL; lastseen = 0; for (i = 0; i < nc->aliases.count; i++) { na2 = (NickAlias *)nc->aliases.list[i]; if (na2->last_seen > lastseen) { na3 = na2; nick = na2->nick; lastseen = na2->last_seen; } } if (nick) { duration(u->na, durastr, sizeof(durastr), time(NULL) - lastseen); if (!stricmp(nick, target)) snprintf(buf, sizeof(buf), lang_get_string(lang, SEEN_WAS_ONLINE), target, durastr); else snprintf(buf, sizeof(buf), lang_get_string(lang, SEEN_WAS_ONLINE_AS), target, durastr, nick); } } } if (!buf[0]) snprintf(buf, sizeof(buf), lang_get_string(lang, SEEN_NEVER), target); send_cmd(ci->bi->nick, "PRIVMSG %s :%s", ci->name, buf); } char *lang_get_string(uint16 lang, uint16 string) { if (lang >= BS_NUM_LANGS) lang = 0; if (string >= BS_NUM_STRINGS) string = SEEN_FAILED; return langtable[lang][string]; } /* EOF */