1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

completion_msgtoyou() -> irc_nick_match()

Implemented -replies option to /ignore.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@287 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-06-04 12:38:28 +00:00 committed by cras
parent 1a541c149d
commit 8562737548
9 changed files with 80 additions and 41 deletions

View File

@ -177,7 +177,7 @@ static void event_privmsg(gchar *data, IRC_SERVER_REC *server, gchar *nick)
return;
}
list = completion_msgtoyou((SERVER_REC *) server, msg) ?
list = irc_nick_match(server->nick, msg) ?
&channel->lastownmsgs :
&channel->lastmsgs;
nick_completion_create(list, time(NULL), nick);
@ -207,31 +207,6 @@ static void cmd_msg(gchar *data, IRC_SERVER_REC *server)
g_free(params);
}
int completion_msgtoyou(SERVER_REC *server, const char *msg)
{
gchar *stripped, *nick;
gboolean ret;
gint len;
g_return_val_if_fail(msg != NULL, FALSE);
if (g_strncasecmp(msg, server->nick, strlen(server->nick)) == 0 &&
!isalnum((gint) msg[strlen(server->nick)])) return TRUE;
stripped = nick_strip(server->nick);
nick = nick_strip(msg);
len = strlen(stripped);
ret = *stripped != '\0' &&
g_strncasecmp(nick, stripped, len) == 0 &&
!isalnum((gint) nick[len]) &&
(guchar) nick[len] < 128;
g_free(nick);
g_free(stripped);
return ret;
}
static void complete_list(GList **outlist, GSList *list, gchar *nick)
{
GSList *tmp;

View File

@ -3,7 +3,6 @@
#include "window-items.h"
int completion_msgtoyou(SERVER_REC *server, const char *msg);
char *completion_line(WINDOW_REC *window, const char *line, int *pos);
char *auto_completion(const char *line, int *pos);

View File

@ -80,7 +80,7 @@ static void event_privmsg(gchar *data, IRC_SERVER_REC *server, gchar *nick, gcha
gchar *color;
chanrec = channel_find(server, target);
toyou = completion_msgtoyou((SERVER_REC *) server, msg);
toyou = irc_nick_match(server->nick, msg);
color = irc_hilight_find_nick(target, nick, addr);
nickrec = chanrec == NULL ? NULL : nicklist_find(chanrec, nick);

View File

@ -112,8 +112,9 @@ static void ignore_print(int index, IGNORE_REC *rec)
IRCTXT_IGNORE_LINE, index,
key != NULL ? key : "",
levels != NULL ? levels : "",
rec->regexp ? " -regexp" : "",
rec->fullword ? " -word" : "",
rec->regexp ? " -regexp" : "");
rec->replies ? " -replies" : "");
g_free(key);
g_free(levels);
}
@ -183,8 +184,9 @@ static void cmd_ignore(const char *data)
}
rec->pattern = *patternarg == '\0' ? NULL : g_strdup(patternarg);
rec->fullword = stristr(args, "-word") != NULL;
rec->regexp = stristr(args, "-regexp") != NULL;
rec->fullword = stristr(args, "-word") != NULL;
rec->replies = stristr(args, "-replies") != NULL;
if (rec->level == 0 && rec->except_level == 0) {
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_UNIGNORED,

View File

@ -25,6 +25,7 @@
#include "irc.h"
#include "ignore.h"
#include "irc-server.h"
#include "nicklist.h"
#include "completion.h"
#include "windows.h"
@ -59,7 +60,7 @@ static void event_privmsg(const char *data, IRC_SERVER_REC *server, const char *
if (window != active_win && !ignore_check(server, nick, addr, target, msg, level)) {
/* hilight */
level = !ischannel(*target) ||
completion_msgtoyou((SERVER_REC *) server, msg) ?
irc_nick_match(server->nick, msg) ?
NEWDATA_MSG_FORYOU : NEWDATA_MSG;
if (item != NULL && item->new_data < level) {
item->new_data = level;

View File

@ -28,11 +28,37 @@
#include "irc.h"
#include "masks.h"
#include "irc-server.h"
#include "channels.h"
#include "nicklist.h"
#include "ignore.h"
GSList *ignores;
/* check if `text' contains ignored nick at the start of the line. */
static int ignore_check_replies(IGNORE_REC *rec, IRC_SERVER_REC *server,
const char *channel, const char *text)
{
CHANNEL_REC *chanrec;
GSList *nicks, *tmp;
chanrec = channel_find(server, channel);
if (chanrec == NULL) return FALSE;
nicks = nicklist_find_multiple(chanrec, rec->mask);
if (nicks == NULL) return FALSE;
for (tmp = nicks; tmp != NULL; tmp = tmp->next) {
NICK_REC *nick = tmp->data;
if (irc_nick_match(nick->nick, text))
return TRUE;
}
g_slist_free(nicks);
return FALSE;
}
int ignore_check(IRC_SERVER_REC *server, const char *nick, const char *host,
const char *channel, const char *text, int level)
{
@ -53,6 +79,14 @@ int ignore_check(IRC_SERVER_REC *server, const char *nick, const char *host,
if (rec->servertag != NULL && g_strcasecmp(server->tag, rec->servertag) != 0)
continue;
/* channel list */
if (rec->channels != NULL) {
if (channel == NULL || !ischannel(*channel))
continue;
if (strarray_find(rec->channels, channel) == -1)
continue;
}
/* nick mask */
mask_len = 0;
if (rec->mask != NULL) {
@ -65,15 +99,11 @@ int ignore_check(IRC_SERVER_REC *server, const char *nick, const char *host,
ok = ((host == NULL || *host == '\0')) ?
match_wildcards(rec->mask, nick) :
irc_mask_match_address(rec->mask, nick, host);
if (!ok) continue;
if (!ok) {
/* nick didn't match, but maybe this is a reply to nick? */
if (!rec->replies || !ignore_check_replies(rec, server, channel, text))
continue;
}
/* channel list */
if (rec->channels != NULL) {
if (channel == NULL || !ischannel(*channel))
continue;
if (strarray_find(rec->channels, channel) == -1)
continue;
}
/* pattern */
@ -178,6 +208,7 @@ static void ignore_set_config(IGNORE_REC *rec)
iconfig_node_set_str(node, "pattern", rec->pattern);
if (rec->regexp) config_node_set_bool(node, "regexp", TRUE);
if (rec->fullword) config_node_set_bool(node, "fullword", TRUE);
if (rec->replies) config_node_set_bool(node, "replies", TRUE);
if (rec->channels != NULL && *rec->channels != NULL) {
node = config_node_section(node, "channels", NODE_TYPE_LIST);
@ -273,6 +304,7 @@ static void read_ignores(void)
rec->except_level = level2bits(config_node_get_str(node, "except_level", ""));
rec->regexp = config_node_get_bool(node, "regexp", FALSE);
rec->fullword = config_node_get_bool(node, "fullword", FALSE);
rec->replies = config_node_get_bool(node, "replies", FALSE);
node = config_node_section(node, "channels", -1);
if (node != NULL) rec->channels = config_node_get_list(node);

View File

@ -12,6 +12,7 @@ typedef struct {
int regexp:1;
int fullword:1;
int replies:1; /* ignore replies to nick in channel */
} IGNORE_REC;
extern GSList *ignores;

View File

@ -197,6 +197,7 @@ int nicklist_compare(NICK_REC *p1, NICK_REC *p2)
(a) == '[' || (a) == ']' || (a) == '{' || (a) == '}' || \
(a) == '|' || (a) == '\\' || (a) == '^')
/* Remove all "extra" characters from `nick'. Like _nick_ -> nick */
char *nick_strip(const char *nick)
{
char *stripped, *spos;
@ -214,6 +215,31 @@ char *nick_strip(const char *nick)
return stripped;
}
/* Check is `msg' is meant for `nick'. */
int irc_nick_match(const char *nick, const char *msg)
{
char *stripnick, *stripmsg;
int ret, len;
g_return_val_if_fail(nick != NULL, FALSE);
g_return_val_if_fail(msg != NULL, FALSE);
if (g_strncasecmp(msg, nick, strlen(nick)) == 0 &&
!isalnum((int) msg[strlen(nick)])) return TRUE;
stripnick = nick_strip(nick);
stripmsg = nick_strip(msg);
len = strlen(stripnick);
ret = len > 0 && g_strncasecmp(stripmsg, stripnick, len) == 0 &&
!isalnum((int) stripmsg[len]) &&
(unsigned char) stripmsg[len] < 128;
g_free(stripnick);
g_free(stripmsg);
return ret;
}
static void event_names_list(const char *data, IRC_SERVER_REC *server)
{
CHANNEL_REC *chanrec;

View File

@ -33,10 +33,13 @@ GSList *nicklist_getnicks(CHANNEL_REC *channel);
/* Get all the nick records of `nick'. Returns channel, nick, channel, ... */
GSList *nicklist_get_same(IRC_SERVER_REC *server, const char *nick);
/* nick record comparision for sort functions */
/* Nick record comparision for sort functions */
int nicklist_compare(NICK_REC *p1, NICK_REC *p2);
/* Remove all "extra" characters from `nick'. Like _nick_ -> nick */
char *nick_strip(const char *nick);
/* Check is `msg' is meant for `nick'. */
int irc_nick_match(const char *nick, const char *msg);
void nicklist_init(void);
void nicklist_deinit(void);