From anonymous, 6 Years ago, written in Plain Text.
Embed
  1. /*
  2.  * IRCbot module for ZNC.
  3.  * Made by Aha2Y.
  4.  */
  5.  
  6. #include "znc.h"
  7. #include "Chan.h"
  8. #include "User.h"
  9. #include "Modules.h"
  10. #include "ZNCString.h"
  11. #include "Server.h"
  12. #include <sstream>
  13. #include <utility>
  14.  
  15. using namespace std;
  16.  
  17. string potato(string orig, string search, string repl)
  18. {
  19.     string rep = orig;
  20.     size_t f = rep.find(search);
  21.     while (f != string::npos)
  22.     {  
  23.         rep.replace(f, search.length(), repl);
  24.         f = rep.find(search, f + 1);
  25.     }  
  26.     return rep;
  27. }
  28.  
  29. class CSampleMod : public CModule {
  30. public:
  31.         MODCONSTRUCTOR(CSampleMod) {}
  32.         virtual EModRet OnPrivMsg(CNick& Nick, CString& sMessage) {
  33.                 if (sMessage == "uptime") {
  34.          PutIRC("PRIVMSG " + Nick.GetNick() + " :Running for: " + uptime + "");
  35.  
  36.                 return CONTINUE;
  37.         }
  38.  
  39. };
  40.  
  41.         virtual EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage) {
  42.       string uptime = potato(string(CZNC::Get().GetVersion(), "h", "hour")
  43.  
  44.                 if (sMessage == "!ping") {
  45.                         PutIRC("PRIVMSG " + Channel.GetName() + " :" + Nick.GetNick() + ": Pong!");
  46.                 }
  47.                 if (sMessage == "!uptime") {
  48.                         PutIRC("PRIVMSG " + Channel.GetName() + " :Running for: " + CZNC::Get().GetUptime() + "");
  49.                 }
  50.                 if (sMessage == "!version") {
  51.                         PutIRC("PRIVMSG " + Channel.GetName() + " :ZncBot 2.0 - Running on ZNC-" + CZNC::Get().GetVersion() + "");
  52.                 }
  53.                 return CONTINUE;
  54.         }
  55.    
  56. };
  57.  
  58. template<> void TModInfo<CSampleMod>(CModInfo& Info) {
  59.         Info.SetWikiPage("IRCbot");
  60. }
  61.  
  62. MODULEDEFS(CSampleMod, "IRCbot")
  63.  
  64.