Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.14 KB | None | 0 0
  1. /***************************************************************************
  2. ** bs_seen.c ********************* Author: GeniusDex ** Version: 0.7.1 **
  3. ***************************************************************************
  4. * *
  5. * Service: BotServ *
  6. * Module: Improved !seen *
  7. * Version: 0.7.1 *
  8. * License: GPL [GNU Public License] *
  9. * Author: GeniusDex *
  10. * E-mail: geniusdex@anope.org *
  11. * Description: Make the !seen command more general *
  12. * *
  13. * This module improves the BotServ !seen command by adding lookups for *
  14. * all registered users allover the network. It's not limited to people *
  15. * on your channel access list anymore; not the tracking, nor the usage. *
  16. * *
  17. ***************************************************************************
  18. * Languages: *
  19. * English GeniusDex <geniusdex@anope.org> *
  20. * Spanish DrStein <gacevedo@anope.org> *
  21. * Portugese MightyRaven *
  22. * French hexa <hexa@insiderz.org> *
  23. * Turkish guru *
  24. * Italian Hal9000 <hal9000@musichat.net> *
  25. * German Certus <certus@anope.org> *
  26. * Catalan *
  27. * Greek *
  28. * Dutch GeniusDex <geniusdex@anope.org> *
  29. * Russian *
  30. * All open languages default to English *
  31. ***************************************************************************
  32. ** CHANGES ***************************************** VERSION HISTORY **
  33. ***************************************************************************
  34. *** 0.7.1 ************************************************** 06/01/2007 ***
  35. * -Fixed a crash when no target was passed to !seen 8
  36. *** 0.7.0 ************************************************** 01/10/2006 ***
  37. * -General code review and cleanup *
  38. * -Minor fixes to make it work right with Anope 1.7.15 *
  39. *** 0.6.0 ************************************************** 01/09/2005 ***
  40. * -Converted language system to use Anope's built-in system *
  41. * -Converted fantasy parser to use events instead of a PRIVMSG handler *
  42. *** 0.5.0 ************************************************** 23/08/2004 ***
  43. * -Fixed compile errors for anope 1.7.6 *
  44. *** 0.4.1 ************************************************** 20/07/2004 ***
  45. * -Added French language *
  46. *** 0.4.0 ************************************************** 20/07/2004 ***
  47. * -Should now work on win32 *
  48. *** 0.3.1 ************************************************** 17/05/2004 ***
  49. * -Added Italian language *
  50. * -Fixed a bug causing incorrect searches due to some memory stuff blabla *
  51. *** 0.3.0 ************************************************** 17/04/2004 ***
  52. * -Made DeMiNi0 happy.... *
  53. * -Added Turkish language *
  54. *** 0.2.0 ************************************************** 11/04/2004 ***
  55. * -BS_UPDATE_LAST_VISIT_ON_PRIVMSG did effecitvely nothing, so removed *
  56. * -Implemented multilingual support. Some languages are still missing and *
  57. * thus default to English. Currently supported: English, Dutch, *
  58. * Spanish, German, Portugese. *
  59. * -Fixed a segfault when ommiting target *
  60. * -Fixed a bug with botserv handling his channel strings for kickers *
  61. *** 0.1.0 ************************************************** 08/04/2004 ***
  62. * -First testing release *
  63. ***************************************************************************
  64. ***************************************************************************
  65. ** CONFIGURATION ************************************* CONFIGURATION **
  66. ***************************************************************************
  67. * Scaringly empty... *
  68. ***************************************************************************
  69. ** END OF CONFIGURATION *************************** END OF CONFIGURATION **
  70. ****************** Don't change anything below this line ******************
  71. **************************************************************************/
  72.  
  73. #include "module.h"
  74.  
  75. #define AUTHOR "GeniusDex"
  76. #define VERSION "0.7.1"
  77.  
  78. #define LNG_NUM_STRINGS 11
  79.  
  80. #define LANG_SEEN_BOT 0
  81. #define LANG_SEEN_YOU 1
  82. #define LANG_SEEN_ON_CHANNEL 2
  83. #define LANG_SEEN_ON_CHANNEL_AS 3
  84. #define LANG_SEEN_ONLINE 4
  85. #define LANG_SEEN_ONLINE_AS 5
  86. #define LANG_SEEN_WAS_ONLINE 6
  87. #define LANG_SEEN_WAS_ONLINE_AS 7
  88. #define LANG_SEEN_NEVER 8
  89. #define LANG_SEEN_UNKNOWN 9
  90. #define LANG_SEEN_FAILED 10
  91.  
  92. int do_fantasy(int ac, char **av);
  93. void do_seen(User * u, ChannelInfo * ci, char *target);
  94. void my_add_languages(void);
  95.  
  96. /* Initialize the module; make all the needed info known to the Anope core */
  97. int AnopeInit(int argc, char **argv)
  98. {
  99. int i;
  100. EvtHook *hook;
  101.  
  102. my_add_languages();
  103.  
  104. /* Hook to the fantasy event (for !* channel messages) */
  105. hook = createEventHook(EVENT_BOT_FANTASY, do_fantasy);
  106. if ((i = moduleAddEventHook(hook))) {
  107. alog("[bs_seen] Unable to hook to fantasy events (%d)", i);
  108. return MOD_STOP;
  109. }
  110.  
  111. /* Let Anope know who we are */
  112. moduleAddAuthor(AUTHOR);
  113. moduleAddVersion(VERSION);
  114.  
  115. /* All done nicely, tell Anope we're fine to go */
  116. return MOD_CONT;
  117. }
  118.  
  119. /* Do any unloading steps if required, but none are required. This
  120. * function is only here to fix compiling on win32.
  121. */
  122. void AnopeFini(void)
  123. {
  124. /* Empty! I told you! */
  125. }
  126.  
  127. /* Fantasy commands handler */
  128. int do_fantasy(int ac, char **av)
  129. {
  130. User *u;
  131. ChannelInfo *ci;
  132. char *target;
  133.  
  134. /* See if we have enough arguments (command, user, channel, target) */
  135. if (ac < 4)
  136. return MOD_CONT;
  137.  
  138. /* Only handle !seen commands */
  139. if (stricmp(av[0], "seen") == 0) {
  140. u = finduser(av[1]);
  141. ci = cs_findchan(av[2]);
  142.  
  143. if (!u || !ci)
  144. return MOD_CONT;
  145.  
  146. /* Get the target we want to inspect */
  147. target = myStrGetToken(av[3], ' ', 0);
  148.  
  149. if (!target)
  150. return MOD_CONT;
  151.  
  152. /* Run the actual seen code */
  153. do_seen(u, ci, target);
  154. free(target);
  155.  
  156. /* We return MOD_STOP here to avoid double answers on !seen
  157. * requests; this includes the !seen from the Anope core
  158. */
  159. return MOD_STOP;
  160. }
  161.  
  162. return MOD_CONT;
  163. }
  164.  
  165. /* Actual seen handler. This function handles the seen requests by the given
  166. * user u on the channel ci for the given target. It uses the buf string to
  167. * save the current response in.
  168. */
  169. void do_seen(User * u, ChannelInfo * ci, char *target)
  170. {
  171. char buf[BUFSIZE];
  172. char durastr[192];
  173. char *nick;
  174. int i;
  175. time_t lastseen;
  176.  
  177. User *u2;
  178. NickAlias *na;
  179. NickAlias *na2;
  180. NickAlias *na3;
  181. NickCore *nc;
  182.  
  183. if (debug)
  184. alog("debug: [bs_seen] Doing a seen for '%s' on '%s' (Requested by '%s')", ci->name, u->nick, target);
  185.  
  186. buf[0] = 0;
  187.  
  188. if (!stricmp(ci->bi->nick, target)) {
  189. /* The user is looking for the channel bot */
  190. snprintf(buf, sizeof(buf), moduleGetLangString(u, LANG_SEEN_BOT), u->nick);
  191. } else if (!(na = findnick(target)) || (na->status & NS_VERBOTEN)) {
  192. /* The user is looking for a forbidden or non-existing nick */
  193. snprintf(buf, sizeof(buf), moduleGetLangString(u, LANG_SEEN_UNKNOWN), target);
  194. } else if ((u2 = nc_on_chan(ci->c, na->nc))) {
  195. /* The user is looking for someone currently on the channel. This
  196. * is either theirselves or someone on the channel. In the last case,
  197. * they could also be in disguise using another nick.
  198. */
  199. if (u == u2 || (u->na && (u->na->nc == na->nc)))
  200. snprintf(buf, sizeof(buf), moduleGetLangString(u, LANG_SEEN_YOU), u->nick);
  201. else if (!stricmp(u2->nick, target))
  202. snprintf(buf, sizeof(buf), moduleGetLangString(u, LANG_SEEN_ON_CHANNEL), u2->nick);
  203. else
  204. snprintf(buf, sizeof(buf), moduleGetLangString(u, LANG_SEEN_ON_CHANNEL_AS), target, u2->nick);
  205. } else if (na->u) {
  206. /* The user is looking for someone online, but not currently on the channel */
  207. snprintf(buf, sizeof(buf), moduleGetLangString(u, LANG_SEEN_ONLINE), na->u->nick);
  208. } else {
  209. /* We have no result so far. We'll first check if the user is online as
  210. * someone else.
  211. */
  212. nc = na->nc;
  213. for (i = 0; i < nc->aliases.count; i++) {
  214. if ((u2 = ((NickAlias *) nc->aliases.list[i])->u))
  215. snprintf(buf, sizeof(buf), moduleGetLangString(u, LANG_SEEN_ONLINE_AS), target, u2->nick);
  216. }
  217. if (!buf[0]) {
  218. /* There is still no result. We'll compare all the NickAliases of
  219. * the person we're looking for and search the highest last seen
  220. * time. This one will be the nick we'll report back to the user
  221. */
  222. na3 = NULL;
  223. nick = NULL;
  224. lastseen = 0;
  225. for (i = 0; i < nc->aliases.count; i++) {
  226. na2 = (NickAlias *) nc->aliases.list[i];
  227. if (na2->last_seen > lastseen) {
  228. na3 = na2;
  229. nick = na2->nick;
  230. lastseen = na2->last_seen;
  231. }
  232. }
  233. if (nick) {
  234. duration(u->na, durastr, sizeof(durastr), time(NULL) - lastseen);
  235. if (!stricmp(nick, target))
  236. snprintf(buf, sizeof(buf), moduleGetLangString(u, LANG_SEEN_WAS_ONLINE), target, durastr);
  237. else
  238. snprintf(buf, sizeof(buf), moduleGetLangString(u, LANG_SEEN_WAS_ONLINE_AS), target, durastr, nick);
  239. }
  240. }
  241. }
  242.  
  243. /* Check if we have a result. If not, claim we never saw the target */
  244. if (!buf[0])
  245. snprintf(buf, sizeof(buf), moduleGetLangString(u, LANG_SEEN_NEVER), target);
  246.  
  247. /* Send the result back to the channel */
  248. anope_cmd_privmsg(ci->bi->nick, ci->name, buf);
  249. }
  250.  
  251. /* Define and add the languages to the system */
  252. void my_add_languages(void)
  253. {
  254. char *langtable_en_us[] = {
  255. /* LANG_SEEN_BOT */
  256. "You found me, %s!",
  257. /* LANG_SEEN_YOU */
  258. "You might see yourself in the mirror, %s...",
  259. /* LANG_SEEN_ON_CHANNEL */
  260. "%s is on the channel right now!",
  261. /* LANG_SEEN_ON_CHANNEL_AS */
  262. "%s is on the channel right now (as %s) !",
  263. /* LANG_SEEN_ONLINE */
  264. "%s is online right now!",
  265. /* LANG_SEEN_ONLINE_AS */
  266. "%s is online right now (as %s) !",
  267. /* LANG_SEEN_WAS_ONLINE */
  268. "%s was last seen online %s ago.",
  269. /* LANG_SEEN_WAS_ONLINE_AS */
  270. "%s was last seen online %s ago (as %s) .",
  271. /* LANG_SEEN_NEVER */
  272. "I've never seen %s.",
  273. /* LANG_SEEN_UNKNOWN */
  274. "I don't know who %s is.",
  275. /* LANG_SEEN_FAILED */
  276. "Seen query failed."
  277. };
  278.  
  279. char *langtable_es[] = {
  280. /* LANG_SEEN_BOT */
  281. "%s me has encontrado!",
  282. /* LANG_SEEN_YOU */
  283. "Te podrias mirar en un espejo, %s...",
  284. /* LANG_SEEN_ON_CHANNEL */
  285. "%s esta en el canal ahora mismo!",
  286. /* LANG_SEEN_ON_CHANNEL_AS */
  287. "%s esta ahora en el canal (como %s) !",
  288. /* LANG_SEEN_ONLINE */
  289. "%s esta ahora en linea!",
  290. /* LANG_SEEN_ONLINE_AS */
  291. "%s esta ahora en linea (como %s) !",
  292. /* LANG_SEEN_WAS_ONLINE */
  293. "%s fue visto en linea %s atras.",
  294. /* LANG_SEEN_WAS_ONLINE_AS */
  295. "%s fue visto en linea %s atras (como %s) .",
  296. /* LANG_SEEN_NEVER */
  297. "Nunca he visto a %s.",
  298. /* LANG_SEEN_UNKNOWN */
  299. "No se quien es %s.",
  300. /* LANG_SEEN_FAILED */
  301. "La busqueda ha fallado."
  302. };
  303.  
  304. char *langtable_pt[] = {
  305. /* LANG_SEEN_BOT */
  306. "Voce me achou, %s!",
  307. /* LANG_SEEN_YOU */
  308. "Talves voce se veja no espelho, %s...",
  309. /* LANG_SEEN_ON_CHANNEL */
  310. "%s esta no canal agora!",
  311. /* LANG_SEEN_ON_CHANNEL_AS */
  312. "%s esta no canal agora (as %s) !",
  313. /* LANG_SEEN_ONLINE */
  314. "%s é online agora!",
  315. /* LANG_SEEN_ONLINE_AS */
  316. "%s é online agora (as %s) !",
  317. /* LANG_SEEN_WAS_ONLINE */
  318. "%s visto online para a ultima veis %s atrais.",
  319. /* LANG_SEEN_WAS_ONLINE_AS */
  320. "%s visto online para a ultima veis %s atrais (as %s) .",
  321. /* LANG_SEEN_NEVER */
  322. "Eu nunca viu %s.",
  323. /* LANG_SEEN_UNKNOWN */
  324. "Eu não sei quen %s é.",
  325. /* LANG_SEEN_FAILED */
  326. "Seen pergunta falhou."
  327. };
  328.  
  329. char *langtable_fr[] = {
  330. /* LANG_SEEN_BOT */
  331. "Tu m'as trouv!, %s!",
  332. /* LANG_SEEN_YOU */
  333. "Tu pourrais te regarder toi-mme dans le miroir, %s.",
  334. /* LANG_SEEN_ON_CHANNEL */
  335. "%s est dans le chatroom en ce moment.",
  336. /* LANG_SEEN_ON_CHANNEL_AS */
  337. "%s est dans le chatroom comme %s en ce moment.",
  338. /* LANG_SEEN_ONLINE */
  339. "%s est en ligne",
  340. /* LANG_SEEN_ONLINE_AS */
  341. "%s est en ligne (comme %s)",
  342. /* LANG_SEEN_WAS_ONLINE */
  343. "%s tait en ligne il y a %s.",
  344. /* LANG_SEEN_WAS_ONLINE_AS */
  345. "%s tait en ligne comme %s il y a %s.",
  346. /* LANG_SEEN_NEVER */
  347. "Je n'ai jamais vu %s.",
  348. /* LANG_SEEN_UNKNOWN */
  349. "Je ne connais pas %s.",
  350. /* LANG_SEEN_FAILED */
  351. "Demande choue."
  352. };
  353.  
  354. char *langtable_tr[] = {
  355. /* LANG_SEEN_BOT */
  356. "%s beni buldun!",
  357. /* LANG_SEEN_YOU */
  358. "%s kendini aynada da görebilirsin...",
  359. /* LANG_SEEN_ON_CHANNEL */
  360. "%s þu an zaten kanalda!",
  361. /* LANG_SEEN_ON_CHANNEL_AS */
  362. "%s þu an zaten kanalda (%s rumuzu ile) !",
  363. /* LANG_SEEN_ONLINE */
  364. "%s þu an çevrimiçi!",
  365. /* LANG_SEEN_ONLINE_AS */
  366. "%s þu an çevrimiçi (%s rumuzu ile) !",
  367. /* LANG_SEEN_WAS_ONLINE */
  368. "%s en son %s önce çevrimiçi görüldü.",
  369. /* LANG_SEEN_WAS_ONLINE_AS */
  370. "%s en son %s önce çevrimiçi görüldü (%s rumuzu ile) .",
  371. /* LANG_SEEN_NEVER */
  372. "%s rumuzlu kiþiyi hiç görmedim.",
  373. /* LANG_SEEN_UNKNOWN */
  374. "%s rumuzlu kiþinin kim olduðunu bilmiyorum.",
  375. /* LANG_SEEN_FAILED */
  376. "En son görülme sorgusu baþarýlamadý."
  377. };
  378.  
  379. char *langtable_it[] = {
  380. /* LANG_SEEN_BOT */
  381. "Mi hai trovato, %s!",
  382. /* LANG_SEEN_YOU */
  383. "Potresti vederti nello specchio, %s...",
  384. /* LANG_SEEN_ON_CHANNEL */
  385. "%s si trova nel canale ora!",
  386. /* LANG_SEEN_ON_CHANNEL_AS */
  387. "%s si trova nel canale ora (come %s) !",
  388. /* LANG_SEEN_ONLINE */
  389. "%s è online ora!",
  390. /* LANG_SEEN_ONLINE_AS */
  391. "%s è online ora (come %s) !",
  392. /* LANG_SEEN_WAS_ONLINE */
  393. "%s è stato visto online %s fa.",
  394. /* LANG_SEEN_WAS_ONLINE_AS */
  395. "%s è stato visto online %s fa (come %s) .",
  396. /* LANG_SEEN_NEVER */
  397. "Non ho mai visto %s.",
  398. /* LANG_SEEN_UNKNOWN */
  399. "Non so chi sia %s.",
  400. /* LANG_SEEN_FAILED */
  401. "La ricerca non ha avuto esito."
  402. };
  403.  
  404. char *langtable_de[] = {
  405. /* LANG_SEEN_BOT */
  406. "Du hast mich gefunden, %s!",
  407. /* LANG_SEEN_YOU */
  408. "Du könntest dich selbst im Spiegel sehen, %s...",
  409. /* LANG_SEEN_ON_CHANNEL */
  410. "%s ist gerade im Channel!",
  411. /* LANG_SEEN_ON_CHANNEL_AS */
  412. "%s ist gerade im Channel (als %s) !",
  413. /* LANG_SEEN_ONLINE */
  414. "%s ist gerade online!",
  415. /* LANG_SEEN_ONLINE_AS */
  416. "%s ist gerade online (als %s) !",
  417. /* LANG_SEEN_WAS_ONLINE */
  418. "%s wurde zuletzt vor %s online gesehen.",
  419. /* LANG_SEEN_WAS_ONLINE_AS */
  420. "%s wurde zuletzt vor %s online gesehen (als %s) .",
  421. /* LANG_SEEN_NEVER */
  422. "Ich habe %s nie gesehen.",
  423. /* LANG_SEEN_UNKNOWN */
  424. "Ich kenne %s nicht.",
  425. /* LANG_SEEN_FAILED */
  426. "Seen Anfrage fehlgeschlagen."
  427. };
  428.  
  429. char *langtable_nl[] = {
  430. /* LANG_SEEN_BOT */
  431. "Je hebt me gevonden, %s!",
  432. /* LANG_SEEN_YOU */
  433. "Een blik in de spiegel zou geen kwaad kunnen, %s...",
  434. /* LANG_SEEN_ON_CHANNEL */
  435. "%s is nu op het kanaal!",
  436. /* LANG_SEEN_ON_CHANNEL_AS */
  437. "%s is nu op het kanaal (als %s) !",
  438. /* LANG_SEEN_ONLINE */
  439. "%s is nu online!",
  440. /* LANG_SEEN_ONLINE_AS */
  441. "%s is nu online (als %s) !",
  442. /* LANG_SEEN_WAS_ONLINE */
  443. "%s is %s geleden voor het laatst online gezien.",
  444. /* LANG_SEEN_WAS_ONLINE_AS */
  445. "%s is %s geleden voor het laatst online gezien (als %s) .",
  446. /* LANG_SEEN_NEVER */
  447. "Ik heb %s nooit gezien.",
  448. /* LANG_SEEN_UNKNOWN */
  449. "Ik weet niet wie %s is.",
  450. /* LANG_SEEN_FAILED */
  451. "Zoekopdracht mislukt."
  452. };
  453.  
  454. moduleInsertLanguage(LANG_EN_US, LNG_NUM_STRINGS, langtable_en_us);
  455. moduleInsertLanguage(LANG_ES, LNG_NUM_STRINGS, langtable_es);
  456. moduleInsertLanguage(LANG_PT, LNG_NUM_STRINGS, langtable_pt);
  457. moduleInsertLanguage(LANG_FR, LNG_NUM_STRINGS, langtable_fr);
  458. moduleInsertLanguage(LANG_TR, LNG_NUM_STRINGS, langtable_tr);
  459. moduleInsertLanguage(LANG_IT, LNG_NUM_STRINGS, langtable_it);
  460. moduleInsertLanguage(LANG_DE, LNG_NUM_STRINGS, langtable_de);
  461. moduleInsertLanguage(LANG_NL, LNG_NUM_STRINGS, langtable_nl);
  462. }
  463.  
  464. /* EOF */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement