def echo_message(message): """ Hace un 'eco' de lo que se recibe y no se ha procesado en algún comando anterior. :param message: :return: """ bot.reply_to(message, message.text)
def handle_location(message): latitude = message.location.latitude longitude = message.location.longitude nombre, imagen = patio_cercano(latitude, longitude) bot.reply_to(message, "El patio más cercano está en " + nombre) #bot.reply_to(message, imagen) bot.send_photo(chat_id=message.chat.id, photo=imagen)
def nextLaunch(message): r = requests.get('https://api.spacexdata.com/v3/launches/next') pipo = json.loads(r.content) a = Launch(pipo) bot.reply_to(message, a.imprimir())
def set_region(lib): uid = lib.message.chat.id Chat.set_config(uid, "region", lib.data) bot.reply_to(lib.message, "%s seleccionada" %lib.data) #"br", "eune", "euw", "jp", "kr", "lan", "las", "na", "oce", "tr", "ru", "pbe"
def load(message): """ Recupera un dato guardado con save """ cid = message.chat.id data = User.get_config(cid) place = "none" status = "none" User.set_config(cid, place, status) bot.reply_to(message, "Salido de %s" % data.place)
def load(message): """ Recupera un dato guardado con save """ chat_id = message.chat.id data = Chat.get_config(chat_id, 'memory') if not data: bot.reply_to(message, "Aún no has guardado nada") return bot.reply_to(message, "Dato recuperado: %s" % data.value)
def save(message): """ Guarda un dato en el chat que se puede recuperar después """ data = util.extract_arguments(message.text) if not data: bot.reply_to(message, "Debe indicar el dato que quiere que guarde") return chat_id = message.chat.id Chat.set_config(chat_id, 'memory', data) bot.reply_to(message, "Dato guardado. Usa /load para recuperar")
def checkin(lib): uid = lib.message.chat.id data = User.get_config(uid) if data.status == "requesting": place = lib.data status = "requesting" User.set_config(uid, place, status) bot.reply_to(lib.message, "Pedido en %s" % place) notifyFrom(lib.message) else: place = lib.data status = "checked in" User.set_config(uid, place, status) bot.reply_to(lib.message, "Entrado a %s" % place)
def notifyFrom(message): data = User.get_config(message.chat.id) users = User.get_checked_in_at(data.place) if len(users) > 0: n_users = 0 for user in users: cid = user.cid getanswer(cid, message.chat.id) n_users = n_users + 1 bot.reply_to( message, "%i Usuarios fueron notificados, esperando respuesta" % n_users) else: bot.reply_to(message, "No hay ningun usuario en la biblioteca")
def rotation(message): response = requests.get( "https://euw1.api.riotgames.com/lol/platform/v3/champion-rotations?api_key=" + RIOT_KEY) content = response.json() champs = "" with open('champion.json') as json_file: file = json.load(json_file) champion_list = file['data'] for item in content["freeChampionIds"]: for champion_name in champion_list.keys(): if champion_list[champion_name]['key'] == str(item): champs += champion_list[champion_name]['name'] champs += '\n' bot.reply_to(message, champs)
def load(message): """ Recupera un dato guardado con save """ users = User.get_all() if len(users) > 0: for user in users: bot.send_message( message.chat.id, "user: %s\n place: %s\n status: %s" % ( user.cid, user.place, user.status, )) else: bot.reply_to(message, "not users")
def load(message): chat_id = message.chat.id data = Song.get_config(chat_id, 'memory') if not data: bot.reply_to(message, "Aún no has guardado nada") return songsMessage = "" for song in data: songTitle = song.title songArtist = song.artist songAlbum = song.album songInfo = "- " + songTitle + " | " + songArtist + " | " + songAlbum + "\n" songsMessage = songsMessage + songInfo.encode('utf-8') + "\n" messageToSend = "*Canciones que has buscado:*\n\n" + songsMessage bot.send_message(message.chat.id, messageToSend, parse_mode="markdown")
def start(message): bot.reply_to(message, 'Hello, ' + message.from_user.first_name)
def start(message): bot.reply_to(message, 'Bienvenido, ' + message.from_user.first_name + ' !!!')
def start(message): bot.reply_to(message, 'Hello, ' + message.from_user.first_name) lista_cat = ["love","science","art","biographies","fantasy","romance","religion","recipes", "mystery","music", "medicine","history", "chilcren","sci-fi"] bot.send_message("Categorías disponibles: " + lista_cat)
def start(message): bot.reply_to(message, 'Welcome, ' + message.from_user.first_name)
def region(message): uid = message.chat.id data = Chat.get_config(uid, "region") if data is not None: bot.reply_to(message, "%s actualmente seleccionada" %data.value) region_board(message)
def recognize_song(message): bot.reply_to(message, "⚙️ Procesando tu audio...", parse_mode="Markdown") fileId = message.voice.file_id getPathRequest = requests.get('https://api.telegram.org/bot' + TOKEN + '/getFile?file_id=' + fileId) if getPathRequest.status_code == 200: path = getPathRequest.json()['result']['file_path'] rawFileRequest = requests.get('https://api.telegram.org/file/bot' + TOKEN + '/' + path) if rawFileRequest.status_code == 200: fileKey = str(uuid.uuid4()) upload = s3.Bucket('musictelegram').put_object( Key=fileKey, Body=rawFileRequest.content, ACL='public-read') bucket_location = s3Client.get_bucket_location( Bucket='musictelegram') object_url = "http://s3-{0}.amazonaws.com/{1}/{2}".format( bucket_location['LocationConstraint'], 'musictelegram', fileKey) method = "recognizeWithOffset/" if humming_mode else "" getSongInfo = requests.get('https://api.audd.io/' + method + '?api_token=' + AUDD_API_TOKEN + '&url=' + object_url) if getSongInfo.status_code == 200: songInfo = getSongInfo.json()['result'] if songInfo: if humming_mode: if songInfo['count']: predictionList = songInfo['list'] bot.send_message( message.chat.id, "Tu canción puede ser una de estas:") for prediction in predictionList: title = None artist = None album = None score = None if prediction.has_key('title'): title = prediction['title'] if prediction.has_key('artist'): artist = prediction['artist'] if prediction.has_key('album'): album = prediction['album'] if prediction.has_key('score'): score = prediction['score'] bot.send_message(message.chat.id, get_song_info( title, artist, album, score).encode('utf-8'), parse_mode="Markdown") else: bot.reply_to( message, "Lo has hecho fatal, intenta tararear de nuevo." ) else: songTitle = songInfo['title'] songArtist = songInfo['artist'] songAlbum = songInfo['album'] messageToSend = "Tu cancion es:\n" + get_song_info( songTitle, songArtist, songAlbum) bot.send_message(message.chat.id, messageToSend, parse_mode="Markdown") spotifySearch = spotify.search( q='track:' + songTitle.encode('utf-8'), type='track') if (len(spotifySearch)): spotifyURL = spotifySearch['tracks']['items'][0][ 'external_urls']['spotify'] bot.send_message(message.chat.id, "*URL Spotify:* " + spotifyURL, parse_mode="Markdown") Song.set_config(message.chat.id, 'memory', songTitle, songAlbum, songArtist) else: bot.reply_to( message, "No se ha podido reconocer ninguna canción. Inténtalo de nuevo." ) else: bot.reply_to(message, "Error de reconocimiento de audio.") else: bot.reply_to(message, "Error procesando tu audio. Intentalo de nuevo.") else: bot.reply_to(message, "Error procesando tu audio. Intentalo de nuevo.")
def set_recording(message): global humming_mode humming_mode = False bot.reply_to(message, 'Se reconocerá como grabación')
def set_humming(message): global humming_mode humming_mode = True bot.reply_to(message, 'Se reconocerá como tarareo')