Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ignoring joins, parts and quits #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ Pull requests welcome.
### Install

```
$ znc-buildmod ignore.cc
$ znc-buildmod ignore.cpp
$ mv ignore.so ~/.znc/modules
```

### Usage

Command | Arguments | Description
------------|-------------------------------|--------------------------------------------------------------------------------
AddHost | [mMaAnNcC] `<nick!user@host>` | Ignore a hostmask from [m]essage, [a]ction, [n]otice, [c]tcp; uppercase = private
AddPattern | [mMaAnNcC] `<regex>` | Ignore text matching a regular expression
Clear | | Clear all ignore entries
Del | `<n>` | Remove an ignore entry by index
Help | search | Generate this output
List | | Display the ignore list
Command | Arguments | Description
------------|-----------------------------------|----------------------------------------------------------------------------
AddHost | [mMaAnNcCjpqk] `<nick!user@host>` | Ignore a hostmask from [m]essage, [a]ction, [n]otice, [c]tcp, [j]oins,
| | [p]arts, [q]uits, nic[k] changes, uppercase = private
AddPattern | [mMaAnNcCjpqk] `<regex>` | Ignore text matching a regular expression
Clear | | Clear all ignore entries
Del | `<n>` | Remove an ignore entry by index
Help | search | Generate this output
List | | Display the ignore list

The required arguments for AddHost and AddPattern should be "quoted" if they contain spaces.

Expand Down
29 changes: 27 additions & 2 deletions ignore.cc → ignore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@

using namespace std;

enum {
enum IMode {
ModeMsg,
ModePrivMsg,
ModeAction,
ModePrivAction,
ModeNotice,
ModePrivNotice,
ModeCTCP,
ModePrivCTCP
ModePrivCTCP,
ModeJoin,
ModePart,
ModeQuit,
ModeNick
};

class MatcherError : public runtime_error {
Expand Down Expand Up @@ -393,6 +397,27 @@ CModule::EModRet ModIgnore::check(CNick& nick, CString& message, int mode) {
return CONTINUE;
}

CModule::EModRet ModIgnore::OnRawMessage(CMessage &message) {
CString msgtext;
IMode msgmode;
CMessage::Type mtype = message.GetType();

if (mtype == CMessage::Type::Join) {
msgmode = ModeJoin;
} else if (mtype == CMessage::Type::Part) {
msgmode = ModePart;
} else if (mtype == CMessage::Type::Quit) {
msgmode = ModeQuit;
} else if (mtype == CMessage::Type::Nick) {
msgmode = ModeNick;
} else {
return CONTINUE;
}

msgtext = message.ToString(message.IncludeAll);
return check(message.GetNick(), msgtext, msgmode);
}

CModule::EModRet ModIgnore::OnChanMsg(CNick& nick, CChan& chan, CString& message) {
return check(nick, message, ModeMsg);
}
Expand Down
9 changes: 5 additions & 4 deletions ignore.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <bitset>
#include <iostream>

const int NUM_MODES = 8;
const char MODES[NUM_MODES+1] = "mMaAnNcC";
const int NUM_MODES = 12;
const char MODES[NUM_MODES+1] = "mMaAnNcCjpqk";

class Matcher {
protected:
Expand Down Expand Up @@ -84,13 +84,14 @@ class ModIgnore : public CModule {
virtual EModRet OnPrivNotice(CNick& nick, CString& message);
virtual EModRet OnChanCTCP(CNick& nick, CChan& chan, CString& message);
virtual EModRet OnPrivCTCP(CNick& nick, CString& message);
virtual EModRet OnRawMessage(CMessage &message);

MODCONSTRUCTOR(ModIgnore) {
AddHelpCommand();
AddCommand("AddHost", static_cast<CModCommand::ModCmdFunc>(&ModIgnore::CmdAddHostMatcher),
"[mMaAnNcC] <nick!user@host>", "Ignore a hostmask from [m]essage, [a]ction, [n]otice, [c]tcp; uppercase = private");
"[mMaAnNcCjpqk] <nick!user@host>", "Ignore a hostmask from [m]essage, [a]ction, [n]otice, [c]tcp, [j]oins, [p]arts, [q]uits, nic[k]; uppercase = private");
AddCommand("AddPattern",static_cast<CModCommand::ModCmdFunc>(&ModIgnore::CmdAddRegexMatcher),
"[mMaAnNcC] <regex>", "Ignore text matching a regular expression");
"[mMaAnNcCjpqk] <regex>", "Ignore text matching a regular expression");
AddCommand("Del", static_cast<CModCommand::ModCmdFunc>(&ModIgnore::CmdDelIgnore),
"<n>", "Remove an ignore entry by index");
AddCommand("List", static_cast<CModCommand::ModCmdFunc>(&ModIgnore::CmdList),
Expand Down
Binary file added ignore.so
Binary file not shown.