Mercurial > irccd
changeset 420:f1414576ceaa
Plugin plugin: enable configurable limits, closes #618
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 29 Jan 2017 13:42:20 +0100 |
parents | faebf6019e70 |
children | 5e9b7ff956b3 |
files | plugins/plugin/plugin.js plugins/plugin/plugin.md |
diffstat | 2 files changed, 39 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/plugin/plugin.js Wed Feb 01 11:53:22 2017 +0100 +++ b/plugins/plugin/plugin.js Sun Jan 29 13:42:20 2017 +0100 @@ -35,6 +35,11 @@ "too-long": "#{nickname}, plugin list too long, ask in query for more details." } +Plugin.config = { + "max-list-lines": 3, + "max-list-columns": 80 +} + var commands = { loadFormats: function () { @@ -75,15 +80,36 @@ list: function (server, origin, target, query) { var kw = commands.keywords(server, target, origin); - var list = Plugin.list(); - var str; + var plugins = Plugin.list(); + var lines = [ "" ]; + var maxl = parseInt(Plugin.config["max-list-lines"]); + var maxc = parseInt(Plugin.config["max-list-columns"]); + + if (isNaN(maxc)) { + maxc = 80; + } + if (isNaN(maxl)) { + maxl = 3; + } + + for (var p = 0; p < plugins.length; ++p) { + var l = lines.length - 1; - if (!query && list.length >= 16) - str = Util.format(Plugin.format["too-long"], kw); - else - str = list.join(" "); + if (plugins[p].length + 1 + lines[l].length > maxc) { + lines.push(""); + l++; + } + + lines[l] += plugins[p] + " "; + } - server.message(target, str); + if (!query && maxl > 0 && lines.length > maxl) { + server.message(target, Util.format(Plugin.format["too-long"], kw)); + } else { + for (var i = 0; i < lines.length; ++i) { + server.message(target, lines[i]); + } + } }, info: function (server, origin, target, name)
--- a/plugins/plugin/plugin.md Wed Feb 01 11:53:22 2017 +0100 +++ b/plugins/plugin/plugin.md Sun Jan 29 13:42:20 2017 +0100 @@ -20,7 +20,7 @@ The plugin **plugin** only reacts to the special command. It understands `info` and `list` sub commands. - The sub command `info` shows information about a plugin, - - The sub command `list` shows loaded plugins. + - The sub command `list` shows loaded plugins (see configuration for limits). Both commands work in a channel or as private message with irccd. @@ -28,6 +28,11 @@ The following options are available under the `[plugin.plugin]` section: + - **max-list-lines**: (int) max number of lines allowed for the `list` sub + command (Optional, default: 3), + - **max-list-columns**: (int) max number of columns allowed per lines + (Optional, default: 80). + **Deprecated in irccd 2.1.0:** - **format-usage**: Use `[format.plugin] usage` instead,