mirror of
https://github.com/irssi/irssi.git
synced 2026-08-10 04:13:32 +02:00
Forgot to move fe-ignore to core.
/unignore now complains if you don't give parameters to it. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@737 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
1627ad03bd
commit
20bac288f6
9 changed files with 40 additions and 28 deletions
|
|
@ -19,7 +19,6 @@ libfe_common_irc_a_SOURCES = \
|
|||
fe-ctcp.c \
|
||||
fe-events.c \
|
||||
fe-events-numeric.c \
|
||||
fe-ignore.c \
|
||||
fe-netjoin.c \
|
||||
fe-netsplit.c \
|
||||
fe-common-irc.c \
|
||||
|
|
|
|||
|
|
@ -55,9 +55,6 @@ void fe_events_deinit(void);
|
|||
void fe_events_numeric_init(void);
|
||||
void fe_events_numeric_deinit(void);
|
||||
|
||||
void fe_ignore_init(void);
|
||||
void fe_ignore_deinit(void);
|
||||
|
||||
void irc_completion_init(void);
|
||||
void irc_completion_deinit(void);
|
||||
|
||||
|
|
@ -105,7 +102,6 @@ void fe_common_irc_init(void)
|
|||
fe_ctcp_init();
|
||||
fe_events_init();
|
||||
fe_events_numeric_init();
|
||||
fe_ignore_init();
|
||||
fe_netsplit_init();
|
||||
fe_netjoin_init();
|
||||
irc_completion_init();
|
||||
|
|
@ -124,7 +120,6 @@ void fe_common_irc_deinit(void)
|
|||
fe_ctcp_deinit();
|
||||
fe_events_deinit();
|
||||
fe_events_numeric_deinit();
|
||||
fe_ignore_deinit();
|
||||
fe_netsplit_deinit();
|
||||
fe_netjoin_deinit();
|
||||
irc_completion_deinit();
|
||||
|
|
|
|||
|
|
@ -1,284 +0,0 @@
|
|||
/*
|
||||
fe-ignore.c : irssi
|
||||
|
||||
Copyright (C) 1999-2000 Timo Sirainen
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "module.h"
|
||||
#include "module-formats.h"
|
||||
#include "signals.h"
|
||||
#include "commands.h"
|
||||
#include "levels.h"
|
||||
#include "misc.h"
|
||||
|
||||
#include "irc.h"
|
||||
#include "irc-servers.h"
|
||||
#include "ignore.h"
|
||||
|
||||
static void fe_unignore(IGNORE_REC *rec);
|
||||
|
||||
static char *ignore_get_key(IGNORE_REC *rec)
|
||||
{
|
||||
char *chans, *ret;
|
||||
|
||||
if (rec->channels == NULL)
|
||||
return rec->mask != NULL ? g_strdup(rec->mask) : NULL;
|
||||
|
||||
chans = g_strjoinv(",", rec->channels);
|
||||
if (rec->mask == NULL) return chans;
|
||||
|
||||
ret = g_strdup_printf("%s %s", rec->mask, chans);
|
||||
g_free(chans);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *ignore_get_levels(int level, int xlevel)
|
||||
{
|
||||
GString *str;
|
||||
char *levelstr, *p, *ret;
|
||||
|
||||
str = g_string_new(NULL);
|
||||
if (level != 0) {
|
||||
levelstr = bits2level(level);
|
||||
g_string_append(str, levelstr);
|
||||
g_free(levelstr);
|
||||
}
|
||||
|
||||
if (xlevel != 0) {
|
||||
if (str->len > 0) g_string_append_c(str, ' ');
|
||||
|
||||
levelstr = bits2level(xlevel);
|
||||
for (p = levelstr; *p != '\0'; p++) {
|
||||
if (!isspace(*p) && (p == levelstr || isspace(p[-1])))
|
||||
g_string_append_c(str, '^');
|
||||
g_string_append_c(str, *p);
|
||||
}
|
||||
g_free(levelstr);
|
||||
}
|
||||
|
||||
ret = str->str;
|
||||
g_string_free(str, FALSE);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* msgs ^notices : level=msgs, xlevel=notices */
|
||||
static void ignore_split_levels(const char *levels, int *level, int *xlevel)
|
||||
{
|
||||
GString *slevel, *sxlevel;
|
||||
char **levellist, **tmp;
|
||||
|
||||
if (*levels == '\0') return;
|
||||
|
||||
slevel = g_string_new(NULL);
|
||||
sxlevel = g_string_new(NULL);
|
||||
|
||||
levellist = g_strsplit(levels, " ", -1);
|
||||
for (tmp = levellist; *tmp != NULL; tmp++) {
|
||||
if (**tmp == '^')
|
||||
g_string_sprintfa(sxlevel, "%s ", (*tmp)+1);
|
||||
else if (**tmp == '-' && (*tmp)[1] == '^')
|
||||
g_string_sprintfa(sxlevel, "-%s ", (*tmp)+2);
|
||||
else
|
||||
g_string_sprintfa(slevel, "%s ", *tmp);
|
||||
}
|
||||
g_strfreev(levellist);
|
||||
|
||||
*level = combine_level(*level, slevel->str);
|
||||
*xlevel = combine_level(*xlevel, sxlevel->str);
|
||||
|
||||
g_string_free(slevel, TRUE);
|
||||
g_string_free(sxlevel, TRUE);
|
||||
}
|
||||
|
||||
static void ignore_print(int index, IGNORE_REC *rec)
|
||||
{
|
||||
GString *options;
|
||||
char *key, *levels;
|
||||
|
||||
key = ignore_get_key(rec);
|
||||
levels = ignore_get_levels(rec->level, rec->except_level);
|
||||
|
||||
options = g_string_new(NULL);
|
||||
if (rec->regexp) g_string_sprintfa(options, "-regexp ");
|
||||
if (rec->fullword) g_string_sprintfa(options, "-word ");
|
||||
if (rec->replies) g_string_sprintfa(options, "-replies ");
|
||||
if (options->len > 1) g_string_truncate(options, options->len-1);
|
||||
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
|
||||
IRCTXT_IGNORE_LINE, index,
|
||||
key != NULL ? key : "",
|
||||
levels != NULL ? levels : "", options->str);
|
||||
g_string_free(options, TRUE);
|
||||
g_free(key);
|
||||
g_free(levels);
|
||||
}
|
||||
|
||||
static int unignore_timeout(IGNORE_REC *rec)
|
||||
{
|
||||
fe_unignore(rec);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void cmd_ignore_show(void)
|
||||
{
|
||||
GSList *tmp;
|
||||
int index;
|
||||
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_IGNORE_HEADER);
|
||||
index = 1;
|
||||
for (tmp = ignores; tmp != NULL; tmp = tmp->next, index++) {
|
||||
IGNORE_REC *rec = tmp->data;
|
||||
|
||||
ignore_print(index, rec);
|
||||
}
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_IGNORE_FOOTER);
|
||||
}
|
||||
|
||||
/* SYNTAX: IGNORE [-regexp | -word] [-pattern <pattern>] [-except] [-replies]
|
||||
[-channels <channel>] [-time <secs>] <mask> <levels>
|
||||
IGNORE [-regexp | -word] [-pattern <pattern>] [-except] [-replies]
|
||||
[-time <secs>] <channels> <levels> */
|
||||
static void cmd_ignore(const char *data)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
IGNORE_REC *rec;
|
||||
char *patternarg, *chanarg, *mask, *levels, *key, *timestr;
|
||||
char **channels;
|
||||
void *free_arg;
|
||||
int new_ignore;
|
||||
|
||||
if (*data == '\0') {
|
||||
cmd_ignore_show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS | PARAM_FLAG_GETREST,
|
||||
"ignore", &optlist, &mask, &levels))
|
||||
return;
|
||||
|
||||
patternarg = g_hash_table_lookup(optlist, "pattern");
|
||||
chanarg = g_hash_table_lookup(optlist, "channels");
|
||||
|
||||
if (*levels == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||
|
||||
if (ischannel(*mask)) {
|
||||
chanarg = mask;
|
||||
mask = NULL;
|
||||
}
|
||||
channels = (chanarg == NULL || *chanarg == '\0') ? NULL :
|
||||
g_strsplit(replace_chars(chanarg, ',', ' '), " ", -1);
|
||||
|
||||
rec = ignore_find(NULL, mask, channels);
|
||||
new_ignore = rec == NULL;
|
||||
|
||||
if (rec == NULL) {
|
||||
rec = g_new0(IGNORE_REC, 1);
|
||||
|
||||
rec->mask = (mask != NULL && *mask != '\0') ?
|
||||
g_strdup(mask) : NULL;
|
||||
rec->channels = channels;
|
||||
} else {
|
||||
g_free_and_null(rec->pattern);
|
||||
g_strfreev(channels);
|
||||
}
|
||||
|
||||
if (g_hash_table_lookup(optlist, "except") != NULL) {
|
||||
rec->except_level = combine_level(rec->except_level, levels);
|
||||
} else {
|
||||
ignore_split_levels(levels, &rec->level, &rec->except_level);
|
||||
}
|
||||
|
||||
rec->pattern = (patternarg == NULL || *patternarg == '\0') ?
|
||||
NULL : g_strdup(patternarg);
|
||||
rec->regexp = g_hash_table_lookup(optlist, "regexp") != NULL;
|
||||
rec->fullword = g_hash_table_lookup(optlist, "word") != NULL;
|
||||
rec->replies = g_hash_table_lookup(optlist, "replies") != NULL;
|
||||
timestr = g_hash_table_lookup(optlist, "time");
|
||||
rec->time = timestr == NULL ? 0 : atoi(timestr);
|
||||
|
||||
if (rec->level == 0 && rec->except_level == 0) {
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_UNIGNORED,
|
||||
rec->mask == NULL ? "" : rec->mask);
|
||||
} else {
|
||||
key = ignore_get_key(rec);
|
||||
levels = ignore_get_levels(rec->level, rec->except_level);
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_IGNORED, key, levels);
|
||||
g_free(key);
|
||||
g_free(levels);
|
||||
}
|
||||
|
||||
if (rec->time > 0)
|
||||
rec->time_tag = g_timeout_add(rec->time*1000, (GSourceFunc) unignore_timeout, rec);
|
||||
|
||||
if (new_ignore)
|
||||
ignore_add_rec(rec);
|
||||
else
|
||||
ignore_update_rec(rec);
|
||||
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
static void fe_unignore(IGNORE_REC *rec)
|
||||
{
|
||||
char *key;
|
||||
|
||||
key = ignore_get_key(rec);
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_UNIGNORED, key);
|
||||
g_free(key);
|
||||
|
||||
rec->level = 0;
|
||||
rec->except_level = 0;
|
||||
ignore_update_rec(rec);
|
||||
}
|
||||
|
||||
/* SYNTAX: UNIGNORE <id>|<mask> */
|
||||
static void cmd_unignore(const char *data)
|
||||
{
|
||||
IGNORE_REC *rec;
|
||||
GSList *tmp;
|
||||
|
||||
if (is_numeric(data, ' ')) {
|
||||
/* with index number */
|
||||
tmp = g_slist_nth(ignores, atoi(data)-1);
|
||||
rec = tmp == NULL ? NULL : tmp->data;
|
||||
} else {
|
||||
/* with mask */
|
||||
const char *chans[2] = { "*", NULL };
|
||||
|
||||
if (ischannel(*data)) chans[0] = data;
|
||||
rec = ignore_find("*", ischannel(*data) ? NULL : data, (char **) chans);
|
||||
}
|
||||
|
||||
if (rec == NULL)
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_IGNORE_NOT_FOUND, data);
|
||||
else
|
||||
fe_unignore(rec);
|
||||
}
|
||||
|
||||
void fe_ignore_init(void)
|
||||
{
|
||||
command_bind("ignore", NULL, (SIGNAL_FUNC) cmd_ignore);
|
||||
command_bind("unignore", NULL, (SIGNAL_FUNC) cmd_unignore);
|
||||
|
||||
command_set_options("ignore", "regexp word except replies -time -pattern -channels");
|
||||
}
|
||||
|
||||
void fe_ignore_deinit(void)
|
||||
{
|
||||
command_unbind("ignore", (SIGNAL_FUNC) cmd_ignore);
|
||||
command_unbind("unignore", (SIGNAL_FUNC) cmd_unignore);
|
||||
}
|
||||
|
|
@ -155,13 +155,5 @@ FORMAT_REC fecommon_irc_formats[] = {
|
|||
{ "unsilenced", "Unsilenced %_$0%_", 1, { 0 } },
|
||||
{ "silence_line", "%_$0%_: silence %c$1", 2, { 0, 0 } },
|
||||
|
||||
{ "ignored", "Ignoring %_$1%_ from %_$0%_", 2, { 0, 0 } },
|
||||
{ "unignored", "Unignored %_$0%_", 1, { 0 } },
|
||||
{ "ignore_not_found", "%_$0%_ is not being ignored", 1, { 0 } },
|
||||
{ "ignore_no_ignores", "There are no ignores", 0 },
|
||||
{ "ignore_header", "Ignorance List:", 0 },
|
||||
{ "ignore_line", "$[-4]0 $1: $2 $3 $4", 4, { 1, 0, 0, 0 } },
|
||||
{ "ignore_footer", "", 0 },
|
||||
|
||||
{ NULL, NULL, 0 }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -123,15 +123,7 @@ enum {
|
|||
|
||||
IRCTXT_SILENCED,
|
||||
IRCTXT_UNSILENCED,
|
||||
IRCTXT_SILENCE_LINE,
|
||||
|
||||
IRCTXT_IGNORED,
|
||||
IRCTXT_UNIGNORED,
|
||||
IRCTXT_IGNORE_NOT_FOUND,
|
||||
IRCTXT_IGNORE_NO_IGNORES,
|
||||
IRCTXT_IGNORE_HEADER,
|
||||
IRCTXT_IGNORE_LINE,
|
||||
IRCTXT_IGNORE_FOOTER
|
||||
IRCTXT_SILENCE_LINE
|
||||
};
|
||||
|
||||
extern FORMAT_REC fecommon_irc_formats[];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue