def move(moving_song_json, other_song_json, after_other: hug.types.boolean = False, user: hug.directives.user = None,
response=None):
"""
Move a song before or after another one.
Needs mod permission.
:param moving_song_json: the song to move
:param other_song_json: the song to move before/after
:param after_other: whether to move after the other song. Passing anything will be evaluated to true.
"""
if not has_permission(user, ['admin', 'mod']):
logger.debug("%s tried to move a song, but isn't allowed to.", user['name'])
response.status = falcon.HTTP_FORBIDDEN
return "Not a mod"
try:
moving_song = Song.from_json(moving_song_json, music_api_names)
other_song = Song.from_json(other_song_json, music_api_names)
except ValueError as e:
logger.debug("Received invalid json (%s): %s , %s", str(e), moving_song_json, other_song_json)
response.status = falcon.HTTP_400
return str(e)
try:
queue.remove(moving_song)
except ValueError:
logger.debug("Tried to move song %s that wasn't in the queue", moving_song)
response.status = falcon.HTTP_400
return "song {} is not in queue".format(moving_song)
try:
index = queue.index(other_song)
if after_other:
index += 1
queue.insert(index, moving_song)
logger.debug("Moved song %s after/before(%s) %s", moving_song, after_other, other_song)
return player_state()
except ValueError:
logger.debug("Couldn't move song %s, because other song %s was removed from queue", moving_song, other_song)
response.status = falcon.HTTP_400
return "song {} is not in queue".format(other_song)
评论列表
文章目录