Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏗️ Using normalized package architecture #21

Merged
merged 19 commits into from
Jul 9, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
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.

44 changes: 18 additions & 26 deletions README.md → docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,45 @@ 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.

```json5
Copy link
Owner

Choose a reason for hiding this comment

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

Why deleting this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I put a config.json.example file people can directly copy and rename. Since the content is within the example file, it isn't much useful in the readme, i believe

Plus having a example file within the vars folder should avoid people to try creating a config.json at another locater, i hope

Copy link
Owner

Choose a reason for hiding this comment

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

Yep it will be easier for some, but harder for a majority. People using this bot are in majority beginners, so we need to make this accessible. I'm just gonna adding it back, and we'll have both available

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure

{
"token": "( ͡° ͜ʖ ͡°)",
"prefix": "!",
"channelID": "000000000000000000",
"username": "demonstration",
"password": "pronotevs",
"url": "https://demo.index-education.net/pronote/eleve.html?login=true"
}
```
THESE ARE JUST EXAMPLES
copy that file as **config.json** and fill in the values as follows:

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>
- `"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()
32 changes: 19 additions & 13 deletions app/bot.py → drawbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
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 .json_types import JsonData
from .utils import json_wr


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 +21,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 +40,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
Empty file added drawbot/cogs/__init__.py
Empty file.
36 changes: 18 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,42 @@

from discord.ext.commands import Context

from app import JsonDict
from ..json_types import JsonDict
from ..utils import json_wr

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 +48,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