Giter Club home page Giter Club logo

spring-discord-bot's Introduction

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

spring-discord-bot's People

Contributors

motyldrogi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.