Advertisement
Aha2Y

Untitled

May 9th, 2012
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 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.  
  27. public:
  28.     MODCONSTRUCTOR(CInfoBot) {}
  29.    
  30.     virtual EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage)
  31.    {  
  32.         if (sMessage == "?ping")
  33.       {
  34.           PutIRC("PRIVMSG " + Channel.GetName() + " :" + Nick.GetNick() + ": Pong!");
  35.      
  36.           return CONTINUE;
  37.         }
  38.      
  39.       else if (sMessage == "?uptime")
  40.       {
  41.           PutIRC("PRIVMSG " + Channel.GetName() + " :The bouncer has been up for: " + replace(CZNC::Get().GetUptime(), "d", " days"));
  42.          
  43.           return CONTINUE;
  44.       }
  45.      
  46.       else if (sMessage == "?version")
  47.       {
  48.           PutIRC("PRIVMSG " + Channel.GetName() + " :" + Nick.GetNick() + ": InfoBot, Running on ZNC-" + CZNC::Get().GetVersion());
  49.          
  50.           return CONTINUE;
  51.          
  52.       }
  53.    }
  54.    
  55.    virtual void OnModCommand(const CString& sCommand)
  56.    {
  57.         if (sCommand.Token(0).Equals("set"))
  58.       {
  59.           if (sCommand.Token(1).Equals("prefix"))
  60.            {
  61.              if (sCommand.Token(2).empty())
  62.               {
  63.                   PutModule("Error: Unknown variable");
  64.               }
  65.               else
  66.               {
  67.                   this->Prefix = sCommand.Token(2);
  68.                   PutModule("Prefix = "+ this->Prefix);
  69.               }
  70.            }
  71.            else
  72.            {
  73.                PutModule("Usage: set <variable> <value>");
  74.            }
  75.       }
  76.       if (sCommand.Token(0).Equals("get"))
  77.       {
  78.          if (sCommand.Token(1).Equals("prefix"))
  79.           {
  80.               PutModule("Prefix = "+ this->Prefix);
  81.           }
  82.           else
  83.           {
  84.               PutModule("Usage: get <variable>");
  85.           }
  86.       }
  87.       else
  88.       {
  89.           PutModule("Unknown command [" + sCommand + "] try 'Help");  
  90.       }
  91.     }
  92. private:
  93. string Prefix = "?";
  94.    
  95. };
  96.  
  97. template<> void TModInfo<CInfoBot>(CModInfo& Info) {
  98.     Info.SetWikiPage("Infobot");
  99. }
  100.  
  101. USERMODULEDEFS(CInfoBot, "Infobot by Aha2Y (BETA)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement