Skip to content

Commit 52c592a

Browse files
committed
Release 1.5
- Add Questions forum related events. - Add auto complete feature. - Send "Oh boy 3 am" at underground channel at 3 am on every day. - Add /transfer command. - Add part of /minesweeper command (not complete yet). - Add Raw Text message command. - Add Reactions message command. - Translate README.md to 4 languages. - Tranlsate /lottery command.
1 parent 41c63c0 commit 52c592a

File tree

8 files changed

+164
-52
lines changed

8 files changed

+164
-52
lines changed

src/main/java/cartoland/Cartoland.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ public static void main(String[] args) throws InterruptedException
3333
new AutoComplete(), //當指令需要自動補完
3434
new ContextMenu(), //當有人使用右鍵功能
3535
new GetRole(), //當有人獲得會員身分組
36-
new JoinServer()/*, //當有人加入創聯
37-
new OpenFormPost()*/) //當有人在Questions論壇發文
36+
new JoinServer(), //當有人加入創聯
37+
new OpenQuestionsForumPost(), //當有人在Questions論壇發文
38+
new QuestionForumMessage()) //當有人在Questions論壇講話
3839
.enableIntents(GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_MEMBERS)
3940
.setMemberCachePolicy(MemberCachePolicy.ALL)
4041
.setActivity(Activity.playing("Use /help to check more information")) //正在玩

src/main/java/cartoland/events/AutoComplete.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void completeProcess(CommandAutoCompleteInteractionEvent event)
7373
.map(word -> new Command.Choice((String) word, (String) word))
7474
.collect(Collectors.toList());
7575

76-
event.replyChoices((choices.size() <= CHOICES_LIMIT) ? choices : choices.subList(0, CHOICES_LIMIT)).queue();
76+
event.replyChoices(choices.size() <= CHOICES_LIMIT ? choices : choices.subList(0, CHOICES_LIMIT)).queue();
7777
}
7878
}
7979
}

src/main/java/cartoland/events/BotOnline.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.jetbrains.annotations.NotNull;
77

88
import java.time.Duration;
9-
import java.time.LocalTime;
9+
import java.time.LocalDateTime;
1010
import java.util.concurrent.Executors;
1111
import java.util.concurrent.TimeUnit;
1212

@@ -35,6 +35,10 @@ public void onReady(@NotNull ReadyEvent event)
3535
if (cartolandServer == null)
3636
problemOccurred("Can't find Cartoland Server");
3737

38+
questionsChannel = cartolandServer.getForumChannelById(QUESTIONS_CHANNEL_ID);
39+
if (questionsChannel == null)
40+
problemOccurred("Can't find Questions Channel.");
41+
3842
lobbyChannel = cartolandServer.getTextChannelById(LOBBY_CHANNEL_ID); //創聯的大廳頻道
3943
if (lobbyChannel == null)
4044
problemOccurred("Can't find Lobby Channel.");
@@ -47,6 +51,14 @@ public void onReady(@NotNull ReadyEvent event)
4751
if (undergroundChannel == null)
4852
problemOccurred("Can't find Underground Channel.");
4953

54+
resolvedForumTag = questionsChannel.getAvailableTagById(RESOLVED_FORUM_TAG_ID);
55+
if (resolvedForumTag == null)
56+
problemOccurred("Can't find Resolved Forum Tag");
57+
58+
unresolvedForumTag = questionsChannel.getAvailableTagById(UNRESOLVED_FORUM_TAG_ID);
59+
if (unresolvedForumTag == null)
60+
problemOccurred("Can't find Unresolved Forum Tag");
61+
5062
memberRole = cartolandServer.getRoleById(MEMBER_ROLE_ID); //會員身分組
5163
if (memberRole == null)
5264
problemOccurred("Can't find Member Role.");
@@ -69,23 +81,25 @@ public void onReady(@NotNull ReadyEvent event)
6981
* When an error occurred, an entity is null.
7082
*
7183
* @param logString The content that will print to standard error stream and log file.
84+
* @throws NullPointerException always throw
7285
*/
7386
private void problemOccurred(String logString)
7487
{
7588
System.err.println(logString);
7689
System.err.print('\u0007');
7790
FileHandle.log(logString);
7891
jda.shutdownNow();
92+
throw new NullPointerException();
7993
}
8094

8195
//https://stackoverflow.com/questions/65984126
8296
private void ohBoy3AM()
8397
{
84-
LocalTime now = LocalTime.now();
85-
LocalTime threeAM = now.withHour(3).withMinute(0).withSecond(0);
98+
LocalDateTime now = LocalDateTime.now();
99+
LocalDateTime threeAM = now.withHour(3).withMinute(0).withSecond(0);
86100

87101
if (now.compareTo(threeAM) > 0)
88-
threeAM = threeAM.plusHours(24);
102+
threeAM = threeAM.plusDays(1L);
89103

90104
long secondsUntil3AM = Duration.between(now, threeAM).getSeconds();
91105

src/main/java/cartoland/events/ChannelMessage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event)
141141
if (Algorithm.chance(20) && rawMessage.contains("wow")) //20%
142142
message.addReaction(wow).queue();
143143

144-
if ((categoryID == IDAndEntities.GENERAL_CATEGORY_ID || categoryID == IDAndEntities.TECH_TALK_CATEGORY_ID)
145-
&& channel.getIdLong() != IDAndEntities.BOT_CHANNEL_ID) //在一般或技術討論區類別 且不是在機器人專區
144+
//在一般、技術討論區或公眾區域類別 且不是在機器人專區
145+
if (channel.getIdLong() != IDAndEntities.BOT_CHANNEL_ID && IDAndEntities.commandBlockCategories.contains(categoryID))
146146
CommandBlocksHandle.addCommandBlocks(userID, rawMessage.length()); //說話加等級
147147
}
148148

src/main/java/cartoland/events/OpenFormPost.java

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package cartoland.events;
2+
3+
import cartoland.utilities.IDAndEntities;
4+
import net.dv8tion.jda.api.EmbedBuilder;
5+
import net.dv8tion.jda.api.entities.MessageEmbed;
6+
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
7+
import net.dv8tion.jda.api.entities.channel.forums.ForumTag;
8+
import net.dv8tion.jda.api.events.channel.ChannelCreateEvent;
9+
import net.dv8tion.jda.api.hooks.ListenerAdapter;
10+
import org.jetbrains.annotations.NotNull;
11+
12+
import java.awt.Color;
13+
import java.util.ArrayList;
14+
import java.util.List;
15+
16+
/**
17+
* {@code OpenQuestionsForumPost} is a listener that triggers when a user create a forum post. This class was
18+
* registered in {@link cartoland.Cartoland#main}, with the build of JDA.
19+
*
20+
* @since 1.5
21+
* @author Alex Cai
22+
*/
23+
public class OpenQuestionsForumPost extends ListenerAdapter
24+
{
25+
private final MessageEmbed startEmbed = new EmbedBuilder()
26+
.setTitle("**-=發問指南=-**", null)
27+
.setDescription("""
28+
-=發問指南=-
29+
30+
• 請清楚說明你想做什麼,並想要什麼結果
31+
• 請提及你正在使用的Minecraft版本,以及是否正在使用任何模組
32+
• 討論完成後,使用✅表情符號關閉貼文
33+
34+
-=Guidelines=-
35+
36+
• Ask your question straight and clearly, tell us what you are trying to do.
37+
• Mention which Minecraft version you are using and any mods.
38+
• Remember to use ✅ to close the post after resolved.
39+
""")
40+
.setColor(new Color(133, 201, 103))
41+
.build();
42+
43+
@Override
44+
public void onChannelCreate(@NotNull ChannelCreateEvent event)
45+
{
46+
if (!event.getChannelType().isThread())
47+
return;
48+
49+
ThreadChannel forumPost = event.getChannel().asThreadChannel();
50+
if (forumPost.getParentChannel().getIdLong() != IDAndEntities.QUESTIONS_CHANNEL_ID)
51+
return;
52+
53+
forumPost.addThreadMember(IDAndEntities.botItself).queue();
54+
forumPost.sendMessageEmbeds(startEmbed).queue();
55+
56+
List<ForumTag> tags = new ArrayList<>(forumPost.getAppliedTags());
57+
tags.remove(IDAndEntities.resolvedForumTag);
58+
if (!tags.contains(IDAndEntities.unresolvedForumTag))
59+
{
60+
if (tags.size() == 5) //不可以超過5個tag
61+
tags.remove(4);
62+
tags.add(IDAndEntities.unresolvedForumTag);
63+
}
64+
forumPost.getManager().setAppliedTags(tags).queue();
65+
}
66+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package cartoland.events;
2+
3+
import cartoland.utilities.IDAndEntities;
4+
import net.dv8tion.jda.api.entities.User;
5+
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
6+
import net.dv8tion.jda.api.entities.channel.forums.ForumTag;
7+
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
8+
import net.dv8tion.jda.api.hooks.ListenerAdapter;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
14+
/**
15+
* {@code QuestionForumMessage} is a listener that triggers when a user types anything in any forum post in
16+
* Questions forum channel. This class was registered in {@link cartoland.Cartoland#main}, with the build of JDA.
17+
*
18+
* @since 1.5
19+
* @author Alex Cai
20+
*/
21+
public class QuestionForumMessage extends ListenerAdapter
22+
{
23+
@Override
24+
public void onMessageReceived(@NotNull MessageReceivedEvent event)
25+
{
26+
if (!event.getChannelType().isThread()) //不是討論串 or 論壇貼文
27+
return;
28+
29+
User author = event.getAuthor();
30+
if (author.isBot() || author.isSystem()) //是機器人或系統
31+
return;
32+
33+
ThreadChannel forumPost = event.getChannel().asThreadChannel();
34+
if (forumPost.getParentChannel().getIdLong() != IDAndEntities.QUESTIONS_CHANNEL_ID) //不在問題論壇
35+
return;
36+
37+
List<ForumTag> tags = forumPost.getAppliedTags();
38+
if (!forumPost.isArchived() && event.getMessage().getContentRaw().equals("✅"))
39+
{
40+
tags = new ArrayList<>(tags);
41+
tags.remove(IDAndEntities.unresolvedForumTag);
42+
tags.add(IDAndEntities.resolvedForumTag);
43+
forumPost.getManager().setAppliedTags(tags).setArchived(true).queue(); //關閉貼文
44+
}
45+
else if (forumPost.isArchived() && tags.contains(IDAndEntities.resolvedForumTag))
46+
{
47+
tags = new ArrayList<>(tags);
48+
tags.remove(IDAndEntities.resolvedForumTag);
49+
tags.add(IDAndEntities.unresolvedForumTag);
50+
forumPost.getManager().setAppliedTags(tags).queue(); //打開貼文
51+
}
52+
}
53+
}

src/main/java/cartoland/utilities/IDAndEntities.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import net.dv8tion.jda.api.entities.Guild;
55
import net.dv8tion.jda.api.entities.Role;
66
import net.dv8tion.jda.api.entities.User;
7+
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
78
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
9+
import net.dv8tion.jda.api.entities.channel.forums.ForumTag;
810

9-
import java.util.concurrent.Executors;
11+
import java.util.ArrayList;
12+
import java.util.List;
1013
import java.util.concurrent.ScheduledExecutorService;
1114
import java.util.concurrent.ScheduledFuture;
1215

@@ -25,21 +28,35 @@ private IDAndEntities()
2528
}
2629

2730
public static final long CARTOLAND_SERVER_ID = 886936474723950603L; //創聯
28-
public static final long QUESTIONS_CHANNEL_ID = 1079073022624940044L; //問題諮詢
31+
public static final long GENERAL_CATEGORY_ID = 886936474723950608L; //創聯的一般類別
32+
public static final long TECH_TALK_CATEGORY_ID = 974224793727537182L; //創聯的技術討論區類別
33+
public static final long PUBLIC_AREA_CATEGORY_ID = 922892242459459657L; //創聯的公眾區域類別
34+
public static final long QUESTIONS_CHANNEL_ID = 1079073022624940044L; //創聯的問題諮詢頻道
2935
public static final long LOBBY_CHANNEL_ID = 886936474723950611L; //創聯的大廳頻道
3036
public static final long BOT_CHANNEL_ID = 891703579289718814L; //創聯的機器人頻道
3137
public static final long UNDERGROUND_CHANNEL_ID = 962688156942073887L; //創聯的地下頻道
32-
public static final long GENERAL_CATEGORY_ID = 886936474723950608L; //創聯的一般類別
33-
public static final long TECH_TALK_CATEGORY_ID = 974224793727537182L; //創聯的技術討論區類別
38+
public static final long RESOLVED_FORUM_TAG_ID = 1079074167468605490L; //已解決的tag
39+
public static final long UNRESOLVED_FORUM_TAG_ID = 1079074098493280347L; //未解決的tag
3440
public static final long MEMBER_ROLE_ID = 892415577002504272L; //會員身分組
3541
public static final long NSFW_ROLE_ID = 919700598612426814L; //地下身分組
3642
public static final long AC_ID = 355953951469731842L;
3743

44+
public static final List<Long> commandBlockCategories = new ArrayList<>(3);
45+
static
46+
{
47+
commandBlockCategories.add(GENERAL_CATEGORY_ID);
48+
commandBlockCategories.add(TECH_TALK_CATEGORY_ID);
49+
commandBlockCategories.add(PUBLIC_AREA_CATEGORY_ID);
50+
}
51+
3852
public static JDA jda;
3953
public static Guild cartolandServer;
54+
public static ForumChannel questionsChannel;
4055
public static TextChannel lobbyChannel;
4156
public static TextChannel botChannel;
4257
public static TextChannel undergroundChannel;
58+
public static ForumTag resolvedForumTag;
59+
public static ForumTag unresolvedForumTag;
4360
public static Role memberRole;
4461
public static Role nsfwRole;
4562
public static User botItself;

0 commit comments

Comments
 (0)