Swiddis / word-debt-bot

A Discord bot for running a little reading game.
MIT License
2 stars 2 forks source link

Store Functionality #14

Closed Swiddis closed 5 months ago

Swiddis commented 6 months ago

Currently, no store items are supported. There should be some way to start applying store items to the game, either adding things to a global modifier state or to a user's inventory.

I think to add modifiers we need to refactor/migrate the game state. We can write the game init to migrate the format.

I'm thinking of transforming the current state:

{
  "1234": {
    "user_id": "1234",
    "user_name": "sample",
    "word_debt": 5000
  }
}

By moving it into a more specific users field and adding a modifier list:

{
  "version": 1,
  "users": {
    "1234": {
      "user_id": "1234",
      "user_name": "sample",
      "word_debt": 5000
    }
  },
  "modifiers": [
    {
      "type": "bonus_genre",
      "genre": "sci-fi",
      "expires": 1705605436.0
    }
  ]
}

The version field will make future migrations easier (the absence of it indicating the current version 0). Modifiers can be iterated to apply bonuses based on the logging. Expired modifiers can be pruned as part of that iteration step.