podbot
is a Discord bot written in TypeScript designed to transpile to ECMAScript 2017 code and to run on Node.js 7.7. It currently supports running multiple bots concurrently through relatively simple configuration (this may become easier in the future). It leverages the discord.js API.
I created this bot initially just to provide some basic commands for the PFC Discord server. Simultaneously, I created a seperate bot to provide other custom commands to the Plush Degenerates Discord server. Eventually I merged both into the same codebase.
Current global commands (implemented in Command/Defaults.ts
)
- Searches the catalog of a 4chan board; by default this is /mlp/ (configurable in
FourChan.ts
). If no argument orrandom
given, then a random thread is returned; otherwise, the first thread that matches thesearch
argument is returned along with a random image from that thread. - Searches Derpibooru. If no argument or
random
given, then a random image is returned; otherwise, a random image based on thesearch
argument is returned. The best searches on Derpibooru are tag searches and commas (,
) can be used to "and" tags together. Implements Embeddable allowing end user to scroll through results. - Searches Google and returns results matching the
search
argument. Implements Embeddable allowing end user to scroll through results. - Searches Google and returns image results matching the
search
argument. Implements Embeddable allowing end user to scroll through results. - Will show the current and average ping times to the bot's server. The current ping time is based on the timestamp value attached to the command's message and the server's timestamp. The average is directly from the discord.js API. This command can only be used either via DM or in a channel which contains the word "bot" in its name.
- Will force the bot to say message using regional indicator emoticons in the current channel.
- Will force the bot to say message in the current channel. This is exposed primarily for testing and likely won't stay that way for long.
- Will show the current uptime for the bot according to the discord.js API. This command can only be used either via DM or in a channel which contains the word "bot" in its name.
- Searches YouTube and returns videos matching the
search
argument. Implements Embeddable allowing end user to scroll through results.
4chan [ random | search ]
db [ random | search ]
google search
image search
ping
regind message
say message
uptime
yt search
Current custom commands and features for PFC (implemented in pfc.ts
)
- If run with
last
then it will post the last video uploaded to the PFC YouTube channel. If the parameter islive
then it will link the PFC live page which should show current livestreams that may be occuring. - This command will reformat and re-state topic, pin that new message to the active channel, and remove the original message. This is intended to making pinning topics to the
#podcast
channel on PFC easier and, as such, will only work if the channel's name is either#podcast
or#bot-fuckery
.
pfc [ last | live ]
topic topic
- The bot will query the PFC YouTube channel once every 30 seconds looking for a newly uploaded video. If one is found, then it will be posted to the #pfc text channel.
- When a new user joins the guild, the bot will automatically assign them a role.
- If a user in the specified group uploads a picture, the bot will automatically react with three specified reaction images (this was done as an inside joke).
Current custom commands for Plush Degenerates (implemented in plush.ts
)
- This will attempt to search for and then display the most likely candidate for the plush thread on the current 4chan board (by default this is /mlp/). This is accomplished first by searching the catalog for a thread with "plush thread" in either the subject or comment and, if nothing is found, then searching for just the word "plush".
thread
- Commands can be issued either in a channel, a group DM, or a direct DM. If in a channel or a group DM, then the command must be prefixed by the trigger string (as configured in both
pfc.ts
andplush.ts
this is!
). In a DM, the command should not contain the prefix. - As configured, the bot is set to log all commands to a local mongodb instance. If you wish to disable this, simply unhook the
any
command from the corresponding bot file (seepfc.ts
orplush.ts
). If you wish to configure the logging, seeCommandLogger.ts
. - All commands are aliasable, renameable, and overrideable. Additionally, new commands can be added easily. See the files
pfc.ts
andplush.ts
for examples.
- Change all commands that fit the Embeddable profile to make use of the new abstract class; current candidates in process:
-
4chan
-
- Eliminate use of old
RichEmbed
class defined within Command.Defaults in favor of my actual RichEmbed implementation - Do some sort of
stats
command, or something that queries mongo and returns the person who issues the most commands or the most used commands or both - Maybe a
weather
command? - To solve random disconnection issues, or at least mitigate the length of disconnection, perhaps reset the bot's connection (kill/restart) every day or so?
- Convert the README.md file back to a HTML file? I hate md
I mean, this really isn't meant for distribution, but if you insist:
- Get a Discord API key for a bot by following these instructions.
- Configure a
bot.ts
file like I have done forpfc.ts
andplush.ts
. Here's a generic example:
import { GenericBot } from "Path/To/GenericBot";
const name: string = "MyBotsName";
const trigger: string = "!";
const commands: GenericBot.Command.Collection = new GenericBot.Command.Collection();
commands.set("4chan", { default: true })
.set("db", { default: true })
.set("dp", { alias: "db" })
.set("google", { default: true })
.set("image", { default: true })
.set("images", { alias: "image" })
.set("ping", { default: true })
.set("regind", { default: true })
.set("say", { default: true })
.set("uptime", { default: true })
.set("yt", { default: true });
const bot: GenericBot = new GenericBot(name, { commands, trigger });
bot.configure().login().catch(console.error);
- Modify the
Crypt.ts
file.- Set the
secretsDirectory
Path to the top level directory. - Add or remove entries from
botFiles
object to correspond with your bot names. - Set the
keyFile
Path to a file that contains a key that will be used for encryption/decryption. - Modify the
Bots
type to match the bot(s) you are configuring
- Set the
- Modify the
.secrets_all.json
file in the top directory with a structure as defined by theSecretsAll
interface inCrypt.ts
.- This file will contain the Discord API key for your bot(s).
- If you want to access the Google search API, then get a Custom Search API key from Google and place it and the CX in this file. If you don't wish to use Google, then set these to empty strings.
- Modify
index.ts
file.- Set the
botDirectory
Path to the top level directory. - Follow the example of how
pfcFile
andpfc
andplushFile
andplush
are initialized and then ensure theconfigure()
method is executed.
- Set the
- Modify
package.json
and set thefiles
property to the top level directory. - Modify
tsconfig.json
and set thecompilerOptions.outDir
to the top level directory. - Download and install dependencies locally by running
npm update
. - Transpile the project by running
node_modules/typescript/bin/tsc
. - Run
node encrypt.js
to encrypt the bot API key(s) and/or the Google API/CX. This will generate corresponding.secrets_
thing
files. Your.secrets_all.json
file will be wiped of all sensitive information. This command should only be executed one time, during setup. - Run
node index.js
to start up your bot(s).
I've yet to test any of this outside of my current bot configurations, but if you run into problems, feel free to open an issue on GitHub. I'm not really planning on providing much support of this outside of my buds online, but if I can answer any inquiries I will try.
podbot
by Corpulent Brony is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Read more here: LICENSE.md
tl;dr DONUT STEELE