-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace backend, add colorblind mode and stats
* Removes Notion as datastore as it was very slow * Introduces simple JSON file-based backend * Add `/colorblind` command * Add `/stats` command Co-authored-by: Tiia Aurora <[email protected]>
- Loading branch information
1 parent
028ae88
commit 7d5546b
Showing
14 changed files
with
403 additions
and
308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
DISCORD_TOKEN= | ||
NOTION_SECRET= | ||
DB_ID= | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/.pytest_cache/ | ||
/.venv/ | ||
.env | ||
database.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Discord Wordy Bot Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
## Version [1.0.0] - 2022-02-01 | ||
|
||
- Initial release using Notion as a backend for the bot | ||
|
||
## Version [2.0.0] - 2022-02-02 | ||
|
||
### Added | ||
|
||
- Added color blind mode as a toggle when using `/colorblind` | ||
- Added language statistics to the `/stats` command | ||
- Added command `/show` to show your current game | ||
- Added Discord status for bot on start | ||
|
||
### Changed | ||
|
||
- Changed database from Notion to a local json file | ||
- Changed dependencies - removed `notion-client` and added `pydantic` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,43 @@ | ||
from pprint import pprint | ||
from wordy_types import ActiveGame | ||
import os | ||
from typing import Optional | ||
|
||
from json_db import JSONDatabase | ||
from wordy_types import ActiveGame, UserInfo | ||
|
||
_active_games: dict[int, ActiveGame] = {} | ||
|
||
_db = JSONDatabase(os.getenv('DATABASE_PATH', 'database.json')) | ||
|
||
def fetch_stored_game(id: int): | ||
return _active_games.get(id, None) | ||
|
||
def get_info_for_user(id: int): | ||
try: | ||
raw = _db[str(id)] | ||
return UserInfo.parse_obj(raw) | ||
except KeyError: | ||
user = UserInfo() | ||
_db[str(id)] = user.dict() | ||
return user | ||
|
||
|
||
def set_info_for_user(id: int, info: UserInfo): | ||
_db[str(id)] = info.dict() | ||
|
||
|
||
def fetch_stored_game(id: int) -> Optional[ActiveGame]: | ||
user = get_info_for_user(id) | ||
return user.current_game | ||
|
||
|
||
def store_game(id: int, game: ActiveGame): | ||
_active_games[id] = game | ||
user = get_info_for_user(id) | ||
user.current_game = game | ||
set_info_for_user(id, user) | ||
|
||
|
||
def clear_game(id: int): | ||
try: | ||
del _active_games[id] | ||
except KeyError: | ||
pass | ||
user = get_info_for_user(id) | ||
user.current_game = None | ||
set_info_for_user(id, user) | ||
|
||
|
||
def write_to_disk(): | ||
_db.save() |
Oops, something went wrong.