Rename Shutdown Behaviour to Channel Locking

This commit is contained in:
Vankka 2022-04-26 15:37:41 +03:00
parent 97a2b5edbe
commit 5ccf8f7cb7
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
6 changed files with 26 additions and 31 deletions

View File

@ -27,7 +27,7 @@ import com.discordsrv.api.module.type.Module;
import com.discordsrv.common.api.util.ApiInstanceUtil; import com.discordsrv.common.api.util.ApiInstanceUtil;
import com.discordsrv.common.bootstrap.IBootstrap; import com.discordsrv.common.bootstrap.IBootstrap;
import com.discordsrv.common.channel.ChannelConfigHelper; import com.discordsrv.common.channel.ChannelConfigHelper;
import com.discordsrv.common.channel.ChannelShutdownBehaviourModule; import com.discordsrv.common.channel.ChannelLockingModule;
import com.discordsrv.common.channel.ChannelUpdaterModule; import com.discordsrv.common.channel.ChannelUpdaterModule;
import com.discordsrv.common.channel.GlobalChannelLookupModule; import com.discordsrv.common.channel.GlobalChannelLookupModule;
import com.discordsrv.common.command.game.GameCommandModule; import com.discordsrv.common.command.game.GameCommandModule;
@ -493,7 +493,7 @@ public abstract class AbstractDiscordSRV<B extends IBootstrap, C extends MainCon
placeholderService().addGlobalContext(new GlobalTextHandlingContext(this)); placeholderService().addGlobalContext(new GlobalTextHandlingContext(this));
// Modules // Modules
registerModule(ChannelShutdownBehaviourModule::new); registerModule(ChannelLockingModule::new);
registerModule(ChannelUpdaterModule::new); registerModule(ChannelUpdaterModule::new);
registerModule(GameCommandModule::new); registerModule(GameCommandModule::new);
registerModule(GlobalChannelLookupModule::new); registerModule(GlobalChannelLookupModule::new);

View File

@ -20,7 +20,7 @@ package com.discordsrv.common.channel;
import com.discordsrv.api.discord.api.entity.channel.DiscordThreadChannel; import com.discordsrv.api.discord.api.entity.channel.DiscordThreadChannel;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.config.main.channels.ShutdownBehaviourConfig; import com.discordsrv.common.config.main.channels.ChannelLockingConfig;
import com.discordsrv.common.config.main.channels.base.BaseChannelConfig; import com.discordsrv.common.config.main.channels.base.BaseChannelConfig;
import com.discordsrv.common.config.main.channels.base.IChannelConfig; import com.discordsrv.common.config.main.channels.base.IChannelConfig;
import com.discordsrv.common.function.OrDefault; import com.discordsrv.common.function.OrDefault;
@ -35,9 +35,9 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
public class ChannelShutdownBehaviourModule extends AbstractModule<DiscordSRV> { public class ChannelLockingModule extends AbstractModule<DiscordSRV> {
public ChannelShutdownBehaviourModule(DiscordSRV discordSRV) { public ChannelLockingModule(DiscordSRV discordSRV) {
super(discordSRV); super(discordSRV);
} }
@ -49,9 +49,9 @@ public class ChannelShutdownBehaviourModule extends AbstractModule<DiscordSRV> {
@Override @Override
public void enable() { public void enable() {
doForAllChannels((config, channelConfig) -> { doForAllChannels((config, channelConfig) -> {
OrDefault<ShutdownBehaviourConfig> shutdownConfig = config.map(cfg -> cfg.shutdownBehaviour); OrDefault<ChannelLockingConfig> shutdownConfig = config.map(cfg -> cfg.channelLocking);
OrDefault<ShutdownBehaviourConfig.Channels> channels = shutdownConfig.map(cfg -> cfg.channels); OrDefault<ChannelLockingConfig.Channels> channels = shutdownConfig.map(cfg -> cfg.channels);
OrDefault<ShutdownBehaviourConfig.Threads> threads = shutdownConfig.map(cfg -> cfg.threads); OrDefault<ChannelLockingConfig.Threads> threads = shutdownConfig.map(cfg -> cfg.threads);
if (threads.get(cfg -> cfg.unarchive, true)) { if (threads.get(cfg -> cfg.unarchive, true)) {
discordSRV.discordAPI().findOrCreateThreads(config, channelConfig, __ -> {}, new ArrayList<>(), false); discordSRV.discordAPI().findOrCreateThreads(config, channelConfig, __ -> {}, new ArrayList<>(), false);
@ -63,9 +63,9 @@ public class ChannelShutdownBehaviourModule extends AbstractModule<DiscordSRV> {
@Override @Override
public void disable() { public void disable() {
doForAllChannels((config, channelConfig) -> { doForAllChannels((config, channelConfig) -> {
OrDefault<ShutdownBehaviourConfig> shutdownConfig = config.map(cfg -> cfg.shutdownBehaviour); OrDefault<ChannelLockingConfig> shutdownConfig = config.map(cfg -> cfg.channelLocking);
OrDefault<ShutdownBehaviourConfig.Channels> channels = shutdownConfig.map(cfg -> cfg.channels); OrDefault<ChannelLockingConfig.Channels> channels = shutdownConfig.map(cfg -> cfg.channels);
OrDefault<ShutdownBehaviourConfig.Threads> threads = shutdownConfig.map(cfg -> cfg.threads); OrDefault<ChannelLockingConfig.Threads> threads = shutdownConfig.map(cfg -> cfg.threads);
if (threads.get(cfg -> cfg.archive, true)) { if (threads.get(cfg -> cfg.archive, true)) {
for (DiscordThreadChannel thread : discordSRV.discordAPI().findThreads(config, channelConfig)) { for (DiscordThreadChannel thread : discordSRV.discordAPI().findThreads(config, channelConfig)) {
@ -81,7 +81,7 @@ public class ChannelShutdownBehaviourModule extends AbstractModule<DiscordSRV> {
private void channelPermissions( private void channelPermissions(
IChannelConfig channelConfig, IChannelConfig channelConfig,
OrDefault<ShutdownBehaviourConfig.Channels> shutdownConfig, OrDefault<ChannelLockingConfig.Channels> shutdownConfig,
boolean state boolean state
) { ) {
JDA jda = discordSRV.jda().orElse(null); JDA jda = discordSRV.jda().orElse(null);

View File

@ -25,7 +25,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@ConfigSerializable @ConfigSerializable
public class ShutdownBehaviourConfig { public class ChannelLockingConfig {
public Channels channels = new Channels(); public Channels channels = new Channels();
public Threads threads = new Threads(); public Threads threads = new Threads();

View File

@ -53,5 +53,5 @@ public class BaseChannelConfig {
public MirroringConfig mirroring = new MirroringConfig(); public MirroringConfig mirroring = new MirroringConfig();
@Order(50) @Order(50)
public ShutdownBehaviourConfig shutdownBehaviour = new ShutdownBehaviourConfig(); public ChannelLockingConfig channelLocking = new ChannelLockingConfig();
} }

View File

@ -187,7 +187,7 @@ public class DiscordAPIImpl implements DiscordAPI {
ThreadConfig threadConfig, ThreadConfig threadConfig,
DiscordTextChannel textChannel DiscordTextChannel textChannel
) { ) {
if (!config.map(cfg -> cfg.shutdownBehaviour).map(cfg -> cfg.threads).get(cfg -> cfg.unarchive, true)) { if (!config.map(cfg -> cfg.channelLocking).map(cfg -> cfg.threads).get(cfg -> cfg.unarchive, true)) {
return textChannel.createThread(threadConfig.threadName, threadConfig.privateThread); return textChannel.createThread(threadConfig.threadName, threadConfig.privateThread);
} }

View File

@ -1,24 +1,19 @@
/* /*
* This file is part of the DiscordSRV API, licensed under the MIT License * This file is part of DiscordSRV, licensed under the GPLv3 License
* Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors * Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * This program is free software: you can redistribute it and/or modify
* of this software and associated documentation files (the "Software"), to deal * it under the terms of the GNU General Public License as published by
* in the Software without restriction, including without limitation the rights * the Free Software Foundation, either version 3 of the License, or
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * (at your option) any later version.
* 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 * This program is distributed in the hope that it will be useful,
* copies or substantial portions of the Software. * 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.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * You should have received a copy of the GNU General Public License
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * along with this program. If not, see <https://www.gnu.org/licenses/>.
* 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.common.discord.api; package com.discordsrv.common.discord.api;