mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-11 20:52:42 +01:00
Replace admin.showuser with prettier whois-style cmds in 'commands' and 'relay'
This commit is contained in:
parent
e1e31f64ad
commit
8976322273
@ -130,25 +130,6 @@ def kick(irc, source, args):
|
||||
irc.proto.kickClient(irc, u, channel, targetu, reason)
|
||||
irc.callHooks([u, 'PYLINK_ADMIN_KICK', {'channel': channel, 'target': targetu, 'text': reason, 'parse_as': 'KICK'}])
|
||||
|
||||
@utils.add_cmd
|
||||
def showuser(irc, source, args):
|
||||
"""<user>
|
||||
|
||||
Admin-only. Shows information about <user>."""
|
||||
utils.checkAuthenticated(irc, source, allowOper=False)
|
||||
try:
|
||||
target = args[0]
|
||||
except IndexError:
|
||||
utils.msg(irc, source, "Error: Not enough arguments. Needs 1: nick.")
|
||||
return
|
||||
u = utils.nickToUid(irc, target)
|
||||
if u is None:
|
||||
utils.msg(irc, source, 'Error: Unknown user %r.' % target)
|
||||
return
|
||||
s = ['\x02%s\x02: %s' % (k, v) for k, v in sorted(irc.users[u].__dict__.items())]
|
||||
s = 'Information on user \x02%s\x02: %s' % (target, '; '.join(s))
|
||||
utils.msg(irc, source, s)
|
||||
|
||||
@utils.add_cmd
|
||||
def showchan(irc, source, args):
|
||||
"""<channel>
|
||||
|
@ -1,6 +1,7 @@
|
||||
# commands.py: base PyLink commands
|
||||
import sys
|
||||
import os
|
||||
from time import ctime
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
import utils
|
||||
@ -86,3 +87,37 @@ def help(irc, source, args):
|
||||
"doesn't offer any help." % (command, mod))
|
||||
return
|
||||
|
||||
@utils.add_cmd
|
||||
def showuser(irc, source, args):
|
||||
"""<user>
|
||||
|
||||
Shows information about <user>."""
|
||||
try:
|
||||
target = args[0]
|
||||
except IndexError:
|
||||
utils.msg(irc, source, "Error: Not enough arguments. Needs 1: nick.")
|
||||
return
|
||||
u = utils.nickToUid(irc, target) or target
|
||||
# Only show private info if the person is calling 'showuser' on themselves,
|
||||
# or is an oper.
|
||||
verbose = utils.isOper(irc, source) or u == source
|
||||
if u not in irc.users:
|
||||
utils.msg(irc, source, 'Error: Unknown user %r.' % target)
|
||||
return
|
||||
|
||||
f = lambda s: utils.msg(irc, source, s)
|
||||
userobj = irc.users[u]
|
||||
f('Information on user \x02%s\x02 (%s@%s): %s' % (userobj.nick, userobj.ident,
|
||||
userobj.host, userobj.realname))
|
||||
sid = utils.clientToServer(irc, u)
|
||||
serverobj = irc.servers[sid]
|
||||
ts = userobj.ts
|
||||
f('\x02Home server\x02: %s (%s); \x02Signon time:\x02 %s (%s)' % \
|
||||
(serverobj.name, sid, ctime(float(ts)), ts))
|
||||
if verbose:
|
||||
f('\x02Protocol UID\x02: %s; \x02PyLink identification\x02: %s' % \
|
||||
(u, userobj.identified))
|
||||
f('\x02User modes\x02: %s' % utils.joinModes(userobj.modes))
|
||||
f('\x02Real host\x02: %s; \x02IP\x02: %s; \x02Away status\x02: %s' % \
|
||||
(userobj.realhost, userobj.ip, userobj.away or '\x1D(not set)\x1D'))
|
||||
f('\x02Channels\x02: %s' % (' '.join(userobj.channels).strip() or '\x1D(none)\x1D'))
|
||||
|
@ -1033,3 +1033,37 @@ def linkacl(irc, source, args):
|
||||
utils.msg(irc, source, 'Done.')
|
||||
else:
|
||||
utils.msg(irc, source, 'Error: Unknown subcommand %r: valid ones are ALLOW, DENY, and LIST.' % cmd)
|
||||
|
||||
@utils.add_cmd
|
||||
def showuser(irc, source, args):
|
||||
"""<user>
|
||||
|
||||
Shows relay data about user <user>. This is intended to be used alongside the 'commands' plugin, which provides a 'showuser' command with more general information."""
|
||||
try:
|
||||
target = args[0]
|
||||
except IndexError:
|
||||
# No errors here; showuser from the commands plugin already does this
|
||||
# for us.
|
||||
return
|
||||
u = utils.nickToUid(irc, target)
|
||||
if u and (utils.isOper(irc, source) or u == source):
|
||||
try:
|
||||
userpair = getLocalUser(irc, u) or (irc.name, u)
|
||||
remoteusers = relayusers[userpair].items()
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
nicks = []
|
||||
if remoteusers:
|
||||
for r in remoteusers:
|
||||
remotenet, remoteuser = r
|
||||
remoteirc = world.networkobjects[remotenet]
|
||||
nicks.append('%s: \x02%s\x02' % (remotenet, remoteirc.users[remoteuser].nick))
|
||||
utils.msg(irc, source, "\x02Relay nicks\x02: %s" % ', '.join(nicks))
|
||||
relaychannels = []
|
||||
for ch in irc.users[u].channels:
|
||||
relay = findRelay((irc.name, ch))
|
||||
if relay:
|
||||
relaychannels.append(''.join(relay))
|
||||
if relaychannels:
|
||||
utils.msg(irc, source, "\x02Relay channels\x02: %s" % ' '.join(relaychannels))
|
||||
|
Loading…
Reference in New Issue
Block a user