mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-23 18:54:05 +01:00
opercmds: simplify code for KILL and KICK
This commit is contained in:
parent
812a866a4e
commit
8f5073d111
@ -125,32 +125,29 @@ def kick(irc, source, args):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Convert the source and target nicks to UIDs.
|
# Convert the source and target nicks to UIDs.
|
||||||
u = irc.nickToUid(sourcenick) or sourcenick
|
sender = irc.nickToUid(sourcenick) or sourcenick
|
||||||
targetu = irc.nickToUid(target)
|
targetu = irc.nickToUid(target)
|
||||||
|
|
||||||
if channel not in irc.channels: # KICK only works on channels that exist.
|
if channel not in irc.channels: # KICK only works on channels that exist.
|
||||||
irc.reply("Error: Unknown channel %r." % channel)
|
irc.reply("Error: Unknown channel %r." % channel)
|
||||||
return
|
return
|
||||||
|
|
||||||
if irc.isInternalServer(u):
|
if (not irc.isInternalClient(sender)) and \
|
||||||
# Send kick from server if the given kicker is a SID
|
(not irc.isInternalServer(sender)):
|
||||||
irc.proto.kick(u, channel, targetu, reason)
|
|
||||||
elif u not in irc.users:
|
|
||||||
# Whatever we were told to send the kick from wasn't valid; try to be
|
# Whatever we were told to send the kick from wasn't valid; try to be
|
||||||
# somewhat user friendly in the error. message
|
# somewhat user friendly in the error message
|
||||||
irc.reply("Error: No such PyLink client '%s'. The first argument to "
|
irc.reply("Error: No such PyLink client '%s'. The first argument to "
|
||||||
"KICK should be the name of a PyLink client (e.g. '%s'; see "
|
"KICK should be the name of a PyLink client (e.g. '%s'; see "
|
||||||
"'help kick' for details." % (sourcenick,
|
"'help kick' for details." % (sourcenick,
|
||||||
irc.pseudoclient.nick))
|
irc.pseudoclient.nick))
|
||||||
return
|
return
|
||||||
elif targetu not in irc.users:
|
elif not targetu:
|
||||||
# Whatever we were told to kick doesn't exist!
|
# Whatever we were told to kick doesn't exist!
|
||||||
irc.reply("Error: No such nick '%s'." % target)
|
irc.reply("Error: No such target nick '%s'." % target)
|
||||||
return
|
return
|
||||||
else:
|
|
||||||
irc.proto.kick(u, channel, targetu, reason)
|
|
||||||
|
|
||||||
irc.callHooks([u, 'CHANCMDS_KICK', {'channel': channel, 'target': targetu,
|
irc.proto.kick(sender, channel, targetu, reason)
|
||||||
|
irc.callHooks([sender, 'CHANCMDS_KICK', {'channel': channel, 'target': targetu,
|
||||||
'text': reason, 'parse_as': 'KICK'}])
|
'text': reason, 'parse_as': 'KICK'}])
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
@ -168,16 +165,14 @@ def kill(irc, source, args):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Convert the source and target nicks to UIDs.
|
# Convert the source and target nicks to UIDs.
|
||||||
u = irc.nickToUid(sourcenick) or sourcenick
|
sender = irc.nickToUid(sourcenick) or sourcenick
|
||||||
targetu = irc.nickToUid(target)
|
targetu = irc.nickToUid(target)
|
||||||
userdata = irc.users.get(targetu)
|
userdata = irc.users.get(targetu)
|
||||||
|
|
||||||
if irc.isInternalServer(u):
|
if (not irc.isInternalClient(sender)) and \
|
||||||
# Send kill from server if the given kicker is a SID
|
(not irc.isInternalServer(sender)):
|
||||||
irc.proto.kill(u, targetu, reason)
|
|
||||||
elif u not in irc.users:
|
|
||||||
# Whatever we were told to send the kick from wasn't valid; try to be
|
# Whatever we were told to send the kick from wasn't valid; try to be
|
||||||
# somewhat user friendly in the error. message
|
# somewhat user friendly in the error message
|
||||||
irc.reply("Error: No such PyLink client '%s'. The first argument to "
|
irc.reply("Error: No such PyLink client '%s'. The first argument to "
|
||||||
"KILL should be the name of a PyLink client (e.g. '%s'; see "
|
"KILL should be the name of a PyLink client (e.g. '%s'; see "
|
||||||
"'help kick' for details." % (sourcenick,
|
"'help kick' for details." % (sourcenick,
|
||||||
@ -187,10 +182,9 @@ def kill(irc, source, args):
|
|||||||
# Whatever we were told to kick doesn't exist!
|
# Whatever we were told to kick doesn't exist!
|
||||||
irc.reply("Error: No such nick '%s'." % target)
|
irc.reply("Error: No such nick '%s'." % target)
|
||||||
return
|
return
|
||||||
else:
|
|
||||||
irc.proto.kill(u, targetu, reason)
|
|
||||||
|
|
||||||
irc.callHooks([u, 'CHANCMDS_KILL', {'target': targetu, 'text': reason,
|
irc.proto.kill(sender, targetu, reason)
|
||||||
|
irc.callHooks([sender, 'CHANCMDS_KILL', {'target': targetu, 'text': reason,
|
||||||
'userdata': userdata, 'parse_as': 'KILL'}])
|
'userdata': userdata, 'parse_as': 'KILL'}])
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
|
Loading…
Reference in New Issue
Block a user