Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
c98e2c381d
Commit
8a43110100
@ -104,6 +104,7 @@ public class SteamwarDiscordBot {
|
|||||||
new DiscordTicketListener();
|
new DiscordTicketListener();
|
||||||
new DiscordAuthListener();
|
new DiscordAuthListener();
|
||||||
new DiscordEventListener();
|
new DiscordEventListener();
|
||||||
|
new PrivateMessageListener();
|
||||||
announcementListener = new AnnouncementListener();
|
announcementListener = new AnnouncementListener();
|
||||||
ingameChatListener = new IngameChatListener();
|
ingameChatListener = new IngameChatListener();
|
||||||
serverTeamChatListener = new ServerTeamChatListener();
|
serverTeamChatListener = new ServerTeamChatListener();
|
||||||
|
68
src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java
Normale Datei
68
src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java
Normale Datei
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
* <p>
|
||||||
|
* Copyright (C) 2021 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.
|
||||||
|
* <p>
|
||||||
|
* 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.
|
||||||
|
* <p>
|
||||||
|
* 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.sql.SchematicNode;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class PrivateMessageListener extends BasicDiscordListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPrivateMessageReceived(@NotNull PrivateMessageReceivedEvent event) {
|
||||||
|
if(!event.getMessage().getAttachments().isEmpty()) {
|
||||||
|
SteamwarUser user = SteamwarUser.get(event.getAuthor().getIdLong());
|
||||||
|
if (user == null) {
|
||||||
|
event.getMessage().reply("Du must dein Minecraft Account mit dem Bot verbinden, gehe dazu auf dem SteamWar Discord in den `regeln-infos` Channel und Klicke auf `Minecraft Verknüpfen`").complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Message.Attachment attachment : event.getMessage().getAttachments()) {
|
||||||
|
if(attachment.getFileExtension() == null ||
|
||||||
|
(!attachment.getFileExtension().equalsIgnoreCase("schem") &&
|
||||||
|
!attachment.getFileExtension().equalsIgnoreCase("schematic"))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean newFormat = attachment.getFileExtension().equalsIgnoreCase("schem");
|
||||||
|
int dot = attachment.getFileName().lastIndexOf(".");
|
||||||
|
String name = attachment.getFileName().substring(0, dot);
|
||||||
|
if(SchematicNode.invalidSchemName(new String[] {name})) {
|
||||||
|
event.getMessage().reply("`" + name + "` hat nicht zugelassene Zeichen im namen").queue();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SchematicNode node = SchematicNode.getSchematicNode(user.getId(), name, 0);
|
||||||
|
if(node == null) {
|
||||||
|
node = SchematicNode.createSchematic(user.getId(), name, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
node.saveFromStream(attachment.retrieveInputStream().get(), newFormat);
|
||||||
|
event.getMessage().reply("`" + name + "` wurde erfolgreich hochgeladen").queue();
|
||||||
|
} catch (Exception e) {
|
||||||
|
event.getMessage().reply("`" + name + "` konnte nicht geholt werden, bitte versuche es später nochmal.").queue();
|
||||||
|
throw new SecurityException("Could not Download", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -467,4 +469,45 @@ public class SchematicNode {
|
|||||||
SchematicNode node = (SchematicNode) obj;
|
SchematicNode node = (SchematicNode) obj;
|
||||||
return node.getId() == id;
|
return node.getId() == id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void saveFromBytes(byte[] bytes, boolean newFormat) {
|
||||||
|
if(isDir)
|
||||||
|
throw new SecurityException("Node is Directory");
|
||||||
|
updateDatabase(new ByteArrayInputStream(bytes), newFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveFromStream(InputStream stream, boolean newFormat) {
|
||||||
|
if(isDir)
|
||||||
|
throw new SecurityException("Node is Directory");
|
||||||
|
updateDatabase(stream, newFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateDatabase(InputStream blob, boolean newFormat) {
|
||||||
|
updateDatabase.update(blob, newFormat, id);
|
||||||
|
schemFormat = newFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final List<String> FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public"));
|
||||||
|
|
||||||
|
public static boolean invalidSchemName(String[] layers) {
|
||||||
|
for (String layer : layers) {
|
||||||
|
if (layer.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (layer.contains("/") ||
|
||||||
|
layer.contains("\\") ||
|
||||||
|
layer.contains("<") ||
|
||||||
|
layer.contains(">") ||
|
||||||
|
layer.contains("^") ||
|
||||||
|
layer.contains("°") ||
|
||||||
|
layer.contains("'") ||
|
||||||
|
layer.contains("\"")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(FORBIDDEN_NAMES.contains(layer.toLowerCase())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren