an experimental irc client

config: don't require user or realname

rockorager.dev 8596cc7b 87060414

verified
+31 -13
+2 -2
docs/comlink.3.scd
··· 39 39 configuration. The table has the following required fields: 40 40 41 41 - *server*: string, the server URL 42 - - *user*: string, username used in SASL 43 42 - *nick*: string, nickname to identify as 44 43 - *password*: string, password to use in SASL 45 - - *real_name*: string, user's real name 46 44 47 45 The following optional fields are available: 48 46 49 47 - *port*: uint16 (default=6697 (tls) or 6667), port to use for 50 48 connection 49 + - *real_name*: string, user's real name 51 50 - *tls*: boolean (default=true), when true, use an encrypted connection 51 + - *user*: string, username used in SASL 52 52 53 53 *comlink.log* 54 54 Accepts a string and inserts a log statement into the comlink
+2 -2
docs/comlink.lua
··· 18 18 ---@class ConnectionConfiguration 19 19 --- 20 20 ---@field server string The server to connect to, eg "chat.sr.ht" 21 - ---@field user string Username for server connection 21 + ---@field user? string Username for server connection 22 22 ---@field nick string Nick to use when connecting via SASL to IRC 23 23 ---@field password string Password for server 24 - ---@field real_name string Real name of user 24 + ---@field real_name? string Real name of user 25 25 ---@field tls? boolean Whether to encrypt connections 26 26 ---@field port? number Optional port to use for server connection. Defaults to 6697 for TLS connections and 6667 for plaintext connections 27 27
+27 -9
src/lua.zig
··· 315 315 lua.argCheck(lua.isTable(1), 1, "expected a table"); 316 316 317 317 // [table] 318 - var lua_type = lua.getField(1, "user"); // [table,string] 319 - lua.argCheck(lua_type == .string, 1, "expected a string for field 'user'"); 320 - const user = lua.toString(-1) catch unreachable; 321 - lua.pop(1); // [table] 322 - 323 - lua_type = lua.getField(1, "nick"); // [table,string] 318 + var lua_type = lua.getField(1, "nick"); // [table,string] 324 319 lua.argCheck(lua_type == .string, 1, "expected a string for field 'nick'"); 325 320 const nick = lua.toString(-1) catch unreachable; 326 321 lua.pop(1); // [table] 327 322 323 + lua_type = lua.getField(1, "user"); // [table,string] 324 + const user: []const u8 = switch (lua_type) { 325 + .nil => blk: { 326 + lua.pop(1); // [table] 327 + break :blk nick; 328 + }, 329 + .string => blk: { 330 + const val = lua.toString(-1) catch ""; 331 + lua.pop(1); // [table] 332 + break :blk val; 333 + }, 334 + else => lua.raiseErrorStr("expected a string for field 'user'", .{}), 335 + }; 336 + 328 337 lua_type = lua.getField(1, "password"); // [table, string] 329 338 lua.argCheck(lua_type == .string, 1, "expected a string for field 'password'"); 330 339 const password = lua.toString(-1) catch unreachable; 331 340 lua.pop(1); // [table] 332 341 333 342 lua_type = lua.getField(1, "real_name"); // [table, string] 334 - lua.argCheck(lua_type == .string, 1, "expected a string for field 'real_name'"); 335 - const real_name = lua.toString(-1) catch unreachable; 336 - lua.pop(1); // [table] 343 + const real_name: []const u8 = switch (lua_type) { 344 + .nil => blk: { 345 + lua.pop(1); // [table] 346 + break :blk nick; 347 + }, 348 + .string => blk: { 349 + const val = lua.toString(-1) catch ""; 350 + lua.pop(1); // [table] 351 + break :blk val; 352 + }, 353 + else => lua.raiseErrorStr("expected a string for field 'real_name'", .{}), 354 + }; 337 355 338 356 lua_type = lua.getField(1, "server"); // [table, string] 339 357 lua.argCheck(lua_type == .string, 1, "expected a string for field 'server'");