Coder Social home page Coder Social logo

togetherjavabot's Introduction

About

This is a small bot intended for use on the Together Java discord server.

Functions

We will see whether it evolves, but it will likely only handle smaller tasks for now.

Technologies

  • JDA
    • Discord API
  • TOML4J
    • A Java implementation of the TOML config language
  • Brigardier
    • Mojang's Minecraft command parser
  • Logback and SLF4J
    • Logging
  • Maven
    • Build system

Some day Junit5 might join that list…

Contribute

You are welcome to raise issues or suggestions in the issue tracker here. PRs are welcome too :)

Setting up a local dev environment

  1. You should probably clone this repository via git clone https://github.com/I-Al-Istannen/TogetherJavaBot.git
  2. Enter the cloned directory and set up your IDE of choice
  3. Copy the default bot config found in src/main/resources to another place and edit it to your heart's content. If you copy it to a file called realized.toml in the root of this project it is already covered by an ignore rule.
    • Edit the run configuration for the ApplicationEntry class to add an environment variable called TJ_CONFIG_PATH which contains the path to the config file.
    • OR pass the path to the config as the first command line argument
  4. Set your bot token in the config
  5. Run the org.togetherjava.ApplicationEntry class

Build instructions

This project uses Maven as its build system. You can generate a jar file by running mvn clean package while inside the root of the project. The jar file can then be found in the target folder.

Writing a new command

  1. Make a new class in the org.togetherjava.command.commands package. All classes in that package are automatically registered at runtime.
  2. Make sure the class has a constructor that takes no arguments or takes a single Toml instance (the bot config).
  3. Implement the mandated method:
    public LiteralCommandNode<CommandSource> getCommand(CommandDispatcher<CommandSource> dispatcher) {
  4. Build your command in there. Here is the echo command, which might serve as an example:
    @Override
    public LiteralCommandNode<CommandSource> getCommand(CommandDispatcher<CommandSource> dispatcher) {
      return CommandGenericHelper.literal("echo")
          .then(
              CommandGenericHelper.argument("message", StringArgumentType.greedyString())
                  .executes(context -> {
                    CommandSource source = context.getSource();
                    String argument = context.getArgument("message", String.class);
    
                    source.getMessageSender()
                        .sendMessage(SimpleMessage.information(argument), source.getChannel());
                    return 0;
                  })
          )
          .build();
    }
  5. For more information on adding commands, refer to the documentation for Brigardier or ask :)

TODO

  • Role assignment via reactions
  • Rep? Maybe give/remove via a given emoji?

togetherjavabot's People

Contributors

i-al-istannen avatar itshobbes avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

togetherjavabot's Issues

Application not starting in windows

I tried to run the application on windows but it fails during startup with the followinf stacktrace.
It seems like there is a problem with a path / url

21:13:09.732 [main] INFO org.togetherjava.ApplicationEntry - Looking for a config path in the 'TJ_CONFIG_PATH' environment variable... 21:13:09.736 [main] INFO org.togetherjava.ApplicationEntry - Using config 'F:\TogetherJavaBot-master\src\main\resources\config.toml'. 21:13:09.783 [main] INFO org.togetherjava.ApplicationEntry - Looking for bot token in the supplied config... 21:13:09.784 [main] INFO org.togetherjava.ApplicationEntry - Token acquired 21:13:09.963 [main] INFO o.f.c.i.license.VersionPrinter - Flyway Community Edition 5.2.4 by Boxfuse 21:13:10.253 [main] INFO o.f.c.i.database.DatabaseFactory - Database: jdbc:sqlite:db.sqlite (SQLite 3.28) 21:13:10.281 [main] INFO o.f.core.internal.command.DbValidate - Successfully validated 1 migration (execution time 00:00.010s) 21:13:10.283 [main] INFO o.f.core.internal.command.DbMigrate - Current version of schema "main": 1 21:13:10.284 [main] INFO o.f.core.internal.command.DbMigrate - Schema "main" is up to date. No migration necessary. Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at de.ialistannen.commandprocrastination.autodiscovery.CommandDiscovery.findAllCommands(CommandDiscovery.java:72) at de.ialistannen.commandprocrastination.autodiscovery.CommandDiscovery.findCommands(CommandDiscovery.java:33) at org.togetherjava.command.CommandListener.<init>(CommandListener.java:40) at org.togetherjava.TogetherJavaBot.start(TogetherJavaBot.java:64) at org.togetherjava.ApplicationEntry.main(ApplicationEntry.java:51) Caused by: java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) at de.ialistannen.commandprocrastination.autodiscovery.CommandDiscovery.instantiate(CommandDiscovery.java:94) at de.ialistannen.commandprocrastination.autodiscovery.CommandDiscovery.findAllCommands(CommandDiscovery.java:70) ... 4 more Caused by: java.nio.file.InvalidPathException: Illegal char <:> at index 5: https://docs.oracle.com/en/java/javase/12/docs/api at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182) at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153) at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77) at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92) at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:229) at java.base/java.nio.file.Path.of(Path.java:147) at de.ialistannen.htmljavadocparser.resolving.UrlDocumentResolver.relativizeAbsoluteUrl(UrlDocumentResolver.java:59) at org.togetherjava.docs.JfxDocumentResolver.relativizeAbsoluteUrl(JfxDocumentResolver.java:29) at de.ialistannen.htmljavadocparser.resolving.DocumentResolver.relativizeAbsoluteUrl(DocumentResolver.java:38) at de.ialistannen.htmljavadocparser.resolving.CachingDocumentResolver.relativizeAbsoluteUrl(CachingDocumentResolver.java:35) at de.ialistannen.htmljavadocparser.resolving.HtmlSummaryParser.extractFqn(HtmlSummaryParser.java:108) at de.ialistannen.htmljavadocparser.resolving.HtmlSummaryParser.index(HtmlSummaryParser.java:71) at de.ialistannen.htmljavadocparser.resolving.HtmlSummaryParser.getTypes(HtmlSummaryParser.java:137) at de.ialistannen.htmljavadocparser.JavadocApi$ApiEntry.<init>(JavadocApi.java:120) at de.ialistannen.htmljavadocparser.JavadocApi.addApi(JavadocApi.java:39) at org.togetherjava.docs.DocsApi.<init>(DocsApi.java:52) at org.togetherjava.command.commands.javadoc.JavadocBaseCommand.<init>(JavadocBaseCommand.java:26) ... 11 more

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.