Git Product home page Git Product logo

eddiebot's Introduction

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, to display some statistics of the server (e.g total number of users and messages)

  • 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] Github token that you can get from here
  • [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

    1. To setup: npm run setup
    2. To start: 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

Standardized Code Formating

  • Before Commit
    1. lint for errors: npm run lint
    2. fix any errors: npm run lint:fix

Using Commitizen for commits

  1. git add <your files>
  2. npm run commit

→ 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, string], embed: MessageEmbed, message: Message): Promise<MessageEmbed>

    The arg parameter contains the arguments given to the command in a string. The arg parameter is a tuple of two strings where, arg[0] is the command name and arg[1] is the string of command arguments. 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

eddiebot's People

Contributors

eddiejaoude avatar bolt04 avatar allanregush avatar allcontributors[bot] avatar raisinten avatar mikeysan avatar stemount avatar eync avatar vyvy-vi avatar prajwal0024 avatar garretcharp avatar ruth-ikegah avatar luckspt avatar ritvij14 avatar morrme avatar dependabot[bot] avatar sashreek1 avatar remcohalman avatar webkhushboo avatar jashpatel1 avatar jacobkim9881 avatar harshkapadia2 avatar frankiefab100 avatar akshu-on-github avatar absphreak avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.