Skip to content

Commit

Permalink
adding a base ticket code 😊
Browse files Browse the repository at this point in the history
  • Loading branch information
ChudziudgiToJa committed Feb 17, 2024
1 parent 9567b38 commit 803ecc4
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 32 deletions.
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
2 changes: 1 addition & 1 deletion src/main/java/com/eternalcode/discordapp/DiscordApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static void main(String... args) throws InterruptedException {
new LeaderboardButtonController(leaderboardService),

// Ticket
new TicketButtonController()
new TicketButtonController(config)
)

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

@Description("# Ticket category channel id")
public long ticketCategoryId = 1079787699336134859L;
@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) {
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
Expand Up @@ -2,42 +2,49 @@

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

import net.dv8tion.jda.api.entities.channel.concrete.Category;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
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 net.dv8tion.jda.api.requests.restaction.ChannelAction;

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")) {
long ticketCategoryId = appConfig.ticketCategoryId;
Category ticketCategory = event.getGuild().getCategoryById(ticketCategoryId);
Member member = event.getMember();
assert member != null;

if (event.getGuild().getTextChannelsByName(member.getId(), true).isEmpty()) {
event.reply("Posiadasz juz otwarty ticket bratku essa");
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());
}

ChannelAction<TextChannel> ticketAction = ticketCategory.createTextChannel(member.getId());
TextChannel ticket = ticketAction.complete();

EmbedBuilder embedBuilder = new EmbedBuilder().setTitle("Twój ticket został utworzony")
.setColor(Color.GREEN)
.setDescription("Tutaj możesz zgłaszać swoje problemy.");
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());
}

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

event.reply("Twój ticket został utworzony.").setEphemeral(true).queue();
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.entities.emoji.Emoji;
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;
Expand All @@ -24,9 +22,7 @@ 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")
Expand All @@ -38,16 +34,16 @@ public StartTicketCommand(AppConfig appConfig) {
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("Ticket")
.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", "Otwórz bilet");
Button firstButton = Button.success("create_ticket", this.appConfig.ticketSystem.ticketButtonMessage);

optionChannel.sendMessageEmbeds(ticketMessage)
.setActionRow(firstButton)
Expand Down

0 comments on commit 803ecc4

Please sign in to comment.