mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-02 17:29:22 +01:00
Used commands.wrap, fixed reconnect again.
This commit is contained in:
parent
640241bd11
commit
6b69d36628
@ -44,15 +44,13 @@ import time
|
|||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
import supybot.world as world
|
import supybot.world as world
|
||||||
|
from supybot.commands import *
|
||||||
import supybot.ircmsgs as ircmsgs
|
import supybot.ircmsgs as ircmsgs
|
||||||
import supybot.ircutils as ircutils
|
import supybot.ircutils as ircutils
|
||||||
import supybot.privmsgs as privmsgs
|
import supybot.privmsgs as privmsgs
|
||||||
import supybot.registry as registry
|
import supybot.registry as registry
|
||||||
import supybot.callbacks as callbacks
|
import supybot.callbacks as callbacks
|
||||||
|
|
||||||
class NetworkError(callbacks.Error):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class Network(callbacks.Privmsg):
|
class Network(callbacks.Privmsg):
|
||||||
_whois = {}
|
_whois = {}
|
||||||
_latency = {}
|
_latency = {}
|
||||||
@ -61,27 +59,19 @@ class Network(callbacks.Privmsg):
|
|||||||
for irc in world.ircs:
|
for irc in world.ircs:
|
||||||
if irc.network.lower() == network:
|
if irc.network.lower() == network:
|
||||||
return irc
|
return irc
|
||||||
raise NetworkError, 'I\'m not currently connected to %s.' % network
|
raise callbacks.Error, 'I\'m not currently connected to %s.' % network
|
||||||
|
|
||||||
def _getNetwork(self, irc, args):
|
def connect(self, irc, msg, args, network, server):
|
||||||
try:
|
|
||||||
self._getIrc(args[0])
|
|
||||||
return args.pop(0)
|
|
||||||
except (NetworkError, IndexError):
|
|
||||||
return irc.network
|
|
||||||
|
|
||||||
def connect(self, irc, msg, args):
|
|
||||||
"""<network> [<host[:port]>]
|
"""<network> [<host[:port]>]
|
||||||
|
|
||||||
Connects to another network (which will be represented by the name
|
Connects to another network (which will be represented by the name
|
||||||
provided in <network>) at <host:port>. If port is not provided, it
|
provided in <network>) at <host:port>. If port is not provided, it
|
||||||
defaults to 6667, the default port for IRC.
|
defaults to 6667, the default port for IRC.
|
||||||
"""
|
"""
|
||||||
(network, server) = privmsgs.getArgs(args, optional=1)
|
|
||||||
try:
|
try:
|
||||||
otherIrc = self._getIrc(network)
|
otherIrc = self._getIrc(network)
|
||||||
irc.error('I\'m already connected to %s.' % network, Raise=True)
|
irc.error('I\'m already connected to %s.' % network, Raise=True)
|
||||||
except NetworkError:
|
except callbacks.Error:
|
||||||
pass
|
pass
|
||||||
if server:
|
if server:
|
||||||
if ':' in server:
|
if ':' in server:
|
||||||
@ -102,9 +92,9 @@ class Network(callbacks.Privmsg):
|
|||||||
conf.supybot.networks().add(network)
|
conf.supybot.networks().add(network)
|
||||||
assert newIrc.callbacks is irc.callbacks, 'callbacks list is different'
|
assert newIrc.callbacks is irc.callbacks, 'callbacks list is different'
|
||||||
irc.replySuccess('Connection to %s initiated.' % network)
|
irc.replySuccess('Connection to %s initiated.' % network)
|
||||||
connect = privmsgs.checkCapability(connect, 'owner')
|
connect = wrap(connect, ['owner', 'something', additional('something')])
|
||||||
|
|
||||||
def disconnect(self, irc, msg, args):
|
def disconnect(self, irc, msg, args, otherIrc, quitMsg):
|
||||||
"""[<network>] [<quit message>]
|
"""[<network>] [<quit message>]
|
||||||
|
|
||||||
Disconnects from the network represented by the network <network>.
|
Disconnects from the network represented by the network <network>.
|
||||||
@ -112,52 +102,36 @@ class Network(callbacks.Privmsg):
|
|||||||
message. <network> is only necessary if the network is different
|
message. <network> is only necessary if the network is different
|
||||||
from the network the command is sent on.
|
from the network the command is sent on.
|
||||||
"""
|
"""
|
||||||
network = self._getNetwork(irc, args)
|
quitMsg = quitMsg or conf.supybot.plugins.Owner.quitMsg or msg.nick
|
||||||
quitMsg = privmsgs.getArgs(args, required=0, optional=1)
|
|
||||||
if not quitMsg:
|
|
||||||
quitMsg = msg.nick
|
|
||||||
otherIrc = self._getIrc(network)
|
|
||||||
# replySuccess here, rather than lower, in case we're being
|
|
||||||
# told to disconnect from the network we received the command on.
|
|
||||||
irc.replySuccess()
|
|
||||||
otherIrc.queueMsg(ircmsgs.quit(quitMsg))
|
otherIrc.queueMsg(ircmsgs.quit(quitMsg))
|
||||||
otherIrc.die()
|
otherIrc.die()
|
||||||
conf.supybot.networks().discard(network)
|
conf.supybot.networks().discard(network)
|
||||||
disconnect = privmsgs.checkCapability(disconnect, 'owner')
|
disconnect = wrap(disconnect, ['owner', 'networkIrc', additional('text')])
|
||||||
|
|
||||||
def reconnect(self, irc, msg, args):
|
def reconnect(self, irc, msg, args, otherIrc, quitMsg):
|
||||||
"""[<network>]
|
"""[<network>] [<quit message>]
|
||||||
|
|
||||||
Disconnects and then reconnects to <network>. If no network is given,
|
Disconnects and then reconnects to <network>. If no network is given,
|
||||||
disconnects and then reconnects to the network the command was given
|
disconnects and then reconnects to the network the command was given
|
||||||
on.
|
on. If no quit message is given, uses the configured one
|
||||||
|
(supybot.plugins.Owner.quitMsg) or the nick of the person giving the
|
||||||
|
command.
|
||||||
"""
|
"""
|
||||||
# XXX Should send a QUIT message.
|
quitMsg = quitMsg or conf.supybot.plugins.Owner.quitMsg() or msg.nick
|
||||||
network = self._getNetwork(irc, args)
|
otherIrc.queueMsg(ircmsgs.quit(quitMsg))
|
||||||
if args:
|
if otherIrc != irc:
|
||||||
irc.error('I\'m not connected to %s.' % privmsgs.getArgs(args))
|
|
||||||
return
|
|
||||||
badIrc = self._getIrc(network)
|
|
||||||
try:
|
|
||||||
badIrc.driver.reconnect()
|
|
||||||
if badIrc != irc:
|
|
||||||
# No need to reply if we're reconnecting ourselves.
|
# No need to reply if we're reconnecting ourselves.
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
except AttributeError: # There's a cleaner way to do this, but I'm lazy.
|
reconnect = wrap(reconnect, ['owner', 'networkIrc', additional('text')])
|
||||||
irc.error('I couldn\'t reconnect. You should restart me instead.')
|
|
||||||
reconnect = privmsgs.checkCapability(reconnect, 'owner')
|
|
||||||
|
|
||||||
def command(self, irc, msg, args):
|
def command(self, irc, msg, args, otherIrc, command, commandArgs):
|
||||||
"""<network> <command> [<arg> ...]
|
"""<network> <command> [<arg> ...]
|
||||||
|
|
||||||
Gives the bot <command> (with its associated <arg>s) on <network>.
|
Gives the bot <command> (with its associated <arg>s) on <network>.
|
||||||
"""
|
"""
|
||||||
if len(args) < 2:
|
self.Proxy(otherIrc, msg, commandArgs)
|
||||||
raise callbacks.ArgumentError
|
command = wrap(command, ['admin', ('networkIrc', True),
|
||||||
network = args.pop(0)
|
'commandName', any('something')])
|
||||||
otherIrc = self._getIrc(network)
|
|
||||||
self.Proxy(otherIrc, msg, args)
|
|
||||||
command = privmsgs.checkCapability(command, 'admin')
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# whois command-related stuff.
|
# whois command-related stuff.
|
||||||
@ -253,24 +227,20 @@ class Network(callbacks.Privmsg):
|
|||||||
replyIrc.reply(s)
|
replyIrc.reply(s)
|
||||||
do401 = do402
|
do401 = do402
|
||||||
|
|
||||||
def whois(self, irc, msg, args):
|
def whois(self, irc, msg, args, otherIrc, nick):
|
||||||
"""[<network>] <nick>
|
"""[<network>] <nick>
|
||||||
|
|
||||||
Returns the WHOIS response <network> gives for <nick>. <network> is
|
Returns the WHOIS response <network> gives for <nick>. <network> is
|
||||||
only necessary if the network is different than the network the command
|
only necessary if the network is different than the network the command
|
||||||
is sent on.
|
is sent on.
|
||||||
"""
|
"""
|
||||||
network = self._getNetwork(irc, args)
|
|
||||||
nick = privmsgs.getArgs(args)
|
|
||||||
if not ircutils.isNick(nick):
|
|
||||||
irc.errorInvalid('nick', nick, Raise=True)
|
|
||||||
nick = ircutils.toLower(nick)
|
|
||||||
otherIrc = self._getIrc(network)
|
otherIrc = self._getIrc(network)
|
||||||
# The double nick here is necessary because single-nick WHOIS only works
|
# The double nick here is necessary because single-nick WHOIS only works
|
||||||
# if the nick is on the same server (*not* the same network) as the user
|
# if the nick is on the same server (*not* the same network) as the user
|
||||||
# giving the command. Yeah, it made me say wtf too.
|
# giving the command. Yeah, it made me say wtf too.
|
||||||
otherIrc.queueMsg(ircmsgs.whois(nick, nick))
|
otherIrc.queueMsg(ircmsgs.whois(nick, nick))
|
||||||
self._whois[(otherIrc, nick)] = (irc, msg, {})
|
self._whois[(otherIrc, nick)] = (irc, msg, {})
|
||||||
|
whois = wrap(whois, ['networkIrc', 'nick'])
|
||||||
|
|
||||||
def networks(self, irc, msg, args):
|
def networks(self, irc, msg, args):
|
||||||
"""takes no arguments
|
"""takes no arguments
|
||||||
@ -280,6 +250,7 @@ class Network(callbacks.Privmsg):
|
|||||||
L = ['%s: %s' % (ircd.network, ircd.server) for ircd in world.ircs]
|
L = ['%s: %s' % (ircd.network, ircd.server) for ircd in world.ircs]
|
||||||
utils.sortBy(str.lower, L)
|
utils.sortBy(str.lower, L)
|
||||||
irc.reply(utils.commaAndify(L))
|
irc.reply(utils.commaAndify(L))
|
||||||
|
networks = wrap(networks)
|
||||||
|
|
||||||
def doPong(self, irc, msg):
|
def doPong(self, irc, msg):
|
||||||
now = time.time()
|
now = time.time()
|
||||||
@ -287,21 +258,17 @@ class Network(callbacks.Privmsg):
|
|||||||
(replyIrc, when) = self._latency.pop(irc)
|
(replyIrc, when) = self._latency.pop(irc)
|
||||||
replyIrc.reply('%.2f seconds.' % (now-when))
|
replyIrc.reply('%.2f seconds.' % (now-when))
|
||||||
|
|
||||||
def latency(self, irc, msg, args):
|
def latency(self, irc, msg, args, otherIrc):
|
||||||
"""[<network>]
|
"""[<network>]
|
||||||
|
|
||||||
Returns the current latency to <network>. <network> is only necessary
|
Returns the current latency to <network>. <network> is only necessary
|
||||||
if the message isn't sent on the network to which this command is to
|
if the message isn't sent on the network to which this command is to
|
||||||
apply.
|
apply.
|
||||||
"""
|
"""
|
||||||
network = self._getNetwork(irc, args)
|
|
||||||
if args:
|
|
||||||
irc.error('I\'m not connected to %s.' % privmsgs.getArgs(args))
|
|
||||||
return
|
|
||||||
otherIrc = self._getIrc(network)
|
|
||||||
otherIrc.queueMsg(ircmsgs.ping('Latency check (from %s).' % msg.nick))
|
otherIrc.queueMsg(ircmsgs.ping('Latency check (from %s).' % msg.nick))
|
||||||
self._latency[otherIrc] = (irc, time.time())
|
self._latency[otherIrc] = (irc, time.time())
|
||||||
irc.noReply()
|
irc.noReply()
|
||||||
|
latency = wrap(latency, ['networkIrc'])
|
||||||
|
|
||||||
|
|
||||||
Class = Network
|
Class = Network
|
||||||
|
Loading…
Reference in New Issue
Block a user