Ejemplo n.º 1
0
    def delete(self, id):
        """Delete user by id."""
        if not JsonHandler.id_exists(id):
            return {"message": "not exists"}

        JsonHandler.delete_user(id)

        return {"message": "deleted"}
Ejemplo n.º 2
0
    def put(self):
        """Add user."""
        if not JsonHandler.is_passed_json_valid(request.json):
            return {"message": "use format: {'name': <name>}"}

        id = str(JsonHandler.last_user_id() + 1)
        user = {"id": id}
        user.update(request.json)

        JsonHandler.update_user(user)

        return user
Ejemplo n.º 3
0
    def post(self, id):
        """Update user data."""
        if not JsonHandler.id_exists(id):
            return {"message": "not exists"}

        if not JsonHandler.is_passed_json_valid(request.json):
            return {"message": "use format: {'name': <name>}"}

        user = {"id": id}
        user.update(request.json)

        JsonHandler.update_user(user)

        return {"message": "updated"}
Ejemplo n.º 4
0
import discord
import json
import asyncio
from discord.ext import commands
from filehandler import FileHandler
from jsonhandler import JsonHandler

jh = JsonHandler()
fh = FileHandler()


class ReactDropItem(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.load_data()

    def load_data(self):
        self.worlditems = fh.load_file('worlditems')
        # self.currency = fh.load_file('currency')
        # self.shops = fh.load_file('shops')
        self.charactersheet = fh.load_file('charactersheet')
        self.characterinventory = fh.load_file('characterinventory')

    def s_c_i_e_ids(self):
        return jh.show_character_inventory_embed_ids()

    def s_c_s_s(self):
        return jh.show_character_sheet_stats()

# Drop inventory items
Ejemplo n.º 5
0
 def get(self, id):
     """Get user by id."""
     users = JsonHandler.get_users()
     return users.get(id, {"message": "not exists"})
Ejemplo n.º 6
0
 def get(self):
     """Return list of users."""
     return JsonHandler.get_users()
Ejemplo n.º 7
0
        if not JsonHandler.id_exists(id):
            return {"message": "not exists"}

        JsonHandler.delete_user(id)

        return {"message": "deleted"}


class UserByName(Resource):
    def put(self):
        """Add user."""
        if not JsonHandler.is_passed_json_valid(request.json):
            return {"message": "use format: {'name': <name>}"}

        id = str(JsonHandler.last_user_id() + 1)
        user = {"id": id}
        user.update(request.json)

        JsonHandler.update_user(user)

        return user


api.add_resource(Users, "/")
api.add_resource(UserById, "/user/<id>")
api.add_resource(UserByName, "/users/add")

if __name__ == "__main__":
    JsonHandler.create_file()  # just pretend nothing will happen to it
    app.run(debug=True)