Skip to content

Commit

Permalink
shazam fix
Browse files Browse the repository at this point in the history
  • Loading branch information
artyshko committed Feb 12, 2019
1 parent ec3be1c commit 4898925
Showing 1 changed file with 42 additions and 25 deletions.
67 changes: 42 additions & 25 deletions telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,15 @@ def controller(self, message, id):

state, data = self.downloader.downloadBySearchQuery(message)

#FIX
if not state:
#logging
self.downloader = main.MusicDownloader()
logging.warning(f'Restarting downloader')
logging.warning(f'Trying do the same')

state, data = self.downloader.downloadBySearchQuery(message)

if state:

fixed_name = f'{data["artist"][0]} - {data["name"]}'
Expand Down Expand Up @@ -399,39 +408,47 @@ def mainloop(self):

update_id = update['update_id']

if 'message' in list(update.keys()):
#in case of new message

#get message data
chat_id = update['message']['chat']['id']
username = update['message']['chat']['username']
try:

if 'text' in list(update['message'].keys()):
#filter unsupported messages
#get message
message = update['message']['text']
if 'message' in list(update.keys()):
#in case of new message

#logging
logging.info(f'USER [{username}]')
logging.info(f'MESSAGE {message}')
#get message data
chat_id = update['message']['chat']['id']
username = update['message']['chat']['username']

try:
#start controller
self.controller(message, chat_id)
if 'text' in list(update['message'].keys()):
#filter unsupported messages
#get message
message = update['message']['text']

except:
#logging
logging.error('ERROR IN CONTROLLER')
logging.info(f'USER [{username}]')
logging.info(f'MESSAGE {message}')

self.bot.sendSticker(chat_id, sticker=open(f"Data/s1.webp",'rb'))
self.bot.sendText(chat_id, 'Couldn\'t find that :(')
try:
#start controller
self.controller(message, chat_id)

else:
#logging
logging.warning('UNSUPPORTED MESSAGE')
except:
#logging
logging.error('ERROR IN CONTROLLER')
self.downloader = main.MusicDownloader()

self.bot.sendSticker(chat_id, sticker=open(f"Data/s4.webp",'rb'))
self.bot.sendText(chat_id, 'Wooops! Something went wrong.\nERROR CODE 42 - You are so funny!')
self.bot.sendSticker(chat_id, sticker=open(f"Data/s1.webp",'rb'))
self.bot.sendText(chat_id, 'Couldn\'t find that :(')

else:
#logging
logging.warning('UNSUPPORTED MESSAGE')

self.bot.sendSticker(chat_id, sticker=open(f"Data/s4.webp",'rb'))
self.bot.sendText(chat_id, 'Wooops! Something went wrong.\nERROR CODE 42 - You are so funny!')
except:
#FIX
#logging
logging.warning('ERROR IN MAIN LOOP')
self.downloader = main.MusicDownloader()

self.offset = update_id + 1

Expand Down

0 comments on commit 4898925

Please sign in to comment.