mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 04:02:46 +01:00
Relay: Implement +draft/display-name specification.
https://github.com/ircv3/ircv3-specifications/pull/452
This commit is contained in:
parent
97a7aa304e
commit
fc2e34956e
@ -28,6 +28,7 @@
|
|||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
###
|
###
|
||||||
|
|
||||||
|
import copy
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
@ -207,12 +208,15 @@ class Relay(callbacks.Plugin):
|
|||||||
|
|
||||||
do401 = do402
|
do401 = do402
|
||||||
|
|
||||||
|
def _formatDisplayName(self, nick, network, channel):
|
||||||
|
displayName = nick
|
||||||
|
if self.registryValue('includeNetwork', channel):
|
||||||
|
displayName += '@' + network
|
||||||
|
|
||||||
|
return displayName
|
||||||
|
|
||||||
def _formatPrivmsg(self, nick, network, msg):
|
def _formatPrivmsg(self, nick, network, msg):
|
||||||
channel = msg.channel
|
channel = msg.channel
|
||||||
if self.registryValue('includeNetwork', channel):
|
|
||||||
network = '@' + network
|
|
||||||
else:
|
|
||||||
network = ''
|
|
||||||
# colorize nicks
|
# colorize nicks
|
||||||
color = self.registryValue('color', channel) # Also used further down.
|
color = self.registryValue('color', channel) # Also used further down.
|
||||||
if color:
|
if color:
|
||||||
@ -225,7 +229,8 @@ class Relay(callbacks.Plugin):
|
|||||||
t = ircutils.mircColor('*', *colors)
|
t = ircutils.mircColor('*', *colors)
|
||||||
else:
|
else:
|
||||||
t = '*'
|
t = '*'
|
||||||
s = format('%s %s%s %s', t, nick, network, ircmsgs.unAction(msg))
|
displayName = self._formatDisplayName(nick, network, msg.channel)
|
||||||
|
s = format('%s %s %s', t, displayName, ircmsgs.unAction(msg))
|
||||||
else:
|
else:
|
||||||
if color:
|
if color:
|
||||||
lt = ircutils.mircColor('<', *colors)
|
lt = ircutils.mircColor('<', *colors)
|
||||||
@ -233,16 +238,28 @@ class Relay(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
lt = '<'
|
lt = '<'
|
||||||
gt = '>'
|
gt = '>'
|
||||||
s = format('%s%s%s%s %s', lt, nick, network, gt, msg.args[1])
|
displayName = self._formatDisplayName(nick, network, msg.channel)
|
||||||
|
s = format('%s%s%s %s', lt, displayName, gt, msg.args[1])
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def _sendToOthers(self, irc, msg):
|
def _sendToOthers(self, irc, msg, nick):
|
||||||
|
|
||||||
assert msg.command in ('PRIVMSG', 'NOTICE', 'TOPIC')
|
assert msg.command in ('PRIVMSG', 'NOTICE', 'TOPIC')
|
||||||
for otherIrc in world.ircs:
|
for otherIrc in world.ircs:
|
||||||
if otherIrc != irc and not otherIrc.zombie:
|
if otherIrc != irc and not otherIrc.zombie:
|
||||||
if msg.channel in otherIrc.state.channels:
|
if msg.channel in otherIrc.state.channels:
|
||||||
msg.tag('relayedMsg')
|
self._sendToOther(otherIrc, msg, nick)
|
||||||
otherIrc.queueMsg(msg)
|
|
||||||
|
def _sendToOther(self, otherIrc, msg, nick):
|
||||||
|
msg = copy.deepcopy(msg)
|
||||||
|
msg.tag('relayedMsg')
|
||||||
|
if 'message-tags' in otherIrc.state.capabilities_ack \
|
||||||
|
and conf.supybot.protocols.irc.experimentalExtensions():
|
||||||
|
displayName = self._formatDisplayName(
|
||||||
|
nick, otherIrc.network, msg.channel)
|
||||||
|
# https://github.com/ircv3/ircv3-specifications/pull/452
|
||||||
|
msg.server_tags['+draft/display-name'] = displayName
|
||||||
|
otherIrc.queueMsg(msg)
|
||||||
|
|
||||||
def _checkRelayMsg(self, msg):
|
def _checkRelayMsg(self, msg):
|
||||||
channel = msg.channel
|
channel = msg.channel
|
||||||
@ -304,7 +321,7 @@ class Relay(callbacks.Plugin):
|
|||||||
network = self._getIrcName(irc)
|
network = self._getIrcName(irc)
|
||||||
s = self._formatPrivmsg(msg.nick, network, msg)
|
s = self._formatPrivmsg(msg.nick, network, msg)
|
||||||
m = self._msgmaker(msg.channel, network, s)
|
m = self._msgmaker(msg.channel, network, s)
|
||||||
self._sendToOthers(irc, m)
|
self._sendToOthers(irc, m, msg.nick)
|
||||||
|
|
||||||
def _msgmaker(self, target, network, s):
|
def _msgmaker(self, target, network, s):
|
||||||
msg = dynamic.msg
|
msg = dynamic.msg
|
||||||
@ -330,7 +347,7 @@ class Relay(callbacks.Plugin):
|
|||||||
hostmask = ''
|
hostmask = ''
|
||||||
s = format(_('%s%s has joined on %s'), msg.nick, hostmask, network)
|
s = format(_('%s%s has joined on %s'), msg.nick, hostmask, network)
|
||||||
m = self._msgmaker(channel, network, s)
|
m = self._msgmaker(channel, network, s)
|
||||||
self._sendToOthers(irc, m)
|
self._sendToOthers(irc, m, msg.nick)
|
||||||
|
|
||||||
def doPart(self, irc, msg):
|
def doPart(self, irc, msg):
|
||||||
irc = self._getRealIrc(irc)
|
irc = self._getRealIrc(irc)
|
||||||
@ -348,7 +365,7 @@ class Relay(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
s = format(_('%s%s has left on %s'), msg.nick, hostmask, network)
|
s = format(_('%s%s has left on %s'), msg.nick, hostmask, network)
|
||||||
m = self._msgmaker(channel, network, s)
|
m = self._msgmaker(channel, network, s)
|
||||||
self._sendToOthers(irc, m)
|
self._sendToOthers(irc, m, msg.nick)
|
||||||
|
|
||||||
def doMode(self, irc, msg):
|
def doMode(self, irc, msg):
|
||||||
irc = self._getRealIrc(irc)
|
irc = self._getRealIrc(irc)
|
||||||
@ -359,7 +376,7 @@ class Relay(callbacks.Plugin):
|
|||||||
s = format(_('mode change by %s on %s: %s'),
|
s = format(_('mode change by %s on %s: %s'),
|
||||||
msg.nick, network, ' '.join(msg.args[1:]))
|
msg.nick, network, ' '.join(msg.args[1:]))
|
||||||
m = self._msgmaker(channel, network, s)
|
m = self._msgmaker(channel, network, s)
|
||||||
self._sendToOthers(irc, m)
|
self._sendToOthers(irc, m, msg.nick)
|
||||||
|
|
||||||
def doKick(self, irc, msg):
|
def doKick(self, irc, msg):
|
||||||
irc = self._getRealIrc(irc)
|
irc = self._getRealIrc(irc)
|
||||||
@ -374,7 +391,7 @@ class Relay(callbacks.Plugin):
|
|||||||
s = format(_('%s was kicked by %s on %s'),
|
s = format(_('%s was kicked by %s on %s'),
|
||||||
msg.args[1], msg.nick, network)
|
msg.args[1], msg.nick, network)
|
||||||
m = self._msgmaker(channel, network, s)
|
m = self._msgmaker(channel, network, s)
|
||||||
self._sendToOthers(irc, m)
|
self._sendToOthers(irc, m, msg.nick)
|
||||||
|
|
||||||
def doNick(self, irc, msg):
|
def doNick(self, irc, msg):
|
||||||
irc = self._getRealIrc(irc)
|
irc = self._getRealIrc(irc)
|
||||||
@ -383,7 +400,7 @@ class Relay(callbacks.Plugin):
|
|||||||
s = format(_('nick change by %s to %s on %s'), msg.nick,newNick,network)
|
s = format(_('nick change by %s to %s on %s'), msg.nick,newNick,network)
|
||||||
for channel in self.registryValue('channels'):
|
for channel in self.registryValue('channels'):
|
||||||
m = self._msgmaker(channel, network, s)
|
m = self._msgmaker(channel, network, s)
|
||||||
self._sendToOthers(irc, m)
|
self._sendToOthers(irc, m, msg.nick)
|
||||||
|
|
||||||
def doTopic(self, irc, msg):
|
def doTopic(self, irc, msg):
|
||||||
irc = self._getRealIrc(irc)
|
irc = self._getRealIrc(irc)
|
||||||
@ -411,7 +428,7 @@ class Relay(callbacks.Plugin):
|
|||||||
s = format(_('topic change by %s on %s: %s'),
|
s = format(_('topic change by %s on %s: %s'),
|
||||||
msg.nick, network, newTopic)
|
msg.nick, network, newTopic)
|
||||||
m = self._msgmaker(channel, network, s)
|
m = self._msgmaker(channel, network, s)
|
||||||
self._sendToOthers(irc, m)
|
self._sendToOthers(irc, m, msg.nick)
|
||||||
|
|
||||||
def doQuit(self, irc, msg):
|
def doQuit(self, irc, msg):
|
||||||
irc = self._getRealIrc(irc)
|
irc = self._getRealIrc(irc)
|
||||||
@ -422,7 +439,7 @@ class Relay(callbacks.Plugin):
|
|||||||
s = format(_('%s has quit %s.'), msg.nick, network)
|
s = format(_('%s has quit %s.'), msg.nick, network)
|
||||||
for channel in self.registryValue('channels'):
|
for channel in self.registryValue('channels'):
|
||||||
m = self._msgmaker(channel, network, s)
|
m = self._msgmaker(channel, network, s)
|
||||||
self._sendToOthers(irc, m)
|
self._sendToOthers(irc, m, msg.nick)
|
||||||
|
|
||||||
def doError(self, irc, msg):
|
def doError(self, irc, msg):
|
||||||
irc = self._getRealIrc(irc)
|
irc = self._getRealIrc(irc)
|
||||||
@ -430,7 +447,7 @@ class Relay(callbacks.Plugin):
|
|||||||
s = format(_('disconnected from %s: %s'), network, msg.args[0])
|
s = format(_('disconnected from %s: %s'), network, msg.args[0])
|
||||||
for channel in self.registryValue('channels'):
|
for channel in self.registryValue('channels'):
|
||||||
m = self._msgmaker(channel, network, s)
|
m = self._msgmaker(channel, network, s)
|
||||||
self._sendToOthers(irc, m)
|
self._sendToOthers(irc, m, msg.nick)
|
||||||
|
|
||||||
def outFilter(self, irc, msg):
|
def outFilter(self, irc, msg):
|
||||||
irc = self._getRealIrc(irc)
|
irc = self._getRealIrc(irc)
|
||||||
@ -442,7 +459,7 @@ class Relay(callbacks.Plugin):
|
|||||||
network = self._getIrcName(irc)
|
network = self._getIrcName(irc)
|
||||||
s = self._formatPrivmsg(irc.nick, network, msg)
|
s = self._formatPrivmsg(irc.nick, network, msg)
|
||||||
relayMsg = self._msgmaker(msg.args[0], network, s)
|
relayMsg = self._msgmaker(msg.args[0], network, s)
|
||||||
self._sendToOthers(irc, relayMsg)
|
self._sendToOthers(irc, relayMsg, irc.nick)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def _addRelayMsg(self, msg):
|
def _addRelayMsg(self, msg):
|
||||||
|
Loading…
Reference in New Issue
Block a user