mirror of
https://github.com/Paillat-dev/presentator.git
synced 2026-01-02 01:06:20 +00:00
Update main.py
This commit is contained in:
49
main.py
49
main.py
@@ -39,7 +39,6 @@ async def get_ln(ctx: discord.AutocompleteContext):
|
||||
return [color for color in languages if color.startswith(ctx.value.lower())]
|
||||
|
||||
@bot.slash_command(name="private_present", description="Generate a presentation with marp, private command for user 707196665668436019")
|
||||
#we create a function that takes the subject of the presentation and the style of the presentation as arguments, and that
|
||||
@option(name="subject", description="The subject of the presentation", required=True)
|
||||
@option(name="style", description="The style of the presentation", required=False, autocomplete=get_style)
|
||||
@option(name="language", description="The language of the presentation", required=False, autocomplete=get_ln)
|
||||
@@ -85,38 +84,9 @@ class:
|
||||
else: marp = marp + "\n---"
|
||||
prompt = f"{intstructions} {indications} The subject of the presentation is: {subject} The Language is: {language} <|endofprompt|> \n {marp}"
|
||||
subject2 = subject
|
||||
subject = subject.replace(" ", "-")
|
||||
#also replae all forbidden characters
|
||||
subject = subject.replace("/", "-")
|
||||
subject = subject.replace("?", "-")
|
||||
subject = subject.replace("!", "-")
|
||||
subject = subject.replace(":", "-")
|
||||
subject = subject.replace(";", "-")
|
||||
subject = subject.replace("(", "-")
|
||||
subject = subject.replace(")", "-")
|
||||
subject = subject.replace("[", "-")
|
||||
subject = subject.replace("]", "-")
|
||||
subject = subject.replace("{", "-")
|
||||
subject = subject.replace("}", "-")
|
||||
subject = subject.replace("'", "-")
|
||||
subject = subject.replace('"', "-")
|
||||
subject = subject.replace("=", "-")
|
||||
subject = subject.replace("+", "-")
|
||||
subject = subject.replace("*", "-")
|
||||
subject = subject.replace("&", "-")
|
||||
subject = subject.replace("^", "-")
|
||||
subject = subject.replace("%", "-")
|
||||
subject = subject.replace("$", "-")
|
||||
subject = subject.replace("#", "-")
|
||||
subject = subject.replace("@", "-")
|
||||
subject = subject.replace("`", "-")
|
||||
subject = subject.replace("~", "-")
|
||||
subject = subject.replace("|", "-")
|
||||
subject = subject.replace("<", "-")
|
||||
subject = subject.replace(">", "-")
|
||||
subject = subject.replace(",", "-")
|
||||
subject = subject.replace(".", "-")
|
||||
subject = subject.replace("?", "-")
|
||||
forbidden = ["\\", "/", "?", "!", ":", ";", "(", ")", "[", "]", "{", "}", "'", '"', "=", "+", "*", "&", "^", "%", "$", "#", "@", "`", "~", "|", "<", ">", ",", ".", "?", " "]
|
||||
for i in forbidden:
|
||||
if i in subject: subject = subject.replace(i, "-")
|
||||
#we save teh subject in base64 in a variable
|
||||
b64 = base64.urlsafe_b64encode(subject.encode("utf-8"))
|
||||
#if dosen't exist, create a directory called "userid" where the userid is the id of the user who called the command
|
||||
@@ -158,11 +128,12 @@ class:
|
||||
print ("generating image " + images + "with " + str(use_images))
|
||||
r = await imagesGeneration.generate(images, f"{os.getcwd()}\\data\\{uid}\\{b64}{datenow}\\", str(use_images), apikey)
|
||||
if str(use_images) == "sd": os.rename(f"{os.getcwd()}\\.\\data\\{uid}\\{b64}{datenow}\\{images}_0.png", f"{os.getcwd()}\\data\\{uid}\\{b64}{datenow}\\{images}.png")
|
||||
if str(use_images) == "dalle":
|
||||
if str(use_images) == "dalle":
|
||||
image_url = r['data'][0]['url']
|
||||
img_data = requests.get(image_url).content
|
||||
with open(f'./data/{uid}/{b64}{datenow}/{images}.png', 'wb') as handler:
|
||||
handler.write(img_data)
|
||||
asyncio.sleep(15) #wait 15 seconds to avoid rate limiting
|
||||
with open(f"./data/{uid}/{b64}{datenow}/{subject}.md", "w", encoding="utf8") as f: f.write(present)
|
||||
cmd = f"--pdf --allow-local-files ./data/{uid}/{b64}{datenow}/{subject}.md"
|
||||
if os.path.exists("./marp.exe"):
|
||||
@@ -189,14 +160,10 @@ class:
|
||||
|
||||
@bot.slash_command(name="list", description="List all the presentations you have created")
|
||||
async def list(ctx: discord.ApplicationContext):
|
||||
#we create an embed with the list of presentations
|
||||
embed = discord.Embed(title="Presentations", description="Here is the list of all the presentations you have created. You can download the presentation in different formats (pdf, markdown, html) by doing `/get` \"*presentation id*\". The images are generated by an ai. If you want to modify your presentation you can use the markdown file. More information about how to modify the file [HERE](https://marp.app).", color=0x00ff00)
|
||||
#we get the list of presentations
|
||||
liste = await get_presentations(str(ctx.author.id))
|
||||
#we add the list of presentations to the embed
|
||||
for key in liste:
|
||||
embed.add_field(name=f"{liste[key]}", value=f"</get:1063051827010084925> `{key}`", inline=False)
|
||||
#now we send the embed
|
||||
await ctx.respond(embed=embed, ephemeral=True)
|
||||
|
||||
async def get_presentations(uid):
|
||||
@@ -211,20 +178,14 @@ async def get_presentations(uid):
|
||||
@option(name="pid", description="The id of the presentation", required=True)
|
||||
async def get(ctx: discord.ApplicationContext, pid: str):
|
||||
uid = str(ctx.author.id)
|
||||
#we get the list of presentations
|
||||
liste = await get_presentations(uid)
|
||||
#we check if the presentation id is in the list
|
||||
if pid in liste:
|
||||
#if it is we send the pdf, markdown and html files
|
||||
files = [discord.File(f"./data/{uid}/{pid}/{liste[pid]}.pdf"), discord.File(f"./data/{uid}/{pid}/{liste[pid]}.md"), discord.File(f"./data/{uid}/{pid}/{liste[pid]}.html")]
|
||||
await ctx.respond(files=files, ephemeral=True)
|
||||
#when the bot is ready we print a message
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print("Bot is ready")
|
||||
#print the name of the os (linux or windows)
|
||||
print(str(os.name))
|
||||
#if the data directory doesn't exist we create it
|
||||
if not os.path.exists("data"):
|
||||
os.mkdir("data")
|
||||
@bot.event
|
||||
|
||||
Reference in New Issue
Block a user