Skip to content

Commit e2c57eb

Browse files
committed
Change DNApi Version (Go to 2.1.10.0-SNAPSHOT)
Fixing start command in console Creating stop command in console Adding start and stop command in Discord (with the bot) Creating link system with the bot (only get the service console for the moment) -> link command added ! Fixing bug (DNClientAPI client manager bug) Adding Help Command in the bot
1 parent 92f0e52 commit e2c57eb

23 files changed

+565
-84
lines changed

.idea/libraries/DreamNetworkV2_1_10_0_SNAPSHOT_api.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/DreamNetwork_api.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

dnapitest.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
</content>
88
<orderEntry type="inheritedJdk" />
99
<orderEntry type="sourceFolder" forTests="false" />
10-
<orderEntry type="library" name="DreamNetwork-api" level="project" />
1110
<orderEntry type="library" name="lombok" level="project" />
1211
<orderEntry type="library" name="json-simple-1.1.1" level="project" />
1312
<orderEntry type="library" name="JDA-4.4.0_350-withDependencies" level="project" />
13+
<orderEntry type="library" name="DreamNetworkV2-1.10.0-SNAPSHOT-api" level="project" />
1414
</component>
1515
</module>

src/fr/benjimania74/dnapitest/Main.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,22 @@
33
import be.alexandre01.dreamnetwork.api.DNClientAPI;
44
import be.alexandre01.dreamnetwork.api.addons.Addon;
55
import be.alexandre01.dreamnetwork.api.addons.DreamExtension;
6-
import be.alexandre01.dreamnetwork.api.connection.core.communication.IClient;
76
import be.alexandre01.dreamnetwork.client.console.Console;
87
import be.alexandre01.dreamnetwork.client.console.colors.Colors;
8+
import fr.benjimania74.dnapitest.bot.BotConfig;
99
import fr.benjimania74.dnapitest.bot.BotMain;
1010
import fr.benjimania74.dnapitest.registers.CommandsRegister;
1111
import fr.benjimania74.dnapitest.registers.ListenerRegister;
1212
import fr.benjimania74.dnapitest.utils.FilesManager;
1313

14-
import java.util.ArrayList;
15-
import java.util.List;
16-
1714
public class Main extends DreamExtension {
1815
public static DNClientAPI clientAPI;
1916
public static String addonName;
20-
public static List<IClient> clients;
2117

2218
@Override
2319
public void onLoad() {
2420
super.onLoad();
2521
addonName = getAddon().getDreamyName();
26-
clients = new ArrayList<>();
2722
new FilesManager();
2823
if(!new BotMain().create()){
2924
//stop();
@@ -50,6 +45,7 @@ public void start() {
5045
@Override
5146
public void stop() {
5247
super.stop();
48+
BotConfig.getInstance().save();
5349
Console.print(Colors.YELLOW + "[" + Colors.GREEN + addonName + Colors.YELLOW + "] " + Colors.CYAN + "The Plugin is Stopped");
5450
}
5551

src/fr/benjimania74/dnapitest/bot/BotConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class BotConfig {
3030
private HashMap<String, String> links = new HashMap<>();
3131
public HashMap<String, String> getLinks() {return links;}
3232
public void setLinks(HashMap<String, String> links) {this.links = links;}
33+
public void addLink(String serviceName, String discordChannel){links.put(serviceName, discordChannel); save();}
3334

3435
public BotConfig(){
3536
try {
@@ -41,7 +42,6 @@ public BotConfig(){
4142
JSONObject connectionsList = (JSONObject) object.get("link");
4243
HashMap<String, String> list = new HashMap<>();
4344
connectionsList.forEach((key, value) -> {
44-
System.out.println(key + " " + value);
4545
list.put((String) key, (String) value);
4646
});
4747

@@ -75,4 +75,6 @@ public void save(){
7575
Console.print(Colors.RED + "Can't save the Configuration File");
7676
}
7777
}
78+
79+
public void reload(){new BotConfig();}
7880
}

src/fr/benjimania74/dnapitest/bot/BotMain.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public boolean create(){
2828
new BotConfig();
2929

3030
String token = FilesManager.getInstance().read("token");
31-
new CommandsRegister().register();
3231

3332
JDABuilder builder = JDABuilder.createDefault(token)
3433
.enableIntents(GatewayIntent.GUILD_MESSAGES)
3534
.setStatus(OnlineStatus.fromKey(BotConfig.getInstance().getStatus()))
36-
.setActivity(Activity.playing(BotConfig.getInstance().getActivity()));
35+
.setActivity(Activity.playing(BotConfig.getInstance().getActivity() + " | Type " + BotConfig.getInstance().getPrefix() + "help"));
3736

3837
jda = builder.build();
38+
new CommandsRegister().register();
3939
jda.addEventListener(new MessageListener());
4040

4141
Console.print(Colors.GREEN_BACKGROUND + "The Bot is started");
@@ -52,4 +52,5 @@ public void registerCommand(Command command, Command... commands){
5252
commandsList.addAll(Arrays.asList(commands));
5353
}
5454
public void unregisterCommand(Command command){commandsList.remove(command);}
55+
public List<Command> getCommands(){return commandsList;}
5556
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package fr.benjimania74.dnapitest.bot;
22

3+
import fr.benjimania74.dnapitest.bot.cmd.utils.LinkCmd;
34
import fr.benjimania74.dnapitest.bot.cmd.services.StartCmd;
45
import fr.benjimania74.dnapitest.bot.cmd.services.StopCmd;
6+
import fr.benjimania74.dnapitest.bot.cmd.utils.HelpCmd;
57

68
public class CommandsRegister {
79
public void register(){
810
BotMain.instance.registerCommand(new StartCmd("start", "Start services command"),
9-
new StopCmd("stop", "Strop services command"));
11+
new StopCmd("stop", "Strop services command"),
12+
new HelpCmd("help", "See all commands"),
13+
new LinkCmd("link", "Link a console to Discord")
14+
);
1015
}
1116
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package fr.benjimania74.dnapitest.bot;
2+
3+
import be.alexandre01.dreamnetwork.api.connection.core.communication.IClient;
4+
import be.alexandre01.dreamnetwork.api.service.IContainer;
5+
import fr.benjimania74.dnapitest.Main;
6+
7+
public class ExecuteServerCmd {
8+
public void execute(String cmd, String serviceName, IContainer.JVMType type){
9+
for(IClient client : Main.clientAPI.getClientManager().getClients().values()){
10+
if(client.getJvmService().getJvmExecutor().getName().equals(serviceName) && client.getJvmType() == type){
11+
// EXECUTE COMMAND
12+
// SERVICE IS ONLINE
13+
return;
14+
}
15+
}
16+
17+
// SERVICE IS OFFLINE
18+
}
19+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package fr.benjimania74.dnapitest.bot;
2+
3+
import net.dv8tion.jda.api.entities.MessageEmbed;
4+
import net.dv8tion.jda.api.entities.TextChannel;
5+
6+
public class SendMessage {
7+
public void send(String msg, String channelID){
8+
if(!channelExist(channelID)){return;}
9+
send(msg, BotMain.instance.jda.getTextChannelById(channelID));
10+
}
11+
12+
public void send(String msg, TextChannel channel){channel.sendMessage(msg).queue(); }
13+
14+
public void send(MessageEmbed embed, String channelID){
15+
if(!channelExist(channelID)){return;}
16+
send(embed, BotMain.instance.jda.getTextChannelById(channelID));
17+
}
18+
19+
public void send(MessageEmbed embed, TextChannel channel) {
20+
channel.sendMessageEmbeds(embed).queue();
21+
}
22+
23+
private boolean channelExist(String channelID){
24+
for(TextChannel channel : BotMain.instance.jda.getTextChannels()){if(channel.getId().equals(channelID)){return true;}}
25+
return false;
26+
}
27+
}

src/fr/benjimania74/dnapitest/bot/cmd/services/StartCmd.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import fr.benjimania74.dnapitest.bot.cmd.Command;
66
import fr.benjimania74.dnapitest.utils.ServicesStarter;
77
import net.dv8tion.jda.api.EmbedBuilder;
8-
import net.dv8tion.jda.api.MessageBuilder;
98
import net.dv8tion.jda.api.entities.Message;
109
import net.dv8tion.jda.api.entities.TextChannel;
1110

0 commit comments

Comments
 (0)