Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket #141

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
13 changes: 10 additions & 3 deletions src/main/java/com/eternalcode/discordapp/DiscordApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import com.eternalcode.discordapp.review.GitHubReviewService;
import com.eternalcode.discordapp.review.GitHubReviewTask;
import com.eternalcode.discordapp.review.command.GitHubReviewCommand;
import com.eternalcode.discordapp.ticket.TicketButtonController;
import com.eternalcode.discordapp.ticket.command.TicketCommand;
import com.eternalcode.discordapp.user.UserRepositoryImpl;
import com.jagrosh.jdautilities.command.CommandClient;
import com.jagrosh.jdautilities.command.CommandClientBuilder;
Expand All @@ -61,7 +63,6 @@
import java.io.File;
import java.sql.SQLException;
import java.time.Duration;
import java.time.Instant;
import java.util.EnumSet;
import java.util.Timer;

Expand Down Expand Up @@ -144,7 +145,10 @@ public static void main(String... args) throws InterruptedException {

// Leveling
new LevelCommand(levelService),
new LeaderboardCommand(leaderboardService)
new LeaderboardCommand(leaderboardService),

// Ticket
new TicketCommand(config)
)
.build();

Expand All @@ -168,7 +172,10 @@ public static void main(String... args) throws InterruptedException {
new CodeGameAnswerController(codeImageGameData, codeGameConfiguration, data, experienceService),

// leaderboard
new LeaderboardButtonController(leaderboardService)
new LeaderboardButtonController(leaderboardService),

// Ticket
new TicketButtonController(config)
)

.setAutoReconnect(true)
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/eternalcode/discordapp/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ public class AppConfig implements CdnConfig {
@Description("# The settings of review system")
public ReviewSystem reviewSystem = new ReviewSystem();

@Description("# The settings of review system")
public TicketSystem ticketSystem = new TicketSystem();

@Contextual
public static class TicketSystem {
@Description("# Ticket category channel id")
public long ticketCategoryId = 1079787699336134859L;

@Description("# Ticket starter title embed message")
public String ticketEmbedTitleMessage = "Ticket ";

@Description("# Ticket starter description embed message")
public String ticketEmbedDescriptionMessage = "Tutaj otworzysz swój ticket";

@Description("# Ticket starter button message")
public String ticketButtonMessage = "Open ticket";
}

@Override
public Resource resource(File folder) {
return Source.of(folder, "config.yml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public void onButtonInteraction(ButtonInteractionEvent event) {
String componentId = event.getComponentId();
long messageId = event.getMessage().getIdLong();

if (!event.getMessage().getContentRaw().startsWith("👑 Leaderboard")) {
return;
}

int totalRecords = this.leaderboardService.getTotalRecords();
int totalPages = this.leaderboardService.getTotalPages(totalRecords);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public void execute(SlashCommandEvent event) {
}

Button firstButton = Button.success("leaderboard_first", "First")
.withEmoji(Emoji.fromUnicode("U+23EE"))
.withDisabled(page == 1);
.withEmoji(Emoji.fromUnicode("U+23EE"))
.withDisabled(page == 1);

Button prevButton = Button.primary("leaderboard_prev", "Previous")
.withEmoji(Emoji.fromFormatted("U+25C0"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.eternalcode.discordapp.ticket;

import com.eternalcode.discordapp.config.AppConfig;
import net.dv8tion.jda.api.EmbedBuilder;

import net.dv8tion.jda.api.entities.channel.concrete.Category;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

import java.awt.*;
import java.util.Objects;

public class TicketButtonController extends ListenerAdapter {

AppConfig appConfig;

public TicketButtonController(AppConfig appConfig) {
this.appConfig = appConfig;
}

@Override
public void onButtonInteraction(ButtonInteractionEvent event) {
if (event.getComponentId().equals("create_ticket")) {
MessageChannel channel = event.getChannel();
Category category = Objects.requireNonNull(event.getGuild()).getCategoryById(this.appConfig.ticketSystem.ticketCategoryId);

if (category != null) {
EmbedBuilder embedBuilder = new EmbedBuilder()
.setTitle("Błąd")
.setColor(Color.decode(this.appConfig.embedSettings.errorEmbed.color))
.setDescription("Kategoria nie jest podana w configu.");
event.replyEmbeds(embedBuilder.build());
}

if (!event.getGuild().getTextChannelsByName(event.getMember().getId(), false).isEmpty()) {
EmbedBuilder embedBuilder = new EmbedBuilder()
.setTitle("Błąd")
.setColor(Color.decode(this.appConfig.embedSettings.errorEmbed.color))
.setDescription("Posiadasz już otwarty ticket.");
event.replyEmbeds(embedBuilder.build());
}

category.createTextChannel(event.getMember().getId())
.flatMap(ticket -> channel.sendMessageFormat("Twój ticket jest tutaj ---> %s", ticket))
.queue();
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.eternalcode.discordapp.ticket.command;

import com.eternalcode.discordapp.config.AppConfig;
import com.eternalcode.discordapp.ticket.command.alias.StartTicketCommand;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import net.dv8tion.jda.api.Permission;

public class TicketCommand extends SlashCommand {
public TicketCommand(AppConfig appConfig) {
this.name = "ticket";
this.help = "huj";
this.userPermissions = new Permission[]{ Permission.MESSAGE_MANAGE };

this.children = new SlashCommand[]{
new StartTicketCommand(appConfig)
};
}

@Override
public void execute(SlashCommandEvent event) {
/* This method is empty because uses children for sub-commands. */
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.eternalcode.discordapp.ticket.command.alias;

import com.eternalcode.discordapp.config.AppConfig;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.api.interactions.components.buttons.Button;

import java.awt.*;
import java.time.Instant;
import java.util.List;

public class StartTicketCommand extends SlashCommand {
private final AppConfig appConfig;

public StartTicketCommand(AppConfig appConfig) {
this.appConfig = appConfig;
this.name = "start";
this.help = "Starter ticket command";
this.userPermissions = new Permission[]{Permission.ADMINISTRATOR};
this.options = List.of(
new OptionData(OptionType.CHANNEL, "channel",
"channel to which the message is to be sent")
.setRequired(true)
);
}

@Override
protected void execute(SlashCommandEvent event) {
long optionChannelId = event.getOption("channel").getAsChannel().getIdLong();
MessageChannel optionChannel = event.getGuild().getTextChannelById(optionChannelId);
if (optionChannel != null) {
MessageEmbed ticketMessage = new EmbedBuilder()
.setTitle(this.appConfig.ticketSystem.ticketEmbedTitleMessage)
.setDescription(this.appConfig.ticketSystem.ticketEmbedDescriptionMessage)
.setColor(Color.decode(appConfig.embedSettings.successEmbed.color))
.setThumbnail(appConfig.embedSettings.successEmbed.thumbnail)
.setTimestamp(Instant.now())
.build();

Button firstButton = Button.success("create_ticket", this.appConfig.ticketSystem.ticketButtonMessage);

optionChannel.sendMessageEmbeds(ticketMessage)
.setActionRow(firstButton)
.queue();

MessageEmbed build = new EmbedBuilder()
.setTitle("Wiadomośc została wysłana")
.setColor(Color.decode(appConfig.embedSettings.successEmbed.color))
.setThumbnail(appConfig.embedSettings.successEmbed.thumbnail)
.setTimestamp(Instant.now())
.build();

event.replyEmbeds(build)
.setEphemeral(true)
.queue();
} else {
MessageEmbed errorMessage = new EmbedBuilder()
.setTitle("Błąd")
.setColor(Color.decode(appConfig.embedSettings.errorEmbed.color))
.setThumbnail(appConfig.embedSettings.errorEmbed.thumbnail)
.setTimestamp(Instant.now())
.setDescription("Podany kanał nie jest kanałem tekstowym")
.build();

event.replyEmbeds(errorMessage)
.setEphemeral(true)
.queue();
}
}
}
Loading