2
0
Fork 0
forked from zynk/zynk

Renamed calc to zynk and refactored all relevant parts.

This commit is contained in:
Johannes Findeisen 2026-07-14 23:52:56 +02:00
commit 2247b9a480
5 changed files with 63 additions and 63 deletions

6
.gitignore vendored
View file

@ -1,7 +1,7 @@
.idea/ .idea/
calc zynk
calc.db zynk.db
*.so *.so
*.o *.o
*.swp

View file

@ -1,19 +1,19 @@
# AGENTS.md — calc # AGENTS.md — zynk
## Project Overview ## Project Overview
`calc` is a single-file IRC bot written in C. It connects to an IRC server, maintains a key-value store via SQLite3 (loaded dynamically at runtime), and responds to commands in channels and private messages. `zynk` is a single-file IRC bot written in C. It connects to an IRC server, maintains a key-value store via SQLite3 (loaded dynamically at runtime), and responds to commands in channels and private messages.
## Build & Run ## Build & Run
- **Build**: `make` (uses `gcc`, requires `libssl-dev` / `libcrypto` / `libdl`) - **Build**: `make` (uses `gcc`, requires `libssl-dev` / `libcrypto` / `libdl`)
- **Run**: `./calc -ssl -nick mybot -join "#chan1,#chan2"` - **Run**: `./zynk -ssl -nick mybot -join "#chan1,#chan2"`
- **Clean**: `make clean` - **Clean**: `make clean`
- **Install**: `make install` - **Install**: `make install`
## Code Style ## Code Style
- C99/C11, single file (`calc.c`) - C99/C11, single file (`zynk.c`)
- No comments in new code unless clarifying a non-obvious edge case - No comments in new code unless clarifying a non-obvious edge case
- Error strings use ANSI color macros (`CLR_RED`, `CLR_GREEN`, etc.) - Error strings use ANSI color macros (`CLR_RED`, `CLR_GREEN`, etc.)
- 2-space indentation, K&R brace style - 2-space indentation, K&R brace style
@ -24,19 +24,19 @@
## Project Structure ## Project Structure
``` ```
calc/ zynk/
calc.c — single-file IRC bot (1129 lines) zynk.c — single-file IRC bot (1129 lines)
Makefile — build system Makefile — build system
.gitignore .gitignore
AGENTS.md — this file AGENTS.md — this file
README.md — user-facing docs README.md — user-facing docs
``` ```
## Key Modules in calc.c ## Key Modules in zynk.c
### SQLite3 Integration (lines 40–228) ### SQLite3 Integration (lines 40–228)
- Dynamically loads `libsqlite3.so.0` from common paths - Dynamically loads `libsqlite3.so.0` from common paths
- Tables: `calc` (key-value store), `ai_pending` (pending AI queries) - Tables: `zynk` (key-value store), `ai_pending` (pending AI queries)
- Functions: `db_set`, `db_get`, `db_get_raw`, `db_update_lastq`, `db_update_lasta` - Functions: `db_set`, `db_get`, `db_get_raw`, `db_update_lastq`, `db_update_lasta`
### IRC Session (lines 303–317) ### IRC Session (lines 303–317)
@ -72,8 +72,8 @@ calc/
| Command | Description | | Command | Description |
|---|---| |---|---|
| `calc <key>` | Look up a stored value | | `zynk <key>` | Look up a stored value |
| `calc <key> = <value>` | Store a value | | `zynk <key> = <value>` | Store a value |
| `!ping` | Responds with pong | | `!ping` | Responds with pong |
| `!weather [city]` | Current weather (default: Berlin) | | `!weather [city]` | Current weather (default: Berlin) |
| `!forecast [city]` | 3-day forecast | | `!forecast [city]` | 3-day forecast |
@ -87,5 +87,5 @@ calc/
- Do NOT add `#include` that aren't strictly needed - Do NOT add `#include` that aren't strictly needed
- Do NOT add comments to obvious code - Do NOT add comments to obvious code
- Match existing style: 2-space indent, no trailing whitespace - Match existing style: 2-space indent, no trailing whitespace
- Test with `make && ./calc -h` - Test with `make && ./zynk -h`
- Keep the single-file structure unless there's a strong reason to split - Keep the single-file structure unless there's a strong reason to split

View file

@ -14,18 +14,18 @@ endif
.PHONY: all clean install uninstall .PHONY: all clean install uninstall
all: calc all: zynk
calc: calc.c calc: zynk.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
clean: clean:
rm -vf calc rm -vf zynk
install: calc install: calc
mkdir -p $(DESTDIR)$(BINDIR) mkdir -p $(DESTDIR)$(BINDIR)
cp calc $(DESTDIR)$(BINDIR)/calc cp calc $(DESTDIR)$(BINDIR)/zynk
uninstall: uninstall:
rm -vf $(DESTDIR)$(BINDIR)/calc rm -vf $(DESTDIR)$(BINDIR)/zynk

View file

@ -1,10 +1,10 @@
# calc - Companion AI Logic Chatbot # 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, and AI-powered replies.
## Features ## Features
- **Key-Value Store**: Persist facts, notes, or any data with `calc key = value` - **Key-Value Store**: Persist facts, notes, or any data with `zynk key = value`
- **Weather**: Current conditions and 3-day forecasts via `wttr.in` - **Weather**: Current conditions and 3-day forecasts via `wttr.in`
- **AI Queries**: Ask questions via `!ai` or by addressing the bot; powered by `opencode` - **AI Queries**: Ask questions via `!ai` or by addressing the bot; powered by `opencode`
- **Chat Greetings**: Responds to `hi`, `hello`, `hey`, `bye`, and more - **Chat Greetings**: Responds to `hi`, `hello`, `hey`, `bye`, and more
@ -19,7 +19,7 @@ A single-file IRC bot in C. Features a key-value store backed by SQLite3, weathe
- `libdl` (dynamic linker) - `libdl` (dynamic linker)
- `libsqlite3` (loaded at runtime via `dlopen`) - `libsqlite3` (loaded at runtime via `dlopen`)
- `curl` (for weather lookups) - `curl` (for weather lookups)
- `opencode` (for AI queries - see `calc.c:229` to configure path) - `opencode` (for AI queries)
## Build ## Build
@ -36,7 +36,7 @@ make CC=clang CFLAGS="-O2 -Wall -Wextra"
## Usage ## Usage
```sh ```sh
./calc [options] ./zynk [options]
``` ```
### Options ### Options
@ -55,15 +55,15 @@ make CC=clang CFLAGS="-O2 -Wall -Wextra"
### Example ### Example
```sh ```sh
./calc -ssl -nick mybot -join "#mychan,#myotherchan" ./zynk -ssl -nick mybot -join "#mychan,#myotherchan"
``` ```
## IRC Commands ## IRC Commands
| Command | Description | | Command | Description |
|---|---| |---|---|
| `calc <key>` | Look up a stored value | | `zynk <key>` | Look up a stored value |
| `calc <key> = <value>` | Store a value (key is lowercased) | | `zynk <key> = <value>` | Store a value (key is lowercased) |
| `!ping` | Responds with `pong` | | `!ping` | Responds with `pong` |
| `!weather [city]` | Current weather (default: Berlin) | | `!weather [city]` | Current weather (default: Berlin) |
| `!forecast [city]` | 3-day forecast (default: Berlin) | | `!forecast [city]` | 3-day forecast (default: Berlin) |
@ -88,14 +88,14 @@ make install PREFIX=$HOME/.local
## Database ## Database
Data is stored in `calc.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 two tables:
- `calc` - key-value pairs with nick and timestamp metadata - `zynk` - key-value pairs with nick and timestamp metadata
- `ai_pending` - single-row table for managing in-flight AI queries - `ai_pending` - single-row table for managing in-flight AI queries
## Architecture ## Architecture
`calc` 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.
## License ## License

View file

@ -157,14 +157,14 @@ static int sqlite_init_lib(void) {
static int db_init(void) { static int db_init(void) {
if (sqlite_init_lib() < 0) { fprintf(stderr, CLR_RED "Cannot load libsqlite3" CLR_RESET "\n"); return -1; } if (sqlite_init_lib() < 0) { fprintf(stderr, CLR_RED "Cannot load libsqlite3" CLR_RESET "\n"); return -1; }
if (db_open("calc.db", &db_handle) != SQLITE_OK) { if (db_open("zynk.db", &db_handle) != SQLITE_OK) {
fprintf(stderr, CLR_RED "DB open failed" CLR_RESET "\n"); return -1; fprintf(stderr, CLR_RED "DB open failed" CLR_RESET "\n"); return -1;
} }
const char *sql_calc = "CREATE TABLE IF NOT EXISTS calc (" const char *sql_zynk = "CREATE TABLE IF NOT EXISTS zynk ("
"key TEXT PRIMARY KEY, value TEXT NOT NULL, " "key TEXT PRIMARY KEY, value TEXT NOT NULL, "
"nick TEXT NOT NULL, updated_at TEXT DEFAULT (datetime('now')))"; "nick TEXT NOT NULL, updated_at TEXT DEFAULT (datetime('now')))";
char *err = NULL; char *err = NULL;
if (db_exec(DB, sql_calc, NULL, NULL, &err) != SQLITE_OK) { if (db_exec(DB, sql_zynk, NULL, NULL, &err) != SQLITE_OK) {
fprintf(stderr, CLR_RED "SQL: %s" CLR_RESET "\n", err); db_free(err); return -1; fprintf(stderr, CLR_RED "SQL: %s" CLR_RESET "\n", err); db_free(err); return -1;
} }
const char *sql_ai = "CREATE TABLE IF NOT EXISTS ai_pending (" const char *sql_ai = "CREATE TABLE IF NOT EXISTS ai_pending ("
@ -175,7 +175,7 @@ static int db_init(void) {
} }
const char *sql_clear_ai = "DELETE FROM ai_pending"; const char *sql_clear_ai = "DELETE FROM ai_pending";
db_exec(DB, sql_clear_ai, NULL, NULL, NULL); db_exec(DB, sql_clear_ai, NULL, NULL, NULL);
const char *sql_clear = "DELETE FROM calc WHERE key LIKE 'lastq%' OR key LIKE 'lasta%'"; const char *sql_clear = "DELETE FROM zynk WHERE key LIKE 'lastq%' OR key LIKE 'lasta%'";
db_exec(DB, sql_clear, NULL, NULL, NULL); db_exec(DB, sql_clear, NULL, NULL, NULL);
return 0; return 0;
} }
@ -186,7 +186,7 @@ static void db_close_cleanup(void) { if (db_handle) { db_close(DB); db_handle =
static int db_set(const char *key, const char *value, const char *nick) { static int db_set(const char *key, const char *value, const char *nick) {
void *stmt; void *stmt;
const char *sql = "INSERT INTO calc(key,value,nick,updated_at)" const char *sql = "INSERT INTO zynk(key,value,nick,updated_at)"
" VALUES(?,?,?,datetime('now'))" " VALUES(?,?,?,datetime('now'))"
" ON CONFLICT(key) DO UPDATE SET value=excluded.value," " ON CONFLICT(key) DO UPDATE SET value=excluded.value,"
" nick=excluded.nick, updated_at=datetime('now')"; " nick=excluded.nick, updated_at=datetime('now')";
@ -201,7 +201,7 @@ static int db_set(const char *key, const char *value, const char *nick) {
static char *db_get_raw(const char *key) { static char *db_get_raw(const char *key) {
void *stmt; void *stmt;
const char *sql = "SELECT value FROM calc WHERE key=?"; const char *sql = "SELECT value FROM zynk WHERE key=?";
if (db_prepare(DB, sql, -1, &stmt, NULL) != SQLITE_OK) return NULL; if (db_prepare(DB, sql, -1, &stmt, NULL) != SQLITE_OK) return NULL;
db_bind_text(stmt, 1, key, -1, SQLITE_STATIC); db_bind_text(stmt, 1, key, -1, SQLITE_STATIC);
if (db_step(stmt) != SQLITE_ROW) { db_finalize(stmt); return NULL; } if (db_step(stmt) != SQLITE_ROW) { db_finalize(stmt); return NULL; }
@ -213,7 +213,7 @@ static char *db_get_raw(const char *key) {
static char *db_get(const char *key) { static char *db_get(const char *key) {
void *stmt; void *stmt;
const char *sql = "SELECT value,nick,updated_at FROM calc WHERE key=?"; const char *sql = "SELECT value,nick,updated_at FROM zynk WHERE key=?";
if (db_prepare(DB, sql, -1, &stmt, NULL) != SQLITE_OK) return NULL; if (db_prepare(DB, sql, -1, &stmt, NULL) != SQLITE_OK) return NULL;
db_bind_text(stmt, 1, key, -1, SQLITE_STATIC); db_bind_text(stmt, 1, key, -1, SQLITE_STATIC);
if (db_step(stmt) != SQLITE_ROW) { db_finalize(stmt); return NULL; } if (db_step(stmt) != SQLITE_ROW) { db_finalize(stmt); return NULL; }
@ -228,7 +228,7 @@ static char *db_get(const char *key) {
static char *db_get_random(void) { static char *db_get_random(void) {
void *stmt; void *stmt;
const char *sql = "SELECT key,value,nick,updated_at FROM calc" const char *sql = "SELECT key,value,nick,updated_at FROM zynk"
" WHERE key NOT LIKE 'lastq%' AND key NOT LIKE 'lasta%'" " WHERE key NOT LIKE 'lastq%' AND key NOT LIKE 'lasta%'"
" ORDER BY RANDOM() LIMIT 1"; " ORDER BY RANDOM() LIMIT 1";
if (db_prepare(DB, sql, -1, &stmt, NULL) != SQLITE_OK) return NULL; if (db_prepare(DB, sql, -1, &stmt, NULL) != SQLITE_OK) return NULL;
@ -252,7 +252,7 @@ static void db_rotate_history(const char *prefix, const char *value) {
old[i] = db_get_raw(kbuf[i]); old[i] = db_get_raw(kbuf[i]);
} }
void *stmt; void *stmt;
const char *sql = "INSERT INTO calc(key,value,nick,updated_at)" const char *sql = "INSERT INTO zynk(key,value,nick,updated_at)"
" VALUES(?,?,?,datetime('now'))" " VALUES(?,?,?,datetime('now'))"
" ON CONFLICT(key) DO UPDATE SET value=excluded.value," " ON CONFLICT(key) DO UPDATE SET value=excluded.value,"
" nick=excluded.nick, updated_at=datetime('now')"; " nick=excluded.nick, updated_at=datetime('now')";
@ -748,7 +748,7 @@ static void ai_child_task(Session *s, long long id) {
s->ssl = NULL; s->ssl = NULL;
db_close(DB); db_close(DB);
db_handle = NULL; db_handle = NULL;
if (db_open("calc.db", &db_handle) != SQLITE_OK) exit(1); if (db_open("zynk.db", &db_handle) != SQLITE_OK) exit(1);
char *q = ai_get_question(id); char *q = ai_get_question(id);
if (!q) { db_close(DB); exit(1); } if (!q) { db_close(DB); exit(1); }
char *history[MAX_HISTORY]; char *history[MAX_HISTORY];
@ -763,13 +763,13 @@ static void ai_child_task(Session *s, long long id) {
int plen; int plen;
if (pending_ai_agent) { if (pending_ai_agent) {
plen = snprintf(prefix, sizeof prefix, plen = snprintf(prefix, sizeof prefix,
"Your name is calc. You are a coding assistant in a project. Execute code changes as requested. " "Your name is zynk. You are a coding assistant in a project. Execute code changes as requested. "
"Make real file edits and run commands as needed. Answer in English when asked in English, answer in German when asked in German. " "Make real file edits and run commands as needed. Answer in English when asked in English, answer in German when asked in German. "
"Max 2000 chars. No disclaimers or AI-sounding phrases. No markdown/formatting. " "Max 2000 chars. No disclaimers or AI-sounding phrases. No markdown/formatting. "
"Just make the changes directly and confirm what you did."); "Just make the changes directly and confirm what you did.");
} else { } else {
plen = snprintf(prefix, sizeof prefix, plen = snprintf(prefix, sizeof prefix,
"Your name is calc. You are in plan mode - you can only answer questions and discuss code, " "Your name is zynk. You are in plan mode - you can only answer questions and discuss code, "
"but you CANNOT make any changes to files or execute commands. If someone asks you to change or edit code, " "but you CANNOT make any changes to files or execute commands. If someone asks you to change or edit code, "
"tell them you are in plan mode and can only answer questions. Suggest they use !code <instruction> to make actual code changes. " "tell them you are in plan mode and can only answer questions. Suggest they use !code <instruction> to make actual code changes. "
"Answer briefly. Answer in English when asked in English, answer in German when asked in German. Max 800 chars. " "Answer briefly. Answer in English when asked in English, answer in German when asked in German. Max 800 chars. "
@ -937,11 +937,11 @@ static void irc_pong(Session *s, const char *r) { if (*r == ':') r++; net_send(s
/* ---- IRC command handlers ---- */ /* ---- IRC command handlers ---- */
static int cmd_calc(Session *s, const char *msg, const char *reply_target, const char *src_nick, const char *tgt) { static int cmd_zynk(Session *s, const char *msg, const char *reply_target, const char *src_nick, const char *tgt) {
if (strncmp(msg, "calc", 4) != 0) return 0; if (strncmp(msg, "zynk", 4) != 0) return 0;
if (msg[4] != '\0' && msg[4] != ' ' && msg[4] != '!') return 0; if (msg[4] != '\0' && msg[4] != ' ' && msg[4] != '!') return 0;
if (rate_limit_check(src_nick) < 0) return 1; if (rate_limit_check(src_nick) < 0) return 1;
/* calc!foo without space after ! falls through to other commands */ /* zynk!foo without space after ! falls through to other commands */
if (msg[4] == '!' && msg[5] != '\0' && msg[5] != ' ') return 0; if (msg[4] == '!' && msg[5] != '\0' && msg[5] != ' ') return 0;
int force = 0; int force = 0;
const char *rest; const char *rest;
@ -949,15 +949,15 @@ static int cmd_calc(Session *s, const char *msg, const char *reply_target, const
char *rand = db_get_random(); char *rand = db_get_random();
if (rand) { if (rand) {
irc_msg(s, reply_target, rand); irc_msg(s, reply_target, rand);
log_stamp(); fprintf(stderr, CLR_MAGENTA "CALC %s from %s:" CLR_RESET " random %s\n", reply_target, src_nick, rand); log_stamp(); fprintf(stderr, CLR_MAGENTA "ZYNK %s from %s:" CLR_RESET " random %s\n", reply_target, src_nick, rand);
free(rand); free(rand);
} else { } else {
irc_msg(s, reply_target, "No calcs saved yet."); irc_msg(s, reply_target, "No zynkss saved yet.");
} }
return 1; return 1;
} else if (msg[4] == '!') { } else if (msg[4] == '!') {
if (msg[5] == '\0') { if (msg[5] == '\0') {
irc_msg(s, reply_target, "Usage: calc! <key> = <value>"); irc_msg(s, reply_target, "Usage: zynk! <key> = <value>");
return 1; return 1;
} }
force = 1; force = 1;
@ -967,7 +967,7 @@ static int cmd_calc(Session *s, const char *msg, const char *reply_target, const
} }
while (*rest == ' ') rest++; while (*rest == ' ') rest++;
if (!*rest) { if (!*rest) {
irc_msg(s, reply_target, "Usage: calc <key> [= <value>]"); irc_msg(s, reply_target, "Usage: zynk <key> [= <value>]");
return 1; return 1;
} }
const char *eq = strstr(rest, " = "); const char *eq = strstr(rest, " = ");
@ -983,14 +983,14 @@ static int cmd_calc(Session *s, const char *msg, const char *reply_target, const
char *existing = db_get_raw(key); char *existing = db_get_raw(key);
if (existing) { if (existing) {
free(existing); free(existing);
snprintf(resp, sizeof resp, "calc already exists (use calc! to overwrite)"); snprintf(resp, sizeof resp, "zynk already exists (use zynk! to overwrite)");
irc_msg(s, reply_target, resp); irc_msg(s, reply_target, resp);
log_stamp(); fprintf(stderr, CLR_MAGENTA "CALC %s from %s:" CLR_RESET " blocked re-add of %s\n", reply_target, src_nick, key); log_stamp(); fprintf(stderr, CLR_MAGENTA "ZYNK %s from %s:" CLR_RESET " blocked re-add of %s\n", reply_target, src_nick, key);
return 1; return 1;
} }
} else { } else {
if (tgt[0] == '#' && !chan_is_op(tgt, src_nick)) { if (tgt[0] == '#' && !chan_is_op(tgt, src_nick)) {
irc_msg(s, reply_target, "You need op to overwrite a calc"); irc_msg(s, reply_target, "You need op to overwrite a zynk");
return 1; return 1;
} }
} }
@ -1016,7 +1016,7 @@ static int cmd_calc(Session *s, const char *msg, const char *reply_target, const
} }
} }
irc_msg(s, reply_target, resp); irc_msg(s, reply_target, resp);
log_stamp(); fprintf(stderr, CLR_MAGENTA "CALC %s from %s:" CLR_RESET " %s\n", reply_target, src_nick, resp); log_stamp(); fprintf(stderr, CLR_MAGENTA "ZYNK %s from %s:" CLR_RESET " %s\n", reply_target, src_nick, resp);
return 1; return 1;
} }
@ -1201,7 +1201,7 @@ static void handle_privmsg(Session *s, const char *params, const char *src_nick)
const char *msg = p; const char *msg = p;
if (strcasecmp(src_nick, s->nick) == 0) return; if (strcasecmp(src_nick, s->nick) == 0) return;
const char *reply_target = (tgt[0] == '#') ? tgt : src_nick; const char *reply_target = (tgt[0] == '#') ? tgt : src_nick;
if (cmd_calc(s, msg, reply_target, src_nick, tgt)) return; if (cmd_zynk(s, msg, reply_target, src_nick, tgt)) return;
if (cmd_ping(s, msg, reply_target, src_nick)) return; if (cmd_ping(s, msg, reply_target, src_nick)) return;
if (cmd_quit(s, msg, reply_target, src_nick, tgt)) return; if (cmd_quit(s, msg, reply_target, src_nick, tgt)) return;
if (cmd_weather(s, msg, reply_target, src_nick)) return; if (cmd_weather(s, msg, reply_target, src_nick)) return;
@ -1403,12 +1403,12 @@ static void usage(const char *prog) {
" -server host IRC server (default: %s)\n" " -server host IRC server (default: %s)\n"
" -port p Port (default: %d)\n" " -port p Port (default: %d)\n"
" -pass p Server password\n" " -pass p Server password\n"
" -nick n Nickname (default: calc<PID>)\n" " -nick n Nickname (default: zynk<PID>)\n"
" -join c Auto-join channels (comma-sep, default: #calc)\n" " -join c Auto-join channels (comma-sep, default: #zynk)\n"
"\n" "\n"
"Calc commands:\n" "Zynk commands:\n"
" calc foo = bar Store 'bar' under key 'foo'\n" " zynk foo = bar Store 'bar' under key 'foo'\n"
" calc foo Retrieve value for 'foo'\n", " zynk foo Retrieve value for 'foo'\n",
prog, DEFAULT_SERVER, DEF_PORT); prog, DEFAULT_SERVER, DEF_PORT);
} }
@ -1457,9 +1457,9 @@ int main(int argc, char **argv) {
char nickbuf[32]; char nickbuf[32];
const char *nick = NULL; const char *nick = NULL;
char passbuf[256] = ""; char passbuf[256] = "";
char joinbuf[256] = "#calc"; char joinbuf[256] = "#zynk";
int pos = 0; int pos = 0;
log_stamp(); fprintf(stderr, CLR_CYAN "[calc] starting up" CLR_RESET "\n"); log_stamp(); fprintf(stderr, CLR_CYAN "[zynk] starting up" CLR_RESET "\n");
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
usage(argv[0]); return 0; usage(argv[0]); return 0;
@ -1503,7 +1503,7 @@ int main(int argc, char **argv) {
} }
if (port <= 0 || port > 65535) port = DEF_PORT; if (port <= 0 || port > 65535) port = DEF_PORT;
if ((port == 6697 || port == 7000) && !use_tls) use_tls = 1; if ((port == 6697 || port == 7000) && !use_tls) use_tls = 1;
if (!nick) { snprintf(nickbuf, sizeof nickbuf, "calc"); nick = nickbuf; } if (!nick) { snprintf(nickbuf, sizeof nickbuf, "zynk"); nick = nickbuf; }
if (db_init() < 0) { fprintf(stderr, CLR_RED "DB init failed" CLR_RESET "\n"); return 1; } if (db_init() < 0) { fprintf(stderr, CLR_RED "DB init failed" CLR_RESET "\n"); return 1; }
Session s; Session s;
memset(&s, 0, sizeof s); memset(&s, 0, sizeof s);
@ -1511,7 +1511,7 @@ int main(int argc, char **argv) {
s.port = port; s.port = port;
snprintf(s.nick, sizeof s.nick, "%s", nick); snprintf(s.nick, sizeof s.nick, "%s", nick);
snprintf(s.user, sizeof s.user, "%s", nick); snprintf(s.user, sizeof s.user, "%s", nick);
snprintf(s.real, sizeof s.real, "calc"); snprintf(s.real, sizeof s.real, "zynk");
snprintf(s.auto_join, sizeof s.auto_join, "%s", joinbuf); snprintf(s.auto_join, sizeof s.auto_join, "%s", joinbuf);
s.fd = -1; s.fd = -1;
s.use_tls = use_tls; s.use_tls = use_tls;
@ -1553,7 +1553,7 @@ int main(int argc, char **argv) {
if (s.connected && s.fd >= 0) { if (s.connected && s.fd >= 0) {
int old_fl = fcntl(s.fd, F_GETFL, 0); int old_fl = fcntl(s.fd, F_GETFL, 0);
fcntl(s.fd, F_SETFL, old_fl & ~O_NONBLOCK); fcntl(s.fd, F_SETFL, old_fl & ~O_NONBLOCK);
net_send(&s, "QUIT :calc\r\n"); net_send(&s, "QUIT :zynk\r\n");
struct timespec ts = { .tv_sec = 0, .tv_nsec = 500000000 }; struct timespec ts = { .tv_sec = 0, .tv_nsec = 500000000 };
nanosleep(&ts, NULL); nanosleep(&ts, NULL);
} }