3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00
PyLink/plugins/global.py

63 lines
2.1 KiB
Python
Raw Normal View History

2017-03-13 17:30:06 +01:00
# global.py: Global Noticing Plugin
2017-03-13 21:38:53 +01:00
import string
2017-03-13 17:30:06 +01:00
from pylinkirc import conf, utils, world
from pylinkirc.log import log
from pylinkirc.coremods import permissions
2017-03-13 21:38:53 +01:00
DEFAULT_FORMAT = "[$sender@$fullnetwork] $text"
2017-03-13 17:30:06 +01:00
def g(irc, source, args):
"""<message text>
2017-03-13 17:30:06 +01:00
Sends out a Instance-wide notice.
"""
permissions.check_permissions(irc, source, ["global.global"])
message = " ".join(args).strip()
if not message:
irc.error("Refusing to send an empty message.")
return
global_conf = conf.conf.get('global') or {}
template = string.Template(global_conf.get('format', DEFAULT_FORMAT))
2017-03-13 21:38:53 +01:00
exempt_channels = set(global_conf.get('exempt_channels', set()))
netcount = 0
chancount = 0
for netname, ircd in world.networkobjects.items():
if ircd.connected.is_set(): # Only attempt to send to connected networks
netcount += 1
for channel in ircd.pseudoclient.channels:
local_exempt_channels = exempt_channels | set(ircd.serverdata.get('global_exempt_channels', set()))
skip = False
for exempt in local_exempt_channels:
if irc.match_text(exempt, channel):
log.debug('global: Skipping channel %s%s for exempt %r', netname, channel, exempt)
skip = True
break
if skip:
continue
subst = {'sender': irc.get_friendly_name(source),
2017-03-13 21:38:53 +01:00
'network': irc.name,
'fullnetwork': irc.get_full_network_name(),
2017-03-13 21:38:53 +01:00
'current_channel': channel,
'current_network': netname,
'current_fullnetwork': ircd.get_full_network_name(),
2017-03-13 21:38:53 +01:00
'text': message}
# Disable relaying or other plugins handling the global message.
2017-03-13 21:38:53 +01:00
ircd.msg(channel, template.safe_substitute(subst), loopback=False)
chancount += 1
irc.reply('Done. Sent to %d channels across %d networks.' % (chancount, netcount))
2017-03-13 17:30:06 +01:00
utils.add_cmd(g, "global", featured=True)