Now it's possible change school time table (testing)
This commit is contained in:
parent
f58b8a06c6
commit
54175f01cd
|
@ -2,9 +2,12 @@ from dotenv import load_dotenv
|
||||||
from bson.objectid import ObjectId
|
from bson.objectid import ObjectId
|
||||||
|
|
||||||
from discord.ext import tasks, commands
|
from discord.ext import tasks, commands
|
||||||
|
from discord.commands.context import ApplicationContext
|
||||||
|
from discord.commands import Option
|
||||||
import discord
|
import discord
|
||||||
import pymongo
|
import pymongo
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
|
||||||
load_dotenv() # Load .env file
|
load_dotenv() # Load .env file
|
||||||
|
@ -17,6 +20,15 @@ database = client["website-class"] # Database name
|
||||||
# Collection school time table current
|
# Collection school time table current
|
||||||
collection = database["school-time-table"]
|
collection = database["school-time-table"]
|
||||||
|
|
||||||
|
#Date
|
||||||
|
current_time = datetime.datetime.now()
|
||||||
|
day = str(current_time.day)
|
||||||
|
month = str(current_time.month)
|
||||||
|
year = str(current_time.year)
|
||||||
|
hour = str(current_time.hour)
|
||||||
|
minute = str(current_time.minute)
|
||||||
|
long_date = day + "-" + month + "-" + year + " " + hour + ":" + minute
|
||||||
|
|
||||||
bot = discord.Bot()
|
bot = discord.Bot()
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
|
@ -38,8 +50,28 @@ async def orario():
|
||||||
channel = bot.get_channel(1063753802638954519)
|
channel = bot.get_channel(1063753802638954519)
|
||||||
await channel.send(f"Day: {day}, Hour school: {i}, Subject found: {subject['Subject']} at index: {i}")
|
await channel.send(f"Day: {day}, Hour school: {i}, Subject found: {subject['Subject']} at index: {i}")
|
||||||
|
|
||||||
@bot.slash_command(name="first_slash", guild_ids=['1063753799874912337']) #Add the guild ids in which the slash command will appear. If it should be in all, remove the argument, but note that it will take some time (up to an hour) to register the command if it's for all guilds.
|
@bot.slash_command(name='change_school_time', description='Change school time')
|
||||||
async def first_slash(ctx):
|
async def change_school_time(
|
||||||
await ctx.respond("You executed the slash command!")
|
ctx : ApplicationContext,
|
||||||
|
day: Option(str,
|
||||||
|
"Select a day",
|
||||||
|
choices=["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
||||||
|
required=True,
|
||||||
|
),
|
||||||
|
hour_school: Option(str,
|
||||||
|
"Select hour school",
|
||||||
|
choices=["1", "2", "3", "4", "5", "6"],
|
||||||
|
required=True,
|
||||||
|
), text: str
|
||||||
|
):
|
||||||
|
|
||||||
|
await ctx.respond(f"Day selected: {day}, Hour school selected: {hour_school}, Text: {text}")
|
||||||
|
# Update the subject on MongoDB
|
||||||
|
find_document = list(collection.find({}, {"Date": long_date}))
|
||||||
|
array_document = find_document[0]["_id"]
|
||||||
|
collection.update_one(
|
||||||
|
{"_id": ObjectId(array_document)},
|
||||||
|
{"$set": {f"School Subject.{day}.{int(hour_school)}.Subject": text}}
|
||||||
|
)
|
||||||
|
|
||||||
bot.run(DISCORD_TOKEN)
|
bot.run(DISCORD_TOKEN)
|
Loading…
Reference in New Issue