mirror of https://github.com/stijndcl/didier
Compare commits
No commits in common. "304ad850b7dfd6591efde25892be99a856bc41a1" and "37dd5ba3e868f166f909b910326664adb90d0d61" have entirely different histories.
304ad850b7
...
37dd5ba3e8
|
|
@ -1,103 +0,0 @@
|
||||||
name: Python CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
dependencies:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Setup Python
|
|
||||||
uses: actions/setup-python@v2
|
|
||||||
with:
|
|
||||||
python-version: '3.9.5'
|
|
||||||
- name: Cache dependencies
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: ~/.m2/repository
|
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-pip-
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pip3 install -r requirements.txt -r requirements-dev.txt
|
|
||||||
tests:
|
|
||||||
needs: [dependencies]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Setup Python
|
|
||||||
uses: actions/setup-python@v2
|
|
||||||
with:
|
|
||||||
python-version: '3.9.5'
|
|
||||||
- name: Cache dependencies
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: ~/.m2/repository
|
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-pip-
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pip3 install -r requirements.txt -r requirements-dev.txt
|
|
||||||
- name: Run Pytest
|
|
||||||
run: pytest tests
|
|
||||||
linting:
|
|
||||||
needs: [tests]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Setup Python
|
|
||||||
uses: actions/setup-python@v2
|
|
||||||
with:
|
|
||||||
python-version: '3.9.5'
|
|
||||||
- name: Cache dependencies
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: ~/.m2/repository
|
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-pip-
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pip3 install -r requirements.txt -r requirements-dev.txt
|
|
||||||
- name: Linting
|
|
||||||
run: pylint didier database
|
|
||||||
typing:
|
|
||||||
needs: [tests]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Setup Python
|
|
||||||
uses: actions/setup-python@v2
|
|
||||||
with:
|
|
||||||
python-version: '3.9.5'
|
|
||||||
- name: Cache dependencies
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: ~/.m2/repository
|
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-pip-
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pip3 install -r requirements.txt -r requirements-dev.txt
|
|
||||||
- name: Typing
|
|
||||||
run: mypy didier database
|
|
||||||
formatting:
|
|
||||||
needs: [tests]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Setup Python
|
|
||||||
uses: actions/setup-python@v2
|
|
||||||
with:
|
|
||||||
python-version: '3.9.5'
|
|
||||||
- name: Cache dependencies
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: ~/.m2/repository
|
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-pip-
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pip3 install -r requirements.txt -r requirements-dev.txt
|
|
||||||
- name: Formatting
|
|
||||||
run: black --check didier database
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
name: Run Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
python-tests:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.9.5'
|
||||||
|
- run: pip3 install -r requirements.txt
|
||||||
|
- run: pytest tests
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
from discord.ext import commands
|
|
||||||
|
|
||||||
from didier import Didier
|
|
||||||
|
|
||||||
|
|
||||||
class TestCog(commands.Cog):
|
|
||||||
client: Didier
|
|
||||||
|
|
||||||
def __init__(self, client: Didier):
|
|
||||||
self.client = client
|
|
||||||
|
|
||||||
|
|
||||||
async def setup(client: Didier):
|
|
||||||
await client.add_cog(TestCog(client))
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import os
|
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
@ -12,8 +10,6 @@ from didier.utils.prefix import get_prefix
|
||||||
class Didier(commands.Bot):
|
class Didier(commands.Bot):
|
||||||
"""DIDIER <3"""
|
"""DIDIER <3"""
|
||||||
|
|
||||||
initial_extensions: tuple[str] = ()
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
activity = discord.Activity(type=discord.ActivityType.playing, name=settings.DISCORD_STATUS_MESSAGE)
|
activity = discord.Activity(type=discord.ActivityType.playing, name=settings.DISCORD_STATUS_MESSAGE)
|
||||||
status = discord.Status.online
|
status = discord.Status.online
|
||||||
|
|
@ -31,31 +27,7 @@ class Didier(commands.Bot):
|
||||||
command_prefix=get_prefix, case_insensitive=True, intents=intents, activity=activity, status=status
|
command_prefix=get_prefix, case_insensitive=True, intents=intents, activity=activity, status=status
|
||||||
)
|
)
|
||||||
|
|
||||||
async def setup_hook(self) -> None:
|
|
||||||
"""Hook called once the bot is initialised"""
|
|
||||||
await self._load_initial_cogs()
|
|
||||||
await self._load_directory_cogs("didier/cogs")
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def db_session(self) -> AsyncSession:
|
def db_session(self) -> AsyncSession:
|
||||||
"""Obtain a database session"""
|
"""Obtain a database session"""
|
||||||
return DBSession()
|
return DBSession()
|
||||||
|
|
||||||
async def on_ready(self):
|
|
||||||
"""Event triggered when the bot is ready"""
|
|
||||||
print(settings.DISCORD_READY_MESSAGE)
|
|
||||||
|
|
||||||
async def _load_initial_cogs(self):
|
|
||||||
"""Load all cogs"""
|
|
||||||
for extension in self.initial_extensions:
|
|
||||||
await self.load_extension(f"didier.cogs.{extension}")
|
|
||||||
|
|
||||||
async def _load_directory_cogs(self, path: str):
|
|
||||||
"""Load all cogs in a given directory"""
|
|
||||||
load_path = path.removeprefix("./").replace("/", ".")
|
|
||||||
|
|
||||||
for file in os.listdir(path):
|
|
||||||
if file.endswith(".py") and not file.startswith("_") and not file.startswith(self.initial_extensions):
|
|
||||||
await self.load_extension(f"{load_path}.{file[:-3]}")
|
|
||||||
elif os.path.isdir(new_path := f"{path}/{file}"):
|
|
||||||
await self._load_directory_cogs(new_path)
|
|
||||||
|
|
|
||||||
2
main.py
2
main.py
|
|
@ -22,9 +22,9 @@ def setup_logging():
|
||||||
|
|
||||||
handler = RotatingFileHandler(settings.LOGFILE, mode="a", maxBytes=max_log_size, backupCount=5)
|
handler = RotatingFileHandler(settings.LOGFILE, mode="a", maxBytes=max_log_size, backupCount=5)
|
||||||
handler.setFormatter(logging.Formatter("[%(asctime)s] [%(levelname)s]: %(message)s"))
|
handler.setFormatter(logging.Formatter("[%(asctime)s] [%(levelname)s]: %(message)s"))
|
||||||
|
handler.setLevel(logging.INFO)
|
||||||
|
|
||||||
didier_log.addHandler(handler)
|
didier_log.addHandler(handler)
|
||||||
didier_log.setLevel(logging.INFO)
|
|
||||||
|
|
||||||
logging.getLogger("discord").setLevel(logging.ERROR)
|
logging.getLogger("discord").setLevel(logging.ERROR)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
def test_dummy():
|
|
||||||
assert True
|
|
||||||
Loading…
Reference in New Issue