(Extended from bots.benrosenberg.info description)
Throughout this document, Discord messages as input to the bot will be denoted as beginning with a >
inside of a code block. Attachments are denoted [ attachment.ext ]
.
The original purpose of the PDF Creator bot was, as the name would imply, to create PDFs. But then I realized I wanted some extra features to help me with homework, and now it needs its own page to describe all that it does.
To use PDF Creator, you should really host your own instance on your own server or computer. Its dependencies follow:
python-dotenv
, for loading the bot token.tex
filescurl
, to upload files to hosting servicesqpdf
, for page countsAfter cloning the repository and installing all the dependencies, create a bot application here and get the token for the bot. Then, create a .env
file in the directory with the file bot.py
in it, and with the following contents:
TOKEN=<insert token from discord developer site here>
(You can create this in one line with echo "TOKEN=<token>" > .env
)
This file will be loaded in and used by bot.py
.
You can run the bot with python bot.py
, or python3 bot.py
depending on how you have configured your Python installation.
This is the most recent syntax (or rather, the most recent syntax that I’ve uploaded to this site).
There are two ways to create a PDF. The first is by putting the contents of the Markdown file to be used in the actual message body, like so:
> pdf This text will be turned into a PDF.
The contents of the message can be as detailed as the contents of any Markdown file acceptable by the bot, and can include multiple lines, of course. The idea is that you can paste any part of a valid Markdown file into the bot (or even the entire thing) and it should give the same output:
> pdf ---
title: This is a title
author: Me
---
# This is a section
This is some math: $1 + 1 = 2$
The other way files can be processed into PDFs is by attaching them. The files can have .md
or .txt
extensions, but both will be processed as Markdown files. The reason support was added for .txt
extensions was so that pasted messages over 2000 characters, which are by default in Discord turned into a file “message.txt”, could be processed.
In order to upload an attachment (or use the default pasting with messages of length > 2000 characters) just upload as normal and make the message content “pdf”:
> pdf
[ message.txt ]
There is a third functionality that PDF Creator has, which is uploading PNG images to a filehosting site and generating a Markdown insert, of the form ![image name](https://image-url.tld)
, for the image. This is done as follows:
> png
[ image.png ]
This is very useful when you need to take a screenshot and insert it into a file quickly, without manually uploading to a hosting site or saving the image to your computer. The fact that you can take a screenshot in a couple keypresses on Windows with Win + Shift + S
and then paste that image into Discord with a simple Ctrl + V
can make this very convenient.
The bot will not look at messages with more than one attachment, or with both content (besides the pdf
/png
at the start) and an attachment, or with png
and then extra message content. It accepts a single message with both the command and content, or a message with just a command and a single attachment. The bot will give error messages on incorrect usage.
PDF Creator uses Pandoc Markdown (details here) to generate PDFs. Pandoc’s Markdown supports a variety of different types of YAML headers, although the simplest is the following type:
---
title: Title
author: Author
date: \today
---