# -*- coding: utf-8 -*-
#!/usr/bin/env python

from flask import Flask, request, jsonify
import mice
import Murmur


app = Flask(__name__)

server = mice.m.getServer(1)

#@app.route("/channels/new", methods=['POST'])
def create_channel():
    data = request.json
    if (data is None):
        return jsonify(error="No data found")
    if not('name' in data):
        return jsonify(error="No channel name found")
    if not('password' in data):
        return jsonify(error="No channel password found")
    channelName = data['name']
    password = data['password']
    channel = server.addChannel(channelName, 0)

    server.setACL(channel, [Murmur.ACL(
        applyHere=True,
        applySubs=False,
        userid=-1, allow=910, deny=0,
        group="#" + password,
        inherited=False)], [], True)
    return jsonify(**{'name': channelName, 'id': channel, 'password': password})

#@app.route("/channels/<int:channel_id>", methods=['DELETE'])
def remove_channel(channel_id):
    server.removeChannel(channel_id)
    return jsonify(id=channel_id, status="removed")

#@app.route("/users/<int:session_id>/mute", methods=['POST'])
def mute_user(session_id):
    try:
        session = server.getState(session_id)
        session.mute = True
        session.deaf = True
        server.setState(session)
        return jsonify(session=session_id, status="muted")
    except:
        return jsonify(session=session_id, error="Failed to mute user")

#@app.route("/users/<int:session_id>/unmute", methods=['POST'])
def unmute_user(session_id):
    try:
        session = server.getState(session_id)
        session.mute = False
        session.deaf = False
        server.setState(session)
        return jsonify(session=session_id, status="unmuted")
    except:
        return jsonify(session=session_id, error="Failed to unmute user")

#@app.route("/users/<int:session_id>/move/<int:channel_id>", methods=['POST'])
def move_user(session_id, channel_id):
    try:
        session = server.getState(session_id)
        session.channel = channel_id
        server.setState(session)
        return jsonify(session=session_id, channel=channel_id)
    except:
        return jsonify(session=session_id, error="Failed to move user")



@app.route("/")
def main():
    users = server.getUsers()
    html = "<html><head></head><body><ol>"
    for k in users.keys():
        html += "<li>" + users[k].name + "</li>"
    html = html + "</ol></body></html>"
    return html

if __name__ == '__main__':
    app.run("127.0.0.1", 5999)
    mice.ice.destroy()

Изменить пасту