コード例 #1
0
def create_playlist():
    #TODO Create method in models.playlist - Attribute Name
    # Handles a json request if the request is json
    if (request.is_json):
        request_data = request.get_json(force=True)
        if 'name' in request_data and 'description' in request_data:
            playlist_name = request_data['name']
            playlist_description = request_data['description']
        else:
            return make_response("There is no name or description in request",
                                 400)
    # Else, we assume the request is a form
    else:
        playlist_name = request.form.get('name')
        playlist_description = request.form.get('description')
        if playlist_name is None or playlist_description is None:
            return make_response("There is no name or description in request",
                                 400)
    user_id = current_user.get_id(token=False)
    new_playlist = Playlist(name=playlist_name,
                            description=playlist_description,
                            user_id=user_id)
    session.add(new_playlist)
    session.commit()
    return make_response(str(new_playlist.id), 200)
コード例 #2
0
ファイル: EmojiManager.py プロジェクト: 3onier/discord_bot
    async def create_emoji_for_member(self,
                                      member: discord.Member) -> discord.Emoji:
        """ Creates the emoji for given member

        :param member: member emoji should be created for
        :return: [discord.Emoji] created Emoji
        """
        # generate name
        name = member.name + member.discriminator

        # download avatar
        profile_picture = await member.avatar_url_as(format="png",
                                                     size=64).read()

        # create avatar and yield
        emoji = await member.guild.create_custom_emoji(name=name,
                                                       image=profile_picture)

        # if failed return
        if not emoji:
            return None

        # create entry for database
        emoji_entry = AvatarEmoji(name=emoji.name,
                                  discord_id=emoji.id,
                                  user_id=str(member.id),
                                  guild_id=str(member.guild.id))
        session.add(emoji_entry)
        session.commit()
        return emoji
コード例 #3
0
def db_update_chat(chat_id, step, place_id=None):
    chat = db_get_chat(chat_id)
    if chat:
        chat.step = step
        if place_id:
            chat.place_id = place_id
    else:
        chat = Chat(id=chat_id, step=step)
        session.add(chat)

    session.commit()
    return chat
コード例 #4
0
def create_new_user():
    # Handles a json request if the request is json
    if (request.is_json):
        request_data = request.get_json(force=True)
        if 'email' in request_data and 'password' in request_data and 'confirm_password' in request_data:
            user_password = request_data['password']
            user_email = request_data['email']
            user_name = request_data['name']
            if (user_password != request_data['confirm_password']):
                return make_response("Passwords don't match", 400)
        else:
            return make_response(
                "There is no email, password or password confirmation in request",
                400)
    # Else, we assume the request is a form
    else:
        user_password = request.form.get('password')
        user_email = request.form.get('email')
        user_name = request.form.get("name")
        if (user_password != request.form.get('confirm_password')):
            return make_response("Passwords don't match", 400)
        if (user_email == None or user_password == None):
            return make_response(
                "There is no password or password confirmation in request",
                400)

    # Create a random session token
    user_token = unicode(os.urandom(24).encode('hex'))

    # Saves new user in the database
    try:
        new_user = User(email=user_email,
                        password=user_password,
                        session_token=user_token,
                        name=user_name)
        # We hash the password
        new_user.set_password()
        session.add(new_user)
        session.commit()
    # Handles any unexpected exception....
    except Exception as e:
        message = jsonify({"status": "failed", "message": str(e)})
        return render_template('register.html', message=message)

    # Success!
    message = jsonify({"status": "ok", "message": "user created with success"})
    return redirect("/")
コード例 #5
0
    async def vc_add(self, ctx: Context, voice_id: str):
        """ Adds a voice channel to managing the temporary text channel

        :param ctx: context of event.
        :param voice_id: the id of the voice channel in discord.
        :return:
        """
        vc = VoiceChannel(discord_id=voice_id, guild_id=ctx.guild.id)
        session.add(vc)
        session.commit()
        embed = discord.Embed(
            type="rich",
            title="Success",
            description="Temporary text channel has been created",
            color=colors.COLOR_SUCCESS
        )
        await ctx.send(embed=embed, reference=ctx.message)
コード例 #6
0
ファイル: handlers.py プロジェクト: ogonbat/samporo
 def prepare(self):
     ip = self.get_argument("ip", None)
     extension = self.get_argument("extension", False)
     user_agent = self.request.headers.get('User-Agent')
     splitted_agent = user_agent.split()
     model = splitted_agent[0]
     mac = splitted_agent[1].split(":")[1]
     if extension:
         #first check if the extension already exist
         query = session.query(Phones).filter(Phones.extension==extension)
         try:
             phone = query.one()
             phone.extension = extension
             phone.mac = mac
         except NoResultFound:
             phone = Phones(mac,ip,extension)
             session.add(phone)
         session.commit()
         self.phone = phone
コード例 #7
0
def db_update_places(message, bot, place_id=None):
    if bot and message.from_user.id != bot.get_me().id:
        if place_id:
            place = session.query(Place).filter_by(id=place_id).first()
            if message.photo and message.photo[0]:
                place.photo_id = message.photo[0].file_id
            elif message.text:
                place.comment = message.text
            elif message.location:
                place.longitude = message.location.longitude
                place.latitude = message.location.latitude
            else:
                return None
        elif message.text:
            place = Place(chat_id=message.chat.id, name=message.text)
            session.add(place)
        else:
            return None
    else:
        return None

    session.commit()
    return place
コード例 #8
0
def create_song():
    # Get the name of the uploaded file

    #TODO !Implement song upload!
    #TODO Create method in models.playlist - Attribute Name
    # Handles a json request if the request is json
    if request.is_json:
        request_data = request.get_json(force=True)
        if 'name' in request_data and 'album' in request_data and 'artist' in request_data:
            song_name = request_data['name']
            song_album = request_data['album']
            song_artist = request_data['artist']
        else:
            return make_response(
                "There is no name, album or artist in request", 400)
    # Else, we assume the request is a form
    else:
        file = request.files['file']
        file.save(
            os.path.join(application.config['SONG_FOLDER'], file.filename))
        song_name = request.form.get('name')
        song_path = application.config['SONG_FOLDER'] + "/%s" % (file.filename)
        song_album = request.form.get('album')
        song_artist = request.form.get('artist')
        if song_name is None or song_album is None or song_artist is None:
            return make_response("There is no name or description in request",
                                 400)

    user_id = current_user.get_id(token=False)
    new_song = Song(name=song_name,
                    album=song_album,
                    artist=song_artist,
                    user_id=user_id,
                    path=song_path)
    session.add(new_song)
    session.commit()
    return make_response(str(new_song.id), 200)