Skip to content

Commit

Permalink
quote: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alanbriolat committed Feb 19, 2022
1 parent 388fea8 commit 02af8e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
15 changes: 10 additions & 5 deletions src/csbot/plugins/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import requests

from csbot.plugin import Plugin
from csbot.util import nick, subdict
from csbot.util import nick


@attr.s
Expand Down Expand Up @@ -51,6 +51,7 @@ def from_udict(cls, udict):
message=udict['message'],
)


class QuoteDB:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -151,7 +152,8 @@ def quote_set(self, nick, channel, pattern=None):
return q
return None

@Plugin.command('remember', help=("remember <nick> [<pattern>]: adds last quote that matches <pattern> to the database"))
@Plugin.command('remember',
help="remember <nick> [<pattern>]: adds last quote that matches <pattern> to the database")
def remember(self, e):
""" Remembers the last matching quote from a user
"""
Expand All @@ -175,7 +177,7 @@ def remember_quote(self, e, user, nick, channel, pattern):
if pattern is not None:
e.reply(f'No data for {nick} found matching "{pattern}"')
else:
e.reply( f'No data for {nick}')
e.reply(f'No data for {nick}')
else:
self.bot.reply(user, 'remembered "{}"'.format(quote.format(show_id=False)))

Expand Down Expand Up @@ -236,7 +238,9 @@ def quote_list(self, e):
if just_channel:
return self.reply_with_summary(nick_, just_channel.group('channel'), None)
elif channel_and_pat:
return self.reply_with_summary(nick_, channel_and_pat.group('channel'), channel_and_pat.group('pattern'))
return self.reply_with_summary(nick_,
channel_and_pat.group('channel'),
channel_and_pat.group('pattern'))

return e.reply('Invalid command. Syntax in privmsg is !quote.list <channel> [<pattern>]')
else:
Expand Down Expand Up @@ -331,6 +335,7 @@ def log_privmsgs(self, e):
quote = QuoteRecord(None, channel, user, msg)
self.channel_logs[channel].appendleft(quote)


def message_matches(msg, pattern=None):
""" Check whether the given message matches the given pattern
Expand All @@ -339,4 +344,4 @@ def message_matches(msg, pattern=None):
if pattern is None:
return True

return re.search(pattern, msg) is not None
return re.search(pattern, msg) is not None
24 changes: 12 additions & 12 deletions tests/test_plugin_quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class TestQuotePlugin:
pytest.mark.bot(config="""
["@bot"]
plugins = ["mongodb", "usertrack", "auth", "quote"]
[auth]
nickaccount = "#First:quote"
otheraccount = "#Second:quote"
[mongodb]
mode = "mock"
"""),
Expand Down Expand Up @@ -96,7 +96,7 @@ async def test_client_quote_add_pattern_find(self):

async def test_client_quotes_not_exist(self):
await self._recv_privmsg('Nick!~user@host', '#First', '!quote Nick')
self.bot_helper.assert_sent('NOTICE {} :{}'.format('#First', 'No data for Nick'))
self.bot_helper.assert_sent('NOTICE #First :No data for Nick')

async def test_client_quote_add_multi(self):
await self._recv_privmsg('Nick!~user@host', '#First', 'test data')
Expand All @@ -110,10 +110,10 @@ async def test_client_quote_channel_specific_logs(self):
await self._recv_privmsg('Nick!~user@host', '#First', 'other data')

await self._recv_privmsg('Other!~user@host', '#Second', '!remember Nick')
self.bot_helper.assert_sent('NOTICE {} :{}'.format('#Second', 'No data for Nick'))
self.bot_helper.assert_sent('NOTICE #Second :No data for Nick')

await self._recv_privmsg('Other!~user@host', '#Second', '!quote Nick')
self.bot_helper.assert_sent('NOTICE {} :{}'.format('#Second', 'No data for Nick'))
self.bot_helper.assert_sent('NOTICE #Second :No data for Nick')

async def test_client_quote_channel_specific_quotes(self):
await self._recv_privmsg('Nick!~user@host', '#First', 'test data')
Expand All @@ -129,8 +129,8 @@ async def test_client_quote_channel_specific_quotes(self):

async def test_client_quote_channel_fill_logs(self):
for i in range(150):
await self._recv_privmsg('Nick!~user@host', '#First', 'test data#{}'.format(i))
await self._recv_privmsg('Nick!~user@host', '#Second', 'other data#{}'.format(i))
await self._recv_privmsg('Nick!~user@host', '#First', f'test data#{i}')
await self._recv_privmsg('Nick!~user@host', '#Second', f'other data#{i}')

await self._recv_privmsg('Other!~user@host', '#Second', '!remember Nick data#135')
await self._recv_privmsg('Other!~user@host', '#Second', '!quote Nick')
Expand All @@ -154,7 +154,7 @@ async def test_client_quotes_list(self):
await self._recv_line(":Other!~other@otherhost ACCOUNT otheraccount")

# stick some quotes in a thing
data = ['test data#{}'.format(i) for i in range(10)]
data = [f'test data#{i}' for i in range(10)]
for msg in data:
await self._recv_privmsg('Nick!~user@host', '#Second', msg)
await self._recv_privmsg('Other!~user@host', '#Second', '!remember Nick')
Expand Down Expand Up @@ -187,7 +187,7 @@ async def test_client_quote_remove(self):
await self._recv_privmsg('Nick!~user@host', '#First', '!quote.remove 0')

await self._recv_privmsg('Nick!~user@host', '#First', '!quote Nick')
self.bot_helper.assert_sent('NOTICE {} :{}'.format('#First', 'No data for Nick'))
self.bot_helper.assert_sent('NOTICE #First :No data for Nick')

async def test_client_quote_remove_no_permission(self):
await self._recv_line(":Other!~other@otherhost ACCOUNT otheraccount")
Expand All @@ -196,13 +196,13 @@ async def test_client_quote_remove_no_permission(self):
await self._recv_privmsg('Other!~user@host', '#First', '!remember Nick')
await self._recv_privmsg('Other!~user@host', '#First', '!quote.remove -1')

self.bot_helper.assert_sent('NOTICE {} :{}'.format('#First', 'error: otheraccount not authorised for #First:quote'))
self.bot_helper.assert_sent('NOTICE #First :error: otheraccount not authorised for #First:quote')

async def test_client_quote_remove_no_quotes(self):
await self._recv_line(":Nick!~user@host ACCOUNT nickaccount")
await self._recv_privmsg('Nick!~user@host', '#First', '!quote.remove -1')

self.bot_helper.assert_sent('NOTICE {} :{}'.format('#First', 'Error: could not remove quote(s) with ID: -1'))
self.bot_helper.assert_sent('NOTICE #First :Error: could not remove quote(s) with ID: -1')

async def test_client_quote_list_no_permission(self):
await self._recv_line(":Other!~other@otherhost ACCOUNT otheraccount")
Expand All @@ -211,7 +211,7 @@ async def test_client_quote_list_no_permission(self):
await self._recv_privmsg('Other!~user@host', '#First', '!remember Nick')
await self._recv_privmsg('Other!~user@host', '#First', '!quote.list')

self.bot_helper.assert_sent('NOTICE {} :{}'.format('#First', 'error: otheraccount not authorised for #First:quote'))
self.bot_helper.assert_sent('NOTICE #First :error: otheraccount not authorised for #First:quote')

async def test_client_quote_channelwide(self):
await self._recv_privmsg('Nick!~user@host', '#First', 'test data!')
Expand Down

0 comments on commit 02af8e9

Please sign in to comment.