3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-30 14:49:28 +01:00

global: configurable output format

This commit is contained in:
James Lu 2017-03-13 13:38:53 -07:00
parent cfe72e2cd0
commit 3ffbbe60ff
2 changed files with 32 additions and 2 deletions

View File

@ -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"

View File

@ -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):
"""<message text>
@ -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)