Skip to content

Commit 0959f61

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents ffa109b + 85eebba commit 0959f61

File tree

13 files changed

+116
-65
lines changed

13 files changed

+116
-65
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Designed to make developing bots faster and simpler!
1616
<dependency>
1717
<groupId>com.github.ice-games</groupId>
1818
<artifactId>java-discord-framework</artifactId>
19-
<version>1.2</version>
19+
<version>1.4</version>
2020
</dependency>
2121
```
2222

SECURITY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
| Version | Supported |
66
| ------- | ------------------ |
7+
| 1.3 | :white_check_mark: |
78
| 1.2 | :white_check_mark: |
89
| 1.1 | :white_check_mark: |
910
| 1.0 | :white_check_mark: |

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<dependency>
6060
<groupId>net.dv8tion</groupId>
6161
<artifactId>JDA</artifactId>
62-
<version>5.0.0-alpha.13</version>
62+
<version>5.0.0-alpha.17</version>
6363
</dependency>
6464
</dependencies>
6565

src/main/java/com/seailz/jdaframework/DiscordBot.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
import com.seailz.jdaframework.contextmenu.listeners.UserContextMenuListener;
99
import com.seailz.jdaframework.contextmenu.registry.ContextMenuRegistry;
1010
import com.seailz.jdaframework.modals.listeners.ModalListener;
11+
import com.seailz.jdaframework.select.SelectMenuListener;
1112
import lombok.Getter;
1213
import lombok.Setter;
1314
import net.dv8tion.jda.api.JDA;
1415
import net.dv8tion.jda.api.JDABuilder;
1516
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
17+
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
1618
import net.dv8tion.jda.api.hooks.EventListener;
1719
import net.dv8tion.jda.api.hooks.ListenerAdapter;
1820

@@ -32,6 +34,10 @@ public class DiscordBot {
3234
private static DiscordBot instance;
3335
@Getter
3436
private static HashMap<String, Consumer<ButtonInteractionEvent>> buttonRegistry;
37+
38+
@Getter
39+
private static HashMap<String, Consumer<SelectMenuInteractionEvent>> selectRegistry;
40+
3541
private String token;
3642
private JDA jda;
3743
private JDABuilder builder;
@@ -54,7 +60,8 @@ public DiscordBot(String token) {
5460
new UserContextMenuListener(),
5561
new CommandRunListener(),
5662
new ModalListener(),
57-
new ButtonListener()
63+
new ButtonListener(),
64+
new SelectMenuListener()
5865
);
5966
}
6067

src/main/java/com/seailz/jdaframework/command/listener/CommandRunListener.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
public class CommandRunListener extends ListenerAdapter {
1313
@Override
1414
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
15-
if (DiscordBot.getInstance().getRegistry().getCommands().containsKey(event.getName())) {
15+
if (DiscordBot.getInstance().getRegistry().getCommands().containsKey(event.getName()))
1616
DiscordBot.getInstance().getRegistry().getCommands().get(event.getName()).onCommand(event);
17-
}
1817
}
1918
}

src/main/java/com/seailz/jdaframework/modals/listeners/ModalListener.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.dv8tion.jda.api.interactions.modals.ModalMapping;
99
import org.jetbrains.annotations.NotNull;
1010

11+
import java.util.ConcurrentModificationException;
1112
import java.util.Map;
1213

1314
/**
@@ -19,14 +20,18 @@
1920
public class ModalListener extends ListenerAdapter {
2021

2122
@Override
22-
public void onModalInteraction(@NotNull ModalInteractionEvent e){
23+
public void onModalInteraction(@NotNull ModalInteractionEvent e) {
24+
Map.Entry<Member, Modal> culprit = null;
2325
for (Map.Entry<Member, Modal> modalEntry : ModalManager.getModals()) {
24-
if (modalEntry.getValue().getId().equals(e.getModalId()) && modalEntry.getKey().getId().equals(e.getMember().getId())){
26+
if (modalEntry.getValue().getId().equals(e.getModalId()) && modalEntry.getKey().getId().equals(e.getMember().getId())) {
2527
ModalMapping[] mappings = e.getValues().toArray(new ModalMapping[0]);
2628
modalEntry.getValue().getOnSubmit().accept(e.getMember(), mappings, e);
27-
ModalManager.getModals().remove(modalEntry);
29+
culprit = modalEntry;
30+
break;
2831
}
2932
}
30-
}
3133

34+
if (culprit != null)
35+
ModalManager.getModals().remove(culprit);
36+
}
3237
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.seailz.jdaframework.select;
2+
3+
import com.seailz.jdaframework.DiscordBot;
4+
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
5+
import net.dv8tion.jda.api.hooks.ListenerAdapter;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
public class SelectMenuListener extends ListenerAdapter {
9+
@Override
10+
public void onSelectMenuInteraction(@NotNull SelectMenuInteractionEvent event) {
11+
if (DiscordBot.getSelectRegistry().containsKey(event.getSelectMenu().getId())) {
12+
DiscordBot.getSelectRegistry().get(event.getSelectMenu().getId()).accept(event);
13+
}
14+
}
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.seailz.jdaframework.select;
2+
3+
import com.seailz.jdaframework.DiscordBot;
4+
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
5+
6+
import java.util.function.Consumer;
7+
8+
public class SelectMenuManager {
9+
10+
public static void listen(String id, Consumer<SelectMenuInteractionEvent> onClick) {
11+
DiscordBot.getSelectRegistry().put(id, onClick);
12+
}
13+
14+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.seailz.jdaframework.utils;
2+
3+
import java.util.Date;
4+
5+
/**
6+
* A util for creating timestamps, with ease.
7+
* @author Seailz
8+
*/
9+
public class TimestampUtil {
10+
11+
/**
12+
* Generates a Discord timestamp
13+
* @param type The type of timestamp you want to create
14+
* @param time The time it will represent
15+
* @return The generated timestamp
16+
*/
17+
public static String createTimestamp(Type type, Date time) {
18+
if (type == Type.BASE)
19+
return String.valueOf(time.getTime());
20+
String base = "<t:" + time.getTime() + ":";
21+
22+
switch (type) {
23+
case SHORT_DATE:
24+
base += "d";
25+
case LONG_DATE:
26+
base += "D";
27+
case SHORT_TIME:
28+
base += "t";
29+
case LONG_TIME:
30+
base += "T";
31+
case DATE_AND_TIME:
32+
base += "f";
33+
case LONG_DATE_AND_TIME:
34+
base += "F";
35+
case AGO:
36+
base += "R";
37+
}
38+
39+
base += ">";
40+
return base;
41+
}
42+
43+
/**
44+
* Timestamp types
45+
*/
46+
public enum Type {
47+
SHORT_DATE,
48+
// For example: 26/07/2022
49+
LONG_DATE,
50+
// For example: 26 July 2022
51+
SHORT_TIME,
52+
// For example 19:50
53+
LONG_TIME,
54+
// For example: 19:50:43
55+
DATE_AND_TIME,
56+
// For example: 26 July 2022 19:50
57+
LONG_DATE_AND_TIME,
58+
// For example: Tuesday, 26 July 2022 19:50
59+
AGO,
60+
// For example: 10 minutes ago
61+
BASE
62+
// For example: 1658861400
63+
}
64+
65+
}

src/main/java/com/seailz/jdaframework/utils/TriConsumer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* @param <T> Type
3636
* @param <U> Value 1
3737
* @param <U1> Value 2
38+
* @author Negative - https://www.github.com/negative-games
3839
*/
3940
@FunctionalInterface
4041
public interface TriConsumer<T, U, U1> {

0 commit comments

Comments
 (0)