Skip to content

Commit

Permalink
Some znc plugins. May not be updated for last version :/
Browse files Browse the repository at this point in the history
  • Loading branch information
ravomavain committed Jul 14, 2015
1 parent 8bf4539 commit 33ba1ee
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 0 deletions.
116 changes: 116 additions & 0 deletions znc-dice.cpp
Original file line number Diff line number Diff line change
@@ -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 <znc/znc.h>
#include <znc/Chan.h>
#include <znc/User.h>
#include <znc/Modules.h>

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")
74 changes: 74 additions & 0 deletions znc-getop.cpp
Original file line number Diff line number Diff line change
@@ -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 <znc/znc.h>
#include <znc/Chan.h>
#include <znc/User.h>
#include <znc/Modules.h>
#include <znc/IRCNetwork.h>

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<CString,CNick>& Nicks = Channel.GetNicks();

for (map<CString,CNick>::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<CChan*>& vChans) {
for(vector<CChan*>::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")
46 changes: 46 additions & 0 deletions znc-whorefilter.cpp
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 33ba1ee

Please sign in to comment.