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.coremods import permissions
|
2019-07-15 00:12:29 +02:00
|
|
|
from pylinkirc.log import log
|
2017-03-13 17:30:06 +01:00
|
|
|
|
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 21:29:04 +01:00
|
|
|
|
2017-03-13 17:30:06 +01:00
|
|
|
Sends out a Instance-wide notice.
|
|
|
|
"""
|
2017-08-02 16:24:23 +02:00
|
|
|
permissions.check_permissions(irc, source, ["global.global"])
|
2018-06-09 03:22:00 +02:00
|
|
|
message = " ".join(args).strip()
|
|
|
|
|
|
|
|
if not message:
|
|
|
|
irc.error("Refusing to send an empty message.")
|
|
|
|
return
|
|
|
|
|
2017-11-06 21:07:33 +01:00
|
|
|
global_conf = conf.conf.get('global') or {}
|
|
|
|
template = string.Template(global_conf.get('format', DEFAULT_FORMAT))
|
2017-03-13 21:38:53 +01:00
|
|
|
|
2018-06-09 03:24:42 +02:00
|
|
|
exempt_channels = set(global_conf.get('exempt_channels', set()))
|
2018-06-09 03:28:28 +02:00
|
|
|
|
|
|
|
netcount = 0
|
|
|
|
chancount = 0
|
2018-06-09 03:24:42 +02:00
|
|
|
for netname, ircd in world.networkobjects.items():
|
2020-03-17 03:05:23 +01:00
|
|
|
# Skip networks that aren't ready and dummy networks which don't have .pseudoclient set
|
|
|
|
if ircd.connected.is_set() and ircd.pseudoclient:
|
2018-06-09 03:28:28 +02:00
|
|
|
netcount += 1
|
2017-03-13 21:23:22 +01:00
|
|
|
for channel in ircd.pseudoclient.channels:
|
2018-06-09 03:24:42 +02:00
|
|
|
|
|
|
|
local_exempt_channels = exempt_channels | set(ircd.serverdata.get('global_exempt_channels', set()))
|
|
|
|
|
|
|
|
skip = False
|
|
|
|
for exempt in local_exempt_channels:
|
2020-03-30 22:09:33 +02:00
|
|
|
if ircd.match_text(exempt, str(channel)):
|
2018-06-09 03:24:42 +02:00
|
|
|
log.debug('global: Skipping channel %s%s for exempt %r', netname, channel, exempt)
|
|
|
|
skip = True
|
|
|
|
break
|
|
|
|
|
|
|
|
if skip:
|
|
|
|
continue
|
|
|
|
|
2017-06-30 08:01:39 +02:00
|
|
|
subst = {'sender': irc.get_friendly_name(source),
|
2017-03-13 21:38:53 +01:00
|
|
|
'network': irc.name,
|
2017-06-30 08:01:39 +02:00
|
|
|
'fullnetwork': irc.get_full_network_name(),
|
2017-03-13 21:38:53 +01:00
|
|
|
'current_channel': channel,
|
2018-06-09 03:24:42 +02:00
|
|
|
'current_network': netname,
|
2017-06-30 08:01:39 +02:00
|
|
|
'current_fullnetwork': ircd.get_full_network_name(),
|
2017-03-13 21:38:53 +01:00
|
|
|
'text': message}
|
|
|
|
|
2017-03-13 21:29:04 +01:00
|
|
|
# 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)
|
2017-03-13 21:29:04 +01:00
|
|
|
|
2018-06-09 03:28:28 +02:00
|
|
|
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)
|