diff --git a/.gitignore b/.gitignore index 9acd3a1..a20dcb2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .env -launch.sh \ No newline at end of file +launch.sh +src/bot/__pycache__ +src/commands/__pycache__ \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index dd7bf60..377acc3 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,9 +2,9 @@ "version": "2.0.0", "tasks": [ { - "label": "Run Project", + "label": "Start Bot", "type": "shell", - "command": "launch.sh", + "command": "./launch.sh", "problemMatcher": [], "group": { "kind": "build", diff --git a/src/bot/__init__.py b/src/bot/__init__.py new file mode 100644 index 0000000..3c32b91 --- /dev/null +++ b/src/bot/__init__.py @@ -0,0 +1,7 @@ +""" +Bot package - Discord bot manager +""" + +__all__ = ["setup_bot", "start_bot"] + +from .bot import * diff --git a/src/bot/bot.py b/src/bot/bot.py new file mode 100644 index 0000000..9b1b4af --- /dev/null +++ b/src/bot/bot.py @@ -0,0 +1,34 @@ +import discord +from discord.ext import commands + +from dotenv import load_dotenv +from os import getenv + +from commands.discord_commands import * + +def setup_bot() -> commands.Bot: + print("Configuring bot...") + load_dotenv() + + bot = commands.Bot(command_prefix="/", intents=discord.Intents.all()) + + @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 !") + + setup_commands(bot) + + return bot + +def start_bot(bot: commands.Bot) -> None: + print("Starting bot...") + token = getenv("DISCORD_TOKEN") + if token: + bot.run(token) + else: + print("token error") diff --git a/src/commands/__init__.py b/src/commands/__init__.py new file mode 100644 index 0000000..0f8fbac --- /dev/null +++ b/src/commands/__init__.py @@ -0,0 +1,7 @@ +""" +Commands package - Discord commands manager +""" + +__all__ = ["setup_commands"] + +from .discord_commands import * diff --git a/src/commands/discord_commands.py b/src/commands/discord_commands.py new file mode 100644 index 0000000..1c76e76 --- /dev/null +++ b/src/commands/discord_commands.py @@ -0,0 +1,7 @@ +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/") diff --git a/src/main.py b/src/main.py index f0e9145..09b1d5d 100644 --- a/src/main.py +++ b/src/main.py @@ -1,52 +1,37 @@ -from dis import disco import discord -import os -from discord.ext import commands -from dotenv import load_dotenv +from bot import * -load_dotenv() - -print("Launching DeltaBot...") +bot = setup_bot() #bot = discord.Client(intents=discord.Intents.all()) -bot = commands.Bot(command_prefix="/", intents=discord.Intents.all()) #bot_channel = bot.get_channel(1424301304225857667) -@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 !") - @bot.event async def on_message(message: discord.Message): if message.author.bot: return - message_content = message.content.lower().__str__() + words = message.content.lower().split() channel = message.channel - if message_content.__contains__("bonjour"): + if "bonjour" in words: await channel.send("bien dormii ?? (˶ᵔᵕᵔ˶)₊˚⊹♡") - if message_content.__contains__("ui"): + if any(mot in words for mot in ["oui", "ui", "ouai", "ouaip", "yes", "yep"]) and not message.content.__contains__("?"): await channel.send("trow bienn~ (˶ᵔᵕᵔ˶) ‹𝟹") - if message_content.__contains__("<@1169377208893194275>"): + if "<@1169377208893194275>" in words: await channel.send("c'est mon mimi nathan qu'on tag ?? ⸜(。˃ ᵕ ˂)⸝♡") - await channel.send("UwU") -@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/") + if "c" in words: + await channel.send("le C c'est trow bienn~ (⸝⸝>ᴗ•⸝⸝)") -token = os.getenv("DISCORD_TOKEN") -if token: - bot.run(token) -else: - print("token error") + if "c++" in words: + await channel.send("le C++ c'est trow coool ╰(°ㅂ°)╯") + +def main(): + start_bot(bot) + +if __name__ == "__main__": + main() \ No newline at end of file