From 33ba1ee4b38304fec48c01dbafa31d988d826439 Mon Sep 17 00:00:00 2001 From: Romain Labolle Date: Tue, 14 Jul 2015 20:11:52 +0200 Subject: [PATCH] Some znc plugins. May not be updated for last version :/ --- znc-dice.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++++ znc-getop.cpp | 74 ++++++++++++++++++++++++++++ znc-whorefilter.cpp | 46 ++++++++++++++++++ 3 files changed, 236 insertions(+) create mode 100644 znc-dice.cpp create mode 100644 znc-getop.cpp create mode 100644 znc-whorefilter.cpp diff --git a/znc-dice.cpp b/znc-dice.cpp new file mode 100644 index 0000000..20a6ce2 --- /dev/null +++ b/znc-dice.cpp @@ -0,0 +1,116 @@ +/** +* ZNC dice bot +* +* Copyright (c) 2012 Romain Labolle +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +*/ + +#include +#include +#include +#include + +class CDiceMod : public CModule { +public: + MODCONSTRUCTOR(CDiceMod) {} + + virtual bool OnLoad(const CString& sArgs, CString& sErrorMsg) { + user = GetUser(); + HighScore = sArgs.Token(0).ToInt(); + PutModule("HighScore: "+CString(HighScore)); + lastturn = false; + return true; + } + + virtual ~CDiceMod() {} + + virtual void OnModCommand(const CString& sCommand) { + if (sCommand.Token(0).Equals("high")) { + HighScore = sCommand.Token(1).ToInt(); + PutModule("HighScore: "+CString(HighScore)); + } + } + + virtual EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage) { + if (sMessage.Equals("!dice start")) { + PutIRC("PRIVMSG " + Channel.GetName() + " :!dice join"); + return CONTINUE; + } + CNick nick = user->GetNick(); + if (Nick.GetNick().Equals("Nimda3")) + { + if (sMessage.Token(0).Equals(nick.GetNick()+"\'s") && sMessage.Token(1).Equals("turn.")) + { + PutIRC("PRIVMSG " + Channel.GetName() + " :!dice roll"); + lastturn = false; + return CONTINUE; + } + if (sMessage.Token(0).Equals(nick.GetNick()) && sMessage.Token(1).Equals("rolls")) + { +// ravomavain rolls a 2. Points: 49 + 2 => 51 - roll again or stand? + int value = sMessage.Token(3).ToInt(); + if (value == 6) { + return CONTINUE; + } + int saved = sMessage.Token(5).ToInt(); + int temp = sMessage.Token(7).ToInt(); + int total = saved + temp; + if (lastturn) { + if (total < score) { + PutIRC("PRIVMSG " + Channel.GetName() + " :!dice roll"); + return CONTINUE; + } + PutIRC("PRIVMSG " + Channel.GetName() + " :!dice stand"); + return CONTINUE; + } + if (total == 49 || total >= HighScore) { + PutIRC("PRIVMSG " + Channel.GetName() + " :!dice stand"); + return CONTINUE; + } + if (total < 49) + { + if (temp >= 20) + { + PutIRC("PRIVMSG " + Channel.GetName() + " :!dice stand"); + return CONTINUE; + } + } + PutIRC("PRIVMSG " + Channel.GetName() + " :!dice roll"); + return CONTINUE; + } + if (sMessage.Left(37).Equals("You broke the highest sum record with")) + { + HighScore = sMessage.Token(7).ToInt()+1; + PutModule("HighScore: "+CString(HighScore)); + return CONTINUE; + } + if (sMessage.Left(26).Equals("Dice game has been started")) + { + lastturn = false; + return CONTINUE; + } + if (sMessage.Left(39).Equals("It is a really bad idea to \x02stand\x02 now.")) + { + PutIRC("PRIVMSG " + Channel.GetName() + " :!dice roll"); + return CONTINUE; + } + if (sMessage.WildCmp("*get one more chance to beat your score*")) + { + lastturn = true; + score = sMessage.Token(11).ToInt(); + return CONTINUE; + } + } + return CONTINUE; + } +private: + CUser *user; + int HighScore; + bool lastturn; + int score; +}; + +MODULEDEFS(CDiceMod, "Dice bot") diff --git a/znc-getop.cpp b/znc-getop.cpp new file mode 100644 index 0000000..85cb424 --- /dev/null +++ b/znc-getop.cpp @@ -0,0 +1,74 @@ +/** +* ZNC Get Op +* +* Allows the user to redirect what boring ppl say to another (fake) chan. +* +* Copyright (c) 2012 Romain Labolle +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +*/ + +#include +#include +#include +#include +#include + +using std::map; +using std::vector; + +class CGetOpMod : public CModule { +public: + MODCONSTRUCTOR(CGetOpMod) {} + + virtual bool OnLoad(const CString& sArgs, CString& sErrorMsg) { + return true; + } + + virtual ~CGetOpMod() {} + + virtual void update(CChan& Channel) { + const map& Nicks = Channel.GetNicks(); + + for (map::const_iterator it = Nicks.begin(); it != Nicks.end(); ++it) { + if (it->second.HasPerm('@')) + return; + } + PutIRC("PRIVMSG R :REQUESTOP " + Channel.GetName() + " " + GetNetwork()->GetIRCNick().GetNick()); + return; + } + + virtual void OnDeop(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange) { + update(Channel); + return; + } + + virtual void OnPart(const CNick& Nick, CChan& Channel, const CString& sMessage) { + update(Channel); + return; + } + + virtual void OnQuit(const CNick& Nick, const CString& sMessage, const vector& vChans) { + for(vector::const_iterator it = vChans.begin(); it != vChans.end(); ++it) + { + update(**it); + } + return; + } + + virtual EModRet OnRaw(CString& sLine) { + // :irc.server.com 366 nick #chan :End of /NAMES list. + if (sLine.Token(1) == "366") + { + CChan* chan = GetNetwork()->FindChan(sLine.Token(3)); + if(chan) + update(*chan); + } + return CONTINUE; + } +private: +}; + +NETWORKMODULEDEFS(CGetOpMod, "Get op") diff --git a/znc-whorefilter.cpp b/znc-whorefilter.cpp new file mode 100644 index 0000000..c2db232 --- /dev/null +++ b/znc-whorefilter.cpp @@ -0,0 +1,46 @@ +/** +* ZNC Whore Filter +* +* Allows the user to redirect what boring ppl say to another (fake) chan. +* +* Copyright (c) 2012 Romain Labolle +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +*/ + +#include "main.h" +#include "User.h" +#include "Nick.h" +#include "Modules.h" +#include "Chan.h" + + +class CWhoreMod : public CModule { +public: + MODCONSTRUCTOR(CWhoreMod) {} + + virtual bool OnLoad(const CString& sArgs, CString& sErrorMsg) { + m_sHostmask = "attentionwhor*!*srs@*"; + m_sChannel = "#srsbsns"; + m_sNewChan = "~#whorefilter"; + return true; + } + + virtual ~CWhoreMod() {} + + virtual EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage) { + if (Nick.GetHostMask().WildCmp(m_sHostmask) && Channel.GetName().AsLower().WildCmp(m_sChannel)) { + PutUser(":" + Nick.GetHostMask() + " PRIVMSG " + m_sNewChan + " :" + sMessage); + return HALT; + } + return CONTINUE; + } +private: + CString m_sHostmask; + CString m_sChannel; + CString m_sNewChan; +}; + +MODULEDEFS(CWhoreMod, "Filter redirect whore msg to another (fake) chan")