Skip to content

Commit a783b1f

Browse files
committed
2.0.0-rc4
* Added Ticket System
1 parent af7f72d commit a783b1f

17 files changed

Lines changed: 793 additions & 98 deletions

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ bin/
4343

4444
### Configs ###
4545
config.yml
46-
votes.json
46+
votes.json
47+
/.idea/copilot.data.migration.agent.xml
48+
/.idea/copilot.data.migration.edit.xml
49+
/tickets.json

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66

77
application.mainClass = "de.skyking_px.PhoenixBot.Bot"
88
group = "de.skyking_px"
9-
version = "2.0.0-rc3"
9+
version = "2.0.0-rc4"
1010

1111
repositories {
1212
mavenCentral()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Fri Mar 07 14:23:45 CET 2025
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

src/main/java/de/skyking_px/PhoenixBot/Bot.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import de.skyking_px.PhoenixBot.listener.SupportListener;
1111
import de.skyking_px.PhoenixBot.listener.ThreadDeleteListener;
1212
import de.skyking_px.PhoenixBot.storage.VoteStorage;
13+
import de.skyking_px.PhoenixBot.storage.TicketStorage;
1314
import de.skyking_px.PhoenixBot.ticket.Panel;
15+
import de.skyking_px.PhoenixBot.util.TicketCloseHandler;
1416
import de.skyking_px.PhoenixBot.util.CloseHandler;
1517
import de.skyking_px.PhoenixBot.util.LogUploader;
1618
import de.skyking_px.PhoenixBot.util.Reload;
@@ -26,18 +28,24 @@
2628
import java.io.IOException;
2729

2830
public class Bot {
29-
public static final String VERSION = "2.0.0-rc3";
31+
public static final String VERSION = "2.0.0-rc4";
3032
private static final Logger logger = LoggerFactory.getLogger(Bot.class);
3133

3234
private static VoteStorage voteStorage;
35+
private static TicketStorage ticketStorage;
3336

3437
public static void initStorage() throws IOException {
3538
voteStorage = new VoteStorage();
39+
ticketStorage = new TicketStorage();
3640
}
3741

3842
public static VoteStorage getVoteStorage() {
3943
return voteStorage;
4044
}
45+
46+
public static TicketStorage getTicketStorage() {
47+
return ticketStorage;
48+
}
4149

4250
public static void main(String[] args) throws Exception {
4351
initStorage();
@@ -57,6 +65,7 @@ public static void main(String[] args) throws Exception {
5765
new FaqHandler(),
5866
new Reload(),
5967
new Panel(),
68+
new TicketCloseHandler(),
6069
new ThreadDeleteListener())
6170
.enableIntents(GatewayIntent.MESSAGE_CONTENT)
6271
.setActivity(Activity.playing(Config.get().getBot().getActivity()))

src/main/java/de/skyking_px/PhoenixBot/Config.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class Config {
2424
private BugReport bugReport;
2525
private Support support;
2626
private Faq faq;
27+
private Tickets tickets;
2728

2829
public static Config get() throws IOException {
2930
if (instance == null) {
@@ -52,6 +53,7 @@ private void load() throws IOException {
5253
this.bugReport = loaded.bugReport;
5354
this.support = loaded.support;
5455
this.faq = loaded.faq;
56+
this.tickets = loaded.tickets;
5557
}
5658
}
5759

@@ -66,6 +68,7 @@ private void createDefaultConfig() throws IOException {
6668
token: "YOUR_BOT_TOKEN"
6769
activity: ""
6870
owner_id: "YOUR_DISCORD_USER_ID"
71+
guild_id: "YOUR_DISCORD_GUILD_ID"
6972
7073
logging:
7174
channel_id: "1353805483428937738"
@@ -89,6 +92,9 @@ private void createDefaultConfig() throws IOException {
8992
answer: "**A:** ."
9093
imageUrl: ""
9194
thumbnailUrl: ""
95+
96+
tickets:
97+
pingRoles: ["1416379517928476773", "1123224748571238430"]
9298
""";
9399

94100
// ImageUrl is below the question and answer
@@ -121,10 +127,14 @@ private void createDefaultConfig() throws IOException {
121127
public Faq getFaq() { return faq; }
122128
public void setFaq(Faq faq) { this.faq = faq; }
123129

130+
public Tickets getTickets() { return tickets; }
131+
public void setTickets(Tickets tickets) { this.tickets = tickets; }
132+
124133
public static class Bot {
125134
private String token;
126135
private String activity;
127136
private String owner_id;
137+
private String guild_id;
128138

129139
public String getToken() { return token; }
130140
public void setToken(String token) { this.token = token; }
@@ -134,6 +144,9 @@ public static class Bot {
134144

135145
public String getOwner_id() { return owner_id; }
136146
public void setOwner_id(String owner_id) { this.owner_id = owner_id; }
147+
148+
public String getGuild_id() { return guild_id; }
149+
public void setGuild_id(String guild_id) { this.guild_id = guild_id; }
137150
}
138151

139152
public static class Logging {
@@ -174,4 +187,10 @@ public static class Faq {
174187
public FaqEntry[] getFaq_entries() { return faq_entries; }
175188
public void setFaq_entries(FaqEntry[] faq_entries) { this.faq_entries = faq_entries; }
176189
}
190+
191+
public static class Tickets {
192+
private String[] pingRoles;
193+
public String[] getPingRoles() { return pingRoles; }
194+
public void setPingRoles(String[] pingRoles) { this.pingRoles = pingRoles; }
195+
}
177196
}
Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package de.skyking_px.PhoenixBot;
22

33
import de.skyking_px.PhoenixBot.command.*;
4-
import de.skyking_px.PhoenixBot.faq.FaqHandler;
5-
import de.skyking_px.PhoenixBot.util.Reload;
64
import net.dv8tion.jda.api.JDA;
75
import net.dv8tion.jda.api.entities.Guild;
86
import net.dv8tion.jda.api.events.session.ReadyEvent;
@@ -14,8 +12,9 @@
1412

1513
import java.io.IOException;
1614
import java.time.Instant;
17-
import java.util.Objects;
1815
import java.util.concurrent.TimeUnit;
16+
import de.skyking_px.PhoenixBot.storage.TicketStorage;
17+
import de.skyking_px.PhoenixBot.ticket.Panel;
1918

2019
public class Listener extends ListenerAdapter {
2120
private static final Logger logger = LoggerFactory.getLogger(Bot.class);
@@ -24,43 +23,26 @@ public class Listener extends ListenerAdapter {
2423
@Override
2524
public void onReady(@NotNull ReadyEvent event) {
2625
JDA api = event.getJDA();
27-
try {
28-
logger.info("[BOT] Resetting Commands...");
29-
api.retrieveCommands().queue(commands -> {
30-
for (Command cmd : commands) {
31-
api.deleteCommandById(cmd.getId()).queue();
32-
}
33-
});
34-
TimeUnit.SECONDS.sleep(2);
35-
for (Guild guild : api.getGuilds()) {
36-
guild.retrieveCommands().queue(commands -> {
37-
for (Command cmd : commands) {
38-
guild.deleteCommandById(cmd.getId()).queue();
39-
}
40-
});
41-
}
42-
logger.info("[BOT] Commands were reset.");
43-
} catch (Exception e) {
44-
logger.error("[BOT] An Error occurred while trying to reset commands!", e);
45-
}
46-
try {
47-
TimeUnit.SECONDS.sleep(10);
48-
logger.info("[BOT] Applying Commands...");
49-
api.updateCommands()
50-
.addCommands(CommandRegistry.regiserCommands())
51-
.queue();
52-
logger.info("[BOT] Commands applied.");
53-
} catch (Exception e) {
54-
logger.error("[BOT] An Error occurred while trying to register commands!", e);
55-
}
26+
27+
logger.info("[BOT] Registering Commands...");
28+
29+
api.updateCommands()
30+
.addCommands(CommandRegistry.registerCommands())
31+
.queue(success -> logger.info("[BOT] Global commands updated."));
32+
5633
try {
5734
logger.info("[BOT] Initializing voting storage...");
5835
Bot.initStorage();
5936
logger.info("[BOT] Voting storage initialized.");
37+
38+
logger.info("[BOT] Restoring pending tickets...");
39+
Panel.restorePendingTickets(api);
40+
logger.info("[BOT] Pending tickets restored.");
6041
} catch (IOException e) {
61-
logger.error("[BOT] An Error occurred while trying to initialize voting storage!");
42+
logger.error("[BOT] An Error occurred while trying to initialize storage!");
6243
}
44+
6345
START_TIME = Instant.now();
6446
logger.info("[BOT] Bot is ready.");
6547
}
66-
}
48+
}

src/main/java/de/skyking_px/PhoenixBot/command/CommandRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.List;
1010

1111
public class CommandRegistry {
12-
public static List<CommandData> regiserCommands() {
12+
public static List<CommandData> registerCommands() {
1313
CommandData faq = Commands.slash("faq", "Suggests a user to read the FAQ")
1414
.addOptions(
1515
new OptionData(OptionType.USER, "user", "Optionally choose if you want to ping a member", false)

src/main/java/de/skyking_px/PhoenixBot/faq/FaqHandler.java

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,37 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent even
3333
return;
3434
}
3535

36-
FaqHandler.sendFaqMessages(event.getGuild());
37-
event.getHook().sendMessage("✅ FAQ messages sent!").setEphemeral(true).queue();
38-
}
39-
}
36+
try {
37+
Config config = Config.get();
38+
TextChannel faqChannel = event.getGuild().getTextChannelById(config.getFaq().getFaq_channel_id());
4039

41-
public static void sendFaqMessages(Guild guild) {
42-
try {
43-
Config config = Config.get();
44-
TextChannel faqChannel = guild.getTextChannelById(config.getFaq().getFaq_channel_id());
40+
if (faqChannel == null) {
41+
logger.info("[BOT] FAQ Channel not found.");
42+
event.getHook().sendMessage("❌ FAQ channel not found!").setEphemeral(true).queue();
43+
return;
44+
}
4545

46-
if (faqChannel == null) {
47-
logger.info("[BOT] FAQ Channel not found.");
48-
return;
49-
}
46+
for (FaqEntry entry : config.getFaq().getFaq_entries()) {
47+
EmbedBuilder embed = new EmbedBuilder()
48+
.setTitle(MessageHandler.parseEmojis(event.getJDA(), entry.getQuestion()))
49+
.setColor(HexFormat.fromHexDigits("2073cb"));
5050

51-
for (FaqEntry entry : config.getFaq().getFaq_entries()) {
52-
EmbedBuilder embed = new EmbedBuilder()
53-
.setTitle(MessageHandler.parseEmojis(guild.getJDA(), entry.getQuestion()))
54-
.setColor(HexFormat.fromHexDigits("2073cb"));
51+
if (entry.getAnswer() != null && !entry.getAnswer().isEmpty()) {
52+
embed.setDescription(MessageHandler.parseEmojis(event.getJDA(), entry.getAnswer()));
53+
}
5554

56-
if (entry.getAnswer() != null && !entry.getAnswer().isEmpty()) {
57-
embed.setDescription(MessageHandler.parseEmojis(guild.getJDA(), entry.getAnswer()));
58-
}
55+
if (entry.getThumbnailUrl() != null && !entry.getThumbnailUrl().isEmpty()) {
56+
embed.setThumbnail(entry.getThumbnailUrl());
57+
} else if (entry.getImageUrl() != null && !entry.getImageUrl().isEmpty()) {
58+
embed.setImage(entry.getImageUrl());
59+
}
5960

60-
if (entry.getThumbnailUrl() != null && !entry.getThumbnailUrl().isEmpty()) {
61-
embed.setThumbnail(entry.getThumbnailUrl());
62-
} else if (entry.getImageUrl() != null && !entry.getImageUrl().isEmpty()) {
63-
embed.setImage(entry.getImageUrl());
61+
faqChannel.sendMessageEmbeds(embed.build()).queue();
6462
}
65-
66-
faqChannel.sendMessageEmbeds(embed.build()).queue();
63+
} catch (IOException e) {
64+
logger.error("[BOT] Error while sending FAQ messages.", e);
6765
}
68-
} catch (IOException e) {
69-
logger.error("[BOT] Error while sending FAQ messages.", e);
66+
event.getHook().sendMessage("✅ FAQ messages sent!").setEphemeral(true).queue();
7067
}
7168
}
7269
}

src/main/java/de/skyking_px/PhoenixBot/listener/BugReportListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ public class BugReportListener extends ListenerAdapter {
2626

2727
@Override
2828
public void onChannelCreate(ChannelCreateEvent event) {
29-
ThreadChannel thread = event.getChannel().asThreadChannel();
30-
ForumChannel parent = thread.getParentChannel().asForumChannel();
3129
try {
30+
ThreadChannel thread = event.getChannel().asThreadChannel();
31+
ForumChannel parent = thread.getParentChannel().asForumChannel();
3232
if (!parent.getId().equals(Config.get().getBugReport().getBugReport_forum_id())) return;
3333
} catch (IOException e) {
3434
logger.error("[BOT] Fatal Error - Couldn't get Bug Report Forum ID");
35+
} catch (IllegalStateException e) {
36+
logger.error("[BOT] Error - Incorrect channel type, ignoring");
3537
}
3638

3739
MessageEmbed embed = new EmbedBuilder()

src/main/java/de/skyking_px/PhoenixBot/listener/SuggestionListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ public SuggestionListener(VoteStorage storage) throws IOException {
3838

3939
@Override
4040
public void onChannelCreate(ChannelCreateEvent event) {
41-
ThreadChannel thread = event.getChannel().asThreadChannel();
42-
ForumChannel parent = thread.getParentChannel().asForumChannel();
4341
try {
42+
ThreadChannel thread = event.getChannel().asThreadChannel();
43+
ForumChannel parent = thread.getParentChannel().asForumChannel();
4444
if (!parent.getId().equals(Config.get().getVoting().getSuggestions_forum_id())) return;
4545
} catch (IOException e) {
4646
logger.error("[BOT] Fatal Error - Couldn't get Suggestions Forum ID");
47+
} catch (IllegalStateException e) {
48+
logger.error("[BOT] Error - Incorrect channel type, ignoring");
4749
}
4850

4951
MessageEmbed embed = new EmbedBuilder()

0 commit comments

Comments
 (0)