Skip to content

Commit

Permalink
repeat photo if there are no new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
fopina committed Jan 29, 2016
1 parent 1680a4b commit 79ad19f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
15 changes: 9 additions & 6 deletions plugins/instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ def _butt(self, chat_id, text):
from time import sleep
sleep(1)

pics = [x for x in pics if not self.read_data(chat_id, x['id'])]
if not pics:
return self.bot.send_message(chat_id, 'Sorry, no new butts found right now...').wait()
return self.bot.send_message(chat_id, 'Sorry, no butts found at the moment...').wait()

pic = choice(pics)
pics = [x for x in pics if not self.read_data(chat_id, x['id'])]
if pics:
pic = choice(pics)
else:
if not text:
text = u'Déjà vu? Sorry, no new butts found at the moment...'

self.save_data(chat_id, key2=pic['id'], obj=True)

Expand Down Expand Up @@ -85,10 +91,7 @@ def buttgmt(self, message, text):
reply_markup=ForceReply.create(selective=True),
parse_mode='Markdown'
).wait()
if isinstance(m, Error):
print 'ERROR:', m
else:
self.need_reply(self.buttgmt, message, out_message=m, selective=True)
self.need_reply(self.buttgmt, message, out_message=m, selective=True)
return

try:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tgbotplug==1.2.10
tgbotplug==1.2.12
bottle==0.12.8
psycopg2==2.6.1
15 changes: 11 additions & 4 deletions tests/test_instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def fget(*args, **kwargs):

with mock.patch('requests.get', fget):
self.receive_message('/butt')
self.assertReplied('Sorry, no new butts found right now...')
self.assertReplied('Sorry, no butts found at the moment...')

def test_butt_repeat(self):
import mock
Expand All @@ -72,9 +72,16 @@ def fget(*args, **kwargs):

with mock.patch('requests.get', fget):
self.receive_message('/butt')
self.assertIn('Snorkeled', self.pop_reply()[1]['caption'])
r = self.pop_reply()
self.assertEqual(r[0], 'sendPhoto')
self.assertEqual(r[2][0].file_info.file_name, 'logo.png')
self.assertIn('Snorkeled', r[1]['caption'])
self.receive_message('/butt')
self.assertReplied('Sorry, no new butts found right now...')
# validate it is the same photo
r = self.pop_reply()
self.assertEqual(r[0], 'sendPhoto')
self.assertEqual(r[2][0].file_info.file_name, 'logo.png')
self.assertEqual(r[1]['caption'], u'Déjà vu? Sorry, no new butts found at the moment...')

def test_butt_cache(self):
import mock
Expand Down Expand Up @@ -111,7 +118,7 @@ def fget(*args, **kwargs):

with mock.patch('requests.get', fget):
self.receive_message('/butt')
self.assertReplied('Sorry, no new butts found right now...')
self.assertReplied('Sorry, no butts found at the moment...')

def test_butt_cron(self):
import mock
Expand Down

0 comments on commit 79ad19f

Please sign in to comment.