def say_request(**payload): command = payload['data'] if command.startswith("request"): new_c = current_song print(command) search_keywords = command[8:] print(search_keywords) # if current_song.is_playing() and current_song.get_creator() != "auto": if current_song.is_playing(): # if there is a song playing wait till it's finish song_data = pl.add_song(search_keywords) response = "Ok I have added {} to queue".format(song_data['name']) else: # else play that song. current_song.stop_audio() pl.add_song(search_keywords) song_data = pl.get_song() print(song_data) current_song = music_player2.YoutubeAudio(song_data) current_song.play_audio() song_name = filter_title(song_data['name']) response = "Now playing {}".format(song_name) print("current play list", pl.get_playlist) webclient = payload['web_client'] webclient.chat_postMessage( )
def handle_command(command, channel, creator, pl, current_song): """ Executes bot command if the command is known """ # Default response is help text for the user default_response = "Not sure what you mean. Try *{}*.".format("play a song") # Finds and executes the given command, filling in response response = None # This is where you start to implement more commands! if command.startswith("request"): print(command) search_keywords = command[8:] print(search_keywords) # if current_song.is_playing() and current_song.get_creator() != "auto": if current_song.is_playing(): # if there is a song playing wait till it's finish song_data = pl.add_song(search_keywords, creator) response = "Ok I have added {} to queue".format(song_data['name']) else: # else play that song. current_song.stop_audio() pl.add_song(search_keywords, creator) song_data = pl.get_song() current_song = music_player2.YoutubeAudio(song_data) current_song.play_audio() song_name = filter_title(song_data['name']) requester = _slackify_user(current_song.get_creator()) response = "*Now playing:* {0} \n*Requested by:* <@{1}>".format(song_name, requester) print("current play list",pl.get_playlist) elif command.startswith("nowplaying"): response = "currently playing: {0}".format(current_song.get_name()) elif command.startswith("skip"): current_song.stop_audio() song_data = pl.get_song() current_song = music_player2.YoutubeAudio(song_data) current_song.play_audio() song_name = filter_title(current_song.get_name()) requester = _slackify_user(current_song.get_creator()) response = "*Now playing:* {0} \n*Requested by:* <@{1}>".format(song_name, requester) elif command.startswith("nextup"): song_list = pl.get_next_info(limit=5) s_list = "" for s in song_list: s_list = s_list + "{}\n".format(s['name']+"\n") response = "Coming up: \n" + s_list elif command.startswith("help"): response = "You can ask me the following: \n" \ "request - request a song \n" \ "skip - skip to the next track \n" \ "nowplaying - report back what is currently playing \n" \ "nextup - report back what is coming up \n" \ "stop - close the app \n" elif command.startswith("stop"): response = "Goodbyes are not forever, Goodbyes are not the end. :robot_face:" slack_client.api_call( "chat.postMessage", channel=channel, text=response ) sys.exit() elif command.startswith("volume"): volume_keywords = command[7:] print(volume_keywords) if volume_keywords.isdigit(): current_song.set_volume(int(volume_keywords)) elif volume_keywords == "louder": song_volume = current_song.get_volume() current_song.set_volume(song_volume+5) elif volume_keywords == "quieter": song_volume = current_song.get_volume() current_song.set_volume(song_volume-5) # Sends the response back to the channel print("internal channel", channel) slack_client.api_call( "chat.postMessage", channel=channel, text=response ) return current_song, channel
return song_name if __name__ == "__main__": if slack_client.rtm_connect(with_team_state=False): print("Starter Bot connected and running!") # Read bot's user ID by calling Web API method `auth.test` starterbot_id = slack_client.api_call("auth.test")["user_id"] # play the first auto song right away. pl = music_player2.Playlist() song_data = pl.get_song() # set default channel to SLACK_DEFAULT_CHANNEL channel = SLACK_DEFAULT_CHANNEL print(song_data['name']) current_song = music_player2.YoutubeAudio(song_data) current_song.play_audio() song_name = filter_title(current_song.get_name()) response = "*Now playing:* {0} \n*Requested by:* {1}".format(song_name, "Auto DJ") slack_client.api_call("chat.postMessage", channel=channel, text=response) while True: command, channel, creator = parse_bot_commands(slack_client.rtm_read()) if command: current_song, this_channel = handle_command(command, channel,creator, pl, current_song) if not channel: this_channel = SLACK_DEFAULT_CHANNEL # when no song is playing play auto song after 3 seconds
def handle_command(command, channel, pl, current_song): """ Executes bot command if the command is known """ # Default response is help text for the user default_response = "Not sure what you mean. Try *{}*.".format("play a song") # Finds and executes the given command, filling in response response = None # This is where you start to implement more commands! if command.startswith("request"): print(command) search_keywords = command[8:] print(search_keywords) # if current_song.is_playing() and current_song.get_creator() != "auto": if current_song.is_playing(): # if there is a song playing wait till it's finish song_data = pl.add_song(search_keywords) response = "Ok I have added {} to queue".format(song_data['name']) else: # else play that song. current_song.stop_audio() pl.add_song(search_keywords) song_data = pl.get_song() print(song_data) current_song = music_player2.YoutubeAudio(song_data) current_song.play_audio() song_name = filter_title(song_data['name']) response = "Now playing {}".format(song_name) print("current play list",pl.get_playlist) @slack.RTMClient.run_on(event='message') def say_request(**payload): command = payload['data'] if command.startswith("request"): new_c = current_song print(command) search_keywords = command[8:] print(search_keywords) # if current_song.is_playing() and current_song.get_creator() != "auto": if current_song.is_playing(): # if there is a song playing wait till it's finish song_data = pl.add_song(search_keywords) response = "Ok I have added {} to queue".format(song_data['name']) else: # else play that song. current_song.stop_audio() pl.add_song(search_keywords) song_data = pl.get_song() print(song_data) current_song = music_player2.YoutubeAudio(song_data) current_song.play_audio() song_name = filter_title(song_data['name']) response = "Now playing {}".format(song_name) print("current play list", pl.get_playlist) webclient = payload['web_client'] webclient.chat_postMessage( ) elif command.startswith("nowplaying"): response = "currently playing: {0}".format(current_song.get_name())