def bg_pleblist_add_song(self, stream_id, youtube_id, force, bot, source): with DBManager.create_session_scope() as db_session: song_info = PleblistManager.get_song_info(youtube_id, db_session) if song_info is None or force: try: # XXX: Should this be a setting in the module? idk PleblistManager.init( bot.config["youtube"]["developer_key"]) except: log.error("No youtube key set up.") bot.whisper(source, "No youtube key set up") return False song_info = PleblistManager.create_pleblist_song_info( youtube_id) if song_info is False: bot.whisper( source, "Invalid song given (or the YouTube API is down)") return False db_session.merge(song_info) db_session.commit() # See if the user has already submitted X songs num_unplayed_songs_requested = int( db_session.query(func.count( PleblistSong.id)).filter_by(stream_id=stream_id, user_id=source.id, date_played=None).one()[0]) if num_unplayed_songs_requested >= self.settings[ "max_songs_per_user"] and not force: bot.whisper( source, f"You can only request {num_unplayed_songs_requested} songs at the same time!" ) return False # Add the song request song_request = PleblistSong(bot.stream_manager.current_stream.id, youtube_id, user_id=source.id) # See if the song is too long # If it is, make it autoskip after that time if song_info.duration > self.settings["max_song_length"]: song_request.skip_after = self.settings["max_song_length"] db_session.add(song_request) bot.say( f'{source} just requested the song "{song_info.title}" to be played KKona' )
def bg_pleblist_add_song(self, stream_id, youtube_id, force, **options): bot = options['bot'] source = options['source'] with DBManager.create_session_scope() as db_session: song_info = PleblistManager.get_song_info(youtube_id, db_session) if song_info is None or force: try: # XXX: Should this be a setting in the module? idk PleblistManager.init(bot.config['youtube']['developer_key']) except: log.error('No youtube key set up.') bot.whisper(source.username, 'No youtube key set up') return False song_info = PleblistManager.create_pleblist_song_info(youtube_id) if song_info is False: bot.whisper(source.username, 'Invalid song given (or the YouTube API is down)') return False db_session.merge(song_info) db_session.commit() # See if the user has already submitted X songs num_unplayed_songs_requested = int(db_session.query(func.count(PleblistSong.id)).filter_by(stream_id=stream_id, user_id=source.id, date_played=None).one()[0]) if num_unplayed_songs_requested >= self.settings['max_songs_per_user']: bot.whisper(source.username, 'You can only request {} songs at the same time!'.format(num_unplayed_songs_requested)) return False # Add the song request song_request = PleblistSong(bot.stream_manager.current_stream.id, youtube_id, user_id=source.id) # See if the song is too long # If it is, make it autoskip after that time if song_info.duration > self.settings['max_song_length']: song_request.skip_after = self.settings['max_song_length'] db_session.add(song_request) bot.say('{} just requested the song "{}" to be played KKona'.format(source.username_raw, song_info.title))
def bg_pleblist_add_song(self, stream_id, youtube_id, force, **options): bot = options['bot'] source = options['source'] with DBManager.create_session_scope() as db_session: song_info = PleblistManager.get_song_info(youtube_id, db_session) if song_info is None or force: try: # XXX: Should this be a setting in the module? idk PleblistManager.init(bot.config['youtube']['developer_key']) except: log.error('No youtube key set up.') bot.whisper(source.username, 'No youtube key set up') return False song_info = PleblistManager.create_pleblist_song_info(youtube_id) if song_info is False: bot.whisper(source.username, 'Invalid song given (or the YouTube API is down)') return False db_session.merge(song_info) db_session.commit() # See if the user has already submitted X songs num_unplayed_songs_requested = int(db_session.query(func.count(PleblistSong.id)).filter_by(stream_id=stream_id, user_id=source.id, date_played=None).one()[0]) if num_unplayed_songs_requested >= self.settings['max_songs_per_user'] and not force: bot.whisper(source.username, 'You can only request {} songs at the same time!'.format(num_unplayed_songs_requested)) return False # Add the song request song_request = PleblistSong(bot.stream_manager.current_stream.id, youtube_id, user_id=source.id) # See if the song is too long # If it is, make it autoskip after that time if song_info.duration > self.settings['max_song_length']: song_request.skip_after = self.settings['max_song_length'] db_session.add(song_request) bot.say('{} just requested the song "{}" to be played KKona'.format(source.username_raw, song_info.title))