v0.35.0: add !calc, !time, !seen, !tell commands
New IRC commands: - !calc <expr>: evaluate math via bc -l (arithmetic, powers, trig, log, vars) - !time [tz]: show current time in any IANA timezone - !seen <nick>: track/query last-seen activity (auto-updated on speak/part/quit) - !tell <nick> <msg>: leave offline messages, delivered when target speaks Database: - Added 'seen' table for user activity tracking (nick, timestamp, channel, action) - Added 'tell' table for pending offline messages Other changes: - Updated !help to list all new commands - Updated README.md with detailed docs for all commands including !calc expression syntax and !time timezone examples - Bumped version to 0.35.0
This commit is contained in:
parent
ce8360111f
commit
c554ed60d9
3 changed files with 395 additions and 28 deletions
11
CHANGELOG.md
11
CHANGELOG.md
|
|
@ -1,3 +1,14 @@
|
|||
2026.07.20 – Calculator, time, seen, and tell commands.
|
||||
|
||||
- Added `!calc <expression>` command: evaluate math expressions via `bc -l` (supports arithmetic, powers, trigonometry, logarithms, variables, and multi-statement expressions).
|
||||
- Added `!time [timezone]` command: display current time in any IANA timezone (e.g. `!time US/Pacific`, `!time Europe/Berlin`).
|
||||
- Added `!seen <nick>` command: track and query when users were last seen (auto-updated on PRIVMSG, PART, and QUIT).
|
||||
- Added `!tell <nick> <message>` command: leave offline messages for users, delivered automatically when they next speak.
|
||||
- Added `seen` and `tell` tables to the SQLite database for persistent user tracking and message storage.
|
||||
- Updated `!help` to list all new commands.
|
||||
- Updated README.md with detailed documentation for all commands, including `!calc` expression syntax and `!time` timezone examples.
|
||||
- Version bumped to 0.35.0.
|
||||
|
||||
2026.07.20 – Disabled stripping feature from 0.34.4 because it needs more testing.
|
||||
|
||||
- Disabled `strip_opencode_header()` (introduced in 0.34.4) as it requires further testing.
|
||||
|
|
|
|||
169
README.md
169
README.md
|
|
@ -1,15 +1,23 @@
|
|||
# zynk - Companion AI Logic Chatbot
|
||||
|
||||
A single-file IRC bot in C. Features a key-value store backed by SQLite3, weather lookups via wttr.in, and AI-powered replies.
|
||||
A single-file IRC bot in C. Features a key-value store backed by SQLite3, weather lookups via wttr.in, stock quotes, calculator, time, user tracking, and AI-powered replies.
|
||||
|
||||
## Features
|
||||
|
||||
- **Key-Value Store**: Persist facts, notes, or any data with `zynk key = value`
|
||||
- **Weather**: Current conditions and 3-day forecasts via `wttr.in`
|
||||
- **Stock Quotes**: Real-time stock prices via Yahoo Finance
|
||||
- **Calculator**: Evaluate math expressions with `!calc`
|
||||
- **Time**: Show current time in any timezone with `!time`
|
||||
- **User Tracking**: Track when users were last seen with `!seen`
|
||||
- **Offline Messages**: Leave messages for offline users with `!tell`
|
||||
- **AI Queries**: Ask questions via `!ai` or by addressing the bot; powered by `opencode`
|
||||
- **Code Changes**: AI-powered code editing with auto-recompile and hot reload
|
||||
- **Chat Greetings**: Responds to `hi`, `hello`, `hey`, `bye`, and more
|
||||
- **Hot Reload**: Reload or restart without disconnecting from IRC
|
||||
- **TLS**: Secure connections via OpenSSL
|
||||
- **Rate Limiting**: Per-nick protection against spam
|
||||
- **Reconnection**: Auto-reconnect with exponential backoff
|
||||
- **Single File**: Easy to deploy and modify
|
||||
|
||||
## Requirements
|
||||
|
|
@ -18,7 +26,8 @@ A single-file IRC bot in C. Features a key-value store backed by SQLite3, weathe
|
|||
- `libssl-dev` (OpenSSL)
|
||||
- `libdl` (dynamic linker)
|
||||
- `libsqlite3` (loaded at runtime via `dlopen`)
|
||||
- `curl` (for weather lookups)
|
||||
- `curl` (for weather, forecast, and stock lookups)
|
||||
- `bc` (for the calculator command)
|
||||
- `opencode` (for AI queries)
|
||||
|
||||
## Build
|
||||
|
|
@ -48,8 +57,9 @@ make CC=clang CFLAGS="-O2 -Wall -Wextra"
|
|||
| `-server <host>` | IRC server (default: `irc.libera.chat`) |
|
||||
| `-port <p>` | Port (default: `6697`) |
|
||||
| `-pass <p>` | Server password |
|
||||
| `-nick <n>` | Nickname (default: `calc`) |
|
||||
| `-join <c>` | Auto-join channels, comma-separated (default: `#calctest`) |
|
||||
| `-nick <n>` | Nickname (default: `zynk`) |
|
||||
| `-join <c>` | Auto-join channels, comma-separated (default: `#zynk`) |
|
||||
| `-opencode <p>` | Path to opencode binary (default: `/usr/bin/opencode`) |
|
||||
| `-h` | Show help |
|
||||
|
||||
### Example
|
||||
|
|
@ -60,43 +70,150 @@ make CC=clang CFLAGS="-O2 -Wall -Wextra"
|
|||
|
||||
## IRC Commands
|
||||
|
||||
| Command | Description |
|
||||
|------------------------|-----------------------------------|
|
||||
| `zynk <key>` | Look up a stored value |
|
||||
### General
|
||||
|
||||
| Command | Description |
|
||||
|---|---|
|
||||
| `!help` | List all available commands |
|
||||
| `!version` | Show the bot version |
|
||||
| `!ping` | Responds with `pong` |
|
||||
| `!uptime` | Show bot uptime |
|
||||
| `!quit` / `!die` | Shut down the bot (ops only) |
|
||||
|
||||
### Key-Value Store
|
||||
|
||||
| Command | Description |
|
||||
|---|---|
|
||||
| `zynk <key>` | Look up a stored value |
|
||||
| `zynk <key> = <value>` | Store a value (key is lowercased) |
|
||||
| `!ping` | Responds with `pong` |
|
||||
| `!version` | Show the program version in IRC |
|
||||
| `!weather [city]` | Current weather (default: Berlin) |
|
||||
| `!forecast [city]` | 3-day forecast (default: Berlin) |
|
||||
| `!ai <question>` | Ask the AI a question |
|
||||
| `!quit` / `!die` | Shut down the bot |
|
||||
| `<nick>: hi` | Greeting response |
|
||||
| `<nick>: <question>` | Ask the bot anything (AI) |
|
||||
| `zynk! <key> = <value>` | Overwrite an existing value (ops in channels) |
|
||||
| `zynk` | Get a random stored entry |
|
||||
|
||||
## Installation
|
||||
### Weather & Finance
|
||||
|
||||
```sh
|
||||
make install
|
||||
```
|
||||
| Command | Description |
|
||||
|---|---|
|
||||
| `!weather [city]` | Current weather (default: Berlin) |
|
||||
| `!forecast [city]` | 3-day forecast (default: Berlin) |
|
||||
| `!stock <SYMBOL>[,SYMBOL...]` | Stock quotes, up to 3 symbols (e.g. `!stock AAPL,MSFT`) |
|
||||
|
||||
Installs to `$(PREFIX)/bin` (default: `/usr/local/bin`).
|
||||
### Utilities
|
||||
|
||||
Override the prefix:
|
||||
| Command | Description |
|
||||
|---|---|
|
||||
| `!calc <expression>` | Evaluate math (see below) |
|
||||
| `!time [timezone]` | Show current time (see below) |
|
||||
| `!seen <nick>` | Check when a user was last seen |
|
||||
| `!tell <nick> <message>` | Leave a message for an offline user |
|
||||
|
||||
```sh
|
||||
make install PREFIX=$HOME/.local
|
||||
```
|
||||
#### Time (`!time`)
|
||||
|
||||
Shows the current date and time. Without arguments, displays the bot's local time. With a timezone argument, displays the time in that timezone using POSIX `TZ` format.
|
||||
|
||||
**Output format:** `YYYY-MM-DD HH:MM:SS TZ`
|
||||
|
||||
**Examples:**
|
||||
|
||||
| Command | Description |
|
||||
|---|---|
|
||||
| `!time` | Bot's local time |
|
||||
| `!time UTC` | Current UTC time |
|
||||
| `!time US/Eastern` | US Eastern time |
|
||||
| `!time US/Pacific` | US Pacific time |
|
||||
| `!time Europe/Berlin` | Central European time |
|
||||
| `!time Europe/London` | UK time |
|
||||
| `!time Asia/Tokyo` | Japan time |
|
||||
| `!time Australia/Sydney` | Australian Eastern time |
|
||||
|
||||
Any timezone name from the IANA/Olson timezone database works. Common examples: `UTC`, `US/Eastern`, `US/Central`, `US/Pacific`, `Europe/Berlin`, `Europe/London`, `Europe/Paris`, `Asia/Tokyo`, `Asia/Shanghai`, `Asia/Kolkata`, `Australia/Sydney`, `Pacific/Auckland`.
|
||||
|
||||
#### Calculator (`!calc`)
|
||||
|
||||
The calculator uses `bc -l` (POSIX arbitrary-precision calculator with the math library). Any valid `bc` expression works.
|
||||
|
||||
**Basic arithmetic:**
|
||||
|
||||
| Expression | Result |
|
||||
|---|---|
|
||||
| `!calc 2+2` | `4` |
|
||||
| `!calc 100-37` | `63` |
|
||||
| `!calc 6*7` | `42` |
|
||||
| `!calc 100/3` | `33.3333333333333333333` |
|
||||
| `!calc 10%3` | `1` |
|
||||
|
||||
**Parentheses for grouping:**
|
||||
|
||||
| Expression | Result |
|
||||
|---|---|
|
||||
| `!calc (3+7)*2` | `20` |
|
||||
| `!calc (100-50)/5` | `10` |
|
||||
|
||||
**Powers:**
|
||||
|
||||
| Expression | Result |
|
||||
|---|---|
|
||||
| `!calc 2^10` | `1024` |
|
||||
| `!calc 3^3` | `27` |
|
||||
|
||||
**Math library functions** (enabled by `-l`):
|
||||
|
||||
| Expression | Description |
|
||||
|---|---|
|
||||
| `!calc s(1)` | Sine of 1 (radians) |
|
||||
| `!calc c(0)` | Cosine of 0 |
|
||||
| `!calc a(1)` | Arctangent of 1 |
|
||||
| `!calc l(100)` | Natural logarithm of 100 |
|
||||
| `!calc e(1)` | e^1 |
|
||||
|
||||
**Scale (decimal places):**
|
||||
|
||||
| Expression | Description |
|
||||
|---|---|
|
||||
| `!calc scale=4; 1/3` | `0.3333` |
|
||||
|
||||
**Variables and multi-statement:**
|
||||
|
||||
| Expression | Description |
|
||||
|---|---|
|
||||
| `!calc x=5; x*2` | `10` |
|
||||
| `!calc 2+2; 3*3` | `4` (first line of output) |
|
||||
|
||||
### AI
|
||||
|
||||
| Command | Description |
|
||||
|---|---|
|
||||
| `!ai <question>` | Ask the AI a question (plan mode, read-only) |
|
||||
| `!code <instruction>` | AI code change with auto-recompile (ops only, in channels) |
|
||||
| `<nick>: <question>` | Address the bot by nick to ask the AI |
|
||||
|
||||
### Admin (Ops Only)
|
||||
|
||||
| Command | Description |
|
||||
|---|---|
|
||||
| `!reload` | Hot reload (save TLS state, fork new process) |
|
||||
| `!restart` | Restart the bot |
|
||||
| `!code <instruction>` | Make AI-powered code changes |
|
||||
|
||||
### Chat
|
||||
|
||||
| Command | Description |
|
||||
|---|---|
|
||||
| `<nick>: hi/hello/hey` | Greeting response |
|
||||
| `<nick>: bye` | Farewell response |
|
||||
| `<nick>: <anything>` | AI-powered conversation |
|
||||
|
||||
## Database
|
||||
|
||||
Data is stored in `zynk.db` (SQLite3) in the working directory. The bot creates two tables:
|
||||
Data is stored in `zynk.db` (SQLite3) in the working directory. The bot creates four tables:
|
||||
|
||||
- `zynk` - key-value pairs with nick and timestamp metadata
|
||||
- `ai_pending` - single-row table for managing in-flight AI queries
|
||||
- `seen` - tracks when users were last seen (nick, timestamp, channel, action)
|
||||
- `tell` - stores pending offline messages for delivery
|
||||
|
||||
## Architecture
|
||||
|
||||
`zynk` uses a single `poll()` loop with a 100ms timeout. AI queries fork a child process that runs the `opencode` CLI; the parent picks up the result on the next poll iteration. SQLite3 is loaded at runtime via `dlopen` to avoid a compile-time dependency.
|
||||
`zynk` uses a single `poll()` loop with a 100ms timeout. AI queries fork a child process that runs the `opencode` CLI; the parent picks up the result on the next poll iteration. SQLite3 is loaded at runtime via `dlopen` to avoid a compile-time dependency. The bot supports hot reload: `!reload` and `!restart` save TLS session state, fork a new process with the inherited socket, and resume without dropping from IRC.
|
||||
|
||||
## License
|
||||
|
||||
|
|
|
|||
243
zynk.c
243
zynk.c
|
|
@ -29,7 +29,7 @@ int asprintf(char **, const char *, ...);
|
|||
|
||||
/* ---- constants ---- */
|
||||
|
||||
#define VERSION "0.34.5"
|
||||
#define VERSION "0.35.0"
|
||||
#define DEFAULT_SERVER "irc.libera.chat"
|
||||
#define OPENCODE_BIN "/usr/bin/opencode"
|
||||
#define CLR_RESET "\033[0m"
|
||||
|
|
@ -76,6 +76,8 @@ typedef struct {
|
|||
/* ---- forward declarations ---- */
|
||||
|
||||
static void irc_msg(Session *, const char *, const char *);
|
||||
static void seen_update(const char *, const char *, const char *);
|
||||
static void tell_deliver(Session *, const char *, const char *);
|
||||
|
||||
/* ---- logging ---- */
|
||||
|
||||
|
|
@ -230,6 +232,13 @@ static int db_init(void) {
|
|||
db_close_cleanup();
|
||||
return -1;
|
||||
}
|
||||
const char *sql_seen = "CREATE TABLE IF NOT EXISTS seen ("
|
||||
"nick TEXT PRIMARY KEY, last_seen TEXT, last_channel TEXT, last_action TEXT)";
|
||||
db_exec(DB, sql_seen, NULL, NULL, NULL);
|
||||
const char *sql_tell = "CREATE TABLE IF NOT EXISTS tell ("
|
||||
"id INTEGER PRIMARY KEY, from_nick TEXT, to_nick TEXT, "
|
||||
"message TEXT, created_at TEXT DEFAULT (datetime('now')))";
|
||||
db_exec(DB, sql_tell, NULL, NULL, NULL);
|
||||
const char *sql_clear_ai = "DELETE FROM ai_pending";
|
||||
db_exec(DB, sql_clear_ai, NULL, NULL, NULL);
|
||||
const char *sql_clear = "DELETE FROM zynk WHERE key LIKE 'lastq%' OR key LIKE 'lasta%'";
|
||||
|
|
@ -574,6 +583,70 @@ static void ai_reset(long long id) {
|
|||
db_finalize(stmt);
|
||||
}
|
||||
|
||||
/* ---- DB seen/tell operations ---- */
|
||||
|
||||
static void seen_update(const char *nick, const char *channel, const char *action) {
|
||||
void *stmt;
|
||||
const char *sql = "INSERT INTO seen(nick,last_seen,last_channel,last_action)"
|
||||
" VALUES(?,datetime('now'),?,?)"
|
||||
" ON CONFLICT(nick) DO UPDATE SET last_seen=datetime('now'),"
|
||||
" last_channel=excluded.last_channel, last_action=excluded.last_action";
|
||||
if (db_prepare(DB, sql, -1, &stmt, NULL) != SQLITE_OK) return;
|
||||
db_bind_text(stmt, 1, nick, -1, SQLITE_STATIC);
|
||||
db_bind_text(stmt, 2, channel ? channel : "", -1, SQLITE_STATIC);
|
||||
db_bind_text(stmt, 3, action ? action : "spoke", -1, SQLITE_STATIC);
|
||||
db_step(stmt);
|
||||
db_finalize(stmt);
|
||||
}
|
||||
|
||||
static char *seen_lookup(const char *nick) {
|
||||
void *stmt;
|
||||
const char *sql = "SELECT last_seen, last_channel, last_action FROM seen WHERE nick=?";
|
||||
if (db_prepare(DB, sql, -1, &stmt, NULL) != SQLITE_OK) return NULL;
|
||||
db_bind_text(stmt, 1, nick, -1, SQLITE_STATIC);
|
||||
if (db_step(stmt) != SQLITE_ROW) { db_finalize(stmt); return NULL; }
|
||||
const char *t = (const char*)db_column_text(stmt, 0);
|
||||
const char *c = (const char*)db_column_text(stmt, 1);
|
||||
const char *a = (const char*)db_column_text(stmt, 2);
|
||||
char *r = NULL;
|
||||
if (asprintf(&r, "%s was last seen %s %s %s", nick, a ? a : "in", c ? c : "?", t ? t : "unknown") < 0) r = NULL;
|
||||
db_finalize(stmt);
|
||||
return r;
|
||||
}
|
||||
|
||||
static void tell_add(const char *from, const char *to, const char *msg) {
|
||||
void *stmt;
|
||||
const char *sql = "INSERT INTO tell(from_nick,to_nick,message) VALUES(?,?,?)";
|
||||
if (db_prepare(DB, sql, -1, &stmt, NULL) != SQLITE_OK) return;
|
||||
db_bind_text(stmt, 1, from, -1, SQLITE_STATIC);
|
||||
db_bind_text(stmt, 2, to, -1, SQLITE_STATIC);
|
||||
db_bind_text(stmt, 3, msg, -1, SQLITE_STATIC);
|
||||
db_step(stmt);
|
||||
db_finalize(stmt);
|
||||
}
|
||||
|
||||
static void tell_deliver(Session *s, const char *nick, const char *channel) {
|
||||
void *stmt;
|
||||
const char *sql = "SELECT id, from_nick, message FROM tell WHERE to_nick=? ORDER BY id ASC";
|
||||
if (db_prepare(DB, sql, -1, &stmt, NULL) != SQLITE_OK) return;
|
||||
db_bind_text(stmt, 1, nick, -1, SQLITE_STATIC);
|
||||
while (db_step(stmt) == SQLITE_ROW) {
|
||||
long long id = 0;
|
||||
const void *idcol = db_column_text(stmt, 0);
|
||||
if (idcol) id = atoll((const char*)idcol);
|
||||
const char *from = (const char*)db_column_text(stmt, 1);
|
||||
const char *msg = (const char*)db_column_text(stmt, 2);
|
||||
char buf[1024];
|
||||
snprintf(buf, sizeof buf, "%s: message from %s: %s", nick, from ? from : "?", msg ? msg : "");
|
||||
irc_msg(s, channel, buf);
|
||||
char dsql[128];
|
||||
snprintf(dsql, sizeof dsql, "DELETE FROM tell WHERE id=%lld", id);
|
||||
void *dstmt;
|
||||
if (db_prepare(DB, dsql, -1, &dstmt, NULL) == SQLITE_OK) { db_step(dstmt); db_finalize(dstmt); }
|
||||
}
|
||||
db_finalize(stmt);
|
||||
}
|
||||
|
||||
/* ---- channel op tracking ---- */
|
||||
|
||||
typedef struct { char name[64]; char ops[MAX_CHAN_OPS][32]; int nops; } ChanEntry;
|
||||
|
|
@ -2130,7 +2203,7 @@ static int cmd_help(Session *s, const char *msg, const char *reply_target, const
|
|||
if (rate_limit_check(src_nick) < 0) return 1;
|
||||
char buf[512];
|
||||
snprintf(buf, sizeof buf,
|
||||
"Commands: !help, !version, !ping, !uptime, !weather [city], !forecast [city], !stock <SYMBOL>[,SYMBOL...], !ai <question>, !code <change> (ops), !reload (ops), !restart (ops), !quit/!die (ops)");
|
||||
"Commands: !help, !version, !ping, !uptime, !weather [city], !forecast [city], !stock <SYMBOL>, !calc <expr>, !time [tz], !seen <nick>, !tell <nick> <msg>, !ai <question>, !code <change> (ops), !reload (ops), !restart (ops), !quit/!die (ops)");
|
||||
irc_msg(s, reply_target, buf);
|
||||
log_stamp(); fprintf(stderr, CLR_CYAN "HELP from %s in %s" CLR_RESET "\n", src_nick, reply_target);
|
||||
return 1;
|
||||
|
|
@ -2484,6 +2557,164 @@ static int cmd_restart(Session *s, const char *msg, const char *reply_target, co
|
|||
*
|
||||
* Returns: void.
|
||||
*/
|
||||
static int cmd_calc(Session *s, const char *msg, const char *reply_target, const char *src_nick) {
|
||||
if (strncmp(msg, "!calc", 5) != 0) return 0;
|
||||
if (msg[5] != ' ' && msg[5] != '\0') return 0;
|
||||
if (rate_limit_check(src_nick) < 0) return 1;
|
||||
const char *rest = msg[5] == ' ' ? msg + 6 : "";
|
||||
while (*rest == ' ') rest++;
|
||||
if (!*rest) {
|
||||
irc_msg(s, reply_target, "Usage: !calc <expression> (e.g. !calc 2+2, !calc (3*7)+1)");
|
||||
return 1;
|
||||
}
|
||||
int fd[2];
|
||||
if (pipe(fd) < 0) { irc_msg(s, reply_target, "Calc: internal error"); return 1; }
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) { close(fd[0]); close(fd[1]); irc_msg(s, reply_target, "Calc: fork failed"); return 1; }
|
||||
if (pid == 0) {
|
||||
close(fd[0]);
|
||||
dup2(fd[1], STDOUT_FILENO);
|
||||
dup2(fd[1], STDERR_FILENO);
|
||||
close(fd[1]);
|
||||
int dn = open("/dev/null", O_WRONLY);
|
||||
if (dn >= 0) { dup2(dn, STDERR_FILENO); close(dn); }
|
||||
execlp("bc", "bc", "-l", (char *)NULL);
|
||||
_exit(127);
|
||||
}
|
||||
close(fd[1]);
|
||||
char buf[512], tmp[256];
|
||||
size_t len = 0;
|
||||
ssize_t n;
|
||||
while ((n = read(fd[0], tmp, sizeof tmp - 1)) > 0) {
|
||||
tmp[n] = 0;
|
||||
size_t avail = sizeof buf - 1 - len;
|
||||
if (avail > 0) {
|
||||
size_t copy = (size_t)n < avail ? (size_t)n : avail;
|
||||
memcpy(buf + len, tmp, copy);
|
||||
len += copy;
|
||||
}
|
||||
}
|
||||
close(fd[0]);
|
||||
int status;
|
||||
waitpid(pid, &status, 0);
|
||||
while (len > 0 && (buf[len-1] == '\n' || buf[len-1] == '\r')) len--;
|
||||
buf[len] = 0;
|
||||
char *nl = strchr(buf, '\n');
|
||||
if (nl) *nl = 0;
|
||||
if (len == 0) {
|
||||
irc_msg(s, reply_target, "Calc: no result (check expression syntax)");
|
||||
} else {
|
||||
char resp[640];
|
||||
snprintf(resp, sizeof resp, "%s: %s", src_nick, buf);
|
||||
irc_msg(s, reply_target, resp);
|
||||
}
|
||||
log_stamp(); fprintf(stderr, CLR_YELLOW "CALC %s from %s:" CLR_RESET " %s\n", reply_target, src_nick, rest);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cmd_time(Session *s, const char *msg, const char *reply_target, const char *src_nick) {
|
||||
if (strncmp(msg, "!time", 5) != 0) return 0;
|
||||
if (msg[5] != ' ' && msg[5] != '\0') return 0;
|
||||
if (rate_limit_check(src_nick) < 0) return 1;
|
||||
time_t now = time(NULL);
|
||||
struct tm *tm;
|
||||
char resp[256];
|
||||
const char *rest = msg[5] == ' ' ? msg + 6 : "";
|
||||
while (*rest == ' ') rest++;
|
||||
if (*rest) {
|
||||
char tzname[64];
|
||||
size_t tl = 0;
|
||||
for (const char *p = rest; *p && tl < sizeof tzname - 1 && *p != ' '; p++)
|
||||
tzname[tl++] = *p;
|
||||
tzname[tl] = 0;
|
||||
char *old_tz = getenv("TZ");
|
||||
char old_tz_buf[256] = "";
|
||||
if (old_tz) { strncpy(old_tz_buf, old_tz, sizeof old_tz_buf - 1); old_tz_buf[sizeof old_tz_buf - 1] = 0; }
|
||||
setenv("TZ", tzname, 1);
|
||||
tzset();
|
||||
tm = localtime(&now);
|
||||
char buf[64];
|
||||
strftime(buf, sizeof buf, "%Y-%m-%d %H:%M:%S %Z", tm);
|
||||
if (old_tz_buf[0]) setenv("TZ", old_tz_buf, 1); else unsetenv("TZ");
|
||||
tzset();
|
||||
snprintf(resp, sizeof resp, "%s: %s %s", src_nick, tzname, buf);
|
||||
} else {
|
||||
tm = localtime(&now);
|
||||
char buf[64];
|
||||
strftime(buf, sizeof buf, "%Y-%m-%d %H:%M:%S %Z", tm);
|
||||
snprintf(resp, sizeof resp, "%s: %s", src_nick, buf);
|
||||
}
|
||||
irc_msg(s, reply_target, resp);
|
||||
log_stamp(); fprintf(stderr, CLR_YELLOW "TIME from %s in %s" CLR_RESET "\n", src_nick, reply_target);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cmd_seen(Session *s, const char *msg, const char *reply_target, const char *src_nick) {
|
||||
if (strncmp(msg, "!seen", 5) != 0) return 0;
|
||||
if (msg[5] != ' ') return 0;
|
||||
if (rate_limit_check(src_nick) < 0) return 1;
|
||||
const char *rest = msg + 6;
|
||||
while (*rest == ' ') rest++;
|
||||
if (!*rest) {
|
||||
irc_msg(s, reply_target, "Usage: !seen <nick>");
|
||||
return 1;
|
||||
}
|
||||
char target[32];
|
||||
int i = 0;
|
||||
while (*rest && *rest != ' ' && i < 31) target[i++] = *rest++;
|
||||
target[i] = 0;
|
||||
if (strcasecmp(target, src_nick) == 0) {
|
||||
irc_msg(s, reply_target, "You are right here, duh!");
|
||||
return 1;
|
||||
}
|
||||
if (strcasecmp(target, s->nick) == 0) {
|
||||
irc_msg(s, reply_target, "I am right here!");
|
||||
return 1;
|
||||
}
|
||||
char *result = seen_lookup(target);
|
||||
if (result) {
|
||||
irc_msg(s, reply_target, result);
|
||||
free(result);
|
||||
} else {
|
||||
char resp[128];
|
||||
snprintf(resp, sizeof resp, "I have never seen %s", target);
|
||||
irc_msg(s, reply_target, resp);
|
||||
}
|
||||
log_stamp(); fprintf(stderr, CLR_CYAN "SEEN %s from %s in %s" CLR_RESET "\n", target, src_nick, reply_target);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cmd_tell(Session *s, const char *msg, const char *reply_target, const char *src_nick) {
|
||||
if (strncmp(msg, "!tell", 5) != 0) return 0;
|
||||
if (msg[5] != ' ') return 0;
|
||||
if (rate_limit_check(src_nick) < 0) return 1;
|
||||
const char *rest = msg + 6;
|
||||
while (*rest == ' ') rest++;
|
||||
if (!*rest) {
|
||||
irc_msg(s, reply_target, "Usage: !tell <nick> <message>");
|
||||
return 1;
|
||||
}
|
||||
char target[32];
|
||||
int i = 0;
|
||||
while (*rest && *rest != ' ' && i < 31) target[i++] = *rest++;
|
||||
target[i] = 0;
|
||||
while (*rest == ' ') rest++;
|
||||
if (!*rest) {
|
||||
irc_msg(s, reply_target, "Usage: !tell <nick> <message>");
|
||||
return 1;
|
||||
}
|
||||
if (strcasecmp(target, src_nick) == 0) {
|
||||
irc_msg(s, reply_target, "You can't tell yourself something!");
|
||||
return 1;
|
||||
}
|
||||
tell_add(src_nick, target, rest);
|
||||
char resp[256];
|
||||
snprintf(resp, sizeof resp, "Ok, I'll tell %s when they're around.", target);
|
||||
irc_msg(s, reply_target, resp);
|
||||
log_stamp(); fprintf(stderr, CLR_CYAN "TELL %s from %s in %s:" CLR_RESET " -> %s: %s\n", reply_target, src_nick, reply_target, target, rest);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void cmd_greeting_or_chat(Session *s, const char *msg, const char *reply_target, const char *src_nick) {
|
||||
int nicklen = strlen(s->nick);
|
||||
const char *cmd = msg;
|
||||
|
|
@ -2551,6 +2782,8 @@ static void handle_privmsg(Session *s, const char *params, const char *src_nick)
|
|||
if (*p == ':') p++;
|
||||
const char *msg = p;
|
||||
if (strcasecmp(src_nick, s->nick) == 0) return;
|
||||
seen_update(src_nick, tgt, "spoke");
|
||||
tell_deliver(s, src_nick, (tgt[0] == '#') ? tgt : src_nick);
|
||||
const char *reply_target = (tgt[0] == '#') ? tgt : src_nick;
|
||||
if (cmd_zynk(s, msg, reply_target, src_nick, tgt)) return;
|
||||
if (cmd_ping(s, msg, reply_target, src_nick)) return;
|
||||
|
|
@ -2561,6 +2794,10 @@ static void handle_privmsg(Session *s, const char *params, const char *src_nick)
|
|||
if (cmd_weather(s, msg, reply_target, src_nick)) return;
|
||||
if (cmd_forecast(s, msg, reply_target, src_nick)) return;
|
||||
if (cmd_stock(s, msg, reply_target, src_nick)) return;
|
||||
if (cmd_calc(s, msg, reply_target, src_nick)) return;
|
||||
if (cmd_time(s, msg, reply_target, src_nick)) return;
|
||||
if (cmd_seen(s, msg, reply_target, src_nick)) return;
|
||||
if (cmd_tell(s, msg, reply_target, src_nick)) return;
|
||||
if (cmd_ai(s, msg, reply_target, src_nick)) return;
|
||||
if (cmd_code(s, msg, reply_target, src_nick, tgt)) return;
|
||||
if (cmd_reload(s, msg, reply_target, src_nick, tgt)) return;
|
||||
|
|
@ -2674,6 +2911,7 @@ static void handle_part(const char *params, const char *src_nick) {
|
|||
char _chan[64];
|
||||
if (sscanf(params, "%63s", _chan) >= 1)
|
||||
chan_del_op(_chan, src_nick);
|
||||
seen_update(src_nick, _chan, "left");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -2708,6 +2946,7 @@ static void handle_kick(const char *params) {
|
|||
static void handle_quit_net(const char *src_nick) {
|
||||
for (int i = 0; i < nchans; i++)
|
||||
chan_del_op(chans[i].name, src_nick);
|
||||
seen_update(src_nick, NULL, "quit");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue