Add threads

This commit is contained in:
Vankka 2022-01-13 18:53:43 +02:00
parent 0e73f80d40
commit 9fe73aa571
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
4 changed files with 223 additions and 1 deletions

View File

@ -0,0 +1,59 @@
/*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2021 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.api;
import com.discordsrv.api.discord.api.entity.channel.DiscordThreadChannel;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public class ThreadChannelLookup {
private final long channelId;
private final boolean privateThreads;
private final CompletableFuture<List<DiscordThreadChannel>> future;
private final CompletableFuture<DiscordThreadChannel> channelFuture = new CompletableFuture<>();
public ThreadChannelLookup(long channelId, boolean privateThreads, CompletableFuture<List<DiscordThreadChannel>> future) {
this.channelId = channelId;
this.privateThreads = privateThreads;
this.future = future;
}
public long getChannelId() {
return channelId;
}
public boolean isPrivateThreads() {
return privateThreads;
}
public CompletableFuture<List<DiscordThreadChannel>> getFuture() {
return future;
}
public CompletableFuture<DiscordThreadChannel> getChannelFuture() {
return channelFuture;
}
}

View File

@ -0,0 +1,41 @@
/*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2021 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.api.entity.channel;
import com.discordsrv.api.DiscordSRVApi;
import net.dv8tion.jda.api.entities.ThreadChannel;
import org.jetbrains.annotations.NotNull;
public interface DiscordThreadChannel extends DiscordMessageChannel, DiscordGuildChannel {
@NotNull
DiscordTextChannel getParentChannel();
/**
* Returns the JDA representation of this object. This should not be used if it can be avoided.
* @return the JDA representation of this object
* @see DiscordSRVApi#jda()
*/
ThreadChannel getAsJDAThreadChannel();
}

View File

@ -16,4 +16,18 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.discordsrv.common.command.game;
package com.discordsrv.common.config.main.channels.base;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
@ConfigSerializable
public class ThreadConfig {
public Long channelId = 0L;
public String threadName = "Minecraft Server chat bridge";
public boolean privateThread = false;
public boolean archiveOnShutdown = true;
public boolean unarchive = true;
}

View File

@ -0,0 +1,108 @@
/*
* This file is part of DiscordSRV, licensed under the GPLv3 License
* Copyright (c) 2016-2021 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.discordsrv.common.discord.api.entity.channel;
import com.discordsrv.api.discord.api.entity.channel.DiscordTextChannel;
import com.discordsrv.api.discord.api.entity.channel.DiscordThreadChannel;
import com.discordsrv.api.discord.api.entity.guild.DiscordGuild;
import com.discordsrv.api.discord.api.entity.message.ReceivedDiscordMessage;
import com.discordsrv.api.discord.api.entity.message.SendableDiscordMessage;
import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.discord.api.entity.guild.DiscordGuildImpl;
import com.discordsrv.common.discord.api.entity.message.ReceivedDiscordMessageImpl;
import com.discordsrv.common.discord.api.entity.message.util.SendableDiscordMessageUtil;
import net.dv8tion.jda.api.entities.IThreadContainer;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.ThreadChannel;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
public class DiscordThreadChannelImpl extends DiscordMessageChannelImpl<ThreadChannel> implements DiscordThreadChannel {
private final DiscordTextChannel textChannel;
private final DiscordGuild guild;
public DiscordThreadChannelImpl(DiscordSRV discordSRV, ThreadChannel thread) {
super(discordSRV, thread);
IThreadContainer container = thread.getParentChannel();
this.textChannel = container instanceof TextChannel
? new DiscordTextChannelImpl(discordSRV, (TextChannel) container)
: null;
this.guild = new DiscordGuildImpl(discordSRV, thread.getGuild());
}
@Override
public @NotNull CompletableFuture<ReceivedDiscordMessage> sendMessage(@NotNull SendableDiscordMessage message) {
if (message.isWebhookMessage()) {
throw new IllegalArgumentException("Cannot send webhook messages to ThreadChannels");
}
return discordSRV.discordAPI().mapExceptions(
channel.sendMessage(SendableDiscordMessageUtil.toJDA(message))
.submit()
.thenApply(msg -> ReceivedDiscordMessageImpl.fromJDA(discordSRV, msg))
);
}
@Override
public CompletableFuture<Void> deleteMessageById(long id, boolean webhookMessage) {
if (webhookMessage) {
throw new IllegalArgumentException("ThreadChannels do not contain webhook messages");
}
return discordSRV.discordAPI().mapExceptions(
channel.deleteMessageById(id).submit()
);
}
@Override
public @NotNull CompletableFuture<ReceivedDiscordMessage> editMessageById(long id, @NotNull SendableDiscordMessage message) {
if (message.isWebhookMessage()) {
throw new IllegalArgumentException("Cannot send webhook messages to ThreadChannels");
}
return discordSRV.discordAPI().mapExceptions(
channel.editMessageById(id, SendableDiscordMessageUtil.toJDA(message))
.submit()
.thenApply(msg -> ReceivedDiscordMessageImpl.fromJDA(discordSRV, msg))
);
}
@Override
public @NotNull String getName() {
return channel.getName();
}
@Override
public @NotNull DiscordGuild getGuild() {
return guild;
}
@Override
public @NotNull DiscordTextChannel getParentChannel() {
return textChannel;
}
@Override
public ThreadChannel getAsJDAThreadChannel() {
return channel;
}
}