RemcoHalman / EddieBot

Discord bot for Eddie Jaoude's Discord server

Home Page:https://discord.gg/jZQs6Wu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

→ Requirements

  • [optional] Docker and Docker-Compose
  • 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
    • 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)

→ How to run EddieBot locally:

1. Set Environment Variables

  1. Copy .env.example to .env.
  2. Generate the "Service Account" from Firebase Settings > Cloud Messaging.
    1. Download Service Account JSON file from this same screen.
  3. Open .env and fill empty strings with matching credentials from the JSON file.

2. To start the application

  • [optional] To run with Docker ensure you have the latest version and Docker Compose installed and run

    • docker-compose up
  • To run locally

    • npm run start:local

→ Useful Commands

  • View Logs

    docker-compose logs --tail=all -f eddiebot-nodejs

  • Use NodeJS instance CLI

    docker-compose exec eddiebot-nodejs /bin/bash

→ 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

About

Discord bot for Eddie Jaoude's Discord server

https://discord.gg/jZQs6Wu

License:MIT License


Languages

Language:TypeScript 97.4%Language:Shell 1.3%Language:Dockerfile 1.3%