From 44ade5e888d9783f2514bdf4abaccaabc63391eb Mon Sep 17 00:00:00 2001 From: Ben Simner Date: Sat, 30 Jun 2018 10:06:24 +0100 Subject: [PATCH 1/8] Reorganise whois.set functionality Alias !whois.set to !whois.setdefault and add !whois.setlocal. Also alias !whois.unset to !whois.unsetdefault and add !whois.unsetlocal --- csbot/plugins/whois.py | 23 +++++++++++++++++------ csbot/test/test_plugin_whois.py | 33 ++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/csbot/plugins/whois.py b/csbot/plugins/whois.py index d782acde..bad2edff 100644 --- a/csbot/plugins/whois.py +++ b/csbot/plugins/whois.py @@ -48,24 +48,35 @@ def whois(self, e): else: e.reply('{}: {}'.format(nick_, str(res))) + @Plugin.command('whois.setlocal', help=('whois.setlocal [whois_text]: sets the whois text' + ' for the user, but only for the current channel.')) + def setlocal(self, e): + """Allow a user to associate data with themselves for this channel.""" + self.whois_set(nick(e['user']), e['data'], channel=e['channel']) @Plugin.command('whois.setdefault', help=('whois.setdefault [default_whois]: sets the default' ' whois text for the user, used when no channel-specific' - ' one is set')) + ' one is set.')) def setdefault(self, e): self.whois_set(nick(e['user']), e['data'], channel=None) - @Plugin.command('whois.set') + @Plugin.command('whois.set', help=('Alias for whois.setdefault.')) def set(self, e): """Allow a user to associate data with themselves for this channel.""" - self.whois_set(nick(e['user']), e['data'], channel=e['channel']) + return self.setdefault(e) - - @Plugin.command('whois.unset') + @Plugin.command('whois.unset', help=('Alias for whois.unsetdefault')) def unset(self, e): + return self.unsetdefault(e) + + @Plugin.command('whois.unsetlocal', help=('whois.unsetlocal: unsets the local whois text for the user' + ' but only for this channel' + ' (the global whois for the user is unaffected).')) + def unsetlocal(self, e): self.whois_unset(nick(e['user']), channel=e['channel']) - @Plugin.command('whois.unsetdefault') + @Plugin.command('whois.unsetdefault', help='whois.unsetdefault: unsets the global whois text for the user.' + ' Locally set whois texts will be unaffected.') def unsetdefault(self, e): self.whois_unset(nick(e['user'])) diff --git a/csbot/test/test_plugin_whois.py b/csbot/test/test_plugin_whois.py index b15615f5..bd6dcb48 100644 --- a/csbot/test/test_plugin_whois.py +++ b/csbot/test/test_plugin_whois.py @@ -101,22 +101,22 @@ def test_whois_setdefault_unset(self): @failsafe @run_client def test_client_reply_whois_after_set(self): - yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.set test1') + yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.setlocal test1') yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois') self.assert_sent('NOTICE {} :{}'.format('#First', 'Nick: test1')) @failsafe @run_client def test_client_reply_whois_different_channel(self): - yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.set test1') + yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.setlocal test1') yield from self._recv_privmsg('Nick!~user@host', '#Second', '!whois') self.assert_sent('NOTICE {} :{}'.format('#Second', 'No data for Nick')) @failsafe @run_client def test_client_reply_whois_multiple_users_channels(self): - yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.set test1') - yield from self._recv_privmsg('Nick!~user@host', '#Second', '!whois.set test2') + yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.setlocal test1') + yield from self._recv_privmsg('Nick!~user@host', '#Second', '!whois.setlocal test2') yield from self._recv_privmsg('Other!~other@otherhost', '#First', '!whois Nick') self.assert_sent('NOTICE {} :{}'.format('#First', 'Nick: test1')) @@ -127,10 +127,25 @@ def test_client_reply_whois_multiple_users_channels(self): @failsafe @run_client def test_client_reply_whois_self(self): - yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.set test1') + yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.setlocal test1') yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois') self.assert_sent('NOTICE {} :{}'.format('#First', 'Nick: test1')) + @failsafe + @run_client + def test_set_alias(self): + yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.set test1') + yield from self._recv_privmsg('Nick!~user@host', '#Second', '!whois') + self.assert_sent('NOTICE {} :{}'.format('#Second', 'Nick: test1')) + + @failsafe + @run_client + def test_unset_alias(self): + yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.set test1') + yield from self._recv_privmsg('Nick!~user@host', '#Second', '!whois.unset') + yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois') + self.assert_sent('NOTICE {} :{}'.format('#First', 'No data for Nick')) + @failsafe @run_client def test_client_reply_whois_setdefault_then_set_channel(self): @@ -141,7 +156,7 @@ def test_client_reply_whois_setdefault_then_set_channel(self): yield from self._recv_privmsg('Other!~other@otherhost', '#Third', '!whois Nick') self.assert_sent('NOTICE {} :{}'.format('#Third', 'Nick: test data')) - yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.set test first') + yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.setlocal test first') yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois') self.assert_sent('NOTICE {} :{}'.format('#First', 'Nick: test first')) @@ -155,11 +170,11 @@ def test_client_reply_whois_setdefault_then_unset_channel(self): yield from self._recv_privmsg('Nick!~user@host', '#Second', '!whois') self.assert_sent('NOTICE {} :{}'.format('#Second', 'Nick: test data')) - yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.set test first') + yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.setlocal test first') yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois') self.assert_sent('NOTICE {} :{}'.format('#First', 'Nick: test first')) - yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.unset') + yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.unsetlocal') yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois') self.assert_sent('NOTICE {} :{}'.format('#First', 'Nick: test data')) @@ -174,7 +189,7 @@ def test_client_reply_whois_setdefault_then_unsetdefault(self): yield from self._recv_privmsg('Other!~other@otherhost', '#Third', '!whois Nick') self.assert_sent('NOTICE {} :{}'.format('#Third', 'Nick: test data')) - yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.unsetdefault') + yield from self._recv_privmsg('Nick!~user@host', '#First', '!whois.unset') yield from self._recv_privmsg('Nick!~user@host', '#Second', '!whois') self.assert_sent('NOTICE {} :{}'.format('#Second', 'No data for Nick')) From 39ed3baa213c85085dff1cd17f4d28417d354830 Mon Sep 17 00:00:00 2001 From: Ben Simner Date: Sat, 30 Jun 2018 10:09:20 +0100 Subject: [PATCH 2/8] Remove fullstops from help text Pedantic change to be consistent. --- csbot/plugins/whois.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/csbot/plugins/whois.py b/csbot/plugins/whois.py index bad2edff..ab5c5da8 100644 --- a/csbot/plugins/whois.py +++ b/csbot/plugins/whois.py @@ -49,14 +49,14 @@ def whois(self, e): e.reply('{}: {}'.format(nick_, str(res))) @Plugin.command('whois.setlocal', help=('whois.setlocal [whois_text]: sets the whois text' - ' for the user, but only for the current channel.')) + ' for the user, but only for the current channel')) def setlocal(self, e): """Allow a user to associate data with themselves for this channel.""" self.whois_set(nick(e['user']), e['data'], channel=e['channel']) @Plugin.command('whois.setdefault', help=('whois.setdefault [default_whois]: sets the default' ' whois text for the user, used when no channel-specific' - ' one is set.')) + ' one is set')) def setdefault(self, e): self.whois_set(nick(e['user']), e['data'], channel=None) @@ -71,12 +71,12 @@ def unset(self, e): @Plugin.command('whois.unsetlocal', help=('whois.unsetlocal: unsets the local whois text for the user' ' but only for this channel' - ' (the global whois for the user is unaffected).')) + ' (the global whois for the user is unaffected')) def unsetlocal(self, e): self.whois_unset(nick(e['user']), channel=e['channel']) @Plugin.command('whois.unsetdefault', help='whois.unsetdefault: unsets the global whois text for the user.' - ' Locally set whois texts will be unaffected.') + ' Locally set whois texts will be unaffected') def unsetdefault(self, e): self.whois_unset(nick(e['user'])) From 3bb4b915994d99e16feb75cebf58f5ce09e3ea4d Mon Sep 17 00:00:00 2001 From: Ben Simner Date: Sat, 30 Jun 2018 16:01:59 +0100 Subject: [PATCH 3/8] Combine redundant aliased functions together and pass same help text through both --- csbot/plugins/whois.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/csbot/plugins/whois.py b/csbot/plugins/whois.py index ab5c5da8..715fb376 100644 --- a/csbot/plugins/whois.py +++ b/csbot/plugins/whois.py @@ -54,20 +54,14 @@ def setlocal(self, e): """Allow a user to associate data with themselves for this channel.""" self.whois_set(nick(e['user']), e['data'], channel=e['channel']) - @Plugin.command('whois.setdefault', help=('whois.setdefault [default_whois]: sets the default' - ' whois text for the user, used when no channel-specific' - ' one is set')) + set_help = ('whois.setdefault [default_whois]: sets the default' + ' whois text for the user, used when no channel-specific' + ' one is set') + @Plugin.command('whois.set', help=set_help) + @Plugin.command('whois.setdefault', help=set_help) def setdefault(self, e): self.whois_set(nick(e['user']), e['data'], channel=None) - @Plugin.command('whois.set', help=('Alias for whois.setdefault.')) - def set(self, e): - """Allow a user to associate data with themselves for this channel.""" - return self.setdefault(e) - - @Plugin.command('whois.unset', help=('Alias for whois.unsetdefault')) - def unset(self, e): - return self.unsetdefault(e) @Plugin.command('whois.unsetlocal', help=('whois.unsetlocal: unsets the local whois text for the user' ' but only for this channel' @@ -75,8 +69,10 @@ def unset(self, e): def unsetlocal(self, e): self.whois_unset(nick(e['user']), channel=e['channel']) - @Plugin.command('whois.unsetdefault', help='whois.unsetdefault: unsets the global whois text for the user.' - ' Locally set whois texts will be unaffected') + unset_help = ('whois.unsetdefault: unsets the global whois text for the user.' + ' Locally set whois texts will be unaffected') + @Plugin.command('whois.unset', help=unset_help) + @Plugin.command('whois.unsetdefault', help=unset_help) def unsetdefault(self, e): self.whois_unset(nick(e['user'])) From 24c3c45451019353f0adbb1cf0ab020dee520cb4 Mon Sep 17 00:00:00 2001 From: Ben Simner Date: Sat, 30 Jun 2018 16:18:38 +0100 Subject: [PATCH 4/8] Add replies to setting/unsetting --- csbot/plugins/whois.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/csbot/plugins/whois.py b/csbot/plugins/whois.py index 715fb376..d8156d2c 100644 --- a/csbot/plugins/whois.py +++ b/csbot/plugins/whois.py @@ -61,7 +61,7 @@ def setlocal(self, e): @Plugin.command('whois.setdefault', help=set_help) def setdefault(self, e): self.whois_set(nick(e['user']), e['data'], channel=None) - + e.reply('Set global whois for {}'.format(nick(e['user']))) @Plugin.command('whois.unsetlocal', help=('whois.unsetlocal: unsets the local whois text for the user' ' but only for this channel' @@ -74,7 +74,13 @@ def unsetlocal(self, e): @Plugin.command('whois.unset', help=unset_help) @Plugin.command('whois.unsetdefault', help=unset_help) def unsetdefault(self, e): - self.whois_unset(nick(e['user'])) + nick_ = nick(e['user']) + whois = self.whois_lookup(nick_, e['channel']) + self.whois_unset(nick_) + if whois: + e.reply('Unset global whois for {} (was: {})'.format(nick_, str(whois))) + else: + e.reply('Unset global whois for {}') def identify_user(self, nick, channel=None): """Identify a user: by account if authed, if not, by nick. Produces a dict From b4e4375ec56a31a59964ff8e63ce885db8cf730f Mon Sep 17 00:00:00 2001 From: Ben Simner Date: Sat, 30 Jun 2018 16:21:08 +0100 Subject: [PATCH 5/8] Factor out looking up globla/local whois text --- csbot/plugins/whois.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/csbot/plugins/whois.py b/csbot/plugins/whois.py index d8156d2c..a1b95efb 100644 --- a/csbot/plugins/whois.py +++ b/csbot/plugins/whois.py @@ -14,11 +14,23 @@ def whois_lookup(self, nick, channel, db=None): """Performs a whois lookup for a nick""" db = db or self.whoisdb - for ident in (self.identify_user(nick, channel), # lookup channel specific first - self.identify_user(nick)): # default fallback - user = db.find_one(ident) - if user: - return user['data'] + for d in (self.whois_lookup_channel(nick, channel), + self.whois_lookup_global(nick)): + if d: + return d + + def whois_lookup_channel(self, nick, channel): + return self._lookup(self.identify_user(nick, channel)) + + def whois_lookup_global(self, nick): + return self._lookup(self.identify_user(nick)) + + def _lookup(self, ident): + user = self.whoisdb.find_one(ident) + if user: + return user['data'] + + return None def whois_set(self, nick, whois_str, channel=None, db=None): db = db or self.whoisdb @@ -75,12 +87,12 @@ def unsetlocal(self, e): @Plugin.command('whois.unsetdefault', help=unset_help) def unsetdefault(self, e): nick_ = nick(e['user']) - whois = self.whois_lookup(nick_, e['channel']) + old_whois = self.whois_lookup_global(nick_) self.whois_unset(nick_) - if whois: - e.reply('Unset global whois for {} (was: {})'.format(nick_, str(whois))) + if old_whois: + e.reply('Unset global whois for {} (was: {})'.format(nick_, str(old_whois))) else: - e.reply('Unset global whois for {}') + e.reply('Unset global whois for {}'.format(nick_)) def identify_user(self, nick, channel=None): """Identify a user: by account if authed, if not, by nick. Produces a dict From 988ce533823d886064a6a11064bbb9dba8b5e713 Mon Sep 17 00:00:00 2001 From: Ben Simner Date: Sat, 30 Jun 2018 16:29:03 +0100 Subject: [PATCH 6/8] Clear reply messages for whois text setting --- csbot/plugins/whois.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/csbot/plugins/whois.py b/csbot/plugins/whois.py index a1b95efb..b7baf10c 100644 --- a/csbot/plugins/whois.py +++ b/csbot/plugins/whois.py @@ -72,8 +72,14 @@ def setlocal(self, e): @Plugin.command('whois.set', help=set_help) @Plugin.command('whois.setdefault', help=set_help) def setdefault(self, e): - self.whois_set(nick(e['user']), e['data'], channel=None) - e.reply('Set global whois for {}'.format(nick(e['user']))) + nick_ = nick(e['user']) + old_whois = self.whois_lookup_global(nick_) + self.whois_set(nick_, e['data'], channel=None) + + if old_whois: + e.reply('set global whois for {} (was: "{}")'.format(nick_, str(old_whois))) + else: + e.reply('set global whois for {}'.format(nick_)) @Plugin.command('whois.unsetlocal', help=('whois.unsetlocal: unsets the local whois text for the user' ' but only for this channel' @@ -81,8 +87,8 @@ def setdefault(self, e): def unsetlocal(self, e): self.whois_unset(nick(e['user']), channel=e['channel']) - unset_help = ('whois.unsetdefault: unsets the global whois text for the user.' - ' Locally set whois texts will be unaffected') + unset_help = ('whois.unsetdefault: unsets the global whois text for the user,' + ' local whois text is unaffected') @Plugin.command('whois.unset', help=unset_help) @Plugin.command('whois.unsetdefault', help=unset_help) def unsetdefault(self, e): @@ -90,9 +96,9 @@ def unsetdefault(self, e): old_whois = self.whois_lookup_global(nick_) self.whois_unset(nick_) if old_whois: - e.reply('Unset global whois for {} (was: {})'.format(nick_, str(old_whois))) + e.reply('unset global whois for {} (was: "{}")'.format(nick_, str(old_whois))) else: - e.reply('Unset global whois for {}'.format(nick_)) + e.reply('unset global whois for {}'.format(nick_)) def identify_user(self, nick, channel=None): """Identify a user: by account if authed, if not, by nick. Produces a dict From ff0bc740f15dbb86b26e6429887aeed87a41fe3b Mon Sep 17 00:00:00 2001 From: Ben Simner Date: Sat, 30 Jun 2018 17:31:38 +0100 Subject: [PATCH 7/8] Make replies be personal messages rather than channel ones --- csbot/plugins/whois.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/csbot/plugins/whois.py b/csbot/plugins/whois.py index b7baf10c..c207fa38 100644 --- a/csbot/plugins/whois.py +++ b/csbot/plugins/whois.py @@ -64,7 +64,15 @@ def whois(self, e): ' for the user, but only for the current channel')) def setlocal(self, e): """Allow a user to associate data with themselves for this channel.""" - self.whois_set(nick(e['user']), e['data'], channel=e['channel']) + nick_ = nick(e['user']) + channel = e['channel'] + old_whois = self.whois_lookup_global(nick_) + self.whois_set(nick_, e['data'], channel=channel) + + if old_whois: + self.bot.reply(nick_, 'set local whois on {} (was: "{}")'.format(channel, str(old_whois))) + else: + self.bot.reply(nick_, 'set local whois on {}'.format(channel)) set_help = ('whois.setdefault [default_whois]: sets the default' ' whois text for the user, used when no channel-specific' @@ -75,17 +83,23 @@ def setdefault(self, e): nick_ = nick(e['user']) old_whois = self.whois_lookup_global(nick_) self.whois_set(nick_, e['data'], channel=None) - if old_whois: - e.reply('set global whois for {} (was: "{}")'.format(nick_, str(old_whois))) + self.bot.reply(nick_, 'set global whois (was: "{}")'.format(str(old_whois))) else: - e.reply('set global whois for {}'.format(nick_)) + self.bot.reply(nick_, 'set new global whois') @Plugin.command('whois.unsetlocal', help=('whois.unsetlocal: unsets the local whois text for the user' ' but only for this channel' ' (the global whois for the user is unaffected')) def unsetlocal(self, e): - self.whois_unset(nick(e['user']), channel=e['channel']) + nick_ = nick(e['user']) + old_whois = self.whois_lookup_global(nick_) + channel = e['channel'] + self.whois_unset(nick_, channel=channel) + if old_whois: + self.bot.reply(nick_, 'unset local whois on {} (was: "{}")'.format(channel, str(old_whois))) + else: + self.bot.reply(nick_, 'unset local whois on {}'.format(channel)) unset_help = ('whois.unsetdefault: unsets the global whois text for the user,' ' local whois text is unaffected') @@ -96,9 +110,9 @@ def unsetdefault(self, e): old_whois = self.whois_lookup_global(nick_) self.whois_unset(nick_) if old_whois: - e.reply('unset global whois for {} (was: "{}")'.format(nick_, str(old_whois))) + self.bot.reply(nick_, 'unset global whois (was: "{}")'.format(str(old_whois))) else: - e.reply('unset global whois for {}'.format(nick_)) + self.bot.reply(nick_, 'unset global whois') def identify_user(self, nick, channel=None): """Identify a user: by account if authed, if not, by nick. Produces a dict From 6ebb66a9425da5e3a902168c4d5b8a2877d73bd1 Mon Sep 17 00:00:00 2001 From: Ben Simner Date: Sun, 1 Jul 2018 10:55:28 +0100 Subject: [PATCH 8/8] Better UX This change makes !set always succeed in setting the whois for this channel, but it will now never over-write the global value if one exists. It also means that !unset behaves similarly, it always succeeds in unsetting whichever whois was set for the channel, including removing the global one should it exist. I think more work needs to be done to decide whether that last decision is a good one: removing/setting global data on accident is bad UX but it's better than what we currently have, and better than unexpectedly being unable to set the whois. --- csbot/plugins/whois.py | 70 ++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/csbot/plugins/whois.py b/csbot/plugins/whois.py index c207fa38..6849eb39 100644 --- a/csbot/plugins/whois.py +++ b/csbot/plugins/whois.py @@ -64,55 +64,59 @@ def whois(self, e): ' for the user, but only for the current channel')) def setlocal(self, e): """Allow a user to associate data with themselves for this channel.""" - nick_ = nick(e['user']) - channel = e['channel'] - old_whois = self.whois_lookup_global(nick_) - self.whois_set(nick_, e['data'], channel=channel) - - if old_whois: - self.bot.reply(nick_, 'set local whois on {} (was: "{}")'.format(channel, str(old_whois))) - else: - self.bot.reply(nick_, 'set local whois on {}'.format(channel)) + self.whois_set(nick(e['user']), e['data'], channel=e['channel']) set_help = ('whois.setdefault [default_whois]: sets the default' ' whois text for the user, used when no channel-specific' ' one is set') - @Plugin.command('whois.set', help=set_help) @Plugin.command('whois.setdefault', help=set_help) def setdefault(self, e): + self.whois_set(nick(e['user']), e['data'], channel=None) + + @Plugin.command('whois.set', help='sets the whois text for this channel') + def set(self, e): nick_ = nick(e['user']) + channel = e['channel'] old_whois = self.whois_lookup_global(nick_) - self.whois_set(nick_, e['data'], channel=None) - if old_whois: - self.bot.reply(nick_, 'set global whois (was: "{}")'.format(str(old_whois))) + local_whois = self.whois_lookup_channel(nick_, channel) + + if local_whois: + self.setlocal(e) + fmt = 'set new local whois for {} (was: "{}"). use whois.setdefault to set for all channels' + self.bot.reply(nick_, fmt.format(channel, str(local_whois))) + elif old_whois: + self.setlocal(e) + fmt = 'set new local whois for {}. use whois.setdefault to set for all channels' + self.bot.reply(nick_, fmt.format(channel)) else: - self.bot.reply(nick_, 'set new global whois') + self.setdefault(e) + self.bot.reply(nick_, 'set default whois for all channels') @Plugin.command('whois.unsetlocal', help=('whois.unsetlocal: unsets the local whois text for the user' - ' but only for this channel' - ' (the global whois for the user is unaffected')) + ' but only for this channel')) def unsetlocal(self, e): - nick_ = nick(e['user']) - old_whois = self.whois_lookup_global(nick_) - channel = e['channel'] - self.whois_unset(nick_, channel=channel) - if old_whois: - self.bot.reply(nick_, 'unset local whois on {} (was: "{}")'.format(channel, str(old_whois))) - else: - self.bot.reply(nick_, 'unset local whois on {}'.format(channel)) + self.whois_unset(nick(e['user']), channel=e['channel']) - unset_help = ('whois.unsetdefault: unsets the global whois text for the user,' - ' local whois text is unaffected') - @Plugin.command('whois.unset', help=unset_help) + unset_help = ('whois.unsetdefault: unsets the default whois text for the user.' + ' local, channel-specific, whois text is unaffected') @Plugin.command('whois.unsetdefault', help=unset_help) def unsetdefault(self, e): + self.whois_unset(nick(e['user'])) + + @Plugin.command('whois.unset', help='unsets the currently set whois for this channel') + def unset(self, e): nick_ = nick(e['user']) - old_whois = self.whois_lookup_global(nick_) - self.whois_unset(nick_) - if old_whois: - self.bot.reply(nick_, 'unset global whois (was: "{}")'.format(str(old_whois))) - else: - self.bot.reply(nick_, 'unset global whois') + old_local_whois = self.whois_lookup_channel(nick_, e['channel']) + old_global_whois = self.whois_lookup_global(nick_) + + if old_local_whois: + self.unsetlocal(e) + fmt = 'unset local whois for {} (was: "{}"), use whois.unsetdefault to unset the global default' + self.bot.reply(nick_, fmt.format(e['channel'], str(old_local_whois))) + elif old_global_whois: + self.unsetdefault(e) + fmt = 'unset default whois for all channels (was: {}). use whois.setdefault to re-set it' + self.bot.reply(nick_, fmt.format(str(old_global_whois))) def identify_user(self, nick, channel=None): """Identify a user: by account if authed, if not, by nick. Produces a dict