How to make Database/Storage for users?

We have 3 function to handle a specific user data.

  1. User.saveData()

  2. User.getData()

  3. User.deleteData()

And We have 3 functions for handling global data

  1. Bot.saveData()

  2. Bot.getData()

  3. Bot.deleteData()

Examples

Example for User.saveData()

User.saveData("dataName", "data") # you can also use User.saveData(name="data", data="data")
bot.replyText(u, "saved")

Example for User.getData()

data = User.getData("dataname")
bot.replyText(
    chat_id=u,
    text=f"your data is {data}"
)

Example For User.deleteData()

deleted_data = User.deleteData("dataname")
bot.replyText(
    chat_id=u,
    text=f"{deleted_data}"
)

Example For Saving Global Data Bot.saveData()

Bot.saveData("dataName", "data") # you can also use User.saveData(name="data", data="data")
bot.replyText(u, "saved")

Example For Getting Global Data Bot.getData()

data = Bot.getData("dataname")
bot.replyText(
    chat_id=u,
    text=f"your data is {data}"
)

Example For Deleting Global Data Bot.deleteData()

deleted_data = Bot.deleteData("dataname")
bot.replyText(
    chat_id=u,
    text=f"{deleted_data}"
)

Last updated