Skip to content

Motyldrogi/spring-discord-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot Discord Bot

Discord all-purpose bot, made using Spring Boot, JPA, Hibernate, REST, HikariCP, JDA.

TravisCI
travis-icon

Requirements for connection

Find the file app.properties in the resources folder and change following variables:

Adding a Command

Every bot command should be a part of the com.motyldrogi.bot.command package and implement the CommandExecutor class, implementing the execute() method at bare-minimum. The execute() method expectes two arguments:

  • dMessage (DiscordMessage): The DiscordMessage object which contains the full information about the message
  • commandSender (CommandSender): The class for sending messages and also for localization

The execute() method needs a CommandInfo() annotation to work, the CommandInfo() annotation can have the following arguments:

  • value: The value that triggers the command, i.e. after the prefix
  • minArguments: Minimum arguments count for the command, defaults to 0
  • maxArguments: Maximum arguments count for the command, defaults to 0
  • usage: Text that gets displayed if the command was not used correctly

For example, the following command echos back the message received in an embeded message:

package com.motyldrogi.bot.command;

import com.motyldrogi.bot.command.defaults.CommandExecutor;
import com.motyldrogi.bot.command.defaults.CommandInfo;
import com.motyldrogi.bot.command.defaults.CommandSender;
import com.motyldrogi.bot.component.DiscordMessage;
import org.springframework.stereotype.Component;
import java.awt.Color;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;

@Component
public class EchoCommand implements CommandExecutor {

  @CommandInfo(value = "echo", minArguments = 1, maxArguments = 1, usage = "<message>")
  @Override
  public void execute(DiscordMessage dMessage, CommandSender commandSender) {

    MessageEmbed messageEmbed = new EmbedBuilder()
          .setColor(Color.decode("#ffffff"))
          .setTitle(dMessage.getSentBy() + " said..")
          .setDescription(dMessage.getData())
          .build();

    commandSender.sendEmbedMessage(messageEmbed);
  }
}

If you created a command, you have to register it:

this.commandRegistry.registerByExecutors(
    [...],
    new EchoCommand()
);

Features

  • Storing all user's data to mysql database
  • Public rest api without oauth
  • Github command, that shows infos about your github profile
  • Say command, that talks in json

Endpoints

Method Optional query parameters Success status codes Error status codes
GET /api/users page, size 200
GET /api/users/by-id/{id} 200 404
GET /api/users/by-name/{name} 200 404

About

Discord all-purpose bot template, made using Spring Boot, JPA, Hibernate, REST, HikariCP and JDA.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Languages