geforkt von SteamWar/BungeeCore
Merge branch 'master' into schem_nodes
# Conflicts: # src/de/steamwar/bungeecore/commands/CheckCommand.java
Dieser Commit ist enthalten in:
Commit
bb1a2d327e
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.*;
|
||||
@ -29,6 +31,7 @@ import de.steamwar.bungeecore.listeners.mods.WorldDownloader;
|
||||
import de.steamwar.bungeecore.sql.SQL;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.bungeecore.sql.Team;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@ -124,6 +127,7 @@ public class BungeeCore extends Plugin {
|
||||
new ResourcereloadCommand();
|
||||
new ListCommand();
|
||||
new StatCommand();
|
||||
new VerifyCommand();
|
||||
|
||||
if(!EVENT_MODE){
|
||||
new WebregisterCommand();
|
||||
@ -141,6 +145,7 @@ public class BungeeCore extends Plugin {
|
||||
new EventStarter();
|
||||
new SessionManager();
|
||||
new SpigotReceiver();
|
||||
new SteamwarDiscordBot();
|
||||
new TablistManager();
|
||||
|
||||
getProxy().getScheduler().schedule(this, () -> {
|
||||
@ -153,6 +158,12 @@ public class BungeeCore extends Plugin {
|
||||
public void onDisable(){
|
||||
ErrorLogger.stop();
|
||||
SQL.close();
|
||||
try {
|
||||
SteamwarDiscordBot.instance().getJda().shutdownNow();
|
||||
SteamwarDiscordBot.instance().getJda().awaitStatus(JDA.Status.SHUTDOWN);
|
||||
} catch (Exception e) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
|
||||
public static BungeeCore get() {
|
||||
@ -254,6 +265,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()){
|
||||
|
86
src/de/steamwar/bungeecore/bot/AuthManager.java
Normale Datei
86
src/de/steamwar/bungeecore/bot/AuthManager.java
Normale Datei
@ -0,0 +1,86 @@
|
||||
/*
|
||||
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.BungeeCore;
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Emoji;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||
import net.dv8tion.jda.api.interactions.components.Button;
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class AuthManager {
|
||||
|
||||
private static final Map<String, Long> TOKENS = new HashMap<>();
|
||||
private static final Random rand = new Random();
|
||||
|
||||
public static String createDiscordAuthToken(Member member) {
|
||||
if(TOKENS.containsValue(member.getIdLong())) return null;
|
||||
|
||||
byte[] randBytes = new byte[16];
|
||||
rand.nextBytes(randBytes);
|
||||
randBytes[0] = 'D';
|
||||
randBytes[1] = 'C';
|
||||
String code = Base64.getEncoder().encodeToString(randBytes);
|
||||
|
||||
TOKENS.put(code, member.getIdLong());
|
||||
BungeeCore.log("Created Discord Auth-Token: " + code + " for: " + member.getUser().getAsTag());
|
||||
ScheduledTask[] task = new ScheduledTask[1];
|
||||
task[0] = BungeeCore.get().getProxy().getScheduler().schedule(BungeeCore.get(), () -> {
|
||||
TOKENS.remove(code);
|
||||
task[0].cancel();
|
||||
}, 10, 10, TimeUnit.MINUTES);
|
||||
return code;
|
||||
}
|
||||
|
||||
public static Member connectAuth(SteamwarUser user, String code) {
|
||||
if (TOKENS.containsKey(code)) {
|
||||
Member member = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).retrieveMemberById(TOKENS.get(code).longValue()).complete();
|
||||
if(member == null) return null;
|
||||
user.setDiscordId(member.getId());
|
||||
MessageBuilder builder = new MessageBuilder();
|
||||
builder.setContent(":white_check_mark: Dein Discord Konto wurde mit **" + user.getUserName() + "** verknüpft");
|
||||
builder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")), Button.danger("invalid", "Ich war das nicht")));
|
||||
|
||||
try {
|
||||
member.getUser().openPrivateChannel().complete().sendMessage(builder.build()).complete();
|
||||
if (member.getNickname() == null) {
|
||||
try {
|
||||
member.getGuild().modifyNickname(member, user.getUserName()).complete();
|
||||
} catch (Exception e) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
TOKENS.remove(code);
|
||||
return member;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
153
src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java
Normale Datei
153
src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java
Normale Datei
@ -0,0 +1,153 @@
|
||||
/*
|
||||
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.BungeeCore;
|
||||
import de.steamwar.bungeecore.bot.commands.*;
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.bot.events.EventManager;
|
||||
import de.steamwar.bungeecore.bot.events.SchematicsManager;
|
||||
import de.steamwar.bungeecore.bot.listeners.*;
|
||||
import de.steamwar.bungeecore.bot.util.DiscordRolesMessage;
|
||||
import de.steamwar.bungeecore.bot.util.DiscordRulesMessage;
|
||||
import de.steamwar.bungeecore.bot.util.DiscordTicketMessage;
|
||||
import de.steamwar.bungeecore.sql.Event;
|
||||
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.entities.Guild;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
|
||||
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SteamwarDiscordBot {
|
||||
|
||||
private static SteamwarDiscordBot INSTANCE;
|
||||
|
||||
public static SteamwarDiscordBot instance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Getter
|
||||
private AnnouncementListener announcementListener;
|
||||
|
||||
@Getter
|
||||
private IngameChatListener ingameChatListener;
|
||||
|
||||
@Getter
|
||||
private ServerTeamChatListener serverTeamChatListener;
|
||||
|
||||
@Getter
|
||||
private final JDA jda;
|
||||
|
||||
@Getter
|
||||
private static Map<String, BasicDiscordCommand> discordCommandMap = new HashMap<>();
|
||||
|
||||
public SteamwarDiscordBot() {
|
||||
INSTANCE = this;
|
||||
JDABuilder builder = JDABuilder.createDefault(SteamwarDiscordBotConfig.TOKEN);
|
||||
builder.setStatus(OnlineStatus.ONLINE);
|
||||
builder.setMemberCachePolicy(MemberCachePolicy.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();
|
||||
}
|
||||
activity();
|
||||
EventManager.update();
|
||||
SchematicsManager.update();
|
||||
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
||||
activity();
|
||||
EventManager.update();
|
||||
SchematicsManager.update();
|
||||
}, 30, 30, TimeUnit.SECONDS);
|
||||
DiscordRolesMessage.sendMessage();
|
||||
DiscordRulesMessage.sendMessage();
|
||||
DiscordTicketMessage.sendMessage();
|
||||
|
||||
new RolesInteractionButtonListener();
|
||||
new DiscordTicketListener();
|
||||
new DiscordAuthListener();
|
||||
announcementListener = new AnnouncementListener();
|
||||
ingameChatListener = new IngameChatListener();
|
||||
serverTeamChatListener = new ServerTeamChatListener();
|
||||
new SlashCommandListener();
|
||||
|
||||
jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).complete());
|
||||
|
||||
Guild guild = jda.getGuildById(SteamwarDiscordBotConfig.GUILD);
|
||||
guild.retrieveCommands().complete().forEach(command -> guild.deleteCommandById(command.getId()).complete());
|
||||
CommandListUpdateAction commands = jda.getGuildById(SteamwarDiscordBotConfig.GUILD).updateCommands();
|
||||
addCommand(commands, new MuteCommand());
|
||||
addCommand(commands, new BanCommand());
|
||||
addCommand(commands, new WhoisCommand());
|
||||
addCommand(commands, new TeamCommand());
|
||||
addCommand(commands, new ListCommand());
|
||||
addCommand(commands, new UnbanCommand());
|
||||
commands.complete();
|
||||
}
|
||||
|
||||
private void addCommand(CommandListUpdateAction commands, BasicDiscordCommand basicDiscordCommand) {
|
||||
commands.addCommands(basicDiscordCommand);
|
||||
discordCommandMap.put(basicDiscordCommand.getName(), basicDiscordCommand);
|
||||
}
|
||||
|
||||
private int index = 0;
|
||||
|
||||
private void activity() {
|
||||
switch (index) {
|
||||
case 0:
|
||||
Event event = Event.get();
|
||||
if (event != null) {
|
||||
jda.getPresence().setActivity(Activity.competing("dem Event " + event.getEventName()));
|
||||
} else {
|
||||
jda.getPresence().setActivity(Activity.playing("auf SteamWar.de"));
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
int count = BungeeCore.get().getProxy().getOnlineCount();
|
||||
if (count == 1) {
|
||||
jda.getPresence().setActivity(Activity.playing("mit 1 Spieler"));
|
||||
} else {
|
||||
jda.getPresence().setActivity(Activity.playing("mit " + count + " Spielern"));
|
||||
}
|
||||
index = 0;
|
||||
return;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
public void addListener(ListenerAdapter listenerAdapter) {
|
||||
jda.addEventListener(listenerAdapter);
|
||||
}
|
||||
}
|
65
src/de/steamwar/bungeecore/bot/commands/BanCommand.java
Normale Datei
65
src/de/steamwar/bungeecore/bot/commands/BanCommand.java
Normale Datei
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.commands;
|
||||
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class BanCommand extends BasicDiscordCommand {
|
||||
|
||||
public BanCommand() {
|
||||
super("ban", "Banne einen Nutzer, wenn du die Rechte hast.");
|
||||
|
||||
addOption(OptionType.STRING, "user", "Der Benutzer", true);
|
||||
addOption(OptionType.STRING, "time", "Bis Wann", true);
|
||||
addOption(OptionType.STRING, "reason", "Warum", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(SlashCommandEvent event) {
|
||||
if (!testPermission(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SteamwarUser sender = SteamwarUser.get(event.getMember().getIdLong());
|
||||
SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(event.getOption("user").getAsString());
|
||||
if (target == null) {
|
||||
event.reply("Angegebener User invalide").setEphemeral(true).complete();
|
||||
return;
|
||||
}
|
||||
|
||||
Timestamp time = de.steamwar.bungeecore.commands.BanCommand.parseTime(null, event.getOption("time").getAsString());
|
||||
if (time == null) {
|
||||
event.reply("Angegebene Zeit invalide").setEphemeral(true).complete();
|
||||
return;
|
||||
}
|
||||
|
||||
String msg = event.getOption("reason").getAsString();
|
||||
boolean isPerma = event.getOption("time").getAsString().equals("perma");
|
||||
|
||||
target.ban(time, msg, sender.getId(), isPerma);
|
||||
Message.team("BAN_TEAM_BANNED", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg);
|
||||
event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + " gebannt").setEphemeral(true).complete();
|
||||
}
|
||||
}
|
54
src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java
Normale Datei
54
src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java
Normale Datei
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.commands;
|
||||
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.bungeecore.sql.UserGroup;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||
|
||||
public abstract class BasicDiscordCommand extends CommandData {
|
||||
|
||||
protected BasicDiscordCommand(String name, String description) {
|
||||
super(name, description);
|
||||
}
|
||||
|
||||
public abstract void run(SlashCommandEvent event);
|
||||
|
||||
protected SteamwarUser getSteamwarUser(SlashCommandEvent event) {
|
||||
Member member = event.getMember();
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
|
||||
if (steamwarUser == null) {
|
||||
return null;
|
||||
}
|
||||
return steamwarUser;
|
||||
}
|
||||
|
||||
protected boolean testPermission(SlashCommandEvent event) {
|
||||
Member member = event.getMember();
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
|
||||
if (steamwarUser == null || (!steamwarUser.getUserGroup().isTeamGroup() && steamwarUser.getUserGroup() != UserGroup.Builder)) {
|
||||
event.reply("Du hast für " + event.getName() + " keine Rechte oder es existiert keine Verknüpfung für dich.").setEphemeral(true).complete();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
43
src/de/steamwar/bungeecore/bot/commands/ListCommand.java
Normale Datei
43
src/de/steamwar/bungeecore/bot/commands/ListCommand.java
Normale Datei
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.commands;
|
||||
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ListCommand extends BasicDiscordCommand {
|
||||
|
||||
public ListCommand() {
|
||||
super("list", "Gebe eine Liste aller online Spieler");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(SlashCommandEvent event) {
|
||||
de.steamwar.bungeecore.commands.ListCommand.updateCustomTablist();
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setTitle("List");
|
||||
de.steamwar.bungeecore.commands.ListCommand.getPlayerMap().forEach((s, proxiedPlayers) -> {
|
||||
embedBuilder.addField(s, proxiedPlayers.stream().map(player -> "`" + player.getName() + "`").collect(Collectors.joining(", ")), true);
|
||||
});
|
||||
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).complete();
|
||||
}
|
||||
}
|
66
src/de/steamwar/bungeecore/bot/commands/MuteCommand.java
Normale Datei
66
src/de/steamwar/bungeecore/bot/commands/MuteCommand.java
Normale Datei
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.commands;
|
||||
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.commands.BanCommand;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class MuteCommand extends BasicDiscordCommand {
|
||||
|
||||
public MuteCommand() {
|
||||
super("mute", "Mute einen Nutzer, wenn du die Rechte hast.");
|
||||
|
||||
addOption(OptionType.STRING, "user", "Der Benutzer", true);
|
||||
addOption(OptionType.STRING, "time", "Bis Wann", true);
|
||||
addOption(OptionType.STRING, "reason", "Warum", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(SlashCommandEvent event) {
|
||||
if (!testPermission(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SteamwarUser sender = SteamwarUser.get(event.getMember().getIdLong());
|
||||
SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(event.getOption("user").getAsString());
|
||||
if (target == null) {
|
||||
event.reply("Angegebener User invalide").setEphemeral(true).complete();
|
||||
return;
|
||||
}
|
||||
|
||||
Timestamp time = BanCommand.parseTime(null, event.getOption("time").getAsString());
|
||||
if (time == null) {
|
||||
event.reply("Angegebene Zeit invalide").setEphemeral(true).complete();
|
||||
return;
|
||||
}
|
||||
|
||||
String msg = event.getOption("reason").getAsString();
|
||||
boolean isPerma = event.getOption("time").getAsString().equals("perma");
|
||||
|
||||
target.mute(time, msg, sender.getId(), isPerma);
|
||||
Message.team("MUTE_TEAM_MUTED", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg);
|
||||
event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + " gemutet").setEphemeral(true).complete();
|
||||
}
|
||||
}
|
96
src/de/steamwar/bungeecore/bot/commands/TeamCommand.java
Normale Datei
96
src/de/steamwar/bungeecore/bot/commands/TeamCommand.java
Normale Datei
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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.commands;
|
||||
|
||||
import de.steamwar.bungeecore.sql.Event;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.bungeecore.sql.Team;
|
||||
import de.steamwar.bungeecore.sql.TeamTeilnahme;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.entities.Emoji;
|
||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TeamCommand extends BasicDiscordCommand {
|
||||
|
||||
public TeamCommand() {
|
||||
super("team", "Alle Team bezogenen Befehle");
|
||||
|
||||
addSubcommands(new SubcommandData("info", "Infos über das Team oder deins")
|
||||
.addOption(OptionType.STRING, "team", "Name oder Kuerzel", false)
|
||||
);
|
||||
}
|
||||
|
||||
private Emoji emoji = Emoji.fromUnicode("U+1F7E2");
|
||||
|
||||
@Override
|
||||
public void run(SlashCommandEvent event) {
|
||||
SteamwarUser steamwarUser = getSteamwarUser(event);
|
||||
|
||||
if (event.getSubcommandName() != null) {
|
||||
switch (event.getSubcommandName()) {
|
||||
case "info":
|
||||
OptionMapping optionMapping = event.getOption("team");
|
||||
Team team;
|
||||
if (optionMapping == null) {
|
||||
if (steamwarUser == null) {
|
||||
event.reply("Dein Discord ist nicht verknüpft").setEphemeral(true).complete();
|
||||
return;
|
||||
}
|
||||
if (steamwarUser.getTeam() == 0) {
|
||||
event.reply("Du bist in keinem Team").setEphemeral(true).complete();
|
||||
return;
|
||||
}
|
||||
team = Team.get(steamwarUser.getTeam());
|
||||
} else {
|
||||
team = Team.get(optionMapping.getAsString());
|
||||
}
|
||||
if (team == null) {
|
||||
event.reply("Unbekanntes Team").setEphemeral(true).complete();
|
||||
return;
|
||||
}
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setTitle("Team: " + team.getTeamName() + " [" + team.getTeamKuerzel() + "]");
|
||||
embedBuilder.setColor(Color.GRAY);
|
||||
List<SteamwarUser> members = team.getMembers().stream().map(SteamwarUser::get).collect(Collectors.toList());
|
||||
|
||||
embedBuilder.addField("Leader", members.stream().filter(SteamwarUser::isLeader).map(user -> "`" + (isOnline(user) ? emoji.getAsMention() : "") + user.getUserName() + "`").collect(Collectors.joining(" ")), false);
|
||||
embedBuilder.addField("Member", members.stream().filter(user -> !user.isLeader()).map(user -> "`" + (isOnline(user) ? emoji.getAsMention() : "") + user.getUserName() + "`").collect(Collectors.joining(" ")), false);
|
||||
embedBuilder.addField("Events", "`" + TeamTeilnahme.getEvents(team.getTeamId()).stream().map(Event::getEventName).collect(Collectors.joining("` `")) + "`", false);
|
||||
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).complete();
|
||||
return;
|
||||
default:
|
||||
event.reply("Unbekannter Befehl").setEphemeral(true).complete();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOnline(SteamwarUser user) {
|
||||
return ProxyServer.getInstance().getPlayer(user.getUuid()) != null;
|
||||
}
|
||||
}
|
59
src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java
Normale Datei
59
src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java
Normale Datei
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.commands;
|
||||
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
public class UnbanCommand extends BasicDiscordCommand {
|
||||
|
||||
public UnbanCommand() {
|
||||
super("unban", "Entbannt einen Nutzer, wenn du die Rechte hast.");
|
||||
|
||||
addOption(OptionType.STRING, "user", "Der Benutzer", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(SlashCommandEvent event) {
|
||||
if (!testPermission(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SteamwarUser sender = SteamwarUser.get(event.getMember().getIdLong());
|
||||
SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(event.getOption("user").getAsString());
|
||||
if (target == null) {
|
||||
event.reply("Angegebener User invalide").setEphemeral(true).complete();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!target.isBanned()) {
|
||||
event.reply("Angegebener User ist nicht gebannt").setEphemeral(true).complete();
|
||||
return;
|
||||
}
|
||||
|
||||
target.ban(Timestamp.from(new Date().toInstant()), "Unban", sender.getId(), false);
|
||||
event.reply("Erfolgreich " + target.getUserName() + " entbannt").setEphemeral(true).complete();
|
||||
}
|
||||
}
|
94
src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java
Normale Datei
94
src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java
Normale Datei
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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.commands;
|
||||
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.bungeecore.sql.Team;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
public class WhoisCommand extends BasicDiscordCommand {
|
||||
|
||||
public WhoisCommand() {
|
||||
super("whois", "Der whois Befehl");
|
||||
|
||||
addOption(OptionType.STRING, "user", "Der Benutzer", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(SlashCommandEvent event) {
|
||||
if (!testPermission(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String s = event.getOption("user").getAsString();
|
||||
|
||||
SteamwarUser user = SteamwarUser.get(s);
|
||||
if (user == null) {
|
||||
try {
|
||||
int id = Integer.parseInt(s);
|
||||
user = SteamwarUser.get(id);
|
||||
} catch (NumberFormatException ignored) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
if (user == null) {
|
||||
try {
|
||||
long id = Long.parseLong(s);
|
||||
user = SteamwarUser.get(id);
|
||||
} catch (NumberFormatException ignored) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
|
||||
if (user == null) {
|
||||
event.reply("Der angegebene Spieler ist unbekannt").setEphemeral(true).complete();
|
||||
return;
|
||||
}
|
||||
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setTitle("Whois: " + user.getUserName());
|
||||
StringBuilder st = new StringBuilder();
|
||||
st.append("UUID: ").append(user.getUuid()).append("\n");
|
||||
st.append("ID: ").append(user.getId()).append("\n");
|
||||
if (user.getDiscordId() != null) {
|
||||
st.append("DiscordID: ").append(user.getDiscordId()).append("\n");
|
||||
}
|
||||
Timestamp timestamp = user.getFirstjoin();
|
||||
st.append("Beigetreten am: ").append(timestamp == null ? "0000-00-00 00:00:00" : timestamp.toString()).append("\n");
|
||||
st.append("Online Time: ").append(new DecimalFormat("###.##").format(user.getOnlinetime() / (double) 3600)).append("h\n");
|
||||
Team team = Team.get(user.getTeam());
|
||||
st.append("Team: [").append(team.getTeamKuerzel()).append("] ").append(team.getTeamName());
|
||||
embedBuilder.addField("Daten:", st.toString(), false);
|
||||
|
||||
List<Punishment> punishmentList = Punishment.getAllPunishmentsOfPlayer(user.getId());
|
||||
for (Punishment punishment : punishmentList) {
|
||||
embedBuilder.addField(punishment.getType().name() + " von " + SteamwarUser.get(punishment.getPunisher()).getUserName(), "Von: " + punishment.getBantime(punishment.getStartTime(), false) + "\nBis: " + punishment.getBantime(punishment.getEndTime(), punishment.isPerma()) + "\nGrund: " + punishment.getReason(), true);
|
||||
}
|
||||
|
||||
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).complete();
|
||||
}
|
||||
}
|
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);
|
||||
}
|
||||
}
|
41
src/de/steamwar/bungeecore/bot/config/DiscordTicketType.java
Normale Datei
41
src/de/steamwar/bungeecore/bot/config/DiscordTicketType.java
Normale Datei
@ -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.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 DiscordTicketType {
|
||||
|
||||
private String key;
|
||||
private String emoji;
|
||||
private String label;
|
||||
private String color;
|
||||
private String preMessage;
|
||||
|
||||
public Button toButton() {
|
||||
return Button.of(ButtonStyle.valueOf(color), key, Emoji.fromUnicode(emoji)).withLabel(label);
|
||||
}
|
||||
}
|
114
src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java
Normale Datei
114
src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java
Normale Datei
@ -0,0 +1,114 @@
|
||||
/*
|
||||
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 de.steamwar.bungeecore.sql.UserGroup;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SteamwarDiscordBotConfig {
|
||||
|
||||
public static String TOKEN;
|
||||
public static String GUILD;
|
||||
public static String ANNOUNCEMENTS_CHANNEL;
|
||||
public static String EVENTS_CHANNEL;
|
||||
public static String INGAME_CHANNEL;
|
||||
public static String SERVER_TEAM_CHANNEL;
|
||||
public static String SCHEMATICS_CHANNEL;
|
||||
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 String TICKET_CATEGORY;
|
||||
public static String TICKET_CHANNEL;
|
||||
public static String TICKET_MESSAGE;
|
||||
public static String TICKET_CREATED;
|
||||
public static String TICKET_LOG;
|
||||
public static Map<String, DiscordTicketType> TICKET_TYPES;
|
||||
public static Map<UserGroup, String> RANKS;
|
||||
|
||||
public static void loadConfig(Configuration config) {
|
||||
TOKEN = config.getString("token");
|
||||
GUILD = config.getString("guild");
|
||||
ANNOUNCEMENTS_CHANNEL = config.getString("announcements-channel");
|
||||
EVENTS_CHANNEL = config.getString("events-channel");
|
||||
INGAME_CHANNEL = config.getString("ingame-channel");
|
||||
SERVER_TEAM_CHANNEL = config.getString("server-team-channel");
|
||||
SCHEMATICS_CHANNEL = config.getString("schematics-channel");
|
||||
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")));
|
||||
}
|
||||
|
||||
Configuration ticketSection = config.getSection("tickets");
|
||||
TICKET_CATEGORY = ticketSection.getString("category");
|
||||
TICKET_CHANNEL = ticketSection.getString("channel");
|
||||
TICKET_MESSAGE = ticketSection.getString("message");
|
||||
TICKET_CREATED = ticketSection.getString("created");
|
||||
TICKET_LOG = ticketSection.getString("log");
|
||||
TICKET_TYPES = new HashMap<>();
|
||||
|
||||
for (String types : ticketSection.getSection("types").getKeys()) {
|
||||
Configuration type = ticketSection.getSection("types").getSection(types);
|
||||
TICKET_TYPES.put(types, new DiscordTicketType(types,
|
||||
type.getString("emoji"),
|
||||
type.getString("label"),
|
||||
type.getString("color"),
|
||||
type.getString("pre")));
|
||||
}
|
||||
|
||||
RANKS = new HashMap<>();
|
||||
Configuration ranksSections = config.getSection("ranks");
|
||||
for (String type : ranksSections.getKeys()) {
|
||||
RANKS.put(UserGroup.getUsergroup(type), ranksSections.getString(type));
|
||||
}
|
||||
}
|
||||
}
|
128
src/de/steamwar/bungeecore/bot/events/EventManager.java
Normale Datei
128
src/de/steamwar/bungeecore/bot/events/EventManager.java
Normale Datei
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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.events;
|
||||
|
||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.sql.Event;
|
||||
import de.steamwar.bungeecore.sql.EventFight;
|
||||
import de.steamwar.bungeecore.sql.Team;
|
||||
import de.steamwar.bungeecore.sql.TeamTeilnahme;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
|
||||
import java.awt.*;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@UtilityClass
|
||||
public class EventManager {
|
||||
|
||||
private Message message;
|
||||
private TextChannel textChannel;
|
||||
|
||||
static {
|
||||
textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.EVENTS_CHANNEL);
|
||||
assert textChannel != null;
|
||||
if(textChannel.hasLatestMessage()) {
|
||||
message = textChannel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (Event.get() == null) {
|
||||
updateComing();
|
||||
} else {
|
||||
updateCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateComing() {
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setColor(Color.GRAY);
|
||||
embedBuilder.setTitle("Zukünftige Events");
|
||||
embedBuilder.setAuthor("SteamWar", "https://www.steamwar.de");
|
||||
|
||||
Timestamp now = Timestamp.from(Instant.now());
|
||||
Event.getComing().forEach(event -> {
|
||||
StringBuilder st = new StringBuilder();
|
||||
if (event.getDeadline().after(now)) {
|
||||
st.append("Deadline: <t:").append(event.getDeadline().getTime() / 1000).append(":R>\n");
|
||||
}
|
||||
st.append("Start: <t:").append(event.getStart().getTime() / 1000).append(":R>");
|
||||
String teilname = TeamTeilnahme.getTeams(event.getEventID()).stream().map(Team::getTeamKuerzel).collect(Collectors.joining(", "));
|
||||
if (!teilname.isEmpty()) {
|
||||
st.append("\nAngemeldete Teams: ").append(teilname);
|
||||
}
|
||||
embedBuilder.addField(event.getEventName(), st.toString(), false);
|
||||
});
|
||||
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.setEmbeds(embedBuilder.build());
|
||||
if (message == null) {
|
||||
message = textChannel.sendMessage(messageBuilder.build()).complete();
|
||||
} else {
|
||||
message.editMessage(messageBuilder.build()).complete();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCurrent() {
|
||||
Event event = Event.get();
|
||||
if (event == null) return;
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setColor(Color.GRAY);
|
||||
embedBuilder.setTitle("Event: " + event.getEventName());
|
||||
embedBuilder.setAuthor("SteamWar", "https://www.steamwar.de");
|
||||
|
||||
Instant now = Instant.now();
|
||||
EventFight.getEvent(event.getEventID()).forEach(eventFight -> {
|
||||
Team teamBlue = Team.get(eventFight.getTeamBlue());
|
||||
Team teamRed = Team.get(eventFight.getTeamRed());
|
||||
|
||||
StringBuilder st = new StringBuilder();
|
||||
st.append("Fightbeginn: <t:").append(eventFight.getStartTime().getTime() / 1000).append(":R>");
|
||||
if(now.isAfter(eventFight.getStartTime().toInstant().plus(35, ChronoUnit.MINUTES))) {
|
||||
st.append("\n");
|
||||
if (eventFight.getErgebnis() == 1) {
|
||||
st.append("Sieg ").append(teamBlue.getTeamKuerzel());
|
||||
} else if (eventFight.getErgebnis() == 2) {
|
||||
st.append("Sieg ").append(teamRed.getTeamKuerzel());
|
||||
} else {
|
||||
st.append("Unentschieden");
|
||||
}
|
||||
}
|
||||
embedBuilder.addField(teamBlue.getTeamKuerzel() + " vs. " + teamRed.getTeamKuerzel(), st.toString(), true);
|
||||
});
|
||||
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.setEmbeds(embedBuilder.build());
|
||||
if (message == null) {
|
||||
message = textChannel.sendMessage(messageBuilder.build()).complete();
|
||||
} else {
|
||||
message.editMessage(messageBuilder.build()).complete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
73
src/de/steamwar/bungeecore/bot/events/SchematicsManager.java
Normale Datei
73
src/de/steamwar/bungeecore/bot/events/SchematicsManager.java
Normale Datei
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.events;
|
||||
|
||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.commands.CheckCommand;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@UtilityClass
|
||||
public class SchematicsManager {
|
||||
|
||||
private Message message;
|
||||
private TextChannel textChannel;
|
||||
|
||||
static {
|
||||
textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.SCHEMATICS_CHANNEL);
|
||||
assert textChannel != null;
|
||||
if(textChannel.hasLatestMessage()) {
|
||||
message = textChannel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void update() {
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setColor(Color.GRAY);
|
||||
embedBuilder.setTitle("Check List");
|
||||
embedBuilder.setAuthor("SteamWar", "https://www.steamwar.de");
|
||||
|
||||
CheckCommand.getSchemsToCheck().forEach(schematic -> {
|
||||
StringBuilder st = new StringBuilder();
|
||||
st.append("Typ: ").append(schematic.getSchemType().getKuerzel());
|
||||
st.append("\nVon: ").append(SteamwarUser.get(schematic.getSchemOwner()).getUserName());
|
||||
String checker = CheckCommand.getChecker(schematic);
|
||||
if (checker != null) {
|
||||
st.append("\nWird Geprüft von: ").append(checker);
|
||||
}
|
||||
embedBuilder.addField(schematic.getSchemName(), st.toString(), true);
|
||||
});
|
||||
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.setEmbeds(embedBuilder.build());
|
||||
if (message == null) {
|
||||
message = textChannel.sendMessage(messageBuilder.build()).complete();
|
||||
} else {
|
||||
message.editMessage(messageBuilder.build()).queue();
|
||||
}
|
||||
}
|
||||
}
|
50
src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.java
Normale Datei
50
src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.java
Normale Datei
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.Message;
|
||||
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.events.message.guild.GuildMessageReceivedEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AnnouncementListener extends BasicDiscordListener {
|
||||
|
||||
@Override
|
||||
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
|
||||
if (!event.getChannel().getId().equals(SteamwarDiscordBotConfig.ANNOUNCEMENTS_CHANNEL)) {
|
||||
return;
|
||||
}
|
||||
if (event.getAuthor().isBot()) {
|
||||
return;
|
||||
}
|
||||
Message.broadcast("ALERT", event.getMessage().getContentDisplay());
|
||||
}
|
||||
|
||||
public void announce(String message) {
|
||||
TextChannel textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.ANNOUNCEMENTS_CHANNEL);
|
||||
assert textChannel != null;
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.append(message.replace("&", ""));
|
||||
textChannel.sendMessage(messageBuilder.build()).complete();
|
||||
}
|
||||
}
|
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);
|
||||
}
|
||||
}
|
59
src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java
Normale Datei
59
src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java
Normale Datei
@ -0,0 +1,59 @@
|
||||
/*
|
||||
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.AuthManager;
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.dv8tion.jda.api.entities.ChannelType;
|
||||
import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent;
|
||||
import net.dv8tion.jda.api.interactions.InteractionType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DiscordAuthListener extends BasicDiscordListener {
|
||||
|
||||
@Override
|
||||
public void onGenericComponentInteractionCreate(@NotNull GenericComponentInteractionCreateEvent event) {
|
||||
if(event.getType() == InteractionType.COMPONENT) {
|
||||
if(event.getChannel().getId().equals(SteamwarDiscordBotConfig.RULES_CHANNEL) && event.getComponentId().equals("auth")) {
|
||||
String authMessage = AuthManager.createDiscordAuthToken(event.getMember());
|
||||
if(authMessage != null) {
|
||||
event.reply("Gebe innerhalb der nächsten 10 Minuten ``/verify " + authMessage + "`` auf dem Minecraft Server ein").setEphemeral(true).complete();
|
||||
} else {
|
||||
event.reply("Du hast bereits einen Code am laufen").setEphemeral(true).complete();
|
||||
}
|
||||
}
|
||||
|
||||
if(event.getComponentId().equals("tada") && event.getChannelType() == ChannelType.PRIVATE) {
|
||||
event.reply(":tada:").setEphemeral(false).complete();
|
||||
}
|
||||
|
||||
if(event.getComponentId().equals("invalid") && event.getChannelType() == ChannelType.PRIVATE) {
|
||||
SteamwarUser user = SteamwarUser.get(event.getUser().getIdLong());
|
||||
if(user == null) {
|
||||
event.reply(":question: Da ist keine verknüpfung?").setEphemeral(false).complete();
|
||||
} else {
|
||||
user.setDiscordId(null);
|
||||
event.reply(":x: Die Verknüpfung wurde beendet").setEphemeral(false).complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
144
src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java
Normale Datei
144
src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java
Normale Datei
@ -0,0 +1,144 @@
|
||||
/*
|
||||
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.BungeeCore;
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.bot.config.DiscordTicketType;
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.interactions.InteractionType;
|
||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||
import net.dv8tion.jda.api.interactions.components.Button;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.*;
|
||||
import java.time.Instant;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class DiscordTicketListener extends BasicDiscordListener {
|
||||
|
||||
@Override
|
||||
public void onGenericComponentInteractionCreate(@NotNull GenericComponentInteractionCreateEvent event) {
|
||||
if(event.getType() == InteractionType.COMPONENT && event.getChannelType() == ChannelType.TEXT && event.getTextChannel().getParent() != null && event.getTextChannel().getParent().getId().equals(SteamwarDiscordBotConfig.TICKET_CATEGORY)) {
|
||||
if(event.getTextChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_CHANNEL) && SteamwarDiscordBotConfig.TICKET_TYPES.containsKey(event.getComponentId())) {
|
||||
DiscordTicketType ticketType = SteamwarDiscordBotConfig.TICKET_TYPES.get(event.getComponentId());
|
||||
Category ct = event.getGuild().getCategoryById(SteamwarDiscordBotConfig.TICKET_CATEGORY);
|
||||
SteamwarUser swUser = SteamwarUser.get(event.getUser().getIdLong());
|
||||
TextChannel ticketChannel = ct.createTextChannel((swUser == null?event.getUser().getName():swUser.getUserName()) + "-" + event.getComponentId() + "-" + System.currentTimeMillis() % 1000).complete();
|
||||
ticketChannel.createPermissionOverride(event.getMember()).setAllow(Permission.VIEW_CHANNEL,
|
||||
Permission.MESSAGE_WRITE,
|
||||
Permission.MESSAGE_ATTACH_FILES,
|
||||
Permission.MESSAGE_ADD_REACTION,
|
||||
Permission.MESSAGE_READ,
|
||||
Permission.MESSAGE_EMBED_LINKS,
|
||||
Permission.MESSAGE_HISTORY).complete();
|
||||
ticketChannel.getManager().setTopic(event.getUser().getId()).complete();
|
||||
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(ticketType.getPreMessage());
|
||||
builder.setTitle("Steamwar Ticket");
|
||||
builder.setColor(Color.GREEN);
|
||||
|
||||
Button closeButton = Button.danger("close-" + ticketChannel.getName(), "Schließen").withEmoji(Emoji.fromUnicode("U+26A0"));
|
||||
messageBuilder.setEmbeds(builder.build());
|
||||
messageBuilder.setActionRows(ActionRow.of(closeButton));
|
||||
|
||||
ticketChannel.sendMessage(messageBuilder.build()).complete();
|
||||
event.reply(SteamwarDiscordBotConfig.TICKET_CREATED.replace("%channel%", ticketChannel.getAsMention())).setEphemeral(true).complete();
|
||||
Message.team("DISCORD_TICKET_NEW", ticketChannel.getName());
|
||||
} else if(event.getComponentId().startsWith("close-")) {
|
||||
TextChannel logChannel = event.getGuild().getTextChannelById(SteamwarDiscordBotConfig.TICKET_LOG);
|
||||
|
||||
MessageBuilder builder = new MessageBuilder();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
new LinkedList<>(event.getTextChannel().getIterableHistory().complete()).descendingIterator().forEachRemaining(message -> {
|
||||
if(message.getAuthor().isSystem() || message.getAuthor().isBot()) return;
|
||||
stringBuilder.append("<t:").append(message.getTimeCreated().toInstant().getEpochSecond()).append("> ")
|
||||
.append("**")
|
||||
.append(message.getAuthor().getName())
|
||||
.append("**: ")
|
||||
.append(message.getContentRaw());
|
||||
if(!message.getAttachments().isEmpty()) {
|
||||
stringBuilder.append("\n")
|
||||
.append("Files: ").append("\n");
|
||||
message.getAttachments().forEach(attachment -> stringBuilder.append(attachment.getUrl()).append("\n"));
|
||||
}
|
||||
|
||||
stringBuilder.append("\n");
|
||||
});
|
||||
|
||||
stringBuilder.append("\n");
|
||||
stringBuilder.append("<t:").append(Instant.now().getEpochSecond()).append("> ")
|
||||
.append("**").append(event.getUser().getName()).append("**: ")
|
||||
.append("Ticket geschlossen");
|
||||
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setColor(Color.GREEN);
|
||||
User user = event.getJDA().retrieveUserById(event.getTextChannel().getTopic()).complete();
|
||||
SteamwarUser swuser = SteamwarUser.get(user.getIdLong());
|
||||
|
||||
embedBuilder.setAuthor(user.getName(), swuser==null?"https://steamwar.de/":("https://steamwar.de/users/" + swuser.getUserName().toLowerCase() + "/"), user.getAvatarUrl());
|
||||
embedBuilder.setTimestamp(Instant.now());
|
||||
embedBuilder.setTitle(event.getTextChannel().getName());
|
||||
embedBuilder.setDescription(stringBuilder);
|
||||
|
||||
builder.setEmbeds(embedBuilder.build());
|
||||
|
||||
logChannel.sendMessage(builder.build()).complete();
|
||||
|
||||
Message.team("DISCORD_TICKET_CLOSED", event.getTextChannel().getName());
|
||||
event.getTextChannel().delete().reason("Closed").complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
|
||||
if(event.getChannel().getParent() != null && event.getChannel().getParent().getId().equals(SteamwarDiscordBotConfig.TICKET_CATEGORY)) {
|
||||
if(!event.getChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_CHANNEL) && !event.getChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_LOG)) {
|
||||
BungeeCore.get().getProxy().getPlayers().forEach(player -> {
|
||||
if(event.getAuthor().isBot() || event.getAuthor().isSystem()) return;
|
||||
SteamwarUser user = SteamwarUser.get(player);
|
||||
if(user.getDiscordId() == null) {
|
||||
if(user.getUserGroup().isTeamGroup()) {
|
||||
Message.sendPrefixless("DISCORD_TICKET_MESSAGE", player, "Zur nachricht", new ClickEvent(ClickEvent.Action.OPEN_URL, event.getMessage().getJumpUrl()), event.getChannel().getName(), event.getAuthor().getName(), event.getMessage().getContentRaw());
|
||||
}
|
||||
} else {
|
||||
if(event.getAuthor().getId().equals(user.getDiscordId())) return;
|
||||
Member member = event.getGuild().retrieveMemberById(user.getDiscordId()).complete();
|
||||
if(member.hasPermission(event.getChannel().getManager().getChannel(), Permission.MESSAGE_WRITE)) {
|
||||
Message.sendPrefixless("DISCORD_TICKET_MESSAGE", player, "Zur nachricht", new ClickEvent(ClickEvent.Action.OPEN_URL, event.getMessage().getJumpUrl()), event.getChannel().getName(), event.getAuthor().getName(), event.getMessage().getContentRaw());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
68
src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java
Normale Datei
68
src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java
Normale Datei
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.listeners.ChatListener;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.bungeecore.sql.UserGroup;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class IngameChatListener extends BasicDiscordListener {
|
||||
|
||||
@Override
|
||||
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
|
||||
if (!event.getChannel().getId().equals(SteamwarDiscordBotConfig.INGAME_CHANNEL)) {
|
||||
return;
|
||||
}
|
||||
if (event.getAuthor().isBot()) {
|
||||
return;
|
||||
}
|
||||
Member member = event.getMember();
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
|
||||
if (steamwarUser == null || event.getMessage().getContentRaw().length() > 250) {
|
||||
event.getMessage().delete().complete();
|
||||
} else {
|
||||
String s = event.getMessage().getContentDisplay();
|
||||
if (steamwarUser.getUserGroup() == UserGroup.Member && (s.contains("http") || s.contains("www"))) {
|
||||
event.getMessage().delete().complete();
|
||||
return;
|
||||
}
|
||||
if (steamwarUser.isMuted() || steamwarUser.isBanned()) {
|
||||
event.getMessage().delete().complete();
|
||||
return;
|
||||
}
|
||||
ChatListener.discordChat(steamwarUser, event.getMessage().getContentDisplay().replaceAll("§[a-f0-9]", "").replace('\n', ' '));
|
||||
}
|
||||
}
|
||||
|
||||
public void send(String message) {
|
||||
TextChannel textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.INGAME_CHANNEL);
|
||||
assert textChannel != null;
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.append(message.replace("&", "").replace("@everyone", "`@everyone`").replace("@here", "`@here`").replaceAll("<[@#]!?\\d+>", "`$0`"));
|
||||
textChannel.sendMessage(messageBuilder.build()).queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
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.entities.ChannelType;
|
||||
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.getChannelType() == ChannelType.TEXT && 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
59
src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java
Normale Datei
59
src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java
Normale Datei
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.commands.ServerTeamchatCommand;
|
||||
import de.steamwar.bungeecore.listeners.ChatListener;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ServerTeamChatListener extends BasicDiscordListener {
|
||||
|
||||
@Override
|
||||
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
|
||||
if (!event.getChannel().getId().equals(SteamwarDiscordBotConfig.SERVER_TEAM_CHANNEL)) {
|
||||
return;
|
||||
}
|
||||
if (event.getAuthor().isBot()) {
|
||||
return;
|
||||
}
|
||||
Member member = event.getMember();
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
|
||||
if (steamwarUser == null) {
|
||||
event.getMessage().delete().complete();
|
||||
} else {
|
||||
ServerTeamchatCommand.sendToTeam(event.getMessage().getContentRaw(), steamwarUser);
|
||||
}
|
||||
}
|
||||
|
||||
public void send(String message) {
|
||||
TextChannel textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.SERVER_TEAM_CHANNEL);
|
||||
assert textChannel != null;
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.append(message.replace("&", ""));
|
||||
textChannel.sendMessage(messageBuilder.build()).queue();
|
||||
}
|
||||
}
|
32
src/de/steamwar/bungeecore/bot/listeners/SlashCommandListener.java
Normale Datei
32
src/de/steamwar/bungeecore/bot/listeners/SlashCommandListener.java
Normale Datei
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.events.interaction.SlashCommandEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SlashCommandListener extends BasicDiscordListener {
|
||||
|
||||
@Override
|
||||
public void onSlashCommand(@NotNull SlashCommandEvent event) {
|
||||
SteamwarDiscordBot.getDiscordCommandMap().get(event.getName()).run(event);
|
||||
}
|
||||
}
|
67
src/de/steamwar/bungeecore/bot/util/DiscordRanks.java
Normale Datei
67
src/de/steamwar/bungeecore/bot/util/DiscordRanks.java
Normale Datei
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.bungeecore.sql.UserGroup;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
public class DiscordRanks {
|
||||
|
||||
public void update(SteamwarUser steamwarUser) {
|
||||
if (steamwarUser.getDiscordId() == null) {
|
||||
return;
|
||||
}
|
||||
Guild guild = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD);
|
||||
Member member = guild.retrieveMemberById(steamwarUser.getDiscordId()).complete();
|
||||
if (member == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Role> roleList = member.getRoles();
|
||||
Set<String> strings = new HashSet<>(SteamwarDiscordBotConfig.RANKS.values());
|
||||
String needed = SteamwarDiscordBotConfig.RANKS.get(steamwarUser.getUserGroup());
|
||||
for (Role role : roleList) {
|
||||
if (!strings.contains(role.getId())) {
|
||||
continue;
|
||||
}
|
||||
if (role.getId().equals(needed)) {
|
||||
needed = "";
|
||||
continue;
|
||||
}
|
||||
guild.removeRoleFromMember(member, role).complete();
|
||||
}
|
||||
|
||||
if (needed != null && !needed.isEmpty()) {
|
||||
guild.addRoleToMember(member, guild.getRoleById(needed)).complete();
|
||||
}
|
||||
}
|
||||
}
|
58
src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java
Normale Datei
58
src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java
Normale Datei
@ -0,0 +1,58 @@
|
||||
/*
|
||||
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 lombok.experimental.UtilityClass;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
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.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@UtilityClass
|
||||
public class DiscordRolesMessage {
|
||||
|
||||
|
||||
public void sendMessage() {
|
||||
TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.ROLES_CHANNEL);
|
||||
assert channel != null;
|
||||
Message message = null;
|
||||
if(channel.hasLatestMessage()) {
|
||||
message = channel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
if (message != null) {
|
||||
message.editMessage(builder.build()).complete();
|
||||
} else {
|
||||
channel.sendMessage(builder.build()).complete();
|
||||
}
|
||||
}
|
||||
}
|
68
src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java
Normale Datei
68
src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java
Normale Datei
@ -0,0 +1,68 @@
|
||||
/*
|
||||
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 lombok.experimental.UtilityClass;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Emoji;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
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;
|
||||
|
||||
@UtilityClass
|
||||
public class DiscordRulesMessage {
|
||||
|
||||
public void sendMessage() {
|
||||
TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.RULES_CHANNEL);
|
||||
assert channel != null;
|
||||
Message message = null;
|
||||
if(channel.hasLatestMessage()) {
|
||||
message = channel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(SteamwarDiscordBotConfig.RULES_RULES.stream().reduce((s, s2) -> s + "\n" + s2).get());
|
||||
builder.setColor(Color.GRAY);
|
||||
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()));
|
||||
|
||||
Button authButton = Button.primary("auth", Emoji.fromUnicode("U+2705")).withLabel("Minecraft verknüpfen");
|
||||
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.setEmbeds(builder.build());
|
||||
messageBuilder.setActionRows(ActionRow.of(buttons), ActionRow.of(authButton));
|
||||
if (message != null) {
|
||||
message.editMessage(messageBuilder.build()).complete();
|
||||
} else {
|
||||
channel.sendMessage(messageBuilder.build()).complete();
|
||||
}
|
||||
}
|
||||
}
|
79
src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java
Normale Datei
79
src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java
Normale Datei
@ -0,0 +1,79 @@
|
||||
/*
|
||||
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.sql.Schematic;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Emoji;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||
import net.dv8tion.jda.api.interactions.components.Button;
|
||||
|
||||
import java.awt.*;
|
||||
import java.time.Instant;
|
||||
|
||||
@UtilityClass
|
||||
public class DiscordSchemAlert {
|
||||
|
||||
public void sendDecline(Schematic schematic, SteamwarUser user, String reason) {
|
||||
if(user.getDiscordId() != null) {
|
||||
User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(user.getDiscordId()).complete();
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png");
|
||||
builder.setColor(Color.RED);
|
||||
builder.setTitle("SteamWar-Schematic Info");
|
||||
builder.setDescription("Deine Schematic **" + schematic.getSchemName() + "** wurde abgelehnt. **Grund:** \n" + reason);
|
||||
builder.setTimestamp(Instant.now());
|
||||
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.setEmbeds(builder.build());
|
||||
try {
|
||||
dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue();
|
||||
} catch (Exception e) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendAccept(Schematic schematic, SteamwarUser user) {
|
||||
if(user.getDiscordId() != null) {
|
||||
User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(user.getDiscordId()).complete();
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png");
|
||||
builder.setColor(Color.GREEN);
|
||||
builder.setTitle("SteamWar-Schematic Info");
|
||||
builder.setDescription("Deine Schematic **" + schematic.getSchemName() + "** wurde angenommen.");
|
||||
builder.setTimestamp(Instant.now());
|
||||
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.setEmbeds(builder.build());
|
||||
messageBuilder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389"))));
|
||||
try {
|
||||
dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue();
|
||||
} catch (Exception e) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
64
src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java
Normale Datei
64
src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java
Normale Datei
@ -0,0 +1,64 @@
|
||||
/*
|
||||
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 lombok.experimental.UtilityClass;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
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;
|
||||
|
||||
@UtilityClass
|
||||
public class DiscordTicketMessage {
|
||||
|
||||
public void sendMessage() {
|
||||
TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.TICKET_CHANNEL);
|
||||
assert channel != null;
|
||||
Message message = null;
|
||||
if(channel.hasLatestMessage()) {
|
||||
message = channel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(SteamwarDiscordBotConfig.TICKET_MESSAGE);
|
||||
builder.setTitle("Steamwar-Tickets");
|
||||
builder.setColor(Color.RED);
|
||||
|
||||
List<Button> buttons = new ArrayList<>();
|
||||
SteamwarDiscordBotConfig.TICKET_TYPES.forEach((s, discordTicketType) -> buttons.add(discordTicketType.toButton()));
|
||||
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.setEmbeds(builder.build());
|
||||
messageBuilder.setActionRows(ActionRow.of(buttons));
|
||||
if (message != null) {
|
||||
message.editMessage(messageBuilder.build()).complete();
|
||||
} else {
|
||||
channel.sendMessage(messageBuilder.build()).complete();
|
||||
}
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
|
||||
@ -36,6 +37,33 @@ public class AlertCommand extends BasicCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
Message.broadcast("ALERT", ChatColor.translateAlternateColorCodes('&', String.join(" ", args)));
|
||||
String s;
|
||||
boolean discordAnnounce = false;
|
||||
if (args[0].equals("-discord")) {
|
||||
if (args.length == 1) {
|
||||
Message.send("USAGE_ALERT", sender);
|
||||
return;
|
||||
}
|
||||
discordAnnounce = true;
|
||||
s = join(1, args);
|
||||
} else {
|
||||
s = join(0, args);
|
||||
}
|
||||
|
||||
Message.broadcast("ALERT", ChatColor.translateAlternateColorCodes('&', s));
|
||||
if (discordAnnounce) {
|
||||
SteamwarDiscordBot.instance().getAnnouncementListener().announce(s);
|
||||
}
|
||||
}
|
||||
|
||||
private String join(int startIndex, String... strings) {
|
||||
StringBuilder st = new StringBuilder();
|
||||
for (int i = startIndex; i < strings.length; i++) {
|
||||
if (i != startIndex) {
|
||||
st.append(" ");
|
||||
}
|
||||
st.append(strings[i]);
|
||||
}
|
||||
return st.toString();
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,9 @@ public class BanCommand extends BasicCommand {
|
||||
Date parsedDate = dateFormat.parse(arg.split("_")[0]);
|
||||
return new java.sql.Timestamp(parsedDate.getTime());
|
||||
}catch(ParseException exception){
|
||||
Message.send("INVALID_TIME", sender);
|
||||
if (sender != null) {
|
||||
Message.send("INVALID_TIME", sender);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.*;
|
||||
import de.steamwar.bungeecore.bot.util.DiscordSchemAlert;
|
||||
import de.steamwar.bungeecore.listeners.ConnectionListener;
|
||||
import de.steamwar.bungeecore.sql.CheckedSchematic;
|
||||
import de.steamwar.bungeecore.sql.SchematicNode;
|
||||
@ -120,6 +121,11 @@ public class CheckCommand extends BasicCommand {
|
||||
return schematicList;
|
||||
}
|
||||
|
||||
public static String getChecker(Schematic schematic) {
|
||||
if (currentSchems.get(schematic.getSchemID()) == null) return null;
|
||||
return currentSchems.get(schematic.getSchemID()).checker.getName();
|
||||
}
|
||||
|
||||
private void list(ProxiedPlayer player) {
|
||||
List<SchematicNode> schematicList = getSchemsToCheck();
|
||||
|
||||
@ -288,9 +294,12 @@ public class CheckCommand extends BasicCommand {
|
||||
CheckedSchematic.create(schematic.getId(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben");
|
||||
SteamwarUser user = SteamwarUser.get(schematic.getOwner());
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid());
|
||||
if(player != null)
|
||||
Message.send("CHECK_ACCEPTED", player, schematic.getSchemtype().name(), schematic.getName());
|
||||
Message.team("CHECK_ACCEPTED_TEAM", schematic.getName(), user.getUserName());
|
||||
if(player != null) {
|
||||
Message.send("CHECK_ACCEPTED", player, schematic.getSchemType().name(), schematic.getSchemName());
|
||||
} else {
|
||||
DiscordSchemAlert.sendAccept(schematic, user);
|
||||
}
|
||||
Message.team("CHECK_ACCEPTED_TEAM", schematic.getSchemName(), user.getUserName());
|
||||
stop();
|
||||
}
|
||||
|
||||
@ -299,9 +308,12 @@ public class CheckCommand extends BasicCommand {
|
||||
CheckedSchematic.create(schematic.getId(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason);
|
||||
SteamwarUser user = SteamwarUser.get(schematic.getOwner());
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid());
|
||||
if(player != null)
|
||||
Message.send("CHECK_DECLINED", player, schematic.getSchemtype().name(), schematic.getName(), reason);
|
||||
Message.team("CHECK_DECLINED_TEAM", schematic.getName(), user.getUserName(), reason);
|
||||
if(player != null) {
|
||||
Message.send("CHECK_DECLINED", player, schematic.getSchemType().name(), schematic.getSchemName(), reason);
|
||||
} else {
|
||||
DiscordSchemAlert.sendDecline(schematic, user, reason);
|
||||
}
|
||||
Message.team("CHECK_DECLINED_TEAM", schematic.getSchemName(), user.getUserName(), reason);
|
||||
stop();
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class DevCommand extends BasicCommand {
|
||||
sendToServer((ProxiedPlayer) sender, server[0], Integer.parseInt(server[1]));
|
||||
} else {
|
||||
if (args.length == 0) {
|
||||
send(devServer, (ProxiedPlayer) sender, s -> s.equalsIgnoreCase(((ProxiedPlayer) sender).getDisplayName()), () -> Message.send("DEV_UNKNOWN_SERVER", sender));
|
||||
send(devServer, (ProxiedPlayer) sender, s -> s.equalsIgnoreCase(sender.getName()), () -> Message.send("DEV_UNKNOWN_SERVER", sender));
|
||||
} else {
|
||||
send(devServer, (ProxiedPlayer) sender, args[0]::equalsIgnoreCase, () -> Message.send("DEV_NO_SERVER", sender));
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ package de.steamwar.bungeecore.commands;
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.Servertype;
|
||||
import de.steamwar.bungeecore.Subserver;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@ -39,9 +40,10 @@ public class ListCommand extends BasicCommand {
|
||||
super("list", "");
|
||||
}
|
||||
|
||||
private final TreeMap<String, List<ProxiedPlayer>> playerMap = new TreeMap<>();
|
||||
@Getter
|
||||
private static final TreeMap<String, List<ProxiedPlayer>> playerMap = new TreeMap<>();
|
||||
|
||||
private synchronized void updateCustomTablist(){
|
||||
public static synchronized void updateCustomTablist(){
|
||||
//Calculate server-player-map
|
||||
playerMap.clear();
|
||||
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
|
||||
|
@ -20,7 +20,9 @@
|
||||
package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||
import de.steamwar.bungeecore.listeners.ChatListener;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@ -49,10 +51,20 @@ public class ServerTeamchatCommand extends BasicCommand {
|
||||
String msg = msgBuilder.toString();
|
||||
msg = ChatColor.translateAlternateColorCodes('&', msg);
|
||||
|
||||
SteamwarDiscordBot.instance().getServerTeamChatListener().send("<t:" + (System.currentTimeMillis() / 1000) + "> " + (player.getName() + "» " + msg).replaceAll("§[a-f0-9r]", ""));
|
||||
sendToTeam(msg, player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendToTeam(String message, SteamwarUser sender){
|
||||
for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||
if ((target.hasPermission("bungeecore.teamchat"))
|
||||
&& target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN){
|
||||
Message.sendPrefixless("STC_FORMAT", target, sender.getUserName(), ChatListener.parseAtMessage(message, "§r", target));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendToTeam(String message, ProxiedPlayer sender){
|
||||
for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||
if ((target.hasPermission("bungeecore.teamchat"))
|
||||
|
60
src/de/steamwar/bungeecore/commands/VerifyCommand.java
Normale Datei
60
src/de/steamwar/bungeecore/commands/VerifyCommand.java
Normale Datei
@ -0,0 +1,60 @@
|
||||
/*
|
||||
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.commands;
|
||||
|
||||
import de.steamwar.bungeecore.BungeeCore;
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.bot.AuthManager;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
public class VerifyCommand extends BasicCommand {
|
||||
|
||||
public VerifyCommand() {
|
||||
super("verify", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] strings) {
|
||||
if(strings.length < 1) {
|
||||
Message.send("VERIFY_USAGE", sender);
|
||||
return;
|
||||
}
|
||||
byte[] bytes = Base64.getDecoder().decode(strings[0]);
|
||||
if(bytes.length != 16) {
|
||||
Message.send("VERIFY_INVALID", sender);
|
||||
return;
|
||||
}
|
||||
if(bytes[0] == 'D' && bytes[1] == 'C') {
|
||||
Member member = AuthManager.connectAuth(SteamwarUser.get(sender.getName()), strings[0]);
|
||||
if(member != null) {
|
||||
BungeeCore.log(sender.getName() + " Verified with Discorduser: " + member.getIdLong());
|
||||
Message.send("VERIFY_SUCCESS", sender, member.getUser().getAsTag());
|
||||
} else {
|
||||
Message.send("VERIFY_INVALID", sender);
|
||||
}
|
||||
} else {
|
||||
Message.send("VERIFY_INVALID", sender);
|
||||
}
|
||||
}
|
||||
}
|
@ -54,6 +54,14 @@ public class WhoisCommand extends BasicCommand {
|
||||
user = SteamwarUser.get(id);
|
||||
}catch (NumberFormatException ignored) {}
|
||||
}
|
||||
if (user == null) {
|
||||
try {
|
||||
long id = Long.parseLong(args[0]);
|
||||
user = SteamwarUser.get(id);
|
||||
} catch (NumberFormatException ignored) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
|
||||
if(user == null) {
|
||||
Message.send("UNKNOWN_PLAYER", player);
|
||||
@ -67,6 +75,9 @@ public class WhoisCommand extends BasicCommand {
|
||||
Message.send("WHOIS_USERNAME", player, user.getUserName());
|
||||
Message.send("WHOIS_UUID", player, Message.parse("WHOIS_UUID_HOVER", player), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, user.getUuid().toString()), user.getUuid().toString());
|
||||
Message.send("WHOIS_ID", player, user.getId());
|
||||
if (user.getDiscordId() != null) {
|
||||
Message.send("WHOIS_DISCORD_ID", player, user.getDiscordId());
|
||||
}
|
||||
Timestamp firstJoin = user.getFirstjoin();
|
||||
if(firstJoin == null)
|
||||
Message.send("WHOIS_JOINED_FIRST", player, "0000-00-00 00:00:00");
|
||||
|
@ -20,6 +20,8 @@
|
||||
package de.steamwar.bungeecore.listeners;
|
||||
|
||||
import de.steamwar.bungeecore.*;
|
||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||
import de.steamwar.bungeecore.bot.listeners.IngameChatListener;
|
||||
import de.steamwar.bungeecore.commands.BauCommand;
|
||||
import de.steamwar.bungeecore.commands.TpCommand;
|
||||
import de.steamwar.bungeecore.comms.packets.PingPacket;
|
||||
@ -170,6 +172,31 @@ public class ChatListener extends BasicListener {
|
||||
}
|
||||
}
|
||||
|
||||
public static void discordChat(SteamwarUser user, String message){
|
||||
String name = "§r" + user.getUserName() + "§r";
|
||||
if (user.getUserGroup() != UserGroup.Member) {
|
||||
name = user.getUserGroup().getColorCode() + user.getUserGroup().name() + " " + user.getUserName() + "§r";
|
||||
}
|
||||
String chatcolor = user.getUserGroup().getChatColorCode();
|
||||
|
||||
if(user.getUserGroup() != UserGroup.Member || user.getTeam() == 12 || user.getTeam() == 285 || user.getTeam() == 54)
|
||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||
|
||||
String msg = name + "§7»" + chatcolor + " " + message;
|
||||
if(user.getTeam() != 0){
|
||||
Team team = Team.get(user.getTeam());
|
||||
msg = "§" + team.getTeamColor() + team.getTeamKuerzel() + " §r" + msg;
|
||||
}
|
||||
msg = "§7Discord §r" + msg;
|
||||
|
||||
for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||
Subserver targetServer = Subserver.getSubserver(target);
|
||||
if(!(targetServer == null || targetServer.getType() != Servertype.ARENA || targetServer.getServer() != target.getServer().getInfo())) continue;
|
||||
|
||||
BungeeCore.send(target, ChatMessageType.CHAT, parseAtMessage(msg, chatcolor, target));
|
||||
}
|
||||
}
|
||||
|
||||
private void publicChat(SteamwarUser user, ProxiedPlayer sender, String message){
|
||||
String name = sender.getDisplayName();
|
||||
String chatcolor = user.getUserGroup().getChatColorCode();
|
||||
@ -183,6 +210,7 @@ public class ChatListener extends BasicListener {
|
||||
msg = "§" + team.getTeamColor() + team.getTeamKuerzel() + " §r" + msg;
|
||||
}
|
||||
|
||||
SteamwarDiscordBot.instance().getIngameChatListener().send("<t:" + (System.currentTimeMillis() / 1000) + "> " + msg.replaceAll("§[a-f0-9r]", ""));
|
||||
for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||
Subserver targetServer = Subserver.getSubserver(target);
|
||||
if(!(targetServer == null || targetServer.getType() != Servertype.ARENA || targetServer.getServer() != target.getServer().getInfo())) continue;
|
||||
|
@ -23,6 +23,7 @@ import de.steamwar.bungeecore.BungeeCore;
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.Servertype;
|
||||
import de.steamwar.bungeecore.Subserver;
|
||||
import de.steamwar.bungeecore.bot.util.DiscordRanks;
|
||||
import de.steamwar.bungeecore.commands.ChallengeCommand;
|
||||
import de.steamwar.bungeecore.commands.CheckCommand;
|
||||
import de.steamwar.bungeecore.commands.MsgCommand;
|
||||
@ -94,6 +95,8 @@ public class ConnectionListener extends BasicListener {
|
||||
Message.broadcast("JOIN_FIRST", player.getName());
|
||||
newPlayers.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
DiscordRanks.update(user);
|
||||
}
|
||||
|
||||
/** To redirect players to the lobby in case of server closure. */
|
||||
|
@ -148,6 +148,9 @@ public class TablistManager extends BasicListener {
|
||||
}
|
||||
|
||||
private void refresh(){
|
||||
if (player.getServer() == null) {
|
||||
return;
|
||||
}
|
||||
ServerInfo currentServer = player.getServer().getInfo();
|
||||
setHeader(calcHeader(player));
|
||||
// TABLIST_FOOTER=§e{0} {1}§8ms §eSpieler§8: §7{2}
|
||||
@ -193,7 +196,7 @@ public class TablistManager extends BasicListener {
|
||||
Team team = getTeam(player);
|
||||
List<ProxiedPlayer> players = playerMap.get(server)
|
||||
.stream()
|
||||
.filter(p -> p.getServer().getInfo() == currentServer || SteamwarUser.get(p).getUserGroup() != UserGroup.Member || (team != null && team == getTeam(p)))
|
||||
.filter(p -> (p.getServer() != null && p.getServer().getInfo() == currentServer) || SteamwarUser.get(p).getUserGroup() != UserGroup.Member || (team != null && team == getTeam(p)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Subserver subserver = Subserver.getSubserver(player);
|
||||
|
@ -52,10 +52,12 @@ public class SteamwarUser {
|
||||
private int team;
|
||||
private boolean leader;
|
||||
private Map<Punishment.PunishmentType, Punishment> punishments;
|
||||
private String discordId;
|
||||
|
||||
private static final Map<String, SteamwarUser> usersByName = new HashMap<>();
|
||||
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
|
||||
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
|
||||
private static final Map<String, SteamwarUser> usersByDiscord = new HashMap<>();
|
||||
private static final InetAddress LIXFEL_DE;
|
||||
private static final String API_URL = "https://api.mojang.com/users/profiles/minecraft/";
|
||||
private static final JsonParser jsonParser = new JsonParser();
|
||||
@ -76,9 +78,12 @@ public class SteamwarUser {
|
||||
userGroup = UserGroup.getUsergroup(rs.getString("UserGroup"));
|
||||
team = rs.getInt("Team");
|
||||
leader = rs.getBoolean("Leader");
|
||||
discordId = rs.getString("DiscordId");
|
||||
usersById.put(id, this);
|
||||
usersByName.put(userName.toLowerCase(), this);
|
||||
usersByUUID.put(uuid, this);
|
||||
if(discordId != null)
|
||||
usersByDiscord.put(discordId, this);
|
||||
punishments = Punishment.getPunishmentsOfPlayer(id);
|
||||
}
|
||||
|
||||
@ -146,10 +151,17 @@ public class SteamwarUser {
|
||||
return dbInit(SQL.select("SELECT * FROM UserData WHERE id = ?", id));
|
||||
}
|
||||
|
||||
public static SteamwarUser get(Long discordId) {
|
||||
if(usersByDiscord.containsKey(discordId.toString()))
|
||||
return usersByDiscord.get(discordId.toString());
|
||||
return dbInit(SQL.select("SELECT * FROM UserData WHERE DiscordId = ?", discordId));
|
||||
}
|
||||
|
||||
public static void clearCache(){
|
||||
usersById.clear();
|
||||
usersByName.clear();
|
||||
usersByUUID.clear();
|
||||
usersByDiscord.clear();
|
||||
}
|
||||
|
||||
public static UUID loadUUID(String playerName) {
|
||||
@ -198,6 +210,19 @@ public class SteamwarUser {
|
||||
return punishments.getOrDefault(type, null);
|
||||
}
|
||||
|
||||
public String getDiscordId() {
|
||||
return discordId;
|
||||
}
|
||||
|
||||
public void setDiscordId(String discordId) {
|
||||
usersByDiscord.remove(this.discordId);
|
||||
this.discordId = discordId;
|
||||
SQL.update("Update UserData SET DiscordId = ? WHERE id = ?", discordId, id);
|
||||
if(discordId != null) {
|
||||
usersByDiscord.put(discordId, this);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBanned() {
|
||||
if(!punishments.containsKey(Punishment.PunishmentType.Ban))
|
||||
return false;
|
||||
|
@ -505,10 +505,21 @@ WHOIS_USERNAME=§7Username§8: §e{0}
|
||||
WHOIS_UUID=§7UUID§8: §e{0}
|
||||
WHOIS_UUID_HOVER=§eUUID Kopieren
|
||||
WHOIS_ID=§7ID§8: §e{0}
|
||||
WHOIS_DISCORD_ID=§7Discord-ID§8: §e{0}
|
||||
WHOIS_JOINED_FIRST=§7Beigetreten am§8: §e{0}
|
||||
WHOIS_HOURS_PLAYED=§7Online Time§8: §e{0}h
|
||||
WHOIS_TEAM=§7Team§8: §e[§{0}{1}§e] {2}
|
||||
WHOIS_TEAM_HOVER=§e{0} anzeigen
|
||||
WHOIS_PUNISHMENTS=§7Strafen:
|
||||
WHOIS_PUNISHMENT=§7{0}§8» §f§l{1}: §e{2} - {3} §f{4}
|
||||
WHOIS_NO_PUNISHMENT=§a✓ §7Der Spieler hat noch nichts getan.
|
||||
WHOIS_NO_PUNISHMENT=§a✓ §7Der Spieler hat noch nichts getan.
|
||||
|
||||
#VerifyCommand
|
||||
VERIFY_USAGE=§c/verify [Code]
|
||||
VERIFY_INVALID=§cInvalider Code
|
||||
VERIFY_SUCCESS=§7Erfolgreich mit dem Discord Account §e{0} §7verknüpft
|
||||
|
||||
#Discord
|
||||
DISCORD_TICKET_MESSAGE=§7Ticket §e{0}§7» §f§l{1}: §7{2}
|
||||
DISCORD_TICKET_NEW=§7Ticket §e{0}§7» §aTicket wurde geöffnet!
|
||||
DISCORD_TICKET_CLOSED=§7Ticket §e{0}§7» §cTicket wurde geschlossen!
|
In neuem Issue referenzieren
Einen Benutzer sperren