Giter Site home page Giter Site logo

java-discord / javabot Goto Github PK

View Code? Open in Web Editor NEW
47.0 5.0 23.0 4.84 MB

General utility bot for the Discord Java Community

Home Page: https://discordjug.net/

License: GNU General Public License v3.0

Java 99.97% Dockerfile 0.03%
discord-bot java jda bot discord

javabot's Introduction

JavaBot — General Utility Bot for the Discord Java Community

Banner

Usage

To start up, run the bot once, and it will generate a config directory. Stop the bot, and set the up all the following values:

  • in systems.json
    • jdaBotToken to your bot's token
    • (some adminUsers which, e.g., can manipulate the database)
  • in {guildId}.json
    • moderation.logChannelId to a channelId
    • moderation.staffRoleId to a roleId
    • moderation.adminRoleId to a roleId
    • jam.adminRoleId to a roleId

NOTE: Don't forget to enable the Presence Intent, Server Members Intent and Message Content Intent on the Discord Developer Portal!

Note that this is just what is required for the bot to start. Certain features may require other values to be set.

Configuration

The bot's configuration consists of a collection of simple JSON files:

  • systems.json contains global settings for the bot's core systems.
  • For every guild, a {guildId}.json file exists, which contains any guild-specific configuration settings.

At startup, the bot will initially start by loading just the global settings, and then when the Discord ready event is received, the bot will add configuration for each guild it's in, loading it from the matching JSON file, or creating a new file if needed.

Commands

We're using DIH4JDA as our Command/Interaction framework, which makes it quite easy to add new commands.

PingCommand.java

/**
 * <h3>This class represents the /ping command.</h3>
 */
public class PingCommand extends SlashCommand {
	/**
	 * The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
	 */
	public PingCommand() {
		setCommandData(Commands.slash("ping", "Shows the bot's gateway ping.")
				.setGuildOnly(true)
		);
	}

	@Override
	public void execute(@NotNull SlashCommandInteractionEvent event) {
		event.replyEmbeds(new EmbedBuilder()
				.setAuthor(event.getJDA().getGatewayPing() + "ms", null, event.getJDA().getSelfUser().getAvatarUrl())
				.setColor(Responses.Type.DEFAULT.getColor())
				.build()
		).queue();
	}
}

For more information on how this works, visit the DIH4JDA Wiki!

API Documentation

GET guilds/{guild_id}/metrics

  • Responds with guild-specific metrics, such as the member- and (approximate) online count.

GET guilds/{guild_id}/users/{user_id}

  • Responds with the specified users' profile which includes some basic info, such as the users' name and avatar url, but also their recent warns, their current help experience and more!

GET guilds/{guild_id}/leaderboard/qotw?page=1

  • A paginated endpoint which responds with an ordered list of users, based on their QOTW points.

GET guilds/{guild_id}/leaderboard/experience?page=1

  • A paginated endpoint which responds with an ordered list of users, based on their help channel experience.

You can try out the API yourself on api.discordjug.net!

Credits

Inspiration we took from other communities:

javabot's People

Contributors

0x3c50 avatar andrewlalis avatar cbrt-x avatar danthe1st avatar defective4 avatar denuxplays avatar developercallum avatar discorddioxin avatar fischstaebchenn avatar jasonlessenich avatar kemikals avatar liquiddevelopmentnet avatar loadingbg avatar maeves2 avatar moontm-git avatar pleezon avatar sahilasopa avatar tharun634 avatar that-guy977 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

javabot's Issues

Make /format-code skip bot messages

Currently, /format-code always formats the LAST message, even if it's sent by the bot itself. This is unnecessary and not what people expect

Messages in threads not being sent to starboard

  1. Describe the bug
    Whenever a message in a text channel gets a sufficient amount of stars, the bot posts it in the starboard channel.
    This does not happen if the message is sent in a thread.

  2. Steps to reproduce

  • Send a message in a thread.
  • Let multiple users star the message so that the configured starboard ratio is reached
  • The message is not copied to the configured starboard channel by the bot
  1. Expected behavior
    The message should be copied to the starboard channel

  2. Additional context
    https://canary.discord.com/channels/648956210850299986/934397458434387969

Improve QOTW Submission Embeds

Add the question's text and the review date to the private threads starter message.
Add some instructions so users don't end up submitting only 3 words.

NullPointerException when adding reactions in development environment

I'm getting the following exception when I add reactions to a message, while I was working on the java jam stuff:

java.lang.NullPointerException: Cannot invoke "com.google.gson.JsonElement.getAsJsonObject()" because the return value of "com.google.gson.JsonObject.get(String)" is null
	at com.javadiscord.javabot.other.Database.getConfigString(Database.java:227)
	at com.javadiscord.javabot.events.StarboardListener.onGuildMessageReactionAdd(StarboardListener.java:298)

Slow Startup Time Due to Privilege and Command Updates

I've noticed that the bot takes a long time to fully start up because it is slowly updating commands and privileges. Can we make it so that it doesn't do this by default, but only if we, for example, add an argument to the command line or do something in discord to trigger it?

Or even better, find some generic way to update the privileges of only a selected list of commands, but not all.

Remove Custom Commands from Privileges Update

I've noticed that the bot tries to update custom commands, which, obviously, have no CommandConfig.
Would be great if someone (or me, when I have some spare time) could remove this.

image

Add Passive Income Method for Economy

We already have /economy account and /economy send, but it would be useful to find a nice way for server members to earn credits by doing small tasks in the server, so that these credits can actually be used.

Here are some suggestions:

  • Correctly reporting users that violate rules.
  • Providing help to users.
  • Asking well-formatted questions.
  • Participating in the Jam and QOTW events.
  • Contributing to this Bot's source code.
  • Getting their message onto the star board.

Add Jam Submission End Date to /jam info

As suggested by Dioxin, we should add the jam end date to /jam info. Only thing is, currently the schema for the jam is defined as:

CREATE TABLE jam (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR(64) NULL DEFAULT NULL,
    guild_id BIGINT NOT NULL,
    started_by BIGINT NOT NULL,
    created_at TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
    starts_at DATE NOT NULL COMMENT 'Official start date of the jam. Usually the start of the month.',
    completed BOOLEAN NOT NULL DEFAULT FALSE,
    current_phase VARCHAR(64) NULL DEFAULT 'Theme Planning' REFERENCES jam_phase(name)
        ON UPDATE CASCADE ON DELETE SET NULL
);

The entire Jam operation is currently manually operated via /jam-admin next-phase, and I think this should still be the case to account for any unforeseen circumstances, so I would suggest doing a schema migration with:

ALTER TABLE jam
    ADD COLUMN ends_at DATE NULL DEFAULT NULL AFTER starts_at;

And with this, comes the necessary requirement to be able to edit certain Jam properties, so we should also consider adding a /jam-admin edit <property-name> <value> command.

In the future I do want to add some sort of scheduler (probably Quartz) to handle automatically updating the jam phase, and other regularly scheduled tasks, but for now this should remain manual.

Use modals for #looking-for-programmer

As the quality of posts in the looking-for-programmers channel is very low, we should make creating posts in there only possible using a modal interaction with some basic information.

Add /staff-apply Command to Apply for Staff Roles within Discord

The server is growing really fast, and we're gonna reach a point where we will really need to add more moderators and staff to help out. So I think it would be nice to add a /staff-apply command that users could use to apply to different staff roles.

Here's a list of the data which is collected on our current airtable form:

  • IRL name
  • Discord tag
  • Age
  • Email
  • Join date (this is sort of redundant since we have this info internally)
  • Time zone
  • Rank you are applying for
  • Why did you join this server?
  • Extra remarks

By doing it via slash commands, we can reduce this down to just the following fields:

  • IRL name
  • Age
  • Email
  • Time zone
  • Rank you are applying for (can be a ROLE option)
  • Extra remarks and whatnot

And then, the benefit is that we can view applications and accept/reject them automatically within Discord, and the bot can then automatically apply the necessary roles and send any welcome messages we'd want.

Proposed Functionality

  1. User submits an application via /staff-apply <name> <age> <email> <timezone> <rank> <remarks>
  2. Existing staff members can view applications with /staff-applications list [page=0], reject applications with /staff-applications reject <id> <reason>, or accept applications with /staff-applications accept <id>.
  3. If rejected, the user is sent a message including the reason for the rejection.
  4. If accepted, the user is given the specified role by the bot, and sent a message indicating that their application was successful. The bot can also send a message in a staff chat channel to welcome them to the team.
  5. Applications older than (for example) 30 days can be automatically rejected with a "Staff applications aren't needed at the moment" message or something of that nature.

Require Users to Pass a Test Before Allowing Them to Ask Questions

As this was a feature we were planning to implement in the now scrapped JavaBot2, I added it here.

We should prevent users from using the help system unless they have passed a test indicating that they have read and understood the help guidelines and some basics of how to ask good questions.

Dan suggested that such a test should include the following:

  • Formatting code (using triple backticks and syntax highlighting).
  • Knowing how to use the help system.
  • Knowing that Javascript is different from Java.

I suggest that we implement such a test in the following way:

  1. A user sends a message in an available help channel. While reserving, we check if the user is not yet approved to ask questions. Continue to next step if not yet approved.
  2. The bot reserves the channel anyways, and replies to the user with a question. The user must answer the question correctly to continue (clicking an interaction button, sending a valid message in the channel, etc.).
  3. If the user answers all questions correctly, the channel is then kept reserved and the user's question can be asked. Otherwise, the bot tells the user to read the help guidelines and try again, and then unreserves the channel.

Add Schema Migration Support

Currently, it's not very easy to update the bot's SQL schema which is used for strictly-typed relational data. This should be made simpler so that newer releases can update the schema without having to manually open a command-line connection to the database.

I have a few ideas for how this can be done:

  1. SQL migrations are performed by sending an SQL code block or SQL file into a Discord channel, so that the bot can read the migration script from that.
  2. Add migrations as SQL files to the bot's resources, so that on startup the bot will look for any migrations to perform.

I'm leaning towards the second option, but in both cases this involves first making a migration table in the database to ensure that we don't try to run a migration that has already been run.

CREATE TABLE migration (
    name VARCHAR(255) PRIMARY KEY,
    created_at TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
    script_hash VARCHAR(1024) NOT NULL,
    performed_at TIMESTAMP(0),
    performed_by BIGINT,
    successful BOOLEAN
);

Unreserve Channels faster after using /unreserve

Currently, if the owner of a help channel uses the /unreserve command but doesn't answer the "Who do you want to thank" question the channel is considered as reserved and only unreserves after the normal timeout - this should be changed so it closes them faster if someone uses /unreserve but doesn't continue.

QOTW Submissions

I've noticed that modifying the state of submission threads via the /qotw submission command is not working like intended.

Add a cooldown to the help-ping command

To stop people from spamming the @help-ping role we should add a cooldown to the command.

I think this should be a per-person cooldown and not server-wide as the number of open questions highly fluctuates.

Fix QOTW Thread Deletion

I've noticed that Threads that are deleted via the Submission Controls System don't get marked as 'reviewed'. Thus, users cannot create another submission for the following week. This needs to be fixed.

Send DM to User When a Transaction on Their Account Happens

The Java Bot should notify you via private message if a transaction occurs on your account. This should be on by default for every user, but each user should be able to opt-out of it. The opt-out functionality involves updating the schema to include a user preferences table.

Something like this:

CREATE TABLE economy_account_preferences (
    user_id BIGINT PRIMARY KEY,
    receive_transaction_dms BOOLEAN NOT NULL DEFAULT TRUE
    # Add other preferences here later.
);

Add Redeployment Command

Add a /redeploy command, or something of that nature, which would automatically fetch the latest version of the bot's source from GitHub, compile it, and restart the bot using the new version.

Require Users to React to Message in Help-Guidelines Channel Before Being Allowed to Ask Question

As mentioned by dan1st, we should require that users read through the help guidelines before allowing them to ask a question in one of the help channels. We can do this by requiring users to react to a message in Help-Guidelines (or possibly other places as well), before being able to send messages or create threads in the help channels.

Once a user does the required actions, the should be given a role that permits them to use the help channels.

SuggestionListener reposts suspicious links which are deleted by Automod

When a user sends a suspicious link (such as phishing urls) the link gets deleted by automod, but if the same link in sent in #Suggestions SuggestionListener does no find anything wrong and posts it as an embed

To reproduce the same issue simply share a suspicious url in #suggestions and see the magic

Its expected for suggestion listener to delete the message rather then reposting it

Automatically generate code-blocks for Github gist links in chat

Description
Allow inlining of code blocks from GitHub links that have highlighted lines.

Example

Dioxin says:
Check this out:
https://gist.github.com/discorddioxin/27a33cf1376847f4ada29d61390c5198#file-main-java-L13-L16

Bot says:

        box.getItems().add(new Student("First", 111, 3));
        box.getItems().add(new Student("Second", 222, 4));
        box.getSelectionModel().select(0);

https://canary.discord.com/channels/648956210850299986/752535909228085348/867505817506414593

Bot hangs when using /regex

When using the /regex command with some regex patterns the bot stops responding to any other commands and starts missing heartbeats. This happens because the pattern the user put it takes a very long time to calculate which in turn hangs the bot.

Bot-moderated help channel automation

Consider adding bot-managed help channels to streamline people's questions and answers.

Proposed Flow

There are several open help channels that are clearly visible. Users are directed to ask their question in one of these channels.

Once the user sends their first message in an open channel, the channel is moved to a separate area for "active questions". It will stay open in a "pending answer" state until another user (not the original question asker) sends a message in the channel, as a response to the question. If no response is given after X hours, the bot sends a message in the channel to ask the user to confirm that the question is still unanswered, and the channel will stay reserved. Repeat this confirmation flow as long as possible (or introduce a hard cutoff limit).

Once some discussion has happened in a reserved help channel, and the user has obtained their answer, the bot will wait for at least X minutes of inactivity, after which it will send a question to the user in the channel, asking if their question was successfully resolved. If they respond affirmatively, the channel is moved back to the list of available channels, or if not, it stays "reserved".

Channel States

  • Available - The channel is available for users to ask questions.
  • Pending Answer - The channel has been reserved by a user and they've asked their question, and it is waiting for a response from another user.
  • Active - Once another user responds, channels are active while any user sends a message within X minutes.
  • Inactive - If there's been no activity in an active channel in X minutes, the channel is considered inactive. After some time, the bot will confirm with the original question asker if they got their question answered. If so, channel returns to Available state. After a long time, the channel will return to Available regardless.

Economy

Add Some Kind Of Currency Exchange
We Currently Have Few /economy commands but are not in use so i would suggest to implement something which will allow people to earn currency with/without participation (for ex:- help, qotw, jams)

Suggstions
staff can monitor people can reward them if they deserve it
people who contribute can earn fixed amount of salary each week

Implement Progressive Channel Reservation Timeout

Each time a user affirms that their help channel is still in use, the time until the next activity check should increase a bit.

For example: Bob reserves his channel for a question, but nobody answers after 30 minutes, so he's prompted with the activity check message from the bot. He affirms that he's still using it, so the bot checks again in 60 minutes. Again he affirms that he's still using it, so the bot checks again in 2 hours.

This should add a configurable factor by which the amount of time the bot waits between each successive activity check increases, in case the reserving user has affirmed that they're still using the channel.

This should also add a configurable maximum wait time, after which the wait time cannot increase further.

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.