{"id":16866361,"url":"https://github.com/jprjr/lua-irc-formatter","last_synced_at":"2025-03-18T17:43:18.082Z","repository":{"id":70966734,"uuid":"464669663","full_name":"jprjr/lua-irc-formatter","owner":"jprjr","description":"A simple formatter/serializer for IRC messages.","archived":false,"fork":false,"pushed_at":"2022-04-08T19:12:53.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-24T21:13:46.093Z","etag":null,"topics":["irc","lua","luajit"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jprjr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-28T22:51:32.000Z","updated_at":"2022-02-28T22:54:08.000Z","dependencies_parsed_at":"2023-04-13T01:49:00.798Z","dependency_job_id":null,"html_url":"https://github.com/jprjr/lua-irc-formatter","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprjr%2Flua-irc-formatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprjr%2Flua-irc-formatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprjr%2Flua-irc-formatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprjr%2Flua-irc-formatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jprjr","download_url":"https://codeload.github.com/jprjr/lua-irc-formatter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244272541,"owners_count":20426754,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["irc","lua","luajit"],"created_at":"2024-10-13T14:50:21.142Z","updated_at":"2025-03-18T17:43:18.048Z","avatar_url":"https://github.com/jprjr.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lua-irc-formatter\n\nA simple formatter/serializer for IRC messages.\n\nIt allows creating a formatter object with default values\nfor your messages. You can then serialize/format your messages\nand have your defaults merged in.\n\nFor example, say you were building a bot that intends to\nmessage the same room, you can create a formatter with\na pre-filled `command` and `params` value:\n\n```lua\nlocal formatter = require('irc-formatter').new({\n  command = 'PRIVMSG',\n  params = { '#some-room' },\n})\n```\n\nThen to send messages, you call `:format` with\nyour additional parameter (the room message):\n\n```lua\nlocal str = formatter:format({\n  params = { 'Hello there!' },\n})\n\n--[[ str is:\nPRIVMSG #some-room :Hello there!\n]]\n```\n\nIf you provide some kind of invalid data, by default `:format()` will\nthrow an error. You can check for this beforehand using `:validate()`:\n\n```lua\nlocal formatter = require('irc-formatter').new({\n  command = 'PRIVMSG',\n  params = { '#some-room', 'param with spaces', 'another param with spaces' },\n})\n\nlocal ok, err = formatter:validate()\n```\n\nYou can also `:validate()` with a table, and the merged parameters\nwill be tested:\n\n```lua\nlocal formatter = require('irc-formatter').new({\n  command = 'PRIVMSG',\n  params = { '#some-room'},\n})\n\nlocal ok, err = formatter:validate({\n  params = { 'this has spaces', 'and so does this' },\n})\n```\n\nBy default, if your final param doesn't require a colon, the generated\nstring won't have one. You can opt-in to have the colon anyway, by passing\nsomething truthy as a second value:\n\n```lua\nlocal formatter = require('irc-formatter').new({\n  command = 'PRIVMSG',\n  params = { '#some-room' },\n})\n\nlocal str = formatter:serialize({\n  params = { 'hello' },\n, true)\n\n--[[ str is:\nPRIVMSG #some-room :hello\n]]\n```\n\nThis will properly escape tags, too. There's also a dedicated\ntype for generating \"missing\" tags (where there's no equals sign or value,\njust the tag name):\n\n```lua\nlocal formatter = require('irc-formatter').new()\n\nlocal str = formatter:format({\n    tags = {\n      a = ':-) Hi there;\\r\\n\\\\s',\n      b = false,\n      c = formatter.missing,\n      d = 1234,\n    },\n    source = {\n      nick = 'nick',\n      user = 'user',\n      host = '127.0.0.1',\n    },\n    command = 'PRIVMSG',\n    params = { '#some-room', ':-)Hello there!' },\n})\n```\n\nThis will encode to:\n\n```\n@a=:-)\\sHi\\sthere\\:\\r\\n\\\\s;b=false;c;d=1234 :nick!user@127.0.0.1 PRIVMSG #some-room ::-)Hello there!\n```\n\nBy default, the strings are returned without a line-ending, this can\nbe set with the `eol` parameter.\n\nThe full list of parameters is:\n\n* `tags` - a table of tags, values will be converted to strings using `tostring`.\n* `source` - a table indicating the message source, formerly called `prefix`,\n it can have the following keys:\n   * `nick`\n   * `user`\n   * `host`\n* `command` - the only required parameter, the IRC Command.\n* `params` - an array-like table of parameters\n* `eol` - an end-of-line marker, like `\\r\\n`.\n\n## Installation\n\n### luarocks\n\nAvailable on [luarocks](https://luarocks.org/modules/jprjr/irc-formatter):\n\n```bash\nluarocks install irc-formatter\n```\n\n### OPM\n\nAvailable on [OPM](https://opm.openresty.org/package/jprjr/irc-formatter/)\n\n```bash\nopm install jprjr/irc-formatter\n```\n\n## LICENSE\n\nMIT (see file `LICENSE`)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjprjr%2Flua-irc-formatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjprjr%2Flua-irc-formatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjprjr%2Flua-irc-formatter/lists"}