Skip to content

Commit

Permalink
Merge pull request #21 from Sigmanificient/pkg
Browse files Browse the repository at this point in the history
🏗️ Using normalized package architecture
  • Loading branch information
drawbu authored Jul 9, 2022
2 parents 2f1c032 + 7decaea commit dc08861
Show file tree
Hide file tree
Showing 22 changed files with 216 additions and 152 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
venv
.idea
app/pronote.json
app/config.json
app/devoirs.json
app/grades.json
drawbot/pronote.json

__pycache__
/desktop.ini

*.egg-info
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
VENV = venv
VBIN = $(VENV)/bin

all: start

clean:
rm -rf venv
rm -rf *.egg-info
rm -rf __pycache__
rm vars/*.json

$(VBIN)/python:
python -m venv venv
chmod +x venv/bin/activate
./venv/bin/activate
pip install -e .

vars/config.json:
cp vars/config.json.example vars/config.json

start: $(VBIN)/python vars/config.json
python drawbot

.PHONY: all clean start
2 changes: 0 additions & 2 deletions app/.gitignore

This file was deleted.

9 changes: 0 additions & 9 deletions app/__init__.py

This file was deleted.

5 changes: 0 additions & 5 deletions app/utils/__init__.py

This file was deleted.

36 changes: 20 additions & 16 deletions README.md → docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,34 @@ Help server: https://discord.gg/XGXydQyKhQ
| :warning: | We do not take responsibility for a possible leak of your passwords, which is why you need to host the bot yourself. |

## Installation

```sh
git clone https://github.com/drawbu/drawbot
cd drawbot

cd /path

pip install -r requirements.txt
pip install -e .
```

## Launch
```sh
py run.py
py drawbot
```

*If you are using a Linux distribution, you can use the `make` command to install dependencies and run the bot.*

## Files documentation

The bot will create **2** json files in the **app** folder:
The bot will create **2** json files in the **vars** folder:

- config.json
- devoirs.json
- grades.json

### app/ config.json
### vars/config.json

This file stocks your private logins and info's to make to bor running:
This file stocks your private logins and info's to make to bot running.
You can find a **config.example.json** file in the **vars** folder.

> `config.json` **Example**
```json5
{
"token": "( ͡° ͜ʖ ͡°)",
Expand All @@ -53,18 +56,19 @@ This file stocks your private logins and info's to make to bor running:
"url": "https://demo.index-education.net/pronote/eleve.html?login=true"
}
```
THESE ARE JUST EXAMPLES

In `"token"`, you need to add your bot token. <br>
In `"prefix"`, the prefix your bot will use. <br>
In `"channelID"`, the ID of the Discord channel. <br>
In `"username"`, your Pronote username. <br>
In `"password"`, your Pronote password. <br>
In `"url"`, the url of your pronote client. <br>
copy that file as **config.json** and fill in the values as follows:

- `"token"`: your bot token. <br>
- `"prefix"`: the prefix your bot will use. <br>
- `"channelID"`: the ID of the Discord channel. <br>
- `"username"`: your Pronote username. <br>
- `"password"`: your Pronote password. <br>
- `"url"`: the url of your pronote client. <br>

If you can't connect to Pronote, check if your establishment is not using an
ENT. In this case, see what you need to do with the help of the pronote wrapper
project: [pronotepy](https://github.com/bain3/pronotepy)

### app/ devoirs.json
### vars/devoirs.json
Automatically generated JSON containing homeworks information.
8 changes: 8 additions & 0 deletions drawbot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""A Pronote notifier discord bot."""
from .bot import Bot

__version__: str = "2.0.0"
__author__: str = "Drawbu"
__maintainer__: str = "Sigmanificient"

__all__ = ("Bot",)
6 changes: 3 additions & 3 deletions run.py → drawbot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from app.bot import Bot
from drawbot import Bot


def main() -> None:
def main():
"""Entry point to run the bot client."""
bot = Bot()
bot.run()


if __name__ == '__main__':
if __name__ == "__main__":
main()
31 changes: 18 additions & 13 deletions app/bot.py → drawbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
import sys
from typing import Optional

from discord import LoginFailure
from discord.ext import commands

from app import JsonData
from app.utils import json_wr
from .utils import json_wr, JsonData


class Bot(commands.Bot):

def __init__(self) -> None:
def __init__(self):
"""Initialize the bot and load config for token and prefix."""
self.embed_color: int = 0x1E744F
self._token: Optional[str] = None
Expand All @@ -21,16 +20,16 @@ def __init__(self) -> None:
"channelID": "",
"username": "",
"password": "",
"url": ""
"url": "",
}

self.config: JsonData = json_wr("config")

for key in default_config.keys():
if self.config.get(key, "") == "":
print(
f"Veuillez indiquer remplir la valeur \"{key}\" "
"dans le fichier config.json"
f'Veuillez indiquer remplir la valeur "{key}" '
"dans le fichier vars/config.json"
)
sys.exit()

Expand All @@ -40,12 +39,18 @@ def __init__(self) -> None:

self.remove_command("help")

for filename in os.listdir("app/cogs"):
if filename.endswith(".py"):
self.load_extension(f"app.cogs.{filename[:-3]}")
for filename in os.listdir("drawbot/cogs"):
if filename.endswith(".py") and filename != "__init__.py":
self.load_extension(f"drawbot.cogs.{filename[:-3]}")

def run(self) -> None:
super().run(self._token)
def run(self):
try:
super().run(self._token)
except LoginFailure:
print(
"Echec de la connexion au client."
"Veuillez vérifier que votre token est correct."
)

async def on_ready(self) -> None:
async def on_ready(self):
print(f"Connecté en temps que {self.user.name} !")
1 change: 1 addition & 0 deletions drawbot/cogs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev.py
1 change: 1 addition & 0 deletions drawbot/cogs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Cogs sub-package for drawbot."""
35 changes: 17 additions & 18 deletions app/cogs/informations.py → drawbot/cogs/information.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,41 @@

from discord.ext.commands import Context

from app import JsonDict
from ..utils import json_wr, JsonDict

from app.utils import json_wr


class Informations(commands.Cog):

class Information(commands.Cog):
def __init__(self, client):
"""Initialize the different commands."""
self.client = client

@commands.command(
name='help', aliases=('h', 'aide'),
name="help",
aliases=("h", "aide"),
)
async def help_command(self, ctx: Context) -> None:
async def help_command(self, ctx: Context):
help_embed: Embed = discord.Embed(
title="Help of the Pronote",
description=(
"Un bot qui traque vos devoir pronote "
"et vous les notifient sur discord."
),
color=self.client.embed_color
color=self.client.embed_color,
).add_field(
name=f'{ctx.prefix}here',
value='change le salon d \'envoi des nouveaux devoirs'
name=f"{ctx.prefix}here",
value="change le salon d 'envoi des nouveaux devoirs",
)

await ctx.send(embed=help_embed)

@commands.command(
name='channel', aliases=('here',),
name="channel",
aliases=("here",),
)
async def change_channel(self, ctx: Context) -> None:
pronote_config: JsonDict = json_wr('pronote')
pronote_config['channelID'] = ctx.channel.id
json_wr('pronote', data=pronote_config)
async def change_channel(self, ctx: Context):
pronote_config: JsonDict = json_wr("pronote")
pronote_config["channelID"] = ctx.channel.id
json_wr("pronote", data=pronote_config)

await ctx.send(
embed=discord.Embed(
Expand All @@ -48,10 +47,10 @@ async def change_channel(self, ctx: Context) -> None:
"Le salon pour envoyer les nouveaux devoirs "
"à bien été mis à jour"
),
color=self.client.embed_color
color=self.client.embed_color,
)
)


def setup(client) -> None:
client.add_cog(Informations(client))
def setup(client):
client.add_cog(Information(client))
Loading

0 comments on commit dc08861

Please sign in to comment.