Finished factoring code, sarted todo lists manager and removed PyCharm compatibility
This commit is contained in:
parent
a2dd3e0e05
commit
a77ed2868a
|
@ -1,4 +1,3 @@
|
||||||
.env
|
.env
|
||||||
launch.sh
|
launch.sh
|
||||||
src/bot/__pycache__
|
src/**/__pycache__
|
||||||
src/commands/__pycache__
|
|
|
@ -1,3 +0,0 @@
|
||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
|
@ -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>
|
|
|
@ -1,6 +0,0 @@
|
||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<settings>
|
|
||||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
|
||||||
<version value="1.0" />
|
|
||||||
</settings>
|
|
||||||
</component>
|
|
|
@ -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>
|
|
|
@ -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>
|
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
|
@ -1,7 +1,3 @@
|
||||||
"""
|
"""
|
||||||
Bot package - Discord bot manager
|
Bot package - Discord bot manager
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__all__ = ["setup_bot", "start_bot"]
|
|
||||||
|
|
||||||
from .bot import *
|
|
||||||
|
|
|
@ -1,34 +1,40 @@
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
|
# Dotenv managing
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from os import getenv
|
from os import getenv
|
||||||
|
|
||||||
from commands.discord_commands import *
|
# Import managers
|
||||||
|
|
||||||
def setup_bot() -> commands.Bot:
|
# Bot main class
|
||||||
print("Configuring bot...")
|
class Bot:
|
||||||
load_dotenv()
|
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
|
load_dotenv()
|
||||||
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 !")
|
|
||||||
|
|
||||||
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:
|
def start_bot(self) -> None:
|
||||||
print("Starting bot...")
|
print("Starting bot...")
|
||||||
token = getenv("DISCORD_TOKEN")
|
token = getenv("DISCORD_TOKEN")
|
||||||
if token:
|
if token:
|
||||||
bot.run(token)
|
self.client.run(token)
|
||||||
else:
|
else:
|
||||||
print("token error")
|
print("token error")
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
"""
|
|
||||||
Commands package - Discord commands manager
|
|
||||||
"""
|
|
||||||
|
|
||||||
__all__ = ["setup_commands"]
|
|
||||||
|
|
||||||
from .discord_commands import *
|
|
|
@ -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/")
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
"""
|
||||||
|
Commands package - Discord commands_manager manager
|
||||||
|
"""
|
||||||
|
|
||||||
|
__all__ = ["setup_commands"]
|
||||||
|
|
||||||
|
from .commands_manager import *
|
|
@ -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)
|
13
src/main.py
13
src/main.py
|
@ -1,13 +1,10 @@
|
||||||
import discord
|
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.client.event
|
||||||
|
|
||||||
#bot_channel = bot.get_channel(1424301304225857667)
|
|
||||||
|
|
||||||
@bot.event
|
|
||||||
async def on_message(message: discord.Message):
|
async def on_message(message: discord.Message):
|
||||||
if message.author.bot:
|
if message.author.bot:
|
||||||
return
|
return
|
||||||
|
@ -31,7 +28,7 @@ async def on_message(message: discord.Message):
|
||||||
await channel.send("le C++ c'est trow coool ╰(°ㅂ°)╯")
|
await channel.send("le C++ c'est trow coool ╰(°ㅂ°)╯")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
start_bot(bot)
|
bot.start_bot()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
|
@ -0,0 +1,7 @@
|
||||||
|
"""
|
||||||
|
Todos manager package - Todos manager
|
||||||
|
"""
|
||||||
|
|
||||||
|
__all__ = ["TodosManager"]
|
||||||
|
|
||||||
|
from .todos_manager import *
|
|
@ -0,0 +1,7 @@
|
||||||
|
from bot.bot import Bot
|
||||||
|
|
||||||
|
# Manager controlled by
|
||||||
|
from todos_manager import *
|
||||||
|
|
||||||
|
def setup_todos_manager_commands(bot: Bot):
|
||||||
|
pass
|
|
@ -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
|
Loading…
Reference in New Issue