Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6aa6f0a
Initial commit
Snipy7374 Jul 15, 2024
c3d3d91
update README, LICENSE and pyproject
Snipy7374 Jul 15, 2024
dd2274e
update gitignore to ignore lock file
Snipy7374 Jul 15, 2024
d4eb5bd
lint and update gitignore
Snipy7374 Jul 15, 2024
10cbb1d
implement bot core structure
Snipy7374 Jul 19, 2024
0d173b2
add depencendcie
Snipy7374 Jul 19, 2024
553264b
lint and reformat
Snipy7374 Jul 19, 2024
12e6d3a
typing tweaks
Snipy7374 Jul 19, 2024
fd61256
Add example .env file (#3)
Mmesek Jul 20, 2024
457f666
Change or switch to getenv's default (#2)
Mmesek Jul 20, 2024
81c9a0b
Add Ad embed (part 1)
EarthKiii Jul 20, 2024
c1d39ce
Add Ad embed (part 2) (test)
EarthKiii Jul 20, 2024
5178637
update authors and disable poetry package mode
Snipy7374 Jul 20, 2024
cf1343e
Add docker setup & instructions (#1)
Mmesek Jul 20, 2024
3725033
Repository Cleanup (#7)
Mmesek Jul 21, 2024
f35d8fe
load exts at startup
Snipy7374 Jul 21, 2024
e1a8c37
Merge pull request #8 from Snipy7374/beta
Snipy7374 Jul 21, 2024
1667195
Use a json of ads instead of random Wikipedia articles
EarthKiii Jul 23, 2024
47c243c
Merge branch 'main' into main
EarthKiii Jul 23, 2024
212eb53
Revert "Merge branch 'main' into main"
EarthKiii Jul 23, 2024
9976632
new: database (#9)
Astroyo Jul 27, 2024
1583117
feat: shoot minigame (#13)
Snipy7374 Jul 28, 2024
fc0ef9b
feat: implement an about command (#12)
Snipy7374 Jul 28, 2024
04f9626
fix shoot command ping in about command
Snipy7374 Jul 28, 2024
4dcf0f4
fix shoot stats incorrect behaviour
Snipy7374 Jul 28, 2024
ece06a0
Add documentation about the application
EarthKiii Jul 31, 2024
a2fd464
Fix images paths
EarthKiii Jul 31, 2024
d976fa1
Add contribution section to the readme
EarthKiii Jul 31, 2024
3d05051
Add missing details for the contribution
EarthKiii Jul 31, 2024
e3cc010
add info about critic bug
Snipy7374 Jul 31, 2024
899fee8
add explanation for shoot game
Snipy7374 Jul 31, 2024
1ade90c
remove wrong section title
Snipy7374 Jul 31, 2024
7959a82
fix installation steps info
Snipy7374 Jul 31, 2024
18bd85e
Merge pull request #14 from Snipy7374/documentation
EarthKiii Jul 31, 2024
10aae7d
Add 'unique-universes/' from commit '18bd85ec64bd29fa29b123667fe0ca5b…
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 unique-universes/.docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM python:3.12-slim AS base

ENV PYTHONUNBUFFERED=1 \
DEBIAN_FRONTEND=noninteractive \
PATH=/app/.venv/bin:$PATH

RUN set -ex \
&& addgroup --gid 50000 python \
&& adduser --shell /bin/false --disabled-password --uid 50000 --gid 50000 --home /python python \
&& apt-get update \
&& apt-get upgrade -y \
&& apt-get clean \
&& apt-get autoremove \
&& rm -rf /var/lib/apt/lists/*

USER python
WORKDIR /app

FROM base AS build

# Install project dependencies
RUN python -m pip install --no-cache --disable-pip-version-check --user poetry
ENV POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_VIRTUALENVS_CREATE=true

COPY pyproject.toml poetry.lock ./
RUN /python/.local/bin/poetry install --no-root --no-dev --sync --no-ansi --no-interaction

FROM base AS runtime
COPY --from=build /app/.venv /app/.venv

# Copy the source code in last to optimize rebuilding the image
COPY --chown=python:python . .

ENTRYPOINT ["python", "-m", "src"]
36 changes: 36 additions & 0 deletions unique-universes/.github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build Docker Image

on:
workflow_call:
workflow_dispatch:

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/Snipy7374/code-jam-24-universes
tags: type=ref,event=branch
- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- name: Build container
uses: docker/build-push-action@v4
with:
context: .
file: .docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
35 changes: 35 additions & 0 deletions unique-universes/.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
35 changes: 35 additions & 0 deletions unique-universes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Files generated by the interpreter
__pycache__/
*.py[cod]

# Environment specific
.venv
venv
.env
env
.history

# Unittest reports
.coverage*

# Logs
*.log

# PyEnv version selector
.python-version

# Built objects
*.so
dist/
build/

# IDEs
# PyCharm
.idea/
# VSCode
.vscode/
# MacOS
.DS_Store

# lock file
poetry.lock
18 changes: 18 additions & 0 deletions unique-universes/.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
- id: ruff-format
7 changes: 7 additions & 0 deletions unique-universes/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2021 Unique Universes

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.
170 changes: 170 additions & 0 deletions unique-universes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# Unique Universes CJ24's Application

Our application is a shooting minigame, based on precise and calculated shots from your ship to the enemy ship.

## How is the theme represented ?

The minigame relies on the user’s ability to calculate a shot with the help of (a lot of) raw information provided to the user.
This is the interesting part, the user has to face an information overflow and extract the important data in order to play the game.

## Availables commands

- /shoot - Play the minigame.

![The game](./readme_assets/minigame.png)

The rules are simple. You are given an amount of ammunitions with which you can hit an enemy. The enemy position is proportional to your position, instead the health is capped at a given value and will decrease when you hit the enemy.
After every shot the enemy will change position, though if you have hitted the enemy you will have 1 ammunition given back and some HP regenerated.
If you miss the enemy nothing happens, you just lost one ammunition and the enemy change position.

- /about - Get information about the application and the team.

![About](./readme_assets/about.png)

# Team members contribution

- **@Snipy7374 (Team Leader)**: Worked on the bot's structure, the game design, the game logic (physics/maths & database communication) and the documentation.
- **@Mmesek**: Worked on the game design, the docker image, the game logic (physics/maths), the UI and the documentation.
- **@stroh13**: Worked on the about command and the game logic (physics/maths).
- **@Astroyo**: Worked on the game logic (database communication).
- **@EarthKiii**: Worked on the game design and the documentation.

# Major Bugs notice

So far everything was too good to be true. Indeed our project have one CRITIC bug (at least known at this time). This bug involve the `/shoot` command. I will provide an hotfix below, pls judges forgive us for this :pray:

```diff
diff --git a/src/exts/minigames.py b/src/exts/minigames.py
index 23709c1..a183fcf 100644
--- a/src/exts/minigames.py
+++ b/src/exts/minigames.py
@@ -6,6 +6,7 @@ from typing import TYPE_CHECKING
import disnake
from disnake.ext import commands
from src.views.shoot import ShootMenu
+from src.database import PlayerNotFoundError

if TYPE_CHECKING:
from src.bot import Universe
@@ -49,7 +50,10 @@ class Minigames(commands.Cog):
@commands.slash_command() # type: ignore[reportUnknownMemberType]
async def shoot(self, inter: disnake.GuildCommandInteraction) -> None:
"""Run an info overloaded shoot minigame."""
- player = await self.bot.database.fetch_player(inter.author.id)
+ try:
+ player = await self.bot.database.fetch_player(inter.author.id)
+ except PlayerNotFoundError:
+ player = await self.bot.database.create_player(inter.author.id)
view = ShootMenu(inter.author, player)
generate_random_stats(view.stats)
embed = disnake.Embed(title="Shoot minigame", description="\n".join(["." * 10] * 5))
```

If you aren't a nerd (like me) and don't know what all that weird things at the top means i got you, you need to copy the green highlited changes and paste them at `src/exts/minigames.py` line 52 (replace the line, paste it on that line), don't forget the import too. With this the major bug should be solved. (I should have listened to Zig words about commits in the last day, sensei forgive me pls)

If the code snippet above is weird looking blame GitHub, to avoid any (and i mean ANY) unfortunate event i have also added a [`diff.txt`](./diff.txt) (yeah click it) file at the root of the project. You can inspect it if necessary, the content is the same as the one provided above.


This repository is the entry of the unique universes team for the Python Discord Code Jam 2024.

You can run the bot either with Docker or manually.

# Running the bot with Docker
## Building

```sh
docker build -t unique-universes -f .docker/Dockerfile .
```

## Running
```sh
docker run --rm -it -e BOT_TOKEN=YOUR_TOKEN_HERE unique-universes
```

# Running the bot manually
## Installing the dependencies

To install all the required dependencies to run the bot execute these commands:

```shell
pip install poetry
poetry install
```

## Creating the .env file

To be able to execute the bot locally you will need to create and grab the token of a discord bot. To create a bot head to the [discord developer portal]("https://discord.com/developers/applications/") and follow these [instructions to create a bot and copy its token]("https://discordpy.readthedocs.io/en/stable/discord.html").

After having copied the token you need to create a file called `.env` at the root of the project. Then type `BOT_TOKEN=` and paste the actual bot token after the equal sign. The file should look like this:

```ini
BOT_TOKEN=ExampleOfBotTokenHere
```

## Run project

```sh
python -m src
```

# For the developers

# Setting Up the Dev Env

If you are a team member make sure to read this section, otherwise you can skip this.

> [!NOTE]
> The steps listed here needs to be done only the first time when setting up the project locally.

## Required Python version

This project requires python 3.12 to work. If you don't have it installed proceed to install it from the official python website.

## Creating and activating a venv (virtual environment)

The most preferable way to work on a project is to create a virtual envirnoment where to install the dependencies. This is extremely useful to avoid conflicts between different projects that install dependencies globally.

To create a virtual environment run the following command in your terminal:

```shell
python3 -m venv .venv
```

> [!NOTE]
> If you are on windows and have different python versions installed without a python version manager, you can run the following command to use python 3.12
> `py -3.12 -m venv .venv`

you can replace `.venv` in the commands with a path (e.g `example_folder/.venv`) if needed. If you provide only `.venv` python will create the environment in the same directory where you are running the command.

After having created the venv (virtual environment) you need to activate it.
To enable the venv run the following commands depending on your platform:

```shell
# Linux, Bash
$ source .venv/bin/activate
# Linux, Fish
$ source .venv/bin/activate.fish
# Linux, Csh
$ source .venv/bin/activate.csh
# Linux, PowerShell Core
$ .venv/bin/Activate.ps1
# Windows, cmd.exe
> .venv\Scripts\activate.bat
# Windows, PowerShell
> .venv\Scripts\Activate.ps1
```

To deactivate the venv type `deactivate` in the terminal.

## Pre-commit

Before commiting, make sure to run any pre-commit checks.
Install pre-commit if you haven't done yet:

```sh
pre-commit install
```

## Final words

Now you're ready to go, your local copy of the repository is ready to be ran.
24 changes: 24 additions & 0 deletions unique-universes/diff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/src/exts/minigames.py b/src/exts/minigames.py
index 23709c1..a183fcf 100644
--- a/src/exts/minigames.py
+++ b/src/exts/minigames.py
@@ -6,6 +6,7 @@ from typing import TYPE_CHECKING
import disnake
from disnake.ext import commands
from src.views.shoot import ShootMenu
+from src.database import PlayerNotFoundError

if TYPE_CHECKING:
from src.bot import Universe
@@ -49,7 +50,10 @@ class Minigames(commands.Cog):
@commands.slash_command() # type: ignore[reportUnknownMemberType]
async def shoot(self, inter: disnake.GuildCommandInteraction) -> None:
"""Run an info overloaded shoot minigame."""
- player = await self.bot.database.fetch_player(inter.author.id)
+ try:
+ player = await self.bot.database.fetch_player(inter.author.id)
+ except PlayerNotFoundError:
+ player = await self.bot.database.create_player(inter.author.id)
view = ShootMenu(inter.author, player)
generate_random_stats(view.stats)
embed = disnake.Embed(title="Shoot minigame", description="\n".join(["." * 10] * 5))
1 change: 1 addition & 0 deletions unique-universes/example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BOT_TOKEN=bot_token_here
Loading