A Discord Bot that takes code messages and converts them into beautiful images. Powered by Carbon.
The repo is written in JavaScript. To run in you need to have node 16
installed. Follow these steps to get started:
git clone https://github.com/OSDG-IIITH/Carbonite.git
cd Carbonite
npm i
node index.js
Note that to run the bot, you need to set up a Discord bot in the Discord Developer Platform and get a bot token. Save this token in a file called .env
at the root directory of the project as:
DISCORD_TOKEN=YOUR_TOKEN_HERE
In the channel, invite Carbonite. You can now invoke it using the carbonite
keyword, followed by the code on a new line. For example, send the following message on the channel that Carbonite has access to:
carbonite
```
print("Hello World")
```
The Bot has 2 main parts:
-
The Bot interface, powered by
Discord.js v13
, that handles receiving, parsing and sending messages. -
The "Carbonizer", powered by
Puppeteer
. It spawns a headless browser that modifies the Carbon webpage's contents to accomodate for the code, then screenshots the DOM element that has the prettified code image and returns a byte stream of the image data back to the bot to send to Discord.
- Delete the original message requesting the carbonification.
- Add a "Carbonite is typing..." prompt to Discord while the bot generates and sends the image.
- Create a help event that explains bot usage.
- Create a list event that lists available themes and languages