Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
6d74edf
Initial commit
gustavwilliam Jul 16, 2024
443f5d4
Added the bot directory
jspmic Jul 20, 2024
73a92e2
Merge pull request #2 from jspmic/add-directory-bot
jspmic Jul 20, 2024
1fe3439
Created a bot with basic commands
Deja-Vu1 Jul 20, 2024
b22ffad
Added database.py
jspmic Jul 20, 2024
4af8f32
Merge pull request #3 from jspmic/main
jspmic Jul 20, 2024
992c0c6
Added the database and modified database.py
jspmic Jul 20, 2024
fc03e5a
Merge pull request #4 from jspmic/modify-database
jspmic Jul 20, 2024
6245642
Add many modifications
rich1richard Jul 20, 2024
ba490d5
Merge branch 'main' of https://github.com/gustavwilliam/cj11-mesmeriz…
rich1richard Jul 20, 2024
7873a34
add names in license (missing the lead name)
rich1richard Jul 20, 2024
72e4376
swapped ruff and ruff-format
rich1richard Jul 20, 2024
216c2e9
Modified the database manager
jspmic Jul 21, 2024
839d5db
Created new DB
jspmic Jul 21, 2024
dcc26a2
Merge pull request #5 from jspmic/modify-database
jspmic Jul 21, 2024
d3d4b01
Minor changes to the database
jspmic Jul 21, 2024
9beb689
Fixed return types in database.py
jspmic Jul 21, 2024
ab8635c
Merge pull request #6 from jspmic/fix-database
jspmic Jul 21, 2024
49456cf
another fix of database.py
jspmic Jul 21, 2024
4ec3689
fix linting-issues
jspmic Jul 21, 2024
c51d1e9
Update database.py
jspmic Jul 21, 2024
ccc52fc
Merge pull request #1 from jspmic/fix-database-1
jspmic Jul 21, 2024
b18aabb
Merge pull request #7 from jspmic/main
jspmic Jul 21, 2024
4694e33
Fixed other issues from linting
jspmic Jul 21, 2024
9ac5f77
Merge branch 'gustavwilliam:main' into fix-database
jspmic Jul 21, 2024
1e87f61
Merge pull request #2 from jspmic/fix-database
jspmic Jul 21, 2024
0dd727d
Merge pull request #8 from jspmic/main
jspmic Jul 21, 2024
d92f649
Removed the Quiz table
jspmic Jul 21, 2024
7733960
Merge branch 'main' into modify-database
jspmic Jul 21, 2024
2a2f129
Merge pull request #9 from jspmic/modify-database
jspmic Jul 21, 2024
cad8a57
Added vim .swp files to gitignore
Noble-47 Jul 21, 2024
16fe710
modified database class and implemented update and fetch functionalit…
Noble-47 Jul 22, 2024
577d13f
Created models for score and scoresheet for easier abstraction
Noble-47 Jul 22, 2024
adb53b6
Added unittest for models
Noble-47 Jul 22, 2024
55a89b1
created test directory
Noble-47 Jul 22, 2024
7dca12a
Merge branch 'main' into include_data_models
Noble-47 Jul 22, 2024
280fb6b
Corrected formatting errors and fixed test assertion error
Noble-47 Jul 22, 2024
df2813a
Corrected formatting errors and fixed test assertion error
Noble-47 Jul 22, 2024
5a61eff
Merge pull request #11 from gustavwilliam/feature_add_model_layer
jspmic Jul 22, 2024
2f642d8
Add generation for a map with a player
gustavwilliam Jul 22, 2024
984d3ae
Merge branch 'main' into feature-map_generation
gustavwilliam Jul 22, 2024
c4ffe1f
Merge pull request #12 from gustavwilliam/feature-map_generation
gustavwilliam Jul 22, 2024
6a3ce70
Allow player to visit arbitrary coordinates
gustavwilliam Jul 22, 2024
e33a45a
Complete functionality of free map movement
gustavwilliam Jul 22, 2024
462da5b
Fix linting
gustavwilliam Jul 22, 2024
8585bbf
Merge pull request #13 from gustavwilliam/feature-map_navigation
gustavwilliam Jul 22, 2024
74455f2
Add player name tags
gustavwilliam Jul 22, 2024
89abaf1
Fix map interactions
gustavwilliam Jul 22, 2024
c6d8a22
Merge pull request #14 from gustavwilliam/feature-player_name_tags
gustavwilliam Jul 22, 2024
fc5d53d
Layout walk controls in a logical way
gustavwilliam Jul 22, 2024
d9569fb
Merge pull request #15 from gustavwilliam/enhance-walk_control
gustavwilliam Jul 22, 2024
079572d
Add missing dependency matplotlib
gustavwilliam Jul 23, 2024
bf737fb
Merge pull request #16 from gustavwilliam/fix-missing_dependency-matp…
gustavwilliam Jul 23, 2024
fc38372
Add basic level and controller classes
gustavwilliam Jul 23, 2024
02b05a8
Add python3 eval command
gustavwilliam Jul 23, 2024
7a87460
Merge pull request #17 from gustavwilliam/feature-code_eval
gustavwilliam Jul 23, 2024
e0faa7e
Add python3 eval command
gustavwilliam Jul 23, 2024
3d424c8
Add Questions class
gustavwilliam Jul 24, 2024
dd9ca6b
Add base question data
gustavwilliam Jul 24, 2024
f03b484
Complete support for auto-parsing questions
gustavwilliam Jul 24, 2024
b5d8108
Add base classes for level 1-4
gustavwilliam Jul 24, 2024
1c1c5ed
Merge pull request #18 from gustavwilliam/feature-levels
gustavwilliam Jul 24, 2024
3d55b1b
Fix bug with question evaluation
gustavwilliam Jul 24, 2024
74c4eee
Integrate level positions with map
gustavwilliam Jul 24, 2024
15b8250
Add logic for presenting and navigating questions
gustavwilliam Jul 25, 2024
55bd764
Complete question logic and answer validation
gustavwilliam Jul 25, 2024
615f9d8
Merge pull request #19 from gustavwilliam/feature-levels_ui
gustavwilliam Jul 25, 2024
728308e
Add optional pre-code field to write code question
gustavwilliam Jul 26, 2024
73f9942
Merge pull request #20 from gustavwilliam/feature-pre_code
gustavwilliam Jul 26, 2024
fa6ed5d
Add title screen to play command
gustavwilliam Jul 26, 2024
347b4d5
Merge pull request #21 from gustavwilliam/feature-title_art
gustavwilliam Jul 26, 2024
48ace86
Added discord_guide.md
Deja-Vu1 Jul 26, 2024
1b0a653
Update discord_guide.md
Deja-Vu1 Jul 26, 2024
1b78071
Refactored database logic. Added player and play_history models
Noble-47 Jul 26, 2024
bc2781a
Update discord_guide.md
Deja-Vu1 Jul 26, 2024
2a8ba6b
Merge branch 'feature-guide' of https://github.com/gustavwilliam/cj11…
Deja-Vu1 Jul 26, 2024
a036f61
Update discord_guide.md
Deja-Vu1 Jul 26, 2024
4d9d7c8
Update discord_guide.md
Deja-Vu1 Jul 26, 2024
3520fb2
Update discord_guide.md
Deja-Vu1 Jul 26, 2024
00546e8
Update discord_guide.md
Deja-Vu1 Jul 26, 2024
cfdc4f6
Update discord_guide.md
Deja-Vu1 Jul 26, 2024
6283e43
Fix defer issue on slower network speeds
gustavwilliam Jul 26, 2024
c581efe
Fixed error with sql statements
Noble-47 Jul 26, 2024
6061fad
Fix defer issue in map.navigate
gustavwilliam Jul 26, 2024
f87619c
Actually fix it
gustavwilliam Jul 26, 2024
671f6ea
Fix bug: update map message instead of sending new
gustavwilliam Jul 26, 2024
592ad9b
Merge pull request #25 from gustavwilliam/fix-defer_issue
gustavwilliam Jul 26, 2024
9cf5cc6
Merge pull request #22 from gustavwilliam/feature-guide
gustavwilliam Jul 26, 2024
2073a8c
Add level fail + success embeds
gustavwilliam Jul 27, 2024
90b3efa
Merge pull request #27 from gustavwilliam/feature-success_fail_images
gustavwilliam Jul 27, 2024
e5a17c5
Added refactor
jspmic Jul 27, 2024
aadca88
Added type-hints to refactor
jspmic Jul 27, 2024
2a57440
Added changes requested
jspmic Jul 27, 2024
c44d6e2
Fixed linting issues
jspmic Jul 27, 2024
6bb379b
Fix missing .value
gustavwilliam Jul 27, 2024
27babb1
Fix Emoji class doctoring
gustavwilliam Jul 27, 2024
be028f4
Merge pull request #30 from gustavwilliam/feature-refactor
gustavwilliam Jul 27, 2024
7ab5832
Modified the letter F
jspmic Jul 27, 2024
0a6360c
Add level running command
gustavwilliam Jul 27, 2024
ab881a2
Merge pull request #32 from gustavwilliam/feature-lvl_command
gustavwilliam Jul 27, 2024
2000708
Merge pull request #31 from gustavwilliam/feature-refactor
gustavwilliam Jul 27, 2024
7045fc3
Added new levels
jspmic Jul 26, 2024
1dae3cc
Modified level 11
jspmic Jul 27, 2024
64d0954
Added modifications
jspmic Jul 27, 2024
cade1e1
Added new change requests
jspmic Jul 27, 2024
7db0753
Clear up questions.json
gustavwilliam Jul 27, 2024
7de8c00
Add back lost questions lvl6 lvl7
gustavwilliam Jul 27, 2024
ccc062e
Merge pull request #29 from gustavwilliam/feature-new_levels
gustavwilliam Jul 27, 2024
3826441
Added storing and setting of map coordinates for player
Noble-47 Jul 27, 2024
2f738b7
Add player only has 3 tries
gustavwilliam Jul 27, 2024
293d7a2
Merge pull request #33 from gustavwilliam/feature-level_lives
gustavwilliam Jul 27, 2024
65ca4d7
Merge pull request #24 from gustavwilliam/feature-update_database
gustavwilliam Jul 27, 2024
cd83e29
Persist player map position
gustavwilliam Jul 27, 2024
4ff1e79
Merge pull request #34 from gustavwilliam/feature-persist_user_position
gustavwilliam Jul 27, 2024
8797a8d
Show player version of map with correct levels unlocked
gustavwilliam Jul 27, 2024
79304d3
Merge pull request #35 from gustavwilliam/feature-unlocked_levels
gustavwilliam Jul 27, 2024
61b4898
Modified README.md
jspmic Jul 27, 2024
b659ffa
Update dREADME.md
jspmic Jul 27, 2024
9c67f45
Updated README.md
jspmic Jul 27, 2024
a3f60c6
Modified README.md
jspmic Jul 27, 2024
f5cdc4c
Added level A question
jspmic Jul 27, 2024
b4d80b4
Add write gode golf question type
gustavwilliam Jul 28, 2024
bdfe7d0
Merge pull request #37 from gustavwilliam/feature-new_levels
gustavwilliam Jul 28, 2024
43d67ac
Remove valueerror when loading levels multiple times
gustavwilliam Jul 28, 2024
756d474
Merge pull request #38 from gustavwilliam/fix-startup_value_error
gustavwilliam Jul 28, 2024
c19ea61
Complete level unlocking for special levels
gustavwilliam Jul 28, 2024
9eedcd6
Merge pull request #39 from gustavwilliam/fix-db_levels
gustavwilliam Jul 28, 2024
4d7b1c7
Add additional success screens about special levels
gustavwilliam Jul 28, 2024
d4e049a
Merge pull request #40 from gustavwilliam/feature-unlocked_graphics
gustavwilliam Jul 28, 2024
515d192
Corrected bugs in player model and database.py file
Noble-47 Jul 28, 2024
82dfb36
Make only user whose map it is able to press buttons
gustavwilliam Jul 28, 2024
516196f
Merge pull request #42 from gustavwilliam/feature-only_user_interactions
gustavwilliam Jul 28, 2024
89f5e42
Merge pull request #41 from gustavwilliam/fix-player_model
gustavwilliam Jul 28, 2024
b4dc4a3
Clean up unused commands / testing commands
gustavwilliam Jul 28, 2024
8d02c36
Merge pull request #43 from gustavwilliam/cleanup
gustavwilliam Jul 28, 2024
c406721
Improve code playground messages
gustavwilliam Jul 28, 2024
5eb2e4b
Added special golfing levels
jspmic Jul 28, 2024
1250418
Merge pull request #45 from gustavwilliam/feature-playground_variable…
gustavwilliam Jul 28, 2024
1094eae
Inserted requested changes
jspmic Jul 28, 2024
8190110
Add notice about lives on level 1
gustavwilliam Jul 28, 2024
6d7f8d4
Merge pull request #47 from gustavwilliam/feature-new_levels
gustavwilliam Jul 28, 2024
b38dab9
Merge pull request #48 from gustavwilliam/fix-level_error_msg
gustavwilliam Jul 28, 2024
3ef273a
Fix critical level bug
gustavwilliam Jul 28, 2024
9298681
Remove extra command
gustavwilliam Jul 28, 2024
50e98a3
Modified introduction
jspmic Jul 31, 2024
8d669d5
Removed conclusion
jspmic Jul 31, 2024
967c92d
Modified venv activation code
jspmic Jul 31, 2024
e1fd747
Modified requirements installation
jspmic Jul 31, 2024
357d851
Deleted README.md.old
jspmic Jul 31, 2024
53fa278
Fixed linting issue
jspmic Jul 31, 2024
666eb21
Fix requested changes
gustavwilliam Aug 1, 2024
6ace6fd
Merge pull request #36 from gustavwilliam/modify-readme
gustavwilliam Aug 1, 2024
1b92379
Modified cloning link
jspmic Aug 1, 2024
39dcfc6
Merge pull request #51 from gustavwilliam/modify-readme
gustavwilliam Aug 1, 2024
8b5905a
Add intro video to README.md
gustavwilliam Aug 1, 2024
53d2bf6
Add gameplay to readme
gustavwilliam Aug 1, 2024
4bbc074
Add final section of gameplay in readme
gustavwilliam Aug 1, 2024
d01c8cc
Add contributions to readme
gustavwilliam Aug 1, 2024
d00be16
Add software architecture to readme
gustavwilliam Aug 1, 2024
844c9b9
Add breathing room to readme images
gustavwilliam Aug 1, 2024
650b840
Add table of contents to readme
gustavwilliam Aug 1, 2024
743825d
Add 'mesmerizing-lightyears/' from commit '650b840ac3c8bec29a03d99ff3…
janine9vn Aug 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions mesmerizing-lightyears/.github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# GitHub Action workflow enforcing our code style.

name: Lint

# Trigger the workflow on both push (to the main repository, on the main branch)
# and pull requests (against the main repository, but from any repo, from any branch).
on:
push:
branches:
- main
pull_request:

# Brand new concurrency setting! This ensures that not more than one run can be triggered for the same commit.
# It is useful for pull requests coming from the main repository since both triggers will match.
concurrency: lint-${{ github.sha }}

jobs:
lint:
runs-on: ubuntu-latest

env:
# The Python version your project uses. Feel free to change this if required.
PYTHON_VERSION: "3.12"

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Run pre-commit hooks
uses: pre-commit/action@v3.0.1
33 changes: 33 additions & 0 deletions mesmerizing-lightyears/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Files generated by the interpreter
__pycache__/
*.py[cod]

# Environment specific
.venv
venv
.env
env

# Unittest reports
.coverage*

# Logs
*.log

# PyEnv version selector
.python-version

# Built objects
*.so
dist/
build/

# IDEs
# PyCharm
.idea/
# VSCode
.vscode/
# MacOS
.DS_Store
# vim
*.swp
18 changes: 18 additions & 0 deletions mesmerizing-lightyears/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Pre-commit configuration.
# See https://github.com/python-discord/code-jam-template/tree/main#pre-commit-run-linting-before-committing

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
hooks:
- id: ruff-format
- id: ruff
7 changes: 7 additions & 0 deletions mesmerizing-lightyears/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2024 Gustav Odinger, Berkin İlkan Seçkin, Jaspe Michael Ingabire, Mouelle Ewane Richard C., Ifeanyichukwu Goodness

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
220 changes: 220 additions & 0 deletions mesmerizing-lightyears/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
# Python Adventures

https://github.com/user-attachments/assets/8f392225-6d21-464f-9e55-bc74ca643df3

*🔈Volume on*

Python Adventures is a Discord game bot where you learn about Python features while progressing your character through a map filled with challenges and secrets!

## Table of contents
- [Python Adventures](#python-adventures)
- [Table of contents](#table-of-contents)
- [Theme: Information Overload](#theme-information-overload)
- [Gameplay](#gameplay)
- [Map](#map)
- [Navigation](#navigation)
- [Levels](#levels)
- [Limited lives](#limited-lives)
- [Code evaluation](#code-evaluation)
- [Hints](#hints)
- [Success/defeat/win screens](#successdefeatwin-screens)
- [Software architecture](#software-architecture)
- [Level/questions](#levelquestions)
- [Adding a new level](#adding-a-new-level)
- [Adding a new question type](#adding-a-new-question-type)
- [Modifying default behavior](#modifying-default-behavior)
- [Setup instructions](#setup-instructions)
- [Discord API Token](#discord-api-token)
- [How to Obtain a Discord API Token](#how-to-obtain-a-discord-api-token)
- [Discord Developer Portal Settings](#discord-developer-portal-settings)
- [Installation and Setup](#installation-and-setup)
- [Contributions](#contributions)


## Theme: Information Overload
Python Adventures immerses players in a learning environment filled with information-rich levels. Each level combines multiple-choice questions and intricate coding challenges, demanding players process and apply vast amounts of information quickly and accurately. The special code golfing levels take this to the next level by requiring players to deal with dense, compact code — all while keeping it light and playful.

# Gameplay

Follow the main character Maria as she sets out on an epic journey to becoming a true Pythonista! The main storyline of the game consists of 11 levels, where completing one unlocks the next.

## Map

![Map](presentation/levels.png)

The levels 1-11 consist of both multiple-choice questions and code writing challenges, to make learning exciting and really challenge your unstanding of the topics at hand.

There are also three *special* levels A, B and C, outside of the main storyline, which tackle code golfing. If your brain doesn't get overloaded from the compact information in oneliners and hacky ways of writing code, these levels perfect for you!

### Navigation
![Map navigation](/presentation/map-navigation.png)

To move between levels in Python Adventures, we have created a vibrant map that can be easily navigated using Discord's interaction buttons. The map is dynamically generated for the user, taking into account factors such as the following:
- **Unlocked levels**, including special levels
- **Completed levels**
- **Current player position**, persisted between sessions
- **Player display name**, for the name tag

In order to not clutter up the chat, navigation simply edits the original interaction response embed with the new map state. Buttons are also dynamically enabled/disabled based on whether or not an action can be taken. For example, if a tree is in the way, moving that direction will be disabled.

## Levels
### Limited lives
![Lives](bot/assets/guide-hearts.png)

With three lives comes a maximum of three mistakes before you have to restart the level. This keeps the game exciting and turns the difficulty of even the multiple choice questions up a notch.

### Code evaluation
The most important part of learning to code is writing code and actually trying things yourself. Because of this, we have made code writing an integral part of the levels, providing a Code Playground to test run your code before submitting. And once submitted, we run a battery of unit tests on the code to ensure it passes the requirements.

By utilizing the [Tio.run](https://tio.run) API to evaluate code, we are able to evaluate and test user code without needing to set up a sandboxed environment and without risking malicious input causing issues for the machine running the bot.

### Hints
Sometimes you get stuck on a problem. While revealing the answer straight away won't help you much in learning, getting a hint or two in the right direction can be a game changer. We have provided hints for all questions that can be accessed one at a time by pressing the **Hint** button:

![Hints](presentation/hints.png)

### Success/defeat/win screens
![Status screens](presentation/level-statuses.png)

With vibrant success/fail messages depending on how a level went for the player, we hope to keep the player engaged and excited to move toward the next goal. The images above are some of these and are displayed in the following situations:
- **Level failed**: the user fails a level
- **Level success**: the user completes a level
- **New level unlocked**: displayed after "level success" when the B or C level is unlocked
- **You win**: displayed when completing the final level of the game (level C) together with a message from the developers :)

# Software architecture

In order to create a game that is easy to maintain and simple to add new features to without breaking existing ones, we have put a lot of effort into designing a software architecture for the game that will allow precisely that.

## Level/questions

Here is a diagram that explains the general level-question software architecture:

![CJ architecture](presentation/CJ_architecture.png)

### Adding a new level

This is how a new level is added:
- Subclass `Level` and set the desired attributes
- Adding `Level.register()` in the `register_all_levels()` function
- Add the level's questions in `questions.json`

The new level is now accessible and ready to be used anywhere in the bot through the `Controller` class! The map description, buttons and functionality at the provided coordinte will automatically match what was provided in the `Level` class. Better yet, all questions in `questions.json` will be automatically parsed, loaded, and ready to be used.

### Adding a new question type

At one point while developing the game, we decided to add a code golf class. In a few minutes, the class was ready to go! By subclassing `WriteCodeQuestion` (which itself is a subclass of `Question`), the code golf question type got all the code execution, unit test and normal "question" logic from the `WriteCodeQuestion` and `Question` classes.

This is how a new question type is added:
- Subclass `Question` and set the desired attributes
- *Optional*: overwrite functions for question parsing, running, on_success, on_fail and other methods
- Add the question type to `Question.view`
- Add the question type to `question_factory`

Your question type is now fully supported by the bot and questions of the type can be added to `questions.json`!

### Modifying default behavior

One major feature of the software architecture at hand, is the ability to extend and overwrite default functionality in question types and levels without touching the base classes. Here are a few of the supported overwrites:

**Question**
- `check_response`: logic to check if a given answer is correct
- `get_embed_description` and `embed`: customize the embed send for the question

**QuestionView**
- `on_quit`: called when the user presses "Quit"
- `on_success`: called when the user succeeds with a question
- `on_fail`: called when the user answers a question incorrectly

**Level**
- `run`: asks the user questions, displays status screen when level is over and then returns the user to the map
- `on_failure`: called when the user fails a level
- `on_success`: called when the user completes a level
- `_success_page` and `_success_more_pages`: used to customize the embeds being sent when the user completes the level, for presenting newly unlocked levels or win screens

These customization options have been crucial for the following and more: showing a quickguide about lives before the first level, unlocking special levels at the right times and customizing the success screens of levels to showcase the current status. In the future, these features would also be great for integrating more story into the game or giving the player certain rewards for completing levels, questions or other tasks.

# Setup instructions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some of this information was duplicated in the discord_guide.md

## Discord API Token
What is a Discord API Token?
A Discord API Token is a unique identifier used to authenticate requests to the Discord API. It acts as a password for your bot, allowing it to interact with Discord's servers, join channels, send messages, and perform other actions as defined by the Discord API.

## How to Obtain a Discord API Token
1. Create a New Application:
- Go to the [***Discord Developer Portal***](https://discord.com/developers/applications)
- Click on ***New Application***
- Give your application a name and click **Create**.

2. Create a Bot:
- Navigate to the ***Bot*** section in the sidebar.
- Click on "Add Bot" and confirm by clicking ***Yes, do it!***

3. Copy the Token:
- Under the "TOKEN" section, click "Copy" to copy your bot's token.
- Keep this token secure and never share it publicly. If your token is exposed, you should regenerate it immediately.

## Discord Developer Portal Settings

1. Log in to **[Discord Developer Portal](https://discord.com/developers/)**
2. Create your new project with the ``New Application`` button.
3. Activate the ``PRESENCE INTENT``, ``SERVER MEMBERS INTENT``, ``MESSAGE CONTENT INTENT`` in the ``Bot > Privileged Gateway Intents`` section.
4. After creating your project, make the necessary settings in the ``Settings > OAuth2`` tab.
- Select the ``bot`` option from the OAuth2 URL Generator section
- Below, select the permissions you wish for the bot to have in the server. We recommend `Administrator` for testing purposes
5. After clicking on the ``bot``, you can choose the permissions your bot will have from the window that opens.

**Recommended settings:**
````
Bot > General Permissions
- Manage Expressions
- Create Expressions
- View Channels
- View Server Insights

Bot > Text Permissions
- Send Messages
- Manage Messages
- Embed Links
- Attach Files
- Use External Emojis
- Use External Stickers
- Add Reactions
- Use Slash Commands
- Use Embeded activites
- Create Polls
````
- Depending on the options you set, you can add your bot to your server by opening the ``GENERATED URL`` in your browser, authenticating with discord, and adding it to a server of your choosing.
- Make sure you give your bot enough room to play.


## Installation and Setup
To get your Discord bot up and running, follow these steps:
1. **Clone the repository**: `git clone https://github.com/gustavwilliam/cj11-mesmerizing-meteors.git && cd cj11-mesmerizing-meteors`

2. **Install Requirements**:
> - You can create a virtual environment by `python -m venv .venv`
> - Activate it by `source .venv/bin/activate` then pursue the setup

Install the dependencies using `pip install -r requirements.txt`. If you are developing the bot and not just running it, also consider installing dev requirements: `pip install -r dev-requirements.txt`.

3. **Set Up Your Environment Variables**:
- Create a .env file in the root of your project and add your Discord API Token: `DISCORD_BOT_KEY="your-discord-token-here"`

4. **Update Emoji Config**:
- Under `bot/assets/icons` you will find all the required emojis for the bot
- Add all these emojis to a server that your bot will be invited to
- Copy the ID of every emoji (send the custom emoji in a Discord channel and add `\` before it to see the ID. It will look something like this: `<:arrowright:1265077270515552339>`
- Update the IDs of every emoji in `bot/config.py`

5. **Run the Bot**: `python bot/main.py`

# Contributions

This is a rough overview of what each team member has contributed:
- @gustavwilliam: graphics, map functionality and question+level classes
- @Noble-47: database functionality
- @jspmic: level questions, documentation and a (sadly not merged in time) help command
- @HeavenMercy: game intro video in this readme, linting and dotenv usage
- @Deja-Vu1: basic bot setup and discord developer portal instructions

Furthermore, each team member has contributed with valuable ideas and feedback throughout the development process.
1 change: 1 addition & 0 deletions mesmerizing-lightyears/bot/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Folder Containing the project itself
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this README doesn't seem to add much value nor can I think of something you could add here that wouldn't just go in the root README. Might be better to remove it.

1 change: 1 addition & 0 deletions mesmerizing-lightyears/bot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# bot __init__ file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: redundant comment

Binary file added mesmerizing-lightyears/bot/assets/game-win.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mesmerizing-lightyears/bot/assets/hearts_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mesmerizing-lightyears/bot/assets/hearts_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mesmerizing-lightyears/bot/assets/hearts_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mesmerizing-lightyears/bot/assets/hearts_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mesmerizing-lightyears/bot/assets/icons/arrow-up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mesmerizing-lightyears/bot/assets/icons/check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mesmerizing-lightyears/bot/assets/icons/cross.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mesmerizing-lightyears/bot/assets/icons/hint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mesmerizing-lightyears/bot/assets/icons/letter_b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mesmerizing-lightyears/bot/assets/icons/letter_d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mesmerizing-lightyears/bot/assets/icons/letter_e.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mesmerizing-lightyears/bot/assets/icons/letter_f.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mesmerizing-lightyears/bot/assets/name-box.png
Binary file added mesmerizing-lightyears/bot/assets/player.png
Binary file added mesmerizing-lightyears/bot/assets/title-art.png
Binary file added mesmerizing-lightyears/bot/assets/unlocked-b.png
Binary file added mesmerizing-lightyears/bot/assets/unlocked-c.png
19 changes: 19 additions & 0 deletions mesmerizing-lightyears/bot/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from enum import Enum


class Emoji(Enum):
"""Configuration for custom Emojis."""

CHECK = "<:check:1265079659448766506>"
ARROW_LEFT = "<:arrowleft:1265077268951339081>"
ARROW_RIGHT = "<:arrowright:1265077270515552339>"
ARROW_UP = "<:arrowup:1265077271970975874>"
ARROW_DOWN = "<:arrowdown:1265077267965673587>"
HINT = "<:hint:1265996402891292675>"
CROSS = "<:exit:1265999816023080991>"
LETTER_A = "<:letter_a:1265996405164474368>"
LETTER_B = "<:letter_b:1265996406028636232>"
LETTER_C = "<:letter_c:1265996407647768716>"
LETTER_D = "<:letter_d:1265996409040277595>"
LETTER_E = "<:letter_e:1265996410453622945>"
LETTER_F = "<:letter_f:1265996412601241663>"
51 changes: 51 additions & 0 deletions mesmerizing-lightyears/bot/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from typing import TYPE_CHECKING, ClassVar

if TYPE_CHECKING:
from levels import Level


class Controller:
"""Manage levels and run them when requested."""

_instance = None
levels: ClassVar[list[type["Level"]]] = []

def __new__(cls, *args, **kwargs) -> "Controller": # noqa: ANN002, ANN003
"""Create a singleton instance of the Controller.

This allows the Levels to sign up directly to the Controller. Since there will only be one
Controller instance in the program, the Levels can be sure that they are signing up to the
correct Controller, without needeing to pass it as an argument.
"""
if not isinstance(cls._instance, cls):
cls._instance = object.__new__(cls, *args, **kwargs)
return cls._instance

def add_level(self, level: type["Level"]) -> None:
"""Add a level to the controller.

Raises a ValueError if a level with the same id or map position already exists.
"""
if level.id in self.levels:
raise ValueError
if level.map_position in [level.map_position for level in self.levels]:
raise ValueError
self.levels.append(level)

def get_level(self, position: tuple[int, int]) -> type["Level"] | None:
"""Get the level at a given map position, or return None if no level exists."""
for level in self.levels:
if level.map_position == position:
return level
return None

def get_level_by_id(self, id: int) -> type["Level"] | None:
"""Get the level with the given id, or return None if no level exists."""
for level in self.levels:
if level.id == id:
return level
return None
Comment on lines +35 to +47
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can optimise one of these cases by storing the levels in a dictionary.


def is_level(self, position: tuple[int, int]) -> bool:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think has_level is a better name.

"""Check if a level exists at the given map position."""
return any(level.map_position == position for level in self.levels)
Binary file added mesmerizing-lightyears/bot/database/.store.db
Binary file not shown.
Empty file.
Loading