Dieser Commit ist enthalten in:
Commit
95698ff276
@ -104,6 +104,7 @@ public class SteamwarDiscordBot {
|
||||
new DiscordTicketListener();
|
||||
new DiscordAuthListener();
|
||||
new DiscordEventListener();
|
||||
new PrivateMessageListener();
|
||||
announcementListener = new AnnouncementListener();
|
||||
ingameChatListener = new IngameChatListener();
|
||||
serverTeamChatListener = new ServerTeamChatListener();
|
||||
|
75
src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java
Normale Datei
75
src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java
Normale Datei
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.BungeeCore;
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
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;
|
||||
|
||||
public class PrivateMessageListener extends BasicDiscordListener {
|
||||
|
||||
@Override
|
||||
public void onPrivateMessageReceived(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;
|
||||
}
|
||||
|
||||
if(user.isPunished(Punishment.PunishmentType.NoSchemReceiving)) {
|
||||
event.getMessage().reply("Du darfst keine Schematics hochladen").complete();
|
||||
return;
|
||||
}
|
||||
|
||||
for (Message.Attachment attachment : event.getMessage().getAttachments()) {
|
||||
if(attachment.getFileExtension() == null ||
|
||||
(!attachment.getFileExtension().equalsIgnoreCase("schem") &&
|
||||
!attachment.getFileExtension().equalsIgnoreCase("schematic"))) {
|
||||
event.getMessage().reply("`" + attachment.getFileName() + "` wird ignoriert, da die Datei keine Schematic ist").queue();
|
||||
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 hochgeladen werden, bitte versuche es später nochmal oder wende dich an einen Developer").queue();
|
||||
BungeeCore.log("Could not Upload Schem \"" + name + "\" from User \"" + user.getUserName() + "\"" + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -19,6 +19,8 @@
|
||||
|
||||
package de.steamwar.bungeecore.sql;
|
||||
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -467,4 +469,39 @@ public class SchematicNode {
|
||||
SchematicNode node = (SchematicNode) obj;
|
||||
return node.getId() == id;
|
||||
}
|
||||
|
||||
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