2015-09-03 08:08:04 +02:00
|
|
|
"""Networks plugin - allows you to manipulate connections to various configured networks."""
|
2016-07-25 20:00:56 +02:00
|
|
|
import importlib
|
2015-09-03 08:08:04 +02:00
|
|
|
|
2016-06-23 04:10:59 +02:00
|
|
|
from pylinkirc import utils, world, conf, classes
|
2016-06-21 03:18:54 +02:00
|
|
|
from pylinkirc.log import log
|
2016-07-02 05:08:38 +02:00
|
|
|
from pylinkirc.coremods import control
|
2015-09-03 08:08:04 +02:00
|
|
|
|
|
|
|
@utils.add_cmd
|
|
|
|
def disconnect(irc, source, args):
|
|
|
|
"""<network>
|
|
|
|
|
|
|
|
Disconnects the network <network>. When all networks are disconnected, PyLink will automatically exit.
|
2016-12-10 06:51:57 +01:00
|
|
|
|
|
|
|
To reconnect a network disconnected using this command, use REHASH to reload the networks list."""
|
2015-09-03 08:08:04 +02:00
|
|
|
try:
|
|
|
|
netname = args[0]
|
|
|
|
network = world.networkobjects[netname]
|
|
|
|
except IndexError: # No argument given.
|
2015-10-24 03:29:10 +02:00
|
|
|
irc.reply('Error: Not enough arguments (needs 1: network name (case sensitive)).')
|
2015-09-03 08:08:04 +02:00
|
|
|
return
|
|
|
|
except KeyError: # Unknown network.
|
2015-10-24 03:29:10 +02:00
|
|
|
irc.reply('Error: No such network "%s" (case sensitive).' % netname)
|
2015-09-03 08:08:04 +02:00
|
|
|
return
|
2016-07-02 04:54:19 +02:00
|
|
|
irc.reply("Done. If you want to reconnect this network, use the 'rehash' command.")
|
2016-01-10 05:03:42 +01:00
|
|
|
|
2016-07-02 05:08:38 +02:00
|
|
|
control.remove_network(network)
|
2016-03-05 18:42:51 +01:00
|
|
|
|
2015-09-03 08:08:04 +02:00
|
|
|
@utils.add_cmd
|
|
|
|
def autoconnect(irc, source, args):
|
|
|
|
"""<network> <seconds>
|
|
|
|
|
|
|
|
Sets the autoconnect time for <network> to <seconds>.
|
|
|
|
You can disable autoconnect for a network by setting <seconds> to a negative value."""
|
2016-05-01 01:54:11 +02:00
|
|
|
irc.checkAuthenticated(source)
|
2015-09-03 08:08:04 +02:00
|
|
|
try:
|
|
|
|
netname = args[0]
|
|
|
|
seconds = float(args[1])
|
|
|
|
network = world.networkobjects[netname]
|
|
|
|
except IndexError: # Arguments not given.
|
2015-10-24 03:29:10 +02:00
|
|
|
irc.reply('Error: Not enough arguments (needs 2: network name (case sensitive), autoconnect time (in seconds)).')
|
2015-09-03 08:08:04 +02:00
|
|
|
return
|
|
|
|
except KeyError: # Unknown network.
|
2015-10-24 03:29:10 +02:00
|
|
|
irc.reply('Error: No such network "%s" (case sensitive).' % netname)
|
2015-09-03 08:08:04 +02:00
|
|
|
return
|
|
|
|
except ValueError:
|
2015-10-24 03:29:10 +02:00
|
|
|
irc.reply('Error: Invalid argument "%s" for <seconds>.' % seconds)
|
2015-09-03 08:08:04 +02:00
|
|
|
return
|
|
|
|
network.serverdata['autoconnect'] = seconds
|
2015-10-24 03:29:10 +02:00
|
|
|
irc.reply("Done.")
|
2015-12-22 19:58:58 +01:00
|
|
|
|
|
|
|
@utils.add_cmd
|
|
|
|
def remote(irc, source, args):
|
|
|
|
"""<network> <command>
|
|
|
|
|
|
|
|
Runs <command> on the remote network <network>. No replies are sent back due to protocol limitations."""
|
2016-05-01 01:54:11 +02:00
|
|
|
irc.checkAuthenticated(source, allowOper=False)
|
2015-12-22 19:58:58 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
netname = args[0]
|
|
|
|
cmd_args = ' '.join(args[1:]).strip()
|
|
|
|
remoteirc = world.networkobjects[netname]
|
|
|
|
except IndexError: # Arguments not given.
|
|
|
|
irc.reply('Error: Not enough arguments (needs 2 or more: network name (case sensitive), command name & arguments).')
|
|
|
|
return
|
|
|
|
except KeyError: # Unknown network.
|
|
|
|
irc.reply('Error: No such network "%s" (case sensitive).' % netname)
|
|
|
|
return
|
|
|
|
|
|
|
|
if not cmd_args:
|
|
|
|
irc.reply('No text entered!')
|
|
|
|
return
|
|
|
|
|
2016-07-01 03:22:45 +02:00
|
|
|
# Force remoteirc.called_in to something private in order to prevent
|
2015-12-22 19:58:58 +01:00
|
|
|
# accidental information leakage from replies.
|
2016-07-01 03:22:45 +02:00
|
|
|
remoteirc.called_in = remoteirc.called_by = remoteirc.pseudoclient.uid
|
2015-12-22 19:58:58 +01:00
|
|
|
|
|
|
|
# Set PyLink's identification to admin.
|
2016-07-30 05:15:31 +02:00
|
|
|
remoteirc.pseudoclient.account = "<PyLink networks.remote override>"
|
2015-12-22 19:58:58 +01:00
|
|
|
|
|
|
|
try: # Remotely call the command (use the PyLink client as a dummy user).
|
|
|
|
remoteirc.callCommand(remoteirc.pseudoclient.uid, cmd_args)
|
|
|
|
finally: # Remove the identification override after we finish.
|
2016-07-30 05:15:31 +02:00
|
|
|
remoteirc.pseudoclient.account = ''
|
2015-12-22 19:58:58 +01:00
|
|
|
|
|
|
|
irc.reply("Done.")
|
2016-07-25 20:00:56 +02:00
|
|
|
|
|
|
|
@utils.add_cmd
|
|
|
|
def reloadproto(irc, source, args):
|
|
|
|
"""<protocol module name>
|
|
|
|
|
|
|
|
Reloads the given protocol module without restart. You will have to manually disconnect and reconnect any network using the module for changes to apply."""
|
|
|
|
irc.checkAuthenticated(source)
|
|
|
|
try:
|
|
|
|
name = args[0]
|
|
|
|
except IndexError:
|
|
|
|
irc.reply('Error: Not enough arguments (needs 1: protocol module name)')
|
|
|
|
return
|
|
|
|
|
|
|
|
proto = utils.getProtocolModule(name)
|
|
|
|
importlib.reload(proto)
|
|
|
|
|
|
|
|
irc.reply("Done. You will have to manually disconnect and reconnect any network using the %r module for changes to apply." % name)
|