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)