Finished factoring code, sarted todo lists manager and removed PyCharm compatibility

This commit is contained in:
Ulysse Cura 2025-10-07 22:19:35 +02:00
parent a2dd3e0e05
commit a77ed2868a
17 changed files with 77 additions and 87 deletions

3
.gitignore vendored
View File

@ -1,4 +1,3 @@
.env
launch.sh
src/bot/__pycache__
src/commands/__pycache__
src/**/__pycache__

3
.idea/.gitignore vendored
View File

@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.compteur_electrique_env" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 (CompteurElectrique)" project-jdk-type="Python SDK" />
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/CompteurElectrique.iml" filepath="$PROJECT_DIR$/.idea/CompteurElectrique.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -1,7 +1,3 @@
"""
Bot package - Discord bot manager
"""
__all__ = ["setup_bot", "start_bot"]
from .bot import *

View File

@ -1,34 +1,40 @@
import discord
from discord.ext import commands
# Dotenv managing
from dotenv import load_dotenv
from os import getenv
from commands.discord_commands import *
# Import managers
def setup_bot() -> commands.Bot:
print("Configuring bot...")
load_dotenv()
# Bot main class
class Bot:
def __init__(self):
self.client = commands.Bot(command_prefix="/", intents=discord.Intents.all())
from todos_manager import TodosManager
self.todos_manager = TodosManager()
bot = commands.Bot(command_prefix="/", intents=discord.Intents.all())
def setup_bot(self) -> None:
print("Configuring bot...")
@bot.event
async def on_ready():
try:
synced = await bot.tree.sync()
print(f"Successfully synced {len(synced)} commands")
except Exception as e:
print(e)
print("Bot ready !")
load_dotenv()
setup_commands(bot)
@self.client.event
async def on_ready() -> None:
try:
synced = await self.client.tree.sync()
print(f"Successfully synced {len(synced)} commands")
except Exception as e:
print(e)
print("Bot ready !")
return bot
from commands_manager import setup_commands
setup_commands(self)
def start_bot(bot: commands.Bot) -> None:
print("Starting bot...")
token = getenv("DISCORD_TOKEN")
if token:
bot.run(token)
else:
print("token error")
def start_bot(self) -> None:
print("Starting bot...")
token = getenv("DISCORD_TOKEN")
if token:
self.client.run(token)
else:
print("token error")

View File

@ -1,7 +0,0 @@
"""
Commands package - Discord commands manager
"""
__all__ = ["setup_commands"]
from .discord_commands import *

View File

@ -1,7 +0,0 @@
import discord
from discord.ext import commands
def setup_commands(bot: commands.Bot) -> None:
@bot.tree.command(name="trustme", description="Come on, shake your body baby.")
async def trustme(interaction: discord.Interaction):
await interaction.response.send_message("https://matias.ma/nsfw/")

View File

@ -0,0 +1,7 @@
"""
Commands package - Discord commands_manager manager
"""
__all__ = ["setup_commands"]
from .commands_manager import *

View File

@ -0,0 +1,12 @@
import discord
from bot.bot import Bot
# Import specifics commands
from todos_manager.todos_commands import *
def setup_commands(bot: Bot) -> None:
@bot.client.tree.command(name="trustme", description="Come on, shake your body baby.")
async def trustme(interaction: discord.Interaction):
await interaction.response.send_message("https://matias.ma/nsfw/")
setup_todos_manager_commands(bot)

View File

@ -1,13 +1,10 @@
import discord
from bot import *
from bot.bot import Bot
bot = setup_bot()
bot = Bot()
bot.setup_bot()
#bot = discord.Client(intents=discord.Intents.all())
#bot_channel = bot.get_channel(1424301304225857667)
@bot.event
@bot.client.event
async def on_message(message: discord.Message):
if message.author.bot:
return
@ -31,7 +28,7 @@ async def on_message(message: discord.Message):
await channel.send("le C++ c'est trow coool ╰(°ㅂ°)╯")
def main():
start_bot(bot)
bot.start_bot()
if __name__ == "__main__":
main()

View File

@ -0,0 +1,7 @@
"""
Todos manager package - Todos manager
"""
__all__ = ["TodosManager"]
from .todos_manager import *

View File

@ -0,0 +1,7 @@
from bot.bot import Bot
# Manager controlled by
from todos_manager import *
def setup_todos_manager_commands(bot: Bot):
pass

View File

@ -0,0 +1,10 @@
import os
class TodosManager:
def __init__(self, data_dir="compteur_electrique_data/todos/"):
try:
os.makedirs(data_dir, exist_ok=True)
except OSError as error:
print(f"Error during creation of \"{data_dir}\" directory")
exit(1)
self.data_dir=data_dir