Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit 7d5546b

Browse files
coldinoTiiaAurora
andcommitted
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]>
1 parent 028ae88 commit 7d5546b

File tree

14 files changed

+403
-308
lines changed

14 files changed

+403
-308
lines changed

.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
DISCORD_TOKEN=
2-
NOTION_SECRET=
3-
DB_ID=
2+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/.pytest_cache/
33
/.venv/
44
.env
5+
database.json

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"cSpell.words": [
44
"disnake",
55
"dotenv",
6+
"pydantic",
67
"Wordle"
78
],
89
"python.analysis.typeCheckingMode": "basic"

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Discord Wordy Bot Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## Version [1.0.0] - 2022-02-01
6+
7+
- Initial release using Notion as a backend for the bot
8+
9+
## Version [2.0.0] - 2022-02-02
10+
11+
### Added
12+
13+
- Added color blind mode as a toggle when using `/colorblind`
14+
- Added language statistics to the `/stats` command
15+
- Added command `/show` to show your current game
16+
- Added Discord status for bot on start
17+
18+
### Changed
19+
20+
- Changed database from Notion to a local json file
21+
- Changed dependencies - removed `notion-client` and added `pydantic`
22+

Pipfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ verify_ssl = true
44
name = "pypi"
55

66
[packages]
7-
python-dotenv = "*"
8-
disnake = "*"
9-
notion-client = "*"
7+
python-dotenv = "==0.19.2"
8+
disnake = "~=2.3.0"
9+
pydantic = "==1.9.0"
1010

1111
[dev-packages]
1212
ipykernel = "*"
13-
pytest = "*"
13+
pytest = "~=6.2.5"
1414

1515
[requires]
1616
python_version = "3.10"

Pipfile.lock

Lines changed: 50 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
11
# Wordy Discord Bot
22
Wordy is a Wordle-like Discord bot but with a twist. It already supports 6 languages from the beginning:
33
English, Italian, French, German, Norwegian (Bokmål) and Austrian.
4+
Wordy also supports colorblind mode and saves it for each user seperately.
45

56
## The Bot
67

78
Wordy uses [Disnake](https://docs.disnake.dev/en/latest/) to connect to the Discord API. Disnake was chosen to support slash commands. You must create a bot and access token within Discord before proceeding, saving it in the `.env` file.
89

910
## The Backend
1011

11-
Wordy connects to a Notion Database to save scores. To set up your own database go to http://notion.so create an account
12-
and workspace and an inline database. Create an integration on https://developers.notion.com/ and share the database with the integration.
13-
The Database ID and the Notion access token should then be put into the `.env` file.
14-
15-
The following columns are needed:
16-
- Title-column: User
17-
- Number-column: DiscordID
18-
- Text-column: LastLang
19-
- Number-column: Win
20-
- Number-column: Lose
21-
- Number-column: Surrender
22-
23-
The bot uses the Notion database to record stats for the `/stat` command for for your entertainment.
12+
The stats of the players and their games are saved in a json database file. The path to the database can be changed in the .env file's `DATABASE_PATH` variable.
2413

2514
Games can then be played in text-rooms and also per direct message to the bot itself.
2615

@@ -37,4 +26,4 @@ pipenv sync --python 3.10
3726
pipenv shell
3827
```
3928

40-
Alternatively to install the dependencies in your global Python install use `pip install -U python-dotenv disnake notion-client`.
29+
Alternatively to install the dependencies in your global Python install use `pip install -U python-dotenv disnake pydantic`.

game_store.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
1-
from pprint import pprint
2-
from wordy_types import ActiveGame
1+
import os
2+
from typing import Optional
33

4+
from json_db import JSONDatabase
5+
from wordy_types import ActiveGame, UserInfo
46

5-
_active_games: dict[int, ActiveGame] = {}
67

8+
_db = JSONDatabase(os.getenv('DATABASE_PATH', 'database.json'))
79

8-
def fetch_stored_game(id: int):
9-
return _active_games.get(id, None)
10+
11+
def get_info_for_user(id: int):
12+
try:
13+
raw = _db[str(id)]
14+
return UserInfo.parse_obj(raw)
15+
except KeyError:
16+
user = UserInfo()
17+
_db[str(id)] = user.dict()
18+
return user
19+
20+
21+
def set_info_for_user(id: int, info: UserInfo):
22+
_db[str(id)] = info.dict()
23+
24+
25+
def fetch_stored_game(id: int) -> Optional[ActiveGame]:
26+
user = get_info_for_user(id)
27+
return user.current_game
1028

1129

1230
def store_game(id: int, game: ActiveGame):
13-
_active_games[id] = game
31+
user = get_info_for_user(id)
32+
user.current_game = game
33+
set_info_for_user(id, user)
1434

1535

1636
def clear_game(id: int):
17-
try:
18-
del _active_games[id]
19-
except KeyError:
20-
pass
37+
user = get_info_for_user(id)
38+
user.current_game = None
39+
set_info_for_user(id, user)
40+
41+
42+
def write_to_disk():
43+
_db.save()

0 commit comments

Comments
 (0)