From 7e6ad089c00054f3316227775c20b82c49a56790 Mon Sep 17 00:00:00 2001 From: Ken Spencer Date: Mon, 13 Mar 2017 12:30:06 -0400 Subject: [PATCH 1/6] plugins: add global notice plugin --- plugins/global.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 plugins/global.py diff --git a/plugins/global.py b/plugins/global.py new file mode 100644 index 0000000..e10ffd3 --- /dev/null +++ b/plugins/global.py @@ -0,0 +1,23 @@ +# global.py: Global Noticing Plugin + +__authors__ = [("Ken Spencer", "Iota ")] +__version__ = "0.0.1" + +from pylinkirc import conf, utils, world +from pylinkirc.log import log +from pylinkirc.coremods import permissions + +def g(irc, source, args): + """ + + Sends out a Instance-wide notice. + """ + permissions.checkPermissions(irc, source, ["global.global"]) + message = " ".join(args) + message = message + " (sent by %s@%s)" % (irc.getFriendlyName(irc.called_by), irc.getFullNetworkName()) + for name, ircd in world.networkobjects.items(): + for channel in ircd.pseudoclient.channels: + ircd.msg(channel, message) + + +utils.add_cmd(g, "global", featured=True) From a3dff204d31d916b78d63acdba6301e9805daf84 Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 13 Mar 2017 13:21:11 -0700 Subject: [PATCH 2/6] global: remove extraneous metadata Core plugins do not need to track authors and version, because git does that for us. --- plugins/global.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/global.py b/plugins/global.py index e10ffd3..ac36831 100644 --- a/plugins/global.py +++ b/plugins/global.py @@ -1,8 +1,5 @@ # global.py: Global Noticing Plugin -__authors__ = [("Ken Spencer", "Iota ")] -__version__ = "0.0.1" - from pylinkirc import conf, utils, world from pylinkirc.log import log from pylinkirc.coremods import permissions From 0a57c084bb24f5904d04897b86728845323bfdf3 Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 13 Mar 2017 13:23:22 -0700 Subject: [PATCH 3/6] global: only send to connected networks --- plugins/global.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/global.py b/plugins/global.py index ac36831..67326ed 100644 --- a/plugins/global.py +++ b/plugins/global.py @@ -13,8 +13,9 @@ def g(irc, source, args): message = " ".join(args) message = message + " (sent by %s@%s)" % (irc.getFriendlyName(irc.called_by), irc.getFullNetworkName()) for name, ircd in world.networkobjects.items(): - for channel in ircd.pseudoclient.channels: - ircd.msg(channel, message) + if ircd.connected.is_set(): # Only attempt to send to connected networks + for channel in ircd.pseudoclient.channels: + ircd.msg(channel, message) utils.add_cmd(g, "global", featured=True) From cfe72e2cd0649f47361e335cdf6bd1ba41188c60 Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 13 Mar 2017 13:29:04 -0700 Subject: [PATCH 4/6] global: set loopback=False on messages to prevent duplicating them via relay --- plugins/global.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/global.py b/plugins/global.py index 67326ed..e03cc23 100644 --- a/plugins/global.py +++ b/plugins/global.py @@ -6,7 +6,7 @@ from pylinkirc.coremods import permissions def g(irc, source, args): """ - + Sends out a Instance-wide notice. """ permissions.checkPermissions(irc, source, ["global.global"]) @@ -15,7 +15,8 @@ def g(irc, source, args): for name, ircd in world.networkobjects.items(): if ircd.connected.is_set(): # Only attempt to send to connected networks for channel in ircd.pseudoclient.channels: - ircd.msg(channel, message) - + # Disable relaying or other plugins handling the global message. + ircd.msg(channel, message, loopback=False) + utils.add_cmd(g, "global", featured=True) From 3ffbbe60ff67078d679082f804271deaf728e0d0 Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 13 Mar 2017 13:38:53 -0700 Subject: [PATCH 5/6] global: configurable output format --- example-conf.yml | 17 +++++++++++++++++ plugins/global.py | 17 +++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/example-conf.yml b/example-conf.yml index dca98a5..80e39e5 100644 --- a/example-conf.yml +++ b/example-conf.yml @@ -418,6 +418,10 @@ plugins: # of kills/saves per X seconds is met. #- servprotect + # Global plugin: Janus-style global plugin; announces messages to all channels the PyLink + # client is in. + #- global + logging: # This configuration block defines targets that PyLink should log commands, # errors, etc., to. @@ -665,3 +669,16 @@ stats: # Determines the time format that the Stats plugin should use for showing dates + times. # Defaults to "%a, %d %b %Y %H:%M:%S +0000" (the RFC 2812 standard) if not specified. time_format: "%c" + +global: + # Sets the text format for the global plugin, if it is loaded. This uses a template string as + # documented at https://docs.python.org/3/library/string.html#template-strings, with the + # following substitutions: + # $sender: the nick of the sender + # $network: the short network name of the origin network + # $fullnetwork: the full network name of the origin network + # $current_channel: the channel we're broadcasting on + # $current_network: the network we're currently broadcasting on + # $current_fullnetwork: the full name of the network we're currently broadcasting on + # $text: the global text + #format: "[$sender@$fullnetwork] $text" diff --git a/plugins/global.py b/plugins/global.py index e03cc23..edebbdc 100644 --- a/plugins/global.py +++ b/plugins/global.py @@ -1,9 +1,13 @@ # global.py: Global Noticing Plugin +import string + from pylinkirc import conf, utils, world from pylinkirc.log import log from pylinkirc.coremods import permissions +DEFAULT_FORMAT = "[$sender@$fullnetwork] $text" + def g(irc, source, args): """ @@ -11,12 +15,21 @@ def g(irc, source, args): """ permissions.checkPermissions(irc, source, ["global.global"]) message = " ".join(args) - message = message + " (sent by %s@%s)" % (irc.getFriendlyName(irc.called_by), irc.getFullNetworkName()) + template = string.Template(conf.conf.get('global', {}).get("format", DEFAULT_FORMAT)) + for name, ircd in world.networkobjects.items(): if ircd.connected.is_set(): # Only attempt to send to connected networks for channel in ircd.pseudoclient.channels: + subst = {'sender': irc.getFriendlyName(source), + 'network': irc.name, + 'fullnetwork': irc.getFullNetworkName(), + 'current_channel': channel, + 'current_network': ircd.name, + 'current_fullnetwork': ircd.getFullNetworkName(), + 'text': message} + # Disable relaying or other plugins handling the global message. - ircd.msg(channel, message, loopback=False) + ircd.msg(channel, template.safe_substitute(subst), loopback=False) utils.add_cmd(g, "global", featured=True) From 787b2548405ea343f26a96fa3aca91c1bf059d02 Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 13 Mar 2017 13:40:09 -0700 Subject: [PATCH 6/6] permissions-reference: document global.global permission --- docs/permissions-reference.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/permissions-reference.md b/docs/permissions-reference.md index 1808372..0513e88 100644 --- a/docs/permissions-reference.md +++ b/docs/permissions-reference.md @@ -60,6 +60,9 @@ Remote versions of the `manage`, `list`, `sync`, and `clear` commands also exist - `exec.raw` - Allows access to the `raw` command. - `exec.inject` - Allows access to the `inject` command. +## Global +- `global.global` - Allows access to the `global` command. + ## Networks - `networks.disconnect` - Allows access to the `disconnect` command. - `networks.autoconnect` - Allows access to the `autoconnect` command.