2
0
Fork 0
forked from zynk/zynk

Improved Wikipedia results formatting and article extracts. (0.43.1)

- Changed multi-result mode from a single pipe-separated message to
  individual messages: each result is now its own IRC message (Title —
  snippet) followed by a separate Read full article: LINK message.
- Removed numbering from multi-result messages.
- Changed single-result extract to show the first chapter instead of only
  the introductory paragraph by removing exintro=true from the Extracts
  API URL.
- Increased extract character limit from 500 to 800 (exchars=800).
- Added truncation indicator (...) for extracts approaching the character
  limit.
- Added Read full article: prefix to the single-result link message.
- Updated CHANGELOG.md with 0.43.1 entry.
This commit is contained in:
Johannes Findeisen 2026-07-26 00:59:16 +02:00
commit 013242f057
3 changed files with 32 additions and 37 deletions

View file

@ -1,8 +1,17 @@
2026.07.26 - Improved Wikipedia results formatting and article extracts. (0.43.1)
- Changed multi-result mode from a single pipe-separated message to individual messages: each result is now sent as its own IRC message (`Title — snippet`) followed by a separate "Read full article: LINK" message. This makes results easier to read in busy channels and ensures each article link is immediately visible.
- Removed numbering from multi-result messages (was `1. Title — ...`, now just `Title — ...`).
- Changed single-result extract to show the first chapter instead of only the introductory paragraph: removed `exintro=true` from the Extracts API URL so the API returns the full article content up to the character limit.
- Increased the extract character limit from 500 to 800 characters (`exchars=800`) to show more article content per result.
- Added truncation indicator ("...") appended to single-result extracts when the text reaches 790+ characters (near the `exchars` limit).
- Added "Read full article: LINK" follow-up message to every single-result response (previously only sent the bare URL as a second message, now uses the "Read full article: " prefix).
2026.07.26 - Wikipedia search command. (0.43.0)
- Added `!wp <search terms>` command: searches Wikipedia using the MediaWiki API (`action=query&list=search`) and displays results. Accepts multiple keywords (e.g. `!wp quantum physics`). Rate-limited via `rate_limit_check()`.
- Single-result mode: when the search returns exactly one article, fetches the first chapter via the Extracts API (`action=query&prop=extracts`, up to 800 characters) and sends the article title, intro text, and a "Read full article: LINK" message. Appends "..." if the extract was truncated.
- Multi-result mode: when the search returns 2-5 articles, sends a compact numbered list with short snippets (truncated to 60 chars) separated by pipes. Each result is followed by a "Read full article: LINK" message. Appends "..." if the result list was truncated.
- Multi-result mode: when the search returns 2–5 articles, sends a compact numbered list with short snippets (truncated to 60 chars) separated by pipes. Each result is followed by a "Read full article: LINK" message. Appends "..." if the result list was truncated.
- Added self-contained JSON parser helpers: `wp_json_get_string()` extracts string values by key, `wp_json_next_array_item()` iterates JSON array objects, `wp_decode_json_string()` handles JSON escape sequences including `\uXXXX` Unicode.
- Added `wp_url_encode()` for percent-encoding search queries and article titles in API URLs (RFC 3986 compliant, spaces as `+`).
- Added `wp_codepoint_to_utf8()` to encode Unicode code points as UTF-8 bytes (handles U+0000 through U+10FFFF).
@ -10,7 +19,7 @@
- Added `wp_hex_digit()` to convert hexadecimal characters to numeric values.
- Added `WITH_WP` CMake feature toggle (ON by default) with compile definition `HAS_CMD_WP`.
- Added `!wp` to the `!help` command listing.
- Added comprehensive doc comments to all 9 functions in `cmd_wp.h`.
- Added comprehensive doc comments to all nine functions in `cmd_wp.h`.
2026.07.25 - Comprehensive flood protection: per-poll limits, userhost rate limiting, outgoing throttle. (0.42.0)

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.13)
project(zynk VERSION 0.43.0 LANGUAGES C)
project(zynk VERSION 0.43.1 LANGUAGES C)
# Prefer C99; the code is compatible with C99/C11
set(CMAKE_C_STANDARD 99)

View file

@ -342,13 +342,16 @@ int cmd_wp(Session *s, const char *msg, const char *reply_target, const char *sr
snprintf(link, sizeof link, "Read full article: https://en.wikipedia.org/wiki/%s", enc_title);
irc_reply(s, reply_target, src_nick, link);
} else {
char resp[1800];
int off = snprintf(resp, sizeof resp, "Wikipedia results for \"%s\":", rest);
char resp[512];
snprintf(resp, sizeof resp, "Wikipedia results for \"%s\":", rest);
irc_reply(s, reply_target, src_nick, resp);
const char *cur = results_key;
int idx = 0;
while (idx < result_count && idx < 5 && off < (int)sizeof resp - 200) {
int shown = 0;
while (idx < result_count && shown < 5) {
const char *brace = wp_json_next_array_item(&cur);
if (!brace) break;
idx++;
char title[256] = "";
char snippet_raw[256] = "";
wp_json_get_string(brace, "\"title\":", title, sizeof title);
@ -359,48 +362,31 @@ int cmd_wp(Session *s, const char *msg, const char *reply_target, const char *sr
if (!title[0]) continue;
char enc_title[512];
wp_url_encode(title, enc_title, sizeof enc_title);
int n;
if (idx == 0) {
n = snprintf(resp + off, sizeof resp - off, " %d. %s", idx + 1, title);
} else {
n = snprintf(resp + off, sizeof resp - off, " | %d. %s", idx + 1, title);
}
off += n;
if (snippet_raw[0] && off < (int)sizeof resp - 128) {
char line[1024];
if (snippet_raw[0]) {
char snippet_short[256];
snprintf(snippet_short, sizeof snippet_short, "%s", snippet_raw);
size_t slen = strlen(snippet_short);
if (slen > 60) {
char *sp = snippet_short + 57;
if (slen > 80) {
char *sp = snippet_short + 77;
while (sp > snippet_short && *sp != ' ') sp--;
if (sp <= snippet_short) sp = snippet_short + 57;
if (sp <= snippet_short) sp = snippet_short + 77;
*sp = '\0';
n = snprintf(resp + off, sizeof resp - off, " (%s...)", snippet_short);
snprintf(line, sizeof line, "%s — %s...", title, snippet_short);
} else {
n = snprintf(resp + off, sizeof resp - off, " (%s)", snippet_short);
snprintf(line, sizeof line, "%s — %s", title, snippet_short);
}
off += n;
} else {
snprintf(line, sizeof line, "%s", title);
}
idx++;
}
irc_reply(s, reply_target, src_nick, resp);
if (idx < result_count) {
irc_reply(s, reply_target, src_nick, "...");
}
cur = results_key;
idx = 0;
while (idx < result_count && idx < 5) {
const char *brace = wp_json_next_array_item(&cur);
if (!brace) break;
char title[256] = "";
wp_json_get_string(brace, "\"title\":", title, sizeof title);
if (!title[0]) { idx++; continue; }
char enc_title[512];
wp_url_encode(title, enc_title, sizeof enc_title);
irc_reply(s, reply_target, src_nick, line);
char link[640];
snprintf(link, sizeof link, "Read full article: https://en.wikipedia.org/wiki/%s", enc_title);
irc_reply(s, reply_target, src_nick, link);
idx++;
shown++;
}
if (idx < result_count) {
irc_reply(s, reply_target, src_nick, "...");
}
}
log_stamp(); fprintf(stderr, CLR_MAGENTA "WP %s from %s:" CLR_RESET " %s\n", reply_target, src_nick, rest);