mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-27 21:19:31 +01:00
Move part, quit, message, notice, topic, _send_with_prefix, _expandPUID to ircs2s_common
This commit is contained in:
parent
f163d7ddde
commit
8ddcc4d9a6
@ -163,6 +163,10 @@ class IRCCommonProtocol(IRCNetwork):
|
||||
"""Handles ERROR messages - these mean that our uplink has disconnected us!"""
|
||||
raise ProtocolError('Received an ERROR, disconnecting!')
|
||||
|
||||
def _send_with_prefix(self, source, msg, **kwargs):
|
||||
"""Sends a RFC 459-style raw command from the given sender."""
|
||||
self.send(':%s %s' % (source, msg), **kwargs)
|
||||
|
||||
class IRCS2SProtocol(IRCCommonProtocol):
|
||||
COMMAND_TOKENS = {}
|
||||
|
||||
@ -236,6 +240,63 @@ class IRCS2SProtocol(IRCCommonProtocol):
|
||||
if parsed_args is not None:
|
||||
return [sender, command, parsed_args]
|
||||
|
||||
def part(self, client, channel, reason=None):
|
||||
"""Sends a part from a PyLink client."""
|
||||
channel = self.to_lower(channel)
|
||||
if not self.is_internal_client(client):
|
||||
log.error('(%s) Error trying to part %r from %r (no such client exists)', self.name, client, channel)
|
||||
raise LookupError('No such PyLink client exists.')
|
||||
msg = "PART %s" % channel
|
||||
if reason:
|
||||
msg += " :%s" % reason
|
||||
self._send_with_prefix(client, msg)
|
||||
self.handle_part(client, 'PART', [channel])
|
||||
|
||||
def quit(self, numeric, reason):
|
||||
"""Quits a PyLink client."""
|
||||
if self.is_internal_client(numeric):
|
||||
self._send_with_prefix(numeric, "QUIT :%s" % reason)
|
||||
self._remove_client(numeric)
|
||||
else:
|
||||
raise LookupError("No such PyLink client exists.")
|
||||
|
||||
|
||||
def _expandPUID(self, uid):
|
||||
"""
|
||||
Returns the nick for the given UID; this method helps support protocol modules that use
|
||||
PUIDs internally but must send nicks in the server protocol.
|
||||
"""
|
||||
return uid
|
||||
|
||||
def message(self, numeric, target, text):
|
||||
"""Sends a PRIVMSG from a PyLink client."""
|
||||
if not self.is_internal_client(numeric):
|
||||
raise LookupError('No such PyLink client exists.')
|
||||
|
||||
# Mangle message targets for IRCds that require it.
|
||||
target = self._expandPUID(target)
|
||||
|
||||
self._send_with_prefix(numeric, 'PRIVMSG %s :%s' % (target, text))
|
||||
|
||||
def notice(self, numeric, target, text):
|
||||
"""Sends a NOTICE from a PyLink client or server."""
|
||||
if (not self.is_internal_client(numeric)) and \
|
||||
(not self.is_internal_server(numeric)):
|
||||
raise LookupError('No such PyLink client/server exists.')
|
||||
|
||||
# Mangle message targets for IRCds that require it.
|
||||
target = self._expandPUID(target)
|
||||
|
||||
self._send_with_prefix(numeric, 'NOTICE %s :%s' % (target, text))
|
||||
|
||||
def topic(self, numeric, target, text):
|
||||
"""Sends a TOPIC change from a PyLink client."""
|
||||
if not self.is_internal_client(numeric):
|
||||
raise LookupError('No such PyLink client exists.')
|
||||
self._send_with_prefix(numeric, 'TOPIC %s :%s' % (target, text))
|
||||
self.channels[target].topic = text
|
||||
self.channels[target].topicset = True
|
||||
|
||||
def check_nick_collision(self, nick):
|
||||
"""
|
||||
Nick collision checker.
|
||||
|
@ -108,19 +108,6 @@ class TS6BaseProtocol(IRCS2SProtocol):
|
||||
# SID generator for TS6.
|
||||
self.sidgen = TS6SIDGenerator(self)
|
||||
|
||||
def _send_with_prefix(self, source, msg, **kwargs):
|
||||
"""Sends a TS6-style raw command from a source numeric to the self.irc connection given."""
|
||||
self.send(':%s %s' % (source, msg), **kwargs)
|
||||
|
||||
def _expandPUID(self, uid):
|
||||
"""
|
||||
Returns the outgoing nick for the given UID. In the base ts6_common implementation,
|
||||
this does nothing, but other modules subclassing this can override it.
|
||||
For example, this can be used to turn PUIDs (used to store legacy, UID-less users)
|
||||
to actual nicks in outgoing messages, so that a remote IRCd can understand it.
|
||||
"""
|
||||
return uid
|
||||
|
||||
### OUTGOING COMMANDS
|
||||
|
||||
def numeric(self, source, numeric, target, text):
|
||||
@ -197,55 +184,6 @@ class TS6BaseProtocol(IRCS2SProtocol):
|
||||
# Update the NICK TS.
|
||||
self.users[numeric].ts = int(time.time())
|
||||
|
||||
def part(self, client, channel, reason=None):
|
||||
"""Sends a part from a PyLink client."""
|
||||
channel = self.to_lower(channel)
|
||||
if not self.is_internal_client(client):
|
||||
log.error('(%s) Error trying to part %r from %r (no such client exists)', self.name, client, channel)
|
||||
raise LookupError('No such PyLink client exists.')
|
||||
msg = "PART %s" % channel
|
||||
if reason:
|
||||
msg += " :%s" % reason
|
||||
self._send_with_prefix(client, msg)
|
||||
self.handle_part(client, 'PART', [channel])
|
||||
|
||||
def quit(self, numeric, reason):
|
||||
"""Quits a PyLink client."""
|
||||
if self.is_internal_client(numeric):
|
||||
self._send_with_prefix(numeric, "QUIT :%s" % reason)
|
||||
self._remove_client(numeric)
|
||||
else:
|
||||
raise LookupError("No such PyLink client exists.")
|
||||
|
||||
def message(self, numeric, target, text):
|
||||
"""Sends a PRIVMSG from a PyLink client."""
|
||||
if not self.is_internal_client(numeric):
|
||||
raise LookupError('No such PyLink client exists.')
|
||||
|
||||
# Mangle message targets for IRCds that require it.
|
||||
target = self._expandPUID(target)
|
||||
|
||||
self._send_with_prefix(numeric, 'PRIVMSG %s :%s' % (target, text))
|
||||
|
||||
def notice(self, numeric, target, text):
|
||||
"""Sends a NOTICE from a PyLink client or server."""
|
||||
if (not self.is_internal_client(numeric)) and \
|
||||
(not self.is_internal_server(numeric)):
|
||||
raise LookupError('No such PyLink client/server exists.')
|
||||
|
||||
# Mangle message targets for IRCds that require it.
|
||||
target = self._expandPUID(target)
|
||||
|
||||
self._send_with_prefix(numeric, 'NOTICE %s :%s' % (target, text))
|
||||
|
||||
def topic(self, numeric, target, text):
|
||||
"""Sends a TOPIC change from a PyLink client."""
|
||||
if not self.is_internal_client(numeric):
|
||||
raise LookupError('No such PyLink client exists.')
|
||||
self._send_with_prefix(numeric, 'TOPIC %s :%s' % (target, text))
|
||||
self.channels[target].topic = text
|
||||
self.channels[target].topicset = True
|
||||
|
||||
def spawn_server(self, name, sid=None, uplink=None, desc=None, endburst_delay=0):
|
||||
"""
|
||||
Spawns a server off a PyLink server. desc (server description)
|
||||
|
Loading…
Reference in New Issue
Block a user