Advertisement
NovaYoshi

Old version of NovaBot

Jun 8th, 2011
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.12 KB | None | 0 0
  1. // Extremely old version of NovaBot from Mon 03 Aug 2009 04:01:54 PM EDT
  2. // ( the oldest .so was Sat 18 Jul 2009 04:02:26 PM EDT )
  3. #include "xchat-plugin.h"
  4.  
  5. #include <string.h>
  6.  
  7. #include <stdio.h>
  8. #include <time.h>
  9.  
  10. #define PNAME "BridgeBot"
  11.  
  12. #define PDESC "Bridges some servers together"
  13.  
  14. #define PVERSION "0.2"
  15.  
  16. static char ServerA[64]="?";
  17.  
  18. static char ServerB[64]="?";
  19. char lastquit[64]="?";
  20. char lastjoin[64]="?";
  21. int Joins=0;
  22. int Messages=0;
  23. int Emotes=0;
  24. int StartTime;
  25. int Mute=0;
  26. static xchat_context *FromContext;
  27.  
  28. static xchat_context *SendContext;
  29.  
  30. static xchat_plugin *ph;   /* plugin handle */
  31.  
  32. static char ChannelName[64];
  33.  
  34. static char ServerName[64];
  35.  
  36. static char Temp[256];
  37.  
  38. static char UseServer[64];
  39.  
  40. static int FoundName=0;
  41.  
  42. static int PrepOkay;
  43.  
  44. static void Prep()
  45.  
  46. {
  47.  
  48.     PrepOkay=0;
  49.  
  50.     FromContext=xchat_get_context(ph);
  51.  
  52.     FoundName=0;
  53.  
  54.     if(xchat_get_info(ph,"channel")==NULL)
  55.  
  56.     {
  57.  
  58.         xchat_print(ph, "Odd. Channel returns as null \n");
  59.  
  60.         return;
  61.  
  62.     }
  63.  
  64.     if(xchat_get_info(ph,"server")==NULL)
  65.  
  66.     {
  67.  
  68.         xchat_print(ph, "Odd. Server returns as null \n");
  69.  
  70.         return;
  71.  
  72.     }
  73.  
  74.     strcpy(ServerName,xchat_get_info(ph,"server"));
  75.  
  76.     strcpy(ChannelName,xchat_get_info(ph,"channel"));
  77.     if(strcasecmp(ChannelName,"#NovaForest"))
  78.         return;
  79.  
  80.     if(!strcasecmp(ServerA,"?"))
  81.  
  82.     {
  83.  
  84.         xchat_print(ph, "Filling in Server A \n");
  85.         strcpy(ServerA,ServerName);
  86.         xchat_command(ph, "SAY Okay, now post a message in the other #NovaForest");
  87.  
  88.         return;
  89.  
  90.     }
  91.  
  92.     if(!strcasecmp(ServerB,"?")&&strcasecmp(ServerA,ServerName))
  93.  
  94.     {
  95.  
  96.         xchat_print(ph, "Filling in Server B \n");
  97.         strcpy(ServerB,ServerName);
  98.  
  99.         xchat_command(ph, "SAY Finished getting server names! Bridgebot should work now :3");
  100.  
  101.         return;
  102.  
  103.     }
  104.  
  105.     if(!strcasecmp(ServerA,"?")||!strcasecmp(ServerB,"?"))  //If both server names aren't filled in, go no furher!
  106.  
  107.     {
  108.  
  109.         xchat_print(ph, "Server names aren't filled in for both servers yet \n");
  110.  
  111.         return;
  112.  
  113.     }
  114.  
  115.     if(!strcasecmp(ServerA,ServerName))
  116.  
  117.     {
  118.  
  119.         FoundName=1;
  120.  
  121.         strcpy(UseServer,ServerB);
  122.  
  123.     }
  124.  
  125.     if(!strcasecmp(ServerB,ServerName))
  126.  
  127.     {
  128.  
  129.         FoundName=1;
  130.  
  131.         strcpy(UseServer,ServerA);
  132.  
  133.     }
  134.  
  135.     if(FoundName==0)
  136.  
  137.     {
  138.  
  139.         xchat_printf(ph, "Huh? Couldn't find the name! \n");
  140.  
  141.         return;
  142.  
  143.     }
  144.  
  145. ////////////////////////////////////////////////////////////////////
  146.  
  147.     if((SendContext=xchat_find_context(ph,UseServer,"#novaforest"))==NULL)
  148.  
  149.     {
  150.  
  151.         xchat_print(ph, "Failed to find the sending context! \n");
  152.  
  153.         strcpy(ServerA,"?");
  154.  
  155.         strcpy(ServerB,"?");
  156.         return;
  157.  
  158.     }
  159.  
  160.     if(xchat_set_context(ph,SendContext)==0)
  161.  
  162.     {
  163.  
  164.         xchat_print(ph, "Failed to set context! \n");
  165.  
  166.         return;
  167.  
  168.     }
  169.  
  170.     if(Mute==1)
  171.         return;
  172.     PrepOkay=1;
  173.  
  174. }
  175.  
  176. static int disconnect_cb(char *word[], void *userdata)  //After getting disconnected the
  177.  
  178. {
  179.  
  180.     strcpy(ServerA,"?");
  181.  
  182.     strcpy(ServerB,"?");
  183.  
  184.     return XCHAT_EAT_NONE;  /* don't eat this event, xchat needs to see it! */
  185.  
  186. }
  187.  
  188. static int join_cb(char *word[], void *userdata)
  189.  
  190. {
  191.     Joins++;
  192.  
  193.     Prep();
  194.  
  195.     sprintf(Temp,"SAY %s has joined", word[1]);
  196.  
  197.     if(PrepOkay==1 && strcasecmp(word[1],"Mare") && strcasecmp(word[1],"Dmare"))
  198.  
  199.         xchat_command(ph, Temp);
  200.     strcpy(lastjoin,word[1]);
  201.  
  202.     return XCHAT_EAT_NONE;  /* don't eat this event, xchat needs to see it! */
  203.  
  204. }
  205.  
  206. static int part_cb(char *word[], void *userdata)
  207.  
  208. {
  209.  
  210.     Prep();
  211.  
  212.     sprintf(Temp,"SAY %s has left", word[1]);
  213.  
  214.     if(PrepOkay==1)
  215.  
  216.         xchat_command(ph, Temp);
  217.  
  218.     return XCHAT_EAT_NONE;  /* don't eat this event, xchat needs to see it! */
  219.  
  220. }
  221.  
  222. static int partr_cb(char *word[], void *userdata)
  223.  
  224. {
  225.  
  226.     Prep();
  227.  
  228.     sprintf(Temp,"SAY %s has left (%s)", word[1],word[4]);
  229.  
  230.     if(PrepOkay==1)
  231.  
  232.         xchat_command(ph, Temp);
  233.  
  234.     return XCHAT_EAT_NONE;  /* don't eat this event, xchat needs to see it! */
  235.  
  236. }
  237.  
  238. static int emote_cb(char *word[], void *userdata)
  239.  
  240. {
  241.     Emotes++;
  242.  
  243.     Prep();
  244.  
  245.     sprintf(Temp,"SAY %s %s", word[1],word[2]);
  246.  
  247.     if(PrepOkay==1)
  248.  
  249.         xchat_command(ph, Temp);
  250.  
  251.     return XCHAT_EAT_NONE;  /* don't eat this event, xchat needs to see it! */
  252.  
  253. }
  254.  
  255. static int message_cb(char *word[], void *userdata)
  256.  
  257. {
  258.     if(!strcasecmp(word[2],"nb.stat"))
  259.     {
  260.         sprintf(Temp,"SAY Joins: %i, Messages: %i, Emotes: %i, %s", Joins,Messages,Emotes,(Mute==0 ?"Bridgebot ON":"Bridgebot OFF"));
  261.         xchat_command(ph, Temp);
  262.         XCHAT_EAT_NONE;
  263.     }
  264.     if(!strcasecmp(word[2],"nb.mute"))
  265.     {
  266.         if(!strcasecmp(word[1],"NovaYoshi"))
  267.         {
  268.             sprintf(Temp,"SAY Bridgebot has been %s", (Mute==0 ?"Muted":"Unmuted"));
  269.             xchat_command(ph, Temp);
  270.             Mute=1-Mute;       
  271.         }
  272.         else
  273.         {
  274.             sprintf(Temp,"SAY I'm gonna ignore you because you're not my master >:[");
  275.             xchat_command(ph, Temp);
  276.         }
  277.         XCHAT_EAT_NONE;
  278.     }
  279.     Messages++;
  280.     Prep();
  281.     sprintf(Temp,"SAY %s: %s", word[1],word[2]);
  282.     if(PrepOkay==1)
  283.  
  284.         xchat_command(ph, Temp);
  285.  
  286.     return XCHAT_EAT_NONE;  /* don't eat this event, xchat needs to see it! */
  287.  
  288. }
  289.  
  290. static int nickchange_cb(char *word[], void *userdata)
  291.  
  292. {
  293.  
  294.     Prep();
  295.  
  296.     sprintf(Temp,"SAY %s is now known as %s", word[1],word[2]);
  297.  
  298.     if(PrepOkay==1)
  299.  
  300.         xchat_command(ph, Temp);
  301.  
  302.     return XCHAT_EAT_NONE;  /* don't eat this event, xchat needs to see it! */
  303.  
  304. }
  305.  
  306. static int kick_cb(char *word[], void *userdata)
  307.  
  308. {
  309.  
  310.     Prep();
  311.  
  312.     sprintf(Temp,"SAY %s has been kicked by %s (%s)", word[2],word[1],word[4]);
  313.  
  314.     if(PrepOkay==1)
  315.  
  316.         xchat_command(ph, Temp);
  317.  
  318.     return XCHAT_EAT_NONE;  /* don't eat this event, xchat needs to see it! */
  319.  
  320. }
  321.  
  322. static int quit_cb(char *word[], void *userdata)
  323.  
  324. {
  325.  
  326.     Prep();
  327.  
  328.     sprintf(Temp,"SAY %s has quit (%s)", word[1],word[2]);
  329.  
  330.     if(PrepOkay==1 && strcasecmp(word[1],"mare") && strcasecmp(word[1],"dmare"))
  331.         xchat_command(ph, Temp);
  332.     strcpy(lastquit,word[1]);
  333.  
  334.     return XCHAT_EAT_NONE;  /* don't eat this event, xchat needs to see it! */
  335.  
  336. }
  337.  
  338. void xchat_plugin_get_info(char **name, char **desc, char **version, void **reserved)
  339.  
  340. {
  341.  
  342.     *name = PNAME;
  343.  
  344.     *desc = PDESC;
  345.  
  346.     *version = PVERSION;
  347.  
  348. }
  349.  
  350. int xchat_plugin_init(xchat_plugin *plugin_handle,
  351.  
  352.                       char **plugin_name,
  353.  
  354.                       char **plugin_desc,
  355.  
  356.                       char **plugin_version,
  357.  
  358.                       char *arg)
  359.  
  360. {
  361.  
  362.    /* we need to save this for use with any xchat_* functions */
  363.  
  364.    ph = plugin_handle;
  365.  
  366.  
  367.    StartTime=time(NULL);
  368.    
  369.  
  370.    /* tell xchat our info */
  371.  
  372.    *plugin_name = PNAME;
  373.  
  374.    *plugin_desc = PDESC;
  375.  
  376.    *plugin_version = PVERSION;
  377.  
  378.  
  379.  
  380.    xchat_hook_print(ph, "Join", XCHAT_PRI_NORM, join_cb, 0);
  381.  
  382.    xchat_hook_print(ph, "Disconnect", XCHAT_PRI_NORM, disconnect_cb, 0);
  383.  
  384.    xchat_hook_print(ph, "Part", XCHAT_PRI_NORM, part_cb, 0);
  385.  
  386.    xchat_hook_print(ph, "Part with reason", XCHAT_PRI_NORM, partr_cb, 0);
  387.  
  388.    xchat_hook_print(ph, "Channel Action", XCHAT_PRI_NORM, emote_cb, 0);
  389.  
  390.    xchat_hook_print(ph, "Channel Message", XCHAT_PRI_NORM, message_cb, 0);
  391.  
  392.    xchat_hook_print(ph, "Channel Nick", XCHAT_PRI_NORM, nickchange_cb, 0);
  393.  
  394.    xchat_hook_print(ph, "Kick", XCHAT_PRI_NORM, kick_cb, 0);
  395.  
  396.    xchat_hook_print(ph, "Quit", XCHAT_PRI_NORM, quit_cb, 0);  
  397.  
  398.  
  399.  
  400.    xchat_print(ph, "Bridge Bot 3 reporting for duty!\n");
  401.  
  402.    return 1;       /* return 1 for success */
  403.  
  404. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement