3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-01-26 20:24:34 +01:00

commands, relay: use irc.reply() with private=True instead of irc.msg()

This is more flexible, etc.
This commit is contained in:
James Lu 2016-06-30 18:43:35 -07:00
parent 5c90cbe01f
commit 91a663d5c7
2 changed files with 13 additions and 10 deletions

View File

@ -35,7 +35,8 @@ def showuser(irc, source, args):
irc.reply('Error: Unknown user %r.' % target) irc.reply('Error: Unknown user %r.' % target)
return return
f = lambda s: irc.msg(source, s) f = lambda s: irc.reply(s, private=True)
userobj = irc.users[u] userobj = irc.users[u]
f('Showing information on user \x02%s\x02 (%s@%s): %s' % (userobj.nick, userobj.ident, f('Showing information on user \x02%s\x02 (%s@%s): %s' % (userobj.nick, userobj.ident,
userobj.host, userobj.realname)) userobj.host, userobj.realname))
@ -73,14 +74,15 @@ def showchan(irc, source, args):
irc.reply('Error: Unknown channel %r.' % channel) irc.reply('Error: Unknown channel %r.' % channel)
return return
f = lambda s: irc.msg(source, s) f = lambda s: irc.reply(s, private=True)
c = irc.channels[channel] c = irc.channels[channel]
# Only show verbose info if caller is oper or is in the target channel. # Only show verbose info if caller is oper or is in the target channel.
verbose = source in c.users or irc.isOper(source) verbose = source in c.users or irc.isOper(source)
secret = ('s', None) in c.modes secret = ('s', None) in c.modes
if secret and not verbose: if secret and not verbose:
# Hide secret channels from normal users. # Hide secret channels from normal users.
irc.msg(source, 'Error: Unknown channel %r.' % channel) irc.reply('Error: Unknown channel %r.' % channel, private=True)
return return
nicks = [irc.users[u].nick for u in c.users] nicks = [irc.users[u].nick for u in c.users]

View File

@ -1518,7 +1518,8 @@ def linked(irc, source, args):
remote_networks.sort() remote_networks.sort()
s = 'Connected networks: \x02%s\x02 %s' % (irc.name, ' '.join(remote_networks)) s = 'Connected networks: \x02%s\x02 %s' % (irc.name, ' '.join(remote_networks))
irc.msg(source, s) # Always reply in private to prevent floods.
irc.reply(s, private=True)
net = '' net = ''
try: try:
@ -1526,7 +1527,7 @@ def linked(irc, source, args):
except: except:
pass pass
else: else:
irc.msg(source, "Showing channels linked to %s:" % net) irc.reply("Showing channels linked to %s:" % net, private=True)
# Sort the list of shared channels when displaying # Sort the list of shared channels when displaying
for k, v in sorted(db.items()): for k, v in sorted(db.items()):
@ -1557,7 +1558,7 @@ def linked(irc, source, args):
else: # Unless it's empty; then, well... just say no relays yet. else: # Unless it's empty; then, well... just say no relays yet.
s += '(no relays yet)' s += '(no relays yet)'
irc.msg(source, s) irc.reply(s, private=True)
if irc.isOper(source): if irc.isOper(source):
s = '' s = ''
@ -1576,7 +1577,7 @@ def linked(irc, source, args):
s += ' on %s' % time.ctime(ts) s += ' on %s' % time.ctime(ts)
if s: # Indent to make the list look nicer if s: # Indent to make the list look nicer
irc.msg(source, ' Channel created%s.' % s) irc.reply(' Channel created%s.' % s, private=True)
linked = utils.add_cmd(linked, featured=True) linked = utils.add_cmd(linked, featured=True)
@utils.add_cmd @utils.add_cmd
@ -1636,7 +1637,7 @@ def showuser(irc, source, args):
return return
u = irc.nickToUid(target) u = irc.nickToUid(target)
if u: if u:
irc.msg(source, "Showing relay information on user \x02%s\x02:" % irc.users[u].nick) irc.reply("Showing relay information on user \x02%s\x02:" % irc.users[u].nick, private=True)
try: try:
userpair = getOrigUser(irc, u) or (irc.name, u) userpair = getOrigUser(irc, u) or (irc.name, u)
remoteusers = relayusers[userpair].items() remoteusers = relayusers[userpair].items()
@ -1651,14 +1652,14 @@ def showuser(irc, source, args):
remotenet, remoteuser = r remotenet, remoteuser = r
remoteirc = world.networkobjects[remotenet] remoteirc = world.networkobjects[remotenet]
nicks.append('%s:\x02%s\x02' % (remotenet, remoteirc.users[remoteuser].nick)) nicks.append('%s:\x02%s\x02' % (remotenet, remoteirc.users[remoteuser].nick))
irc.msg(source, "\x02Relay nicks\x02: %s" % ', '.join(nicks)) irc.reply("\x02Relay nicks\x02: %s" % ', '.join(nicks), private=True)
relaychannels = [] relaychannels = []
for ch in irc.users[u].channels: for ch in irc.users[u].channels:
relay = getRelay((irc.name, ch)) relay = getRelay((irc.name, ch))
if relay: if relay:
relaychannels.append(''.join(relay)) relaychannels.append(''.join(relay))
if relaychannels and (irc.isOper(source) or u == source): if relaychannels and (irc.isOper(source) or u == source):
irc.msg(source, "\x02Relay channels\x02: %s" % ' '.join(relaychannels)) irc.reply("\x02Relay channels\x02: %s" % ' '.join(relaychannels), private=True)
@utils.add_cmd @utils.add_cmd
def save(irc, source, args): def save(irc, source, args):