Skip to content

A Discord bot written in TypeScript for ES2017 output on node.js using the discord.js Discord API library.

License

Notifications You must be signed in to change notification settings

CorpulentBrony/podbot

Repository files navigation

podbot

notices your bot

OwO what's this?

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.

Why?

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.

What can it do?

Current global commands (implemented in Command/Defaults.ts)

4chan [ random | search ]
Searches the catalog of a 4chan board; by default this is /mlp/ (configurable in FourChan.ts). If no argument or random given, then a random thread is returned; otherwise, the first thread that matches the search argument is returned along with a random image from that thread.
db [ random | search ]
Searches Derpibooru. If no argument or random given, then a random image is returned; otherwise, a random image based on the search 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.
google search
Searches Google and returns results matching the search argument. Implements Embeddable allowing end user to scroll through results.
image search
Searches Google and returns image results matching the search argument. Implements Embeddable allowing end user to scroll through results.
ping
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.
regind message
Will force the bot to say message using regional indicator emoticons in the current channel.
say message
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.
uptime
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.
yt search
Searches YouTube and returns videos matching the search argument. Implements Embeddable allowing end user to scroll through results.

Current custom commands and features for PFC (implemented in pfc.ts)

pfc [ last | live ]
If run with last then it will post the last video uploaded to the PFC YouTube channel. If the parameter is live then it will link the PFC live page which should show current livestreams that may be occuring.
topic topic
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.

Other implemented non-command features for PFC

  • 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)

thread
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".

Other notes

  • 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 and plush.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 (see pfc.ts or plush.ts). If you wish to configure the logging, see CommandLogger.ts.
  • All commands are aliasable, renameable, and overrideable. Additionally, new commands can be added easily. See the files pfc.ts and plush.ts for examples.

To-do List

  • 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

How can I set it up?

I mean, this really isn't meant for distribution, but if you insist:

  1. Get a Discord API key for a bot by following these instructions.
  2. Configure a bot.ts file like I have done for pfc.ts and plush.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);
  1. 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
  2. Modify the .secrets_all.json file in the top directory with a structure as defined by the SecretsAll interface in Crypt.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.
  3. Modify index.ts file.
    • Set the botDirectory Path to the top level directory.
    • Follow the example of how pfcFile and pfc and plushFile and plush are initialized and then ensure the configure() method is executed.
  4. Modify package.json and set the files property to the top level directory.
  5. Modify tsconfig.json and set the compilerOptions.outDir to the top level directory.
  6. Download and install dependencies locally by running npm update.
  7. Transpile the project by running node_modules/typescript/bin/tsc.
  8. 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.
  9. 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.

Creative Commons License

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

About

A Discord bot written in TypeScript for ES2017 output on node.js using the discord.js Discord API library.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published