Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions csbot/plugins/whois.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
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.'))
Comment thread
LordAro marked this conversation as resolved.
Outdated
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'))
Comment thread
LordAro marked this conversation as resolved.
Outdated
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']))

Expand Down
33 changes: 24 additions & 9 deletions csbot/test/test_plugin_whois.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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):
Expand All @@ -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'))
Expand All @@ -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'))

Expand All @@ -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'))
Expand Down