Skip to content

ABSphreak/EddieBot

Β 
Β 

Repository files navigation

EddieBot

Production workflow Develop workflow

All Contributors

Discord bot for Eddie Jaoude's Discord server

Features of EddieBot

  • Set/Get user bio with description and social links

  • Timezone, listens for messages that contain 1:30pm UTC and replies with common timezones translation

  • Code of Conduct

  • Daily standup message consistently formatted

  • Help showing a list of available commands

  • Members role rewards

  • Gets tips of resources on a given subject

  • Server status

  • Firebase (Firestore) integration, allowing people to easily add commands and persist data

  • GitHub Actions deploys mainline branch to Azure

Required

  • node v10+ installed

  • discord token. To get one follow these instructions

  • general channel ID of your discord server, read the instructions on one of these links to get yours:

  • ID of your discord server, to get your server ID follow these steps:

    • First make sure you have Developer Mode enabled on your Discord by visiting your Discord settings and going to Appearance

    user settings button developer mode toggle button

    • Right click on the server icon on the left hand sidebar then click on "Copy ID"
  • firebase key for the project, check these docs to get your key

  • [optional] GCP account to deploy to (using GitHub Actions)

Quickstart

  1. Clone the project or your fork (if you plan to make changes use your fork)
  2. Install dependencies by running the command npm install

Run the project locally on Mac and Linux using below command

  1. DISCORD_TOKEN=<GET YOUR DISCORD TOKEN> GENERAL_CHANNEL_ID=<GET YOUR GENERAL CHANNEL ID> DISCORD_SERVER_ID=<YOUR SERVER_ID> DISCORD_BOT_CHANNEL_ID=<ID> COMMAND_PREFIX=<PREFIX> FIREBASE_KEY=<FIREBASE_KEY> npm run start:local

or you can the envars in a file envars.tmp.sh and run the command source envars.tmp.sh && npm run start:local

Example envars.tmp.sh file

export DISCORD_TOKEN=<DISCORD_TOKEN>
export COMMAND_PREFIX='^'
export DISCORD_SERVER_ID=<DISCORD_SERVER_ID>
export DISCORD_BOT_CHANNEL_ID=<DISCORD_BOT_CHANNEL_ID>
export FIREBASE_KEY=<FIREBASE_KEY>

Run on Windows using below commands

  1. set DISCORD_TOKEN=<GET YOUR DISCORD TOKEN>
  2. set GENERAL_CHANNEL_ID=<GET YOUR GENERAL CHANNEL ID>
  3. set DISCORD_SERVER_ID=<YOUR SERVER_ID>
  4. set DISCORD_BOT_CHANNEL_ID=<ID>
  5. set COMMAND_PREFIX=<PREFIX>
  6. npm run start:local

Note

FIREBASE_KEY is the firebase service key and expected key structure is json string that needs to be valid json with single quotes around the whole string and the field names/values need double quotes. An example below:

export FIREBASE_KEY='{"type": "service_account","project_id": ... }'

Logging

Logging will happen to the console as well as to the Discord bot channel.

  1. Include the logger object...
import { log } from './logger';
  1. Usage
log.info('Message', 'Details');

or

log.warn('Message', 'Details');

or

log.error('Message', 'Details');

or

log.fatal('Message', 'Details');

If you want the bot to receive a new type of event, you might need to add the required intent in client.ts to receive that event. Have a look at discord.js docs for the list of intents.

Example adding ban capabilities to moderators:

  1. Add the GUILD_BANS intent in client.ts:
export const client = new Client({
    partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
    ws: { intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MESSAGE_REACTIONS', 'GUILD_BANS', PrivilegedIntents.GUILD_MEMBERS] }
});
  1. Add an event handler function for the events you want in index.ts:
client.on('guildBanAdd', guild => guildBanAdd(guild));

Note: We are using the GUILD_MEMBERS privileged intent to receive the guildMemberAdd event. To know more about Privileged Intents check the official docs.


How to add a new command to the bot

All the commands are located in the folder src/commandHandlers so that each command has its own file. They are then executed in src/commands.ts when a user types a command with the configured command prefix in config.ts.

To create a new command, follow these steps:

  1. Create a new file on the /commandHandlers folder with the name of the new command. Note: If you need to, use camel case for the file name, like codeOfConduct.ts

  2. On this file you must export a function and three variables:

    • command - the function that executes the command. The signature of this function is the following:
    (arg: string, embed: MessageEmbed, message: Message): Promise<MessageEmbed>

    The arg parameter contains the arguments given to the command in a string. The embed parameter is a MessageEmbed instance, and it represents the message that is returned by the bot, in response to the user. The command should return this parameter or a new instance with an appropriate message to the user. The message parameter is a Message instance that represents the message inputted by the user to execute a given command.

    • description - a string with a more detailed description of the command. Used for example by the help command
    • triggers - a string array with the values that trigger this command. If the user types the configured command prefix followed by one of these values, the command should be executed
    • usage - a string explaining how the command is used (e.g. specifying the number of arguments and their separator)
  3. After creating that file, you have to import it and add it to the exported list of commands on the index.ts file located in this folder. Here is an example of adding the standup command:

import * as codeOfConduct from './codeOfConduct';
import * as help from './help';
+ import * as standup from './standup';
import * as stats from './stats';

- export default [codeOfConduct, help, stats];
+ export default [codeOfConduct, help, standup, stats];

export { fallback } from './fallback';

Database

Using Firestore from Firebase.

Source

classDiagram
	User -- Bio : Nested

	User: bio (object)
	User: avatar (string)
	User: joinedAt (date)
	User: updatedAt (date)
	User: username (string)

	Bio: description
	Bio: twitter
	Bio: github
	Bio: youtube
	Bio: linkedin

If you are having trouble creating a new command, here is an example. Feel free to create an issue or make a PR with a new command πŸ˜ƒ. Please see our Contributing file first, before making new commits or opening a PR. We appreciate it ❀️!


Socials

Join our discord community here

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Mohamed Al-Rifay

⚠️ πŸ‘€

David

πŸ’»

Stephen Mount

⚠️ πŸ€”

Michael Mba

πŸ’»

Eddie Jaoude

πŸ’»

Garret Harp

πŸ’» 🚧

Khushboo Agrawal

πŸ“–

Allan Regush

πŸ’» 🚧

Ruth Ikegah

πŸ’» πŸ“–

morrme

🚧

Harsh Kapadia

🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

About

Discord bot for Eddie Jaoude's Discord server

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%