Only show QUIT/NICK in channels where user was present, suppress English echo
- QUIT messages only appear in channels where the user was in nick list - NICK changes only shown in channels where user is present - Suppress translation when English result matches original (50%+ word overlap)
This commit is contained in:
@@ -619,9 +619,9 @@ static void nicklist_add(int idx, const char *n)
|
|||||||
NICK_LEN, "%s", n);
|
NICK_LEN, "%s", n);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nicklist_remove(int idx, const char *n)
|
static int nicklist_remove(int idx, const char *n)
|
||||||
{
|
{
|
||||||
if (idx < 0 || idx >= MAX_CHAN_WINS) return;
|
if (idx < 0 || idx >= MAX_CHAN_WINS) return 0;
|
||||||
for (int i = 0; i < win_chans[idx].nick_count; i++) {
|
for (int i = 0; i < win_chans[idx].nick_count; i++) {
|
||||||
if (strcasecmp(win_chans[idx].nicks[i], n) == 0) {
|
if (strcasecmp(win_chans[idx].nicks[i], n) == 0) {
|
||||||
win_chans[idx].nick_count--;
|
win_chans[idx].nick_count--;
|
||||||
@@ -629,21 +629,10 @@ static void nicklist_remove(int idx, const char *n)
|
|||||||
memcpy(win_chans[idx].nicks[i],
|
memcpy(win_chans[idx].nicks[i],
|
||||||
win_chans[idx].nicks[win_chans[idx].nick_count],
|
win_chans[idx].nicks[win_chans[idx].nick_count],
|
||||||
NICK_LEN);
|
NICK_LEN);
|
||||||
return;
|
return 1;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void nicklist_rename(const char *old, const char *new_nick)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < MAX_CHAN_WINS; i++) {
|
|
||||||
for (int j = 0; j < win_chans[i].nick_count; j++) {
|
|
||||||
if (strcasecmp(win_chans[i].nicks[j], old) == 0) {
|
|
||||||
snprintf(win_chans[i].nicks[j], NICK_LEN, "%s", new_nick);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int chan_win_idx(const char *chan)
|
static int chan_win_idx(const char *chan)
|
||||||
@@ -926,10 +915,10 @@ static void handle_line(char *line)
|
|||||||
} else if (strcmp(cmd, "QUIT") == 0) {
|
} else if (strcmp(cmd, "QUIT") == 0) {
|
||||||
char *reason = params;
|
char *reason = params;
|
||||||
if (reason && reason[0] == ':') reason++;
|
if (reason && reason[0] == ':') reason++;
|
||||||
/* Show quit in all active channel windows and remove nick */
|
/* Show quit only in channels where the user was present */
|
||||||
for (int i = 0; i < MAX_CHAN_WINS; i++) {
|
for (int i = 0; i < MAX_CHAN_WINS; i++) {
|
||||||
if (win_chans[i].name[0]) {
|
if (win_chans[i].name[0]) {
|
||||||
nicklist_remove(i, sender);
|
if (nicklist_remove(i, sender))
|
||||||
wprintf(WL_CHAN + i, "\033[1m* %s has quit (%s)\033[0m\n",
|
wprintf(WL_CHAN + i, "\033[1m* %s has quit (%s)\033[0m\n",
|
||||||
sender, reason ? reason : "");
|
sender, reason ? reason : "");
|
||||||
}
|
}
|
||||||
@@ -937,13 +926,23 @@ static void handle_line(char *line)
|
|||||||
} else if (strcmp(cmd, "NICK") == 0) {
|
} else if (strcmp(cmd, "NICK") == 0) {
|
||||||
char *newnick = params;
|
char *newnick = params;
|
||||||
if (newnick && newnick[0] == ':') newnick++;
|
if (newnick && newnick[0] == ':') newnick++;
|
||||||
/* Update nick lists and show in all active channel windows */
|
/* Update nick lists and show only in channels where user is present */
|
||||||
if (newnick) nicklist_rename(sender, newnick);
|
|
||||||
for (int i = 0; i < MAX_CHAN_WINS; i++) {
|
for (int i = 0; i < MAX_CHAN_WINS; i++) {
|
||||||
if (win_chans[i].name[0])
|
if (win_chans[i].name[0]) {
|
||||||
|
int found = 0;
|
||||||
|
for (int j = 0; j < win_chans[i].nick_count; j++) {
|
||||||
|
if (strcasecmp(win_chans[i].nicks[j], sender) == 0) {
|
||||||
|
if (newnick)
|
||||||
|
snprintf(win_chans[i].nicks[j], NICK_LEN, "%s", newnick);
|
||||||
|
found = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found)
|
||||||
wprintf(WL_CHAN + i, "* %s is now known as %s\n",
|
wprintf(WL_CHAN + i, "* %s is now known as %s\n",
|
||||||
sender, newnick ? newnick : "");
|
sender, newnick ? newnick : "");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (strcasecmp(sender, nick) == 0 && newnick) {
|
if (strcasecmp(sender, nick) == 0 && newnick) {
|
||||||
snprintf(nick, sizeof(nick), "%s", newnick);
|
snprintf(nick, sizeof(nick), "%s", newnick);
|
||||||
draw_statusbar();
|
draw_statusbar();
|
||||||
@@ -1578,6 +1577,31 @@ int main(int argc, char *argv[])
|
|||||||
strncasecmp(english, "SKIP", 4) == 0)
|
strncasecmp(english, "SKIP", 4) == 0)
|
||||||
suppress = 1;
|
suppress = 1;
|
||||||
|
|
||||||
|
/* Suppress if English translation matches original */
|
||||||
|
if (!suppress && translate_pending[ti].original[0]) {
|
||||||
|
char orig_l[512], eng_l[1024];
|
||||||
|
snprintf(orig_l, sizeof(orig_l), "%s",
|
||||||
|
translate_pending[ti].original);
|
||||||
|
snprintf(eng_l, sizeof(eng_l), "%s", english);
|
||||||
|
for (char *p = orig_l; *p; p++)
|
||||||
|
if (*p >= 'A' && *p <= 'Z') *p += 32;
|
||||||
|
for (char *p = eng_l; *p; p++)
|
||||||
|
if (*p >= 'A' && *p <= 'Z') *p += 32;
|
||||||
|
int total = 0, matches = 0;
|
||||||
|
char orig_copy[512];
|
||||||
|
snprintf(orig_copy, sizeof(orig_copy), "%s", orig_l);
|
||||||
|
char *tok = strtok(orig_copy, " ,.!?:;");
|
||||||
|
while (tok) {
|
||||||
|
if (strlen(tok) > 2) {
|
||||||
|
total++;
|
||||||
|
if (strstr(eng_l, tok)) matches++;
|
||||||
|
}
|
||||||
|
tok = strtok(NULL, " ,.!?:;");
|
||||||
|
}
|
||||||
|
if (total > 0 && matches * 100 / total >= 50)
|
||||||
|
suppress = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (!suppress && english[0]) {
|
if (!suppress && english[0]) {
|
||||||
/* Strip trailing whitespace from english */
|
/* Strip trailing whitespace from english */
|
||||||
size_t elen = strlen(english);
|
size_t elen = strlen(english);
|
||||||
|
|||||||
Reference in New Issue
Block a user