mirror of
https://github.com/irssi/irssi.git
synced 2026-08-19 08:32:07 +02:00
Merge pull request #80 from dgl/noact
Change NO_ACT so it can be combined with other levels
This commit is contained in:
commit
ed51629514
9 changed files with 139 additions and 51 deletions
|
|
@ -58,30 +58,6 @@ static int ignore_check_replies_rec(IGNORE_REC *rec, CHANNEL_REC *channel,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
#define ignore_match_channel(rec, channel) \
|
||||
((rec)->channels == NULL || ((channel) != NULL && \
|
||||
strarray_find((rec)->channels, (channel)) != -1))
|
||||
|
||||
static int ignore_check_replies(CHANNEL_REC *chanrec, const char *text)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
if (text == NULL || chanrec == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* check reply ignores */
|
||||
for (tmp = ignores; tmp != NULL; tmp = tmp->next) {
|
||||
IGNORE_REC *rec = tmp->data;
|
||||
|
||||
if (rec->mask != NULL && rec->replies &&
|
||||
ignore_match_channel(rec, chanrec->name) &&
|
||||
ignore_check_replies_rec(rec, chanrec, text))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int ignore_match_pattern(IGNORE_REC *rec, const char *text)
|
||||
{
|
||||
if (rec->pattern == NULL)
|
||||
|
|
@ -104,8 +80,15 @@ static int ignore_match_pattern(IGNORE_REC *rec, const char *text)
|
|||
stristr(text, rec->pattern) != NULL;
|
||||
}
|
||||
|
||||
/* MSGLEVEL_NO_ACT is special in ignores, when provided to ignore_check() it's
|
||||
* used as a flag to indicate it should only look at ignore items with NO_ACT.
|
||||
* However we also want to allow NO_ACT combined with levels, so mask it out and
|
||||
* match levels if set. */
|
||||
#define ignore_match_level(rec, level) \
|
||||
((level & (rec)->level) != 0)
|
||||
(((level & MSGLEVEL_NO_ACT) != 0) ? \
|
||||
((~MSGLEVEL_NO_ACT & level) & (rec)->level) != 0 : \
|
||||
((rec)->level & MSGLEVEL_NO_ACT ? 0 : \
|
||||
(level & (rec)->level) != 0))
|
||||
|
||||
#define ignore_match_nickmask(rec, nick, nickmask) \
|
||||
((rec)->mask == NULL || \
|
||||
|
|
@ -117,6 +100,31 @@ static int ignore_match_pattern(IGNORE_REC *rec, const char *text)
|
|||
((rec)->servertag == NULL || \
|
||||
g_ascii_strcasecmp((server)->tag, (rec)->servertag) == 0)
|
||||
|
||||
#define ignore_match_channel(rec, channel) \
|
||||
((rec)->channels == NULL || ((channel) != NULL && \
|
||||
strarray_find((rec)->channels, (channel)) != -1))
|
||||
|
||||
static int ignore_check_replies(CHANNEL_REC *chanrec, const char *text, int level)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
if (text == NULL || chanrec == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* check reply ignores */
|
||||
for (tmp = ignores; tmp != NULL; tmp = tmp->next) {
|
||||
IGNORE_REC *rec = tmp->data;
|
||||
|
||||
if (rec->mask != NULL && rec->replies &&
|
||||
ignore_match_level(rec, level) &&
|
||||
ignore_match_channel(rec, chanrec->name) &&
|
||||
ignore_check_replies_rec(rec, chanrec, text))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int ignore_check(SERVER_REC *server, const char *nick, const char *host,
|
||||
const char *channel, const char *text, int level)
|
||||
{
|
||||
|
|
@ -176,11 +184,18 @@ int ignore_check(SERVER_REC *server, const char *nick, const char *host,
|
|||
if (best_match || (level & MSGLEVEL_PUBLIC) == 0)
|
||||
return best_match;
|
||||
|
||||
return ignore_check_replies(chanrec, text);
|
||||
return ignore_check_replies(chanrec, text, level);
|
||||
}
|
||||
|
||||
IGNORE_REC *ignore_find(const char *servertag, const char *mask,
|
||||
char **channels)
|
||||
char **channels)
|
||||
{
|
||||
return ignore_find_noact(servertag, mask, channels, 0);
|
||||
}
|
||||
|
||||
|
||||
IGNORE_REC *ignore_find_noact(const char *servertag, const char *mask,
|
||||
char **channels, int noact)
|
||||
{
|
||||
GSList *tmp;
|
||||
char **chan;
|
||||
|
|
@ -202,6 +217,12 @@ IGNORE_REC *ignore_find(const char *servertag, const char *mask,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (noact && (rec->level & MSGLEVEL_NO_ACT) == 0)
|
||||
continue;
|
||||
|
||||
if (!noact && (rec->level & MSGLEVEL_NO_ACT) != 0)
|
||||
continue;
|
||||
|
||||
if ((rec->mask == NULL && mask != NULL) ||
|
||||
(rec->mask != NULL && mask == NULL)) continue;
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ int ignore_check(SERVER_REC *server, const char *nick, const char *host,
|
|||
const char *channel, const char *text, int level);
|
||||
|
||||
IGNORE_REC *ignore_find(const char *servertag, const char *mask, char **channels);
|
||||
IGNORE_REC *ignore_find_noact(const char *servertag, const char *mask, char **channels, int noact);
|
||||
|
||||
void ignore_add_rec(IGNORE_REC *rec);
|
||||
void ignore_update_rec(IGNORE_REC *rec);
|
||||
|
|
|
|||
|
|
@ -136,19 +136,25 @@ char *bits2level(int bits)
|
|||
if (bits == 0)
|
||||
return g_strdup("");
|
||||
|
||||
if (bits == MSGLEVEL_ALL)
|
||||
return g_strdup("ALL");
|
||||
|
||||
str = g_string_new(NULL);
|
||||
if (bits & MSGLEVEL_NEVER)
|
||||
if (bits & MSGLEVEL_NEVER) {
|
||||
g_string_append(str, "NEVER ");
|
||||
bits &= ~MSGLEVEL_NEVER;
|
||||
}
|
||||
|
||||
if (bits & MSGLEVEL_NO_ACT)
|
||||
if (bits & MSGLEVEL_NO_ACT) {
|
||||
g_string_append(str, "NO_ACT ");
|
||||
bits &= ~MSGLEVEL_NO_ACT;
|
||||
}
|
||||
|
||||
for (n = 0; levels[n] != NULL; n++) {
|
||||
if (bits & (1L << n))
|
||||
g_string_append_printf(str, "%s ", levels[n]);
|
||||
if (bits == MSGLEVEL_ALL) {
|
||||
g_string_append(str, "ALL ");
|
||||
} else {
|
||||
for (n = 0; levels[n] != NULL; n++) {
|
||||
if (bits & (1L << n))
|
||||
g_string_append_printf(str, "%s ", levels[n]);
|
||||
}
|
||||
}
|
||||
if (str->len > 0)
|
||||
g_string_truncate(str, str->len-1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue