geforkt von SteamWar/BungeeCore
Add DiscordBot
Dieser Commit ist enthalten in:
Ursprung
4a4f185c81
Commit
01cf6fdb58
39
pom.xml
39
pom.xml
@ -35,10 +35,31 @@
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>bungeecore</finalName>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>dv8tion</id>
|
||||
<name>m2-dv8tion</name>
|
||||
<url>https://m2.dv8tion.net/releases</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>steamwar</groupId>
|
||||
@ -61,5 +82,23 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${main.basedir}/lib/BungeeTabListPlus.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<version>4.3.0_299</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>club.minnced</groupId>
|
||||
<artifactId>opus-java</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.20</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -19,6 +19,8 @@
|
||||
|
||||
package de.steamwar.bungeecore;
|
||||
|
||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.commands.*;
|
||||
import de.steamwar.bungeecore.comms.SpigotReceiver;
|
||||
import de.steamwar.bungeecore.listeners.*;
|
||||
@ -141,6 +143,7 @@ public class BungeeCore extends Plugin {
|
||||
new EventStarter();
|
||||
new SessionManager();
|
||||
new SpigotReceiver();
|
||||
new SteamwarDiscordBot();
|
||||
new TablistManager();
|
||||
|
||||
getProxy().getScheduler().schedule(this, () -> {
|
||||
@ -254,6 +257,7 @@ public class BungeeCore extends Plugin {
|
||||
);
|
||||
|
||||
ArenaMode.init(config.getSection("games"));
|
||||
SteamwarDiscordBotConfig.loadConfig(config.getSection("discord"));
|
||||
|
||||
final Configuration servers = config.getSection("servers");
|
||||
for(final String serverName : servers.getKeys()){
|
||||
|
70
src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java
Normale Datei
70
src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java
Normale Datei
@ -0,0 +1,70 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.bot;
|
||||
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.bot.listeners.RolesInteractionButtonListener;
|
||||
import de.steamwar.bungeecore.bot.util.DiscordRolesMessage;
|
||||
import de.steamwar.bungeecore.bot.util.DiscordRulesMessage;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.OnlineStatus;
|
||||
import net.dv8tion.jda.api.entities.Activity;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
public class SteamwarDiscordBot {
|
||||
|
||||
private static SteamwarDiscordBot INSTANCE;
|
||||
|
||||
public static SteamwarDiscordBot instance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Getter
|
||||
private final JDA jda;
|
||||
|
||||
public SteamwarDiscordBot() {
|
||||
INSTANCE = this;
|
||||
JDABuilder builder = JDABuilder.createDefault(SteamwarDiscordBotConfig.TOKEN);
|
||||
builder.setActivity(Activity.playing("auf Steamwar.de"));
|
||||
builder.setStatus(OnlineStatus.ONLINE);
|
||||
try {
|
||||
jda = builder.build();
|
||||
} catch (LoginException e) {
|
||||
throw new SecurityException("Could not Login: " + SteamwarDiscordBotConfig.TOKEN, e);
|
||||
}
|
||||
try {
|
||||
jda.awaitReady();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
DiscordRolesMessage.sendMessage();
|
||||
DiscordRulesMessage.sendMessage();
|
||||
|
||||
new RolesInteractionButtonListener();
|
||||
}
|
||||
|
||||
public void addListener(ListenerAdapter listenerAdapter) {
|
||||
jda.addEventListener(listenerAdapter);
|
||||
}
|
||||
}
|
39
src/de/steamwar/bungeecore/bot/config/DiscordRole.java
Normale Datei
39
src/de/steamwar/bungeecore/bot/config/DiscordRole.java
Normale Datei
@ -0,0 +1,39 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.bot.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import net.dv8tion.jda.api.entities.Emoji;
|
||||
import net.dv8tion.jda.api.interactions.components.Button;
|
||||
import net.dv8tion.jda.api.interactions.components.ButtonStyle;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class DiscordRole {
|
||||
|
||||
private String emoji;
|
||||
private String label;
|
||||
private String roleId;
|
||||
|
||||
public Button toButton() {
|
||||
return Button.of(ButtonStyle.SECONDARY, roleId, label, Emoji.fromUnicode(emoji));
|
||||
}
|
||||
}
|
36
src/de/steamwar/bungeecore/bot/config/DiscordRulesLink.java
Normale Datei
36
src/de/steamwar/bungeecore/bot/config/DiscordRulesLink.java
Normale Datei
@ -0,0 +1,36 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.bot.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import net.dv8tion.jda.api.interactions.components.Button;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class DiscordRulesLink {
|
||||
|
||||
private String label;
|
||||
private String link;
|
||||
|
||||
public Button toButton() {
|
||||
return Button.link(link, label);
|
||||
}
|
||||
}
|
71
src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java
Normale Datei
71
src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java
Normale Datei
@ -0,0 +1,71 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.bot.config;
|
||||
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SteamwarDiscordBotConfig {
|
||||
|
||||
public static String TOKEN;
|
||||
public static String GUILD;
|
||||
public static String ROLES_CHANNEL;
|
||||
public static String ROLES_BASE_MESSAGE;
|
||||
public static String ROLES_ADDED;
|
||||
public static String ROLES_REMOVED;
|
||||
public static List<DiscordRole> ROLES;
|
||||
public static String RULES_CHANNEL;
|
||||
public static String RULES_TITLE;
|
||||
public static List<String> RULES_RULES;
|
||||
public static List<DiscordRulesLink> RULES_LINKS;
|
||||
|
||||
public static void loadConfig(Configuration config) {
|
||||
TOKEN = config.getString("token");
|
||||
GUILD = config.getString("guild");
|
||||
Configuration rolesSection = config.getSection("roles-claim");
|
||||
ROLES_CHANNEL = rolesSection.getString("channel");
|
||||
ROLES_BASE_MESSAGE = rolesSection.getString("base");
|
||||
ROLES_ADDED = rolesSection.getString("added");
|
||||
ROLES_REMOVED = rolesSection.getString("removed");
|
||||
ROLES = new ArrayList<>();
|
||||
|
||||
for (String roles : rolesSection.getSection("roles").getKeys()) {
|
||||
Configuration role = rolesSection.getSection("roles").getSection(roles);
|
||||
ROLES.add(new DiscordRole(role.getString("emoji"),
|
||||
role.getString("label"),
|
||||
role.getString("roleId")));
|
||||
}
|
||||
|
||||
Configuration rulesSection = config.getSection("rules");
|
||||
RULES_CHANNEL = rulesSection.getString("channel");
|
||||
RULES_TITLE = rulesSection.getString("title");
|
||||
RULES_RULES = rulesSection.getStringList("rules");
|
||||
|
||||
RULES_LINKS = new ArrayList<>();
|
||||
|
||||
for (String links : rulesSection.getSection("links").getKeys()) {
|
||||
Configuration link = rulesSection.getSection("links").getSection(links);
|
||||
RULES_LINKS.add(new DiscordRulesLink(link.getString("label"),
|
||||
link.getString("url")));
|
||||
}
|
||||
}
|
||||
}
|
30
src/de/steamwar/bungeecore/bot/listeners/BasicDiscordListener.java
Normale Datei
30
src/de/steamwar/bungeecore/bot/listeners/BasicDiscordListener.java
Normale Datei
@ -0,0 +1,30 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.bot.listeners;
|
||||
|
||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
public abstract class BasicDiscordListener extends ListenerAdapter {
|
||||
|
||||
BasicDiscordListener() {
|
||||
SteamwarDiscordBot.instance().addListener(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.bot.listeners;
|
||||
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent;
|
||||
import net.dv8tion.jda.api.interactions.InteractionType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RolesInteractionButtonListener extends BasicDiscordListener {
|
||||
|
||||
@Override
|
||||
public void onGenericComponentInteractionCreate(@NotNull GenericComponentInteractionCreateEvent event) {
|
||||
if(event.getType() == InteractionType.COMPONENT && event.getTextChannel().getId().equals(SteamwarDiscordBotConfig.ROLES_CHANNEL) && SteamwarDiscordBotConfig.ROLES.stream().anyMatch(discordRole -> discordRole.getRoleId().equals(event.getComponentId()))) {
|
||||
if (event.getMember().getRoles().stream().anyMatch(role -> role.getId().equals(event.getComponentId()))) {
|
||||
event.getGuild().removeRoleFromMember(event.getMember(), event.getGuild().getRoleById(event.getComponentId())).complete();
|
||||
event.reply(SteamwarDiscordBotConfig.ROLES_REMOVED.replace("%role%", event.getGuild().getRoleById(event.getComponentId()).getAsMention())).setEphemeral(true).complete();
|
||||
} else {
|
||||
event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(event.getComponentId())).complete();
|
||||
event.reply(SteamwarDiscordBotConfig.ROLES_ADDED.replace("%role%", event.getGuild().getRoleById(event.getComponentId()).getAsMention())).setEphemeral(true).complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
51
src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java
Normale Datei
51
src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java
Normale Datei
@ -0,0 +1,51 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.bot.util;
|
||||
|
||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||
import net.dv8tion.jda.api.interactions.components.Button;
|
||||
import net.dv8tion.jda.api.requests.restaction.MessageAction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DiscordRolesMessage {
|
||||
|
||||
public static void sendMessage() {
|
||||
TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.ROLES_CHANNEL);
|
||||
assert channel != null;
|
||||
if(channel.hasLatestMessage()) {
|
||||
channel.getIterableHistory().complete().forEach(message -> message.delete().complete());
|
||||
}
|
||||
|
||||
MessageBuilder builder = new MessageBuilder();
|
||||
builder.setContent(SteamwarDiscordBotConfig.ROLES_BASE_MESSAGE);
|
||||
List<Button> buttons = new ArrayList<>();
|
||||
SteamwarDiscordBotConfig.ROLES.forEach(discordRole -> buttons.add(discordRole.toButton()));
|
||||
builder.setActionRows(ActionRow.of(buttons));
|
||||
|
||||
MessageAction message = channel.sendMessage(builder.build());
|
||||
message.complete();
|
||||
}
|
||||
}
|
57
src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java
Normale Datei
57
src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java
Normale Datei
@ -0,0 +1,57 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.bot.util;
|
||||
|
||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||
import net.dv8tion.jda.api.interactions.components.Button;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DiscordRulesMessage {
|
||||
|
||||
public static void sendMessage() {
|
||||
TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.RULES_CHANNEL);
|
||||
assert channel != null;
|
||||
if(channel.hasLatestMessage()) {
|
||||
channel.getIterableHistory().complete().forEach(message -> message.delete().complete());
|
||||
}
|
||||
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(SteamwarDiscordBotConfig.RULES_RULES.stream().reduce((s, s2) -> s + "\n" + s2).get());
|
||||
builder.setColor(Color.CYAN);
|
||||
builder.setAuthor("SteamWar", "https://www.steamwar.de");
|
||||
builder.setTitle(SteamwarDiscordBotConfig.RULES_TITLE);
|
||||
|
||||
List<Button> buttons = new ArrayList<>();
|
||||
SteamwarDiscordBotConfig.RULES_LINKS.forEach(discordRulesLink -> buttons.add(discordRulesLink.toButton()));
|
||||
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.setEmbeds(builder.build());
|
||||
messageBuilder.setActionRows(ActionRow.of(buttons));
|
||||
channel.sendMessage(messageBuilder.build()).complete();
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren