Advertisement
Aha2Y

Untitled

May 9th, 2012
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. /*
  2.  * IRCbot "Infobot" module for ZNC.
  3.  * Made by Aha2Y.
  4. */
  5.  
  6. #include <znc/znc.h>
  7. #include <znc/Client.h>
  8. #include <znc/Chan.h>
  9. #include <znc/User.h>
  10. #include <znc/Modules.h>
  11.  
  12. string replace(string orig, string search, string repl)
  13. {
  14.     string rep = orig;
  15.     size_t f = rep.find(search);
  16.     while (f != string::npos)
  17.     {  
  18.         rep.replace(f, search.length(), repl);
  19.         f = rep.find(search, f + repl.length() + 1 + 1);
  20.     }  
  21.     return rep;
  22. }
  23.  
  24. //Start code of InfoBot
  25. class CInfoBot : public CModule {
  26. public:
  27.     MODCONSTRUCTOR(CInfoBot) {}
  28.    
  29.     virtual EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage)
  30.    {  
  31.         if (sMessage == "?ping")
  32.       {
  33.           PutIRC("PRIVMSG " + Channel.GetName() + " :" + Nick.GetNick() + ": Pong!");
  34.      
  35.           return CONTINUE;
  36.         }
  37.      
  38.       else if (sMessage == "?uptime")
  39.       {
  40.           PutIRC("PRIVMSG " + Channel.GetName() + " :The bouncer has been up for: " + replace(CZNC::Get().GetUptime(), "d", " days"));
  41.          
  42.           return CONTINUE;
  43.       }
  44.      
  45.       else if (sMessage == "?version")
  46.       {
  47.           PutIRC("PRIVMSG " + Channel.GetName() + " :" + Nick.GetNick() + ": InfoBot, Running on ZNC-" + CZNC::Get().GetVersion());
  48.          
  49.           return CONTINUE;
  50.          
  51.       }
  52.    }
  53.    
  54.    virtual void OnModCommand(const CString& sCommand)
  55.    {
  56.         if (sCommand.Token(0).Equals("set"))
  57.       {
  58.           if (sCommand.Token(1).Equals("prefix"))
  59.            {
  60.              if (sCommand.Token(2).empty())
  61.               {
  62.                   PutModule("Error: Unknown variable");
  63.               }
  64.               else
  65.               {
  66.                   Prefix = sCommand.Token(2);
  67.                   PutModule("Prefix = "+ Prefix);
  68.               }
  69.            }
  70.            else
  71.            {
  72.                PutModule("Usage: set <variable> <value>");
  73.            }
  74.       }
  75.       if (sCommand.Token(0).Equals("get"))
  76.       {
  77.          if (sCommand.Token(1).Equals("prefix"))
  78.           {
  79.               PutModule("Prefix = "+ Prefix);
  80.           }
  81.           else
  82.           {
  83.               PutModule("Usage: get <variable>");
  84.           }
  85.       }
  86.       else
  87.       {
  88.           PutModule("Unknown command [" + sCommand + "] try 'Help");  
  89.       }
  90.     }
  91.    
  92. };
  93.  
  94. template<> void TModInfo<CInfoBot>(CModInfo& Info) {
  95.     Info.SetWikiPage("Infobot");
  96. }
  97.  
  98. USERMODULEDEFS(CInfoBot, "Infobot by Aha2Y (BETA)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement