mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-24 19:52:53 +01:00
protocols: Move kill() into ts6_common, and make unreal.py use it
Ref #239. protocols/unreal was hardcoding a killpath, lazy me...
This commit is contained in:
parent
d0b7d44f1a
commit
3457da16bd
@ -189,39 +189,6 @@ class TS6Protocol(TS6BaseProtocol):
|
||||
joinedmodes = self.irc.joinModes(modes)
|
||||
self._send(numeric, 'MODE %s %s' % (target, joinedmodes))
|
||||
|
||||
def kill(self, numeric, target, reason):
|
||||
"""Sends a kill from a PyLink client/server."""
|
||||
|
||||
if (not self.irc.isInternalClient(numeric)) and \
|
||||
(not self.irc.isInternalServer(numeric)):
|
||||
raise LookupError('No such PyLink client/server exists.')
|
||||
|
||||
# From TS6 docs:
|
||||
# KILL:
|
||||
# parameters: target user, path
|
||||
|
||||
# The format of the path parameter is some sort of description of the source of
|
||||
# the kill followed by a space and a parenthesized reason. To avoid overflow,
|
||||
# it is recommended not to add anything to the path.
|
||||
|
||||
assert target in self.irc.users, "Unknown target %r for kill()!" % target
|
||||
|
||||
if numeric in self.irc.users:
|
||||
# Killer was an user. Follow examples of setting the path to be "killer.host!killer.nick".
|
||||
userobj = self.irc.users[numeric]
|
||||
killpath = '%s!%s' % (userobj.host, userobj.nick)
|
||||
elif numeric in self.irc.servers:
|
||||
# Sender was a server; killpath is just its name.
|
||||
killpath = self.irc.servers[numeric].name
|
||||
else:
|
||||
# Invalid sender?! This shouldn't happen, but make the killpath our server name anyways.
|
||||
log.warning('(%s) Invalid sender %s for kill(); using our server name instead.',
|
||||
self.irc.name, numeric)
|
||||
killpath = self.irc.servers[self.irc.sid].name
|
||||
|
||||
self._send(numeric, 'KILL %s :%s (%s)' % (target, killpath, reason))
|
||||
self.removeClient(target)
|
||||
|
||||
def topicBurst(self, numeric, target, text):
|
||||
"""Sends a topic change from a PyLink server. This is usually used on burst."""
|
||||
if not self.irc.isInternalServer(numeric):
|
||||
|
@ -160,6 +160,39 @@ class TS6BaseProtocol(Protocol):
|
||||
# handle_part() does that just fine.
|
||||
self.handle_part(target, 'KICK', [channel])
|
||||
|
||||
def kill(self, numeric, target, reason):
|
||||
"""Sends a kill from a PyLink client/server."""
|
||||
|
||||
if (not self.irc.isInternalClient(numeric)) and \
|
||||
(not self.irc.isInternalServer(numeric)):
|
||||
raise LookupError('No such PyLink client/server exists.')
|
||||
|
||||
# From TS6 docs:
|
||||
# KILL:
|
||||
# parameters: target user, path
|
||||
|
||||
# The format of the path parameter is some sort of description of the source of
|
||||
# the kill followed by a space and a parenthesized reason. To avoid overflow,
|
||||
# it is recommended not to add anything to the path.
|
||||
|
||||
assert target in self.irc.users, "Unknown target %r for kill()!" % target
|
||||
|
||||
if numeric in self.irc.users:
|
||||
# Killer was an user. Follow examples of setting the path to be "killer.host!killer.nick".
|
||||
userobj = self.irc.users[numeric]
|
||||
killpath = '%s!%s' % (userobj.host, userobj.nick)
|
||||
elif numeric in self.irc.servers:
|
||||
# Sender was a server; killpath is just its name.
|
||||
killpath = self.irc.servers[numeric].name
|
||||
else:
|
||||
# Invalid sender?! This shouldn't happen, but make the killpath our server name anyways.
|
||||
log.warning('(%s) Invalid sender %s for kill(); using our server name instead.',
|
||||
self.irc.name, numeric)
|
||||
killpath = self.irc.servers[self.irc.sid].name
|
||||
|
||||
self._send(numeric, 'KILL %s :%s (%s)' % (target, killpath, reason))
|
||||
self.removeClient(target)
|
||||
|
||||
def nick(self, numeric, newnick):
|
||||
"""Changes the nick of a PyLink client."""
|
||||
if not self.irc.isInternalClient(numeric):
|
||||
|
@ -196,20 +196,6 @@ class UnrealProtocol(TS6BaseProtocol):
|
||||
if not (target is None or source is None):
|
||||
self._send(source, 'PING %s %s' % (self.irc.servers[source].name, self.irc.servers[target].name))
|
||||
|
||||
def kill(self, numeric, target, reason):
|
||||
"""Sends a kill from a PyLink client/server."""
|
||||
# <- :GL KILL 38QAAAAAA :hidden-1C620195!GL (test)
|
||||
|
||||
if (not self.irc.isInternalClient(numeric)) and \
|
||||
(not self.irc.isInternalServer(numeric)):
|
||||
raise LookupError('No such PyLink client/server exists.')
|
||||
|
||||
assert target in self.irc.users, "Unknown target %r for kill()!" % target
|
||||
|
||||
# The killpath doesn't really matter here...
|
||||
self._send(numeric, 'KILL %s :%s!PyLink (%s)' % (target, self.irc.serverdata['hostname'], reason))
|
||||
self.removeClient(target)
|
||||
|
||||
def mode(self, numeric, target, modes, ts=None):
|
||||
"""
|
||||
Sends mode changes from a PyLink client/server. The mode list should be
|
||||
|
Loading…
Reference in New Issue
Block a user