# HG changeset patch # User David Demelier # Date 1512044378 -3600 # Node ID 3d0dbc0bee7d0e9189c99721e56ba152e9dd6e32 # Parent 763d41e3828c6d905cc38440066606c7e8875d55 Irccd: update references to onChannel(Mode|Notice), onMode - Update hangman, logger and their tests, - Update dynlib_plugin and js_plugin. diff -r 763d41e3828c -r 3d0dbc0bee7d MIGRATING.md --- a/MIGRATING.md Wed Nov 29 15:06:11 2017 +0100 +++ b/MIGRATING.md Thu Nov 30 13:19:38 2017 +0100 @@ -11,6 +11,15 @@ - The functions `server-cnotice` and `server-cmode` have been removed, use `server-notice` and `server-mode` instead. +### Plugins + +#### Logger + + - The keyword `source` has been removed and replaced by `channel`, + - The keyword `origin` has been added, + - Formats `cnotice`, `cmode`, `query` have been removed. + + ### Network API - The requests `server-cnotice` and `server-cmode` have been removed, use @@ -31,7 +40,9 @@ #### Events - The events `onChannelMode` and `onChannelNotice` have been removed, plugins - must use `Server.isSelf(target)` to determine a channel/private message. + must use `Server.isSelf(target)` to determine a channel/private message, + - The event `onNotice` takes a new `channel` argument, + - The event `onMode` takes new `channel`, `limit`, `user`, `mask` arguments. #### Module Server diff -r 763d41e3828c -r 3d0dbc0bee7d libirccd-js/irccd/js/js_plugin.cpp --- a/libirccd-js/irccd/js/js_plugin.cpp Wed Nov 29 15:06:11 2017 +0100 +++ b/libirccd-js/irccd/js/js_plugin.cpp Thu Nov 30 13:19:38 2017 +0100 @@ -238,8 +238,12 @@ dukx_push(context_, std::move(event.server)); dukx_push(context_, event.origin); + dukx_push(context_, event.channel); dukx_push(context_, event.mode); - call("onMode", 3); + dukx_push(context_, event.limit); + dukx_push(context_, event.user); + dukx_push(context_, event.mask); + call("onMode", 7); } void js_plugin::on_names(irccd& , const names_event &event) @@ -269,8 +273,9 @@ dukx_push(context_, std::move(event.server)); dukx_push(context_, event.origin); + dukx_push(context_, event.channel); dukx_push(context_, event.message); - call("onNotice", 3); + call("onNotice", 4); } void js_plugin::on_part(irccd& , const part_event &event) @@ -284,26 +289,6 @@ call("onPart", 4); } -void js_plugin::on_query(irccd& , const query_event &event) -{ - dukx_stack_assert sa(context_); - - dukx_push(context_, std::move(event.server)); - dukx_push(context_, event.origin); - dukx_push(context_, event.message); - call("onQuery", 3); -} - -void js_plugin::on_query_command(irccd& , const query_event &event) -{ - dukx_stack_assert sa(context_); - - dukx_push(context_, std::move(event.server)); - dukx_push(context_, event.origin); - dukx_push(context_, event.message); - call("onQueryCommand", 3); -} - void js_plugin::on_reload(irccd& ) { dukx_stack_assert sa(context_); diff -r 763d41e3828c -r 3d0dbc0bee7d libirccd-js/irccd/js/js_plugin.hpp --- a/libirccd-js/irccd/js/js_plugin.hpp Wed Nov 29 15:06:11 2017 +0100 +++ b/libirccd-js/irccd/js/js_plugin.hpp Thu Nov 30 13:19:38 2017 +0100 @@ -201,16 +201,6 @@ void on_part(irccd& irccd, const part_event& event) override; /** - * \copydoc Plugin::on_query - */ - void on_query(irccd& irccd, const query_event& event) override; - - /** - * \copydoc Plugin::on_query_command - */ - void on_query_command(irccd& irccd, const query_event& event) override; - - /** * \copydoc Plugin::on_reload */ void on_reload(irccd& irccd) override; diff -r 763d41e3828c -r 3d0dbc0bee7d libirccd-test/irccd/plugin_test.cpp --- a/libirccd-test/irccd/plugin_test.cpp Wed Nov 29 15:06:11 2017 +0100 +++ b/libirccd-test/irccd/plugin_test.cpp Thu Nov 30 13:19:38 2017 +0100 @@ -45,6 +45,7 @@ log::set_verbose(false); log::set_logger(std::make_unique()); + server_->set_nickname("irccd"); plugin_ = std::make_unique(std::move(name), std::move(path)); irccd_.plugins().add(plugin_); diff -r 763d41e3828c -r 3d0dbc0bee7d libirccd/irccd/dynlib_plugin.cpp --- a/libirccd/irccd/dynlib_plugin.cpp Wed Nov 29 15:06:11 2017 +0100 +++ b/libirccd/irccd/dynlib_plugin.cpp Thu Nov 30 13:19:38 2017 +0100 @@ -130,16 +130,6 @@ plugin_->on_part(irccd, ev); } -void dynlib_plugin::on_query(irccd& irccd, const query_event& ev) -{ - plugin_->on_query(irccd, ev); -} - -void dynlib_plugin::on_query_command(irccd& irccd, const query_event& ev) -{ - plugin_->on_query_command(irccd, ev); -} - void dynlib_plugin::on_reload(irccd& irccd) { plugin_->on_reload(irccd); diff -r 763d41e3828c -r 3d0dbc0bee7d libirccd/irccd/dynlib_plugin.hpp --- a/libirccd/irccd/dynlib_plugin.hpp Wed Nov 29 15:06:11 2017 +0100 +++ b/libirccd/irccd/dynlib_plugin.hpp Thu Nov 30 13:19:38 2017 +0100 @@ -115,16 +115,6 @@ void on_part(irccd& irccd, const part_event& event) override; /** - * \copydoc plugin::on_query - */ - void on_query(irccd& irccd, const query_event& event) override; - - /** - * \copydoc plugin::on_query_command - */ - void on_query_command(irccd& irccd, const query_event& event) override; - - /** * \copydoc plugin::on_reload */ void on_reload(irccd& irccd) override; diff -r 763d41e3828c -r 3d0dbc0bee7d libirccd/irccd/plugin.hpp --- a/libirccd/irccd/plugin.hpp Wed Nov 29 15:06:11 2017 +0100 +++ b/libirccd/irccd/plugin.hpp Thu Nov 30 13:19:38 2017 +0100 @@ -400,28 +400,6 @@ } /** - * On user query. - * - * \param irccd the irccd instance - * \param event the event - */ - virtual void on_query(irccd& irccd, const query_event& event) - { - util::unused(irccd, event); - } - - /** - * On user query command. - * - * \param irccd the irccd instance - * \param event the event - */ - virtual void on_query_command(irccd& irccd, const query_event& event) - { - util::unused(irccd, event); - } - - /** * On reload. * * \param irccd the irccd instance diff -r 763d41e3828c -r 3d0dbc0bee7d plugins/hangman/hangman.js --- a/plugins/hangman/hangman.js Wed Nov 29 15:06:11 2017 +0100 +++ b/plugins/hangman/hangman.js Thu Nov 30 13:19:38 2017 +0100 @@ -336,7 +336,12 @@ function onCommand(server, origin, channel, message) { - channel = channel.toLowerCase(); + var isquery = server.isSelf(channel); + + if (isquery) + channel = origin; + else + channel = channel.toLowerCase(); var game = Hangman.find(server, channel); var kw = { @@ -362,6 +367,7 @@ } } else { game = Hangman.create(server, channel); + game.query = isquery; kw.word = game.formatWord(); server.message(channel, Util.format(Plugin.format["start"], kw)); } @@ -371,7 +377,10 @@ function onMessage(server, origin, channel, message) { - channel = channel.toLowerCase(); + if (server.isSelf(channel)) + channel = origin; + else + channel = channel.toLowerCase(); var game = Hangman.find(server, channel); @@ -381,13 +390,3 @@ if (message.length === 1 && Unicode.isLetter(message.charCodeAt(0))) propose(server, channel, origin, game, message.charCodeAt(0)); } - -function onQueryCommand(server, origin, message) -{ - onCommand(server, origin, Util.splituser(origin), message).query = true; -} - -function onQuery(server, origin, message) -{ - onMessage(server, origin, Util.splituser(origin), message); -} diff -r 763d41e3828c -r 3d0dbc0bee7d plugins/logger/logger.js --- a/plugins/logger/logger.js Wed Nov 29 15:06:11 2017 +0100 +++ b/plugins/logger/logger.js Thu Nov 30 13:19:38 2017 +0100 @@ -35,14 +35,12 @@ * All available formats. */ Plugin.format = { - "cmode": "%H:%M:%S :: #{nickname} changed the mode to: #{mode} #{arg}", - "cnotice": "%H:%M:%S :: [notice] (#{channel}) #{nickname}: #{message}", "join": "%H:%M:%S >> #{nickname} joined #{channel}", "kick": "%H:%M:%S :: #{target} has been kicked by #{nickname} [reason: #{reason}]", "me": "%H:%M:%S * #{nickname} #{message}", "message": "%H:%M:%S #{nickname}: #{message}", "mode": "%H:%M:%S :: #{nickname} set mode #{mode} to #{arg}", - "notice": "%H:%M:%S [notice] (#{nickname}) #{message}", + "notice": "%H:%M:%S [notice] #{channel} (#{nickname}) #{message}", "part": "%H:%M:%S << #{nickname} left #{channel} [#{reason}]", "query": "%H:%M:%S #{nickname}: #{message}", "topic": "%H:%M:%S :: #{nickname} changed the topic of #{channel} to: #{topic}" @@ -122,37 +120,12 @@ loadFormats(); } -function onChannelMode(server, origin, channel, mode, arg) -{ - origin = origin.toLowerCase(); - channel = channel.toLowerCase(); - - write("cmode", keywords(server, channel, origin, { - "arg": arg, - "mode": mode, - "source": channel - })); -} - -function onChannelNotice(server, origin, channel, notice) -{ - origin = origin.toLowerCase(); - channel = channel.toLowerCase(); - - write("cnotice", keywords(server, channel, origin, { - "message": notice, - "source": channel - })); -} - function onInvite(server, origin, channel) { origin = origin.toLowerCase(); channel = channel.toLowerCase(); - write("invite", keywords(server, channel, origin, { - "source": channel - })); + write("invite", keywords(server, channel, origin)); } function onJoin(server, origin, channel) @@ -160,9 +133,7 @@ origin = origin.toLowerCase(); channel = channel.toLowerCase(); - write("join", keywords(server, channel, origin, { - "source": channel - })); + write("join", keywords(server, channel, origin)); } function onKick(server, origin, channel, target, reason) @@ -172,7 +143,6 @@ write("kick", keywords(server, channel, origin, { "target": target, - "source": channel, "reason": reason })); } @@ -184,7 +154,6 @@ write("me", keywords(server, channel, origin, { "message": message, - "source": channel })); } @@ -195,17 +164,18 @@ write("message", keywords(server, channel, origin, { "message": message, - "source": channel })); } -function onMode(server, origin, mode) +function onMode(server, origin, channel, mode, limit, user, mask) { origin = origin.toLowerCase(); - write("mode", keywords(server, undefined, origin, { + write("mode", keywords(server, channel, origin, { "mode": mode, - "source": Util.splituser(origin) + "limit": limit, + "user": user, + "mask": mask })); } @@ -214,13 +184,12 @@ // TODO: write for all servers/channels a log entry } -function onNotice(server, origin, notice) +function onNotice(server, origin, channel, notice) { origin = origin.toLowerCase(); - write("notice", keywords(server, undefined, origin, { + write("notice", keywords(server, channel, origin, { "message": notice, - "source": Util.splituser(origin) })); } @@ -231,17 +200,6 @@ write("part", keywords(server, channel, origin, { "reason": reason, - "source": channel - })); -} - -function onQuery(server, origin, message) -{ - origin = origin.toLowerCase(); - - write("query", keywords(server, undefined, origin, { - "source": Util.splituser(origin), - "message": message })); } @@ -251,7 +209,6 @@ channel = channel.toLowerCase(); write("topic", keywords(server, channel, origin, { - "source": channel, "topic": topic })); } diff -r 763d41e3828c -r 3d0dbc0bee7d plugins/logger/logger.md --- a/plugins/logger/logger.md Wed Nov 29 15:06:11 2017 +0100 +++ b/plugins/logger/logger.md Thu Nov 30 13:19:38 2017 +0100 @@ -4,28 +4,27 @@ guide: yes --- -The plugin **logger** may be used to log everything you want. It supports the following events: +The plugin **logger** may be used to log everything you want. It supports the +following events: - - Channel mode, - - Channel notice, - - Join, - - Kick, - - Me, - - Message, - - Mode, - - Notice, - - Part, - - Query, - - Topic. + - onJoin, + - onKick, + - onMe, + - onMessage, + - onMode, + - onNotice, + - onPart, + - onTopic. ## Installation -The plugin **logger** is distributed with irccd. To enable it add the following to your `plugins` section: +The plugin **logger** is distributed with irccd. To enable it add the following +to your `plugins` section: -````ini +```ini [plugins] logger = "" -```` +``` ## Usage @@ -37,26 +36,11 @@ - **path**: (string) the path to the file where to store logs, -**Deprecated in irccd 2.1.0:** - - - **format-cmode**: Use `[format.logger] cmode` instead, - - **format-cnotice**: Use `[format.logger] cnotice` instead, - - **format-join**: Use `[format.logger] join` instead, - - **format-kick**: Use `[format.logger] kick` instead, - - **format-me**: Use `[format.logger] me` instead, - - **format-message**: Use `[format.logger] message` instead, - - **format-mode**: Use `[format.logger] mode` instead, - - **format-notice**: Use `[format.logger] notice` instead, - - **format-part**: Use `[format.logger] part` instead, - - **format-query**: Use `[format.logger] query` instead, - - **format-topic**: Use `[format.logger] topic` instead, - ## Formats -The **logger** plugin supports the following formats in `[format.logger]` section: +The **logger** plugin supports the following formats in `[format.logger]` +section: - - **cmode**: (string) format for channel mode change, - - **cnotice**: (string) format for channel notices, - **join**: (string) format when someone joins a channel, - **kick**: (string) format when someone has been kicked, - **me**: (string) format for emote actions, @@ -64,41 +48,34 @@ - **mode**: (string) format for user mode change, - **notice**: (string) format on private notices, - **part**: (string) format when someone leaves a channel, - - **query**: (string) format on private messages, - **topic**: (string) format when a topic is changed. ### Keywords supported The following keywords are supported: -| Format | Keywords | Notes | -|-------------|-----------------------------------|---------------------------------| -| (any) | nickname, origin, server, source | source is the channel or nick | -| **cmode** | arg, channel, mode, | the mode and its arguments | -| **cnotice** | channel, message | the message notice | -| **join** | channel | | -| **kick** | channel, reason, target | | -| **me** | channel, message | message is the emote action | -| **message** | channel, message | | -| **mode** | arg, mode | the mode and its arguments | -| **notice** | message | the notice message | -| **part** | channel, reason | | -| **query** | message | | -| **topic** | channel, topic | | - -The **source** keyword is specially designed to use a generic path for the path parameter. +| Format | Keywords | Notes | +|-------------|-----------------------------------|-----------------------------| +| (any) | channel, nickname, origin, server | channel may be a nickname | +| **kick** | reason, target | | +| **me** | message | message is the emote action | +| **message** | message | | +| **mode** | mode, limit, user, mask | the mode and its arguments | +| **notice** | message | the notice message | +| **part** | reason | | +| **topic** | topic | | Example:
~/.config/irccd/irccd.conf
-````ini +```ini [plugin.logger] -path = "/var/log/irccd/#{server}/%y/%m/%d/#{source}.txt" +path = "/var/log/irccd/#{server}/%y/%m/%d/#{channel}.txt" [format.logger] join = "user #{nickname} joined #{channel}" -```` +```
diff -r 763d41e3828c -r 3d0dbc0bee7d tests/plugin-hangman/main.cpp --- a/tests/plugin-hangman/main.cpp Wed Nov 29 15:06:11 2017 +0100 +++ b/tests/plugin-hangman/main.cpp Thu Nov 30 13:19:38 2017 +0100 @@ -280,34 +280,34 @@ load(); // Query mode is never collaborative. - plugin_->on_query_command(irccd_, {server_, "jean!jean@localhost", ""}); + plugin_->on_command(irccd_, {server_, "jean!jean@localhost", "irccd", ""}); auto cmd = server_->cqueue().back(); BOOST_TEST(cmd["command"].get() == "message"); - BOOST_TEST(cmd["target"].get() == "jean"); - BOOST_TEST(cmd["message"].get() == "start=hangman:!hangman:test:jean:jean!jean@localhost:jean:_ _ _"); + BOOST_TEST(cmd["target"].get() == "jean!jean@localhost"); + BOOST_TEST(cmd["message"].get() == "start=hangman:!hangman:test:jean!jean@localhost:jean!jean@localhost:jean:_ _ _"); - plugin_->on_query(irccd_, {server_, "jean!jean@localhost", "s"}); + plugin_->on_message(irccd_, {server_, "jean!jean@localhost", "irccd", "s"}); cmd = server_->cqueue().back(); BOOST_TEST(cmd["command"].get() == "message"); - BOOST_TEST(cmd["target"].get() == "jean"); - BOOST_TEST(cmd["message"].get() == "found=hangman:!hangman:test:jean:jean!jean@localhost:jean:s _ _"); + BOOST_TEST(cmd["target"].get() == "jean!jean@localhost"); + BOOST_TEST(cmd["message"].get() == "found=hangman:!hangman:test:jean!jean@localhost:jean!jean@localhost:jean:s _ _"); - plugin_->on_query(irccd_, {server_, "jean!jean@localhost", "k"}); + plugin_->on_message(irccd_, {server_, "jean!jean@localhost", "irccd", "k"}); cmd = server_->cqueue().back(); BOOST_TEST(cmd["command"].get() == "message"); - BOOST_TEST(cmd["target"].get() == "jean"); - BOOST_TEST(cmd["message"].get() == "found=hangman:!hangman:test:jean:jean!jean@localhost:jean:s k _"); + BOOST_TEST(cmd["target"].get() == "jean!jean@localhost"); + BOOST_TEST(cmd["message"].get() == "found=hangman:!hangman:test:jean!jean@localhost:jean!jean@localhost:jean:s k _"); - plugin_->on_query_command(irccd_, {server_, "jean!jean@localhost", "sky"}); + plugin_->on_command(irccd_, {server_, "jean!jean@localhost", "irccd", "sky"}); cmd = server_->cqueue().back(); BOOST_TEST(cmd["command"].get() == "message"); - BOOST_TEST(cmd["target"].get() == "jean"); - BOOST_TEST(cmd["message"].get() == "win=hangman:!hangman:test:jean:jean!jean@localhost:jean:sky"); + BOOST_TEST(cmd["target"].get() == "jean!jean@localhost"); + BOOST_TEST(cmd["message"].get() == "win=hangman:!hangman:test:jean!jean@localhost:jean!jean@localhost:jean:sky"); } BOOST_AUTO_TEST_CASE(running) diff -r 763d41e3828c -r 3d0dbc0bee7d tests/plugin-logger/main.cpp --- a/tests/plugin-logger/main.cpp Wed Nov 29 15:06:11 2017 +0100 +++ b/tests/plugin-logger/main.cpp Thu Nov 30 13:19:38 2017 +0100 @@ -50,8 +50,8 @@ { "kick", "kick=#{server}:#{channel}:#{origin}:#{nickname}:#{target}:#{reason}" }, { "me", "me=#{server}:#{channel}:#{origin}:#{nickname}:#{message}" }, { "message", "message=#{server}:#{channel}:#{origin}:#{nickname}:#{message}" }, - { "mode", "mode=#{server}:#{origin}:#{nickname}:#{mode}:#{arg}" }, - { "notice", "notice=#{server}:#{origin}:#{nickname}:#{message}" }, + { "mode", "mode=#{server}:#{origin}:#{channel}:#{mode}:#{limit}:#{user}:#{mask}" }, + { "notice", "notice=#{server}:#{origin}:#{channel}:#{message}" }, { "part", "part=#{server}:#{channel}:#{origin}:#{nickname}:#{reason}" }, { "query", "query=#{server}:#{origin}:#{nickname}:#{message}" }, { "topic", "topic=#{server}:#{channel}:#{origin}:#{nickname}:#{topic}" }, @@ -110,18 +110,18 @@ { load(); - plugin_->on_mode(irccd_, {server_, "jean!jean@localhost", "+i"}); + plugin_->on_mode(irccd_, {server_, "jean!jean@localhost", "chris", "+i", "l", "u", "m"}); - BOOST_REQUIRE_EQUAL("mode=test:jean!jean@localhost:jean:+i:\n", last()); + BOOST_REQUIRE_EQUAL("mode=test:jean!jean@localhost:chris:+i:l:u:m\n", last()); } BOOST_AUTO_TEST_CASE(format_notice) { load(); - plugin_->on_notice(irccd_, {server_, "jean!jean@localhost", "tu veux voir mon chat ?"}); + plugin_->on_notice(irccd_, {server_, "jean!jean@localhost", "chris", "tu veux voir mon chat ?"}); - BOOST_REQUIRE_EQUAL("notice=test:jean!jean@localhost:jean:tu veux voir mon chat ?\n", last()); + BOOST_REQUIRE_EQUAL("notice=test:jean!jean@localhost:chris:tu veux voir mon chat ?\n", last()); } BOOST_AUTO_TEST_CASE(format_part) @@ -133,15 +133,6 @@ BOOST_REQUIRE_EQUAL("part=test:#staff:jean!jean@localhost:jean:too noisy here\n", last()); } -BOOST_AUTO_TEST_CASE(format_query) -{ - load(); - - plugin_->on_query(irccd_, {server_, "jean!jean@localhost", "much irccd, wow"}); - - BOOST_REQUIRE_EQUAL("query=test:jean!jean@localhost:jean:much irccd, wow\n", last()); -} - BOOST_AUTO_TEST_CASE(format_topic) { load();