Skip to content

GitFitCode/gitfitbot

Repository files navigation

gitfitbot

Table of Contents:

Setting up the project

What you'll need

Note: You DO NOT need docker to run the bot locally.

Installing dependencies

pnpm i

Setting up .env

cp .env.example .env
copy .env.example .env # pwsh
  • Populate fields in the .env file.

    • Sign up on Keybase!
    • Ask Sirrele or Pratik for an invite to the GitFitCode Team in Keybase.
    • Upon receiving the invite, navigate to the Files section in Keybase.
    • Inside Files, look for team -> gitfitcode -> discord bot secrets -> autobot -> .env.
    • Download or copy contents into your local .env file.
  • Get access to the Digital Junkyard development server on Discord.

Run the bot

pnpm dev # the bot is online in the Digital Junkyard discord server

Development

Commit message

When committing code to the repo, please follow the commit message guidelines/patterns set here and here.

Currently supported commands

Supported Commands

Create new slash commands

  • Add command constants in src/utils/constants.ts file.

    // Info command constants
    export const COMMAND_INFO = {
      COMMAND_NAME: 'info',
      COMMAND_DESCRIPTION: 'Displays info about yourself and the server.',
    };
  • Create a new .ts file in src/commands directory.

  • Name it same as the slash command (e.g. Info.ts).

  • Follow the example format below to create a new slash command:

    /**
     * Slash command that replies with the information of the server and the user who
     * triggered the command.
     *
     * To trigger, type `/info` in the discord server.
     */
    
    import { CommandInteraction, Client } from 'discord.js';
    import { version } from '../../package.json';
    import { COMMAND_INFO } from '../utils';
    import { SlashCommand } from '../Command';
    
    async function executeRun(interaction: CommandInteraction) {
      const content = `\`Your username\`: ${interaction.user.username}
    \`Your ID\`: ${interaction.user.id}
    \`Server name\`: ${interaction.guild?.name}
    \`Total members\`: ${interaction.guild?.memberCount}
    \`${interaction.client.user.username} version\`: ${version}`;
    
      await interaction.followUp({ ephemeral: true, content });
    }
    
    const Info: SlashCommand = {
      name: COMMAND_INFO.COMMAND_NAME,
      description: COMMAND_INFO.COMMAND_DESCRIPTION,
      run: async (_client: Client, interaction: CommandInteraction) => {
        await executeRun(interaction);
      },
    };
    
    export default Info;
  • Update the code for the required logic.

  • Import the command in src/Commands.ts file to register the command on discord.

    import Info from './commands/Info';
    
    const Commands: SlashCommand[] = [
      //...
      Info,
      //...
    ];
  • Run the bot:

    pnpm dev

Your newly added slash commands are now ready to be used on discord!

Create new discord event listeners

  • Create a new .ts file in src/listeners directory.

  • Name it according to the event you want to listen to from here (e.g. ready.ts).

  • Follow the example below to create a new event listener:

    import { ActivityType, Client } from 'discord.js';
    import Commands from '../Commands';
    
    export default (client: Client): void => {
      client.on('ready', async () => {
        if (!client.user || !client.application) {
          return;
        }
    
        console.log(`${client.user.username} is online`);
      });
    };
  • Register the listener in src/Bot.ts file:

    function start () {
    ...
      ready(client);
    ...
    }
  • Run the bot:

    pnpm dev

Note: If you're having issues listening to events, ensure the intents are accurately provided in src/Bot.ts file.

[OPTIONAL] Local Docker Setup

  • Ensure you've followed every step in Setting up the project step.

  • Install Docker

  • Build image:

    docker build --tag gitfitbot .
  • Run the bot:

      docker run --detach --name gitfitbot-container --env-file ./.env gitfitbot
  • Stop/Restart the bot

    • List all docker processes:
      docker ps
    • Stop the bot's container:
      docker stop <CONTAINER ID>
    • Restart the bot's container:
      docker restart <CONTAINER ID>

About

Discord bot for GitFitCode needs written in Nodejs and TypeScript.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages