|
@@ -1,27 +1,64 @@
|
|
|
|
|
+### IMPORTS ###
|
|
|
|
|
+
|
|
|
|
|
+# Discord #
|
|
|
import discord
|
|
import discord
|
|
|
-from today import today, tomorrow
|
|
|
|
|
|
|
+from discord.ext import commands
|
|
|
|
|
+from discord import app_commands
|
|
|
|
|
+
|
|
|
|
|
+# For env variables #
|
|
|
|
|
+from os import environ
|
|
|
|
|
+from dotenv import load_dotenv
|
|
|
|
|
+
|
|
|
|
|
+# Other #
|
|
|
|
|
+from typing import Literal
|
|
|
|
|
+
|
|
|
|
|
+# Commands #
|
|
|
|
|
+from day_planning import today, tomorrow
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+### BOT CLASS ###
|
|
|
|
|
+
|
|
|
|
|
+class Bot(commands.Bot):
|
|
|
|
|
+ def __init__(self):
|
|
|
|
|
+ intents = discord.Intents.default()
|
|
|
|
|
+ intents.message_content = True
|
|
|
|
|
+ super().__init__(command_prefix = "?", intents = intents)
|
|
|
|
|
+
|
|
|
|
|
+ async def setup_hook(self):
|
|
|
|
|
+ await self.tree.sync(guild= discord.Object(id=guild))
|
|
|
|
|
+ print("Bot started")
|
|
|
|
|
+
|
|
|
|
|
+ async def on_command_error(self, ctx, error):
|
|
|
|
|
+ await ctx.reply(error, ephemeral = True)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+### VARIABLES ###
|
|
|
|
|
+
|
|
|
|
|
+load_dotenv()
|
|
|
|
|
+token = environ["TOKEN"]
|
|
|
|
|
+guild = environ["GUILD"]
|
|
|
|
|
+
|
|
|
|
|
+bot = Bot()
|
|
|
|
|
|
|
|
-# Creating a client instance
|
|
|
|
|
-intents = discord.Intents.default()
|
|
|
|
|
-intents.message_content = True
|
|
|
|
|
|
|
|
|
|
-client = discord.Client(intents=intents)
|
|
|
|
|
|
|
+### COMMANDS ###
|
|
|
|
|
|
|
|
-@client.event
|
|
|
|
|
-async def on_ready(): # Print a message when the bot turns on
|
|
|
|
|
- print(f'We have logged in as {client.user}')
|
|
|
|
|
|
|
+@bot.hybrid_command(name="day", with_app_command=True, description="Give your attends for one day")
|
|
|
|
|
+@app_commands.guilds(discord.Object(id=guild))
|
|
|
|
|
+@app_commands.describe(date="The day for which your attends will be displayed")
|
|
|
|
|
+async def day(ctx, date: Literal["today", "tomorrow"]):
|
|
|
|
|
|
|
|
-@client.event
|
|
|
|
|
-async def on_message(message):
|
|
|
|
|
- if message.author == client.user: # Check if the message was sens by the bot
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ if date == "today":
|
|
|
|
|
+ msg = today()
|
|
|
|
|
|
|
|
- if message.content.startswith("edt?"): # Check if the message starts with 'edt', which is the command we defined to view the timetable.
|
|
|
|
|
- await message.channel.send(today())
|
|
|
|
|
|
|
+ elif date == "tomorrow":
|
|
|
|
|
+ msg = tomorrow()
|
|
|
|
|
+
|
|
|
|
|
+ else:
|
|
|
|
|
+ msg = "This date doesn't exist"
|
|
|
|
|
|
|
|
- if message.content.startswith("demain?"):
|
|
|
|
|
- await message.channel.send(tomorrow())
|
|
|
|
|
|
|
+ await ctx.reply(msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
-client.run("YOUR_TOKEN_HERE")
|
|
|
|
|
|
|
+bot.run(token)
|
|
|
|
|
|