Fully implement Discord bot

This commit is contained in:
Paul Reilly
2023-08-28 01:53:48 -05:00
parent a676207afa
commit c71ab845b9
33 changed files with 892 additions and 65 deletions

View File

@ -8,6 +8,8 @@ repositories {
dependencies {
library 'io.projectreactor:reactor-core:3.5.4'
library 'io.github.classgraph:classgraph:4.8.162'
library 'org.tomlj:tomlj:1.1.0'
library 'com.google.code.gson:gson:2.8.9'
api 'org.slf4j:slf4j-api:1.7.36'
testImplementation platform('org.junit:junit-bom:5.9.1')

View File

@ -1,44 +0,0 @@
/*
* This file is part of Freedom-Network-Suite - https://github.com/AtlasMediaGroup/Freedom-Network-Suite
* Copyright (C) 2023 Total Freedom Server Network and 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 fns.patchwork.api;
/**
* Interpolates a range of values and returns the results in a {@link Double} array.
* <br>
* This is a functional interface, to allow for lambda expressions, but also for anonymous custom interpolation
* implementations.
*/
@FunctionalInterface
public interface Interpolator
{
/**
* Interpolates a range of values and returns the results in a {@link Double} array.
*
* @param from The starting value.
* @param to The ending value.
* @param max The number of values to interpolate.
* @return The interpolated values.
*/
double[] interpolate(final double from, final double to, final int max);
}

View File

@ -23,12 +23,12 @@
package fns.patchwork.base;
import fns.patchwork.data.ConfigRegistry;
import fns.patchwork.data.EventRegistry;
import fns.patchwork.data.GroupRegistry;
import fns.patchwork.data.ModuleRegistry;
import fns.patchwork.data.ServiceTaskRegistry;
import fns.patchwork.data.UserRegistry;
import fns.patchwork.registry.ConfigRegistry;
import fns.patchwork.registry.EventRegistry;
import fns.patchwork.registry.GroupRegistry;
import fns.patchwork.registry.ModuleRegistry;
import fns.patchwork.registry.ServiceTaskRegistry;
import fns.patchwork.registry.UserRegistry;
/**
* This class is a holder for each registry in the data package.

View File

@ -23,9 +23,8 @@
package fns.patchwork.config;
import fns.patchwork.api.Context;
import fns.patchwork.provider.Context;
import fns.patchwork.provider.ContextProvider;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
import java.io.File;

View File

@ -0,0 +1,184 @@
/*
* This file is part of Freedom-Network-Suite - https://github.com/AtlasMediaGroup/Freedom-Network-Suite
* Copyright (C) 2023 Total Freedom Server Network and 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 fns.patchwork.config;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.Unmodifiable;
import org.tomlj.Toml;
import org.tomlj.TomlParseResult;
// TODO: Finish implementation
public class WrappedTomlConfiguration implements Configuration
{
private final Map<String, Object> previousValues = new HashMap<>();
private final TomlParseResult toml;
private final File file;
public WrappedTomlConfiguration(final JavaPlugin plugin, final File file) throws IOException
{
if (!file.exists() && file.createNewFile())
{
plugin.saveResource(file.getName(), true);
}
this.toml = Toml.parse(Path.of(file.toURI()));
this.file = file;
}
@Override
public void save() throws IOException
{
// Create a backup file
final File backup = new File(this.file.getParentFile(), this.file.getName() + ".bak");
if (backup.exists() && !Files.deleteIfExists(Path.of(backup.toURI())))
{
throw new IOException("Failed to delete existing backup file: " + backup.getName());
}
// Serialize the current configuration to a temporary file
final File tempFile = new File(this.file.getParentFile(), this.file.getName() + ".temp");
try (FileWriter tempFileWriter = new FileWriter(tempFile))
{
// Convert the updated TomlTable to TOML format and write it to the temporary file
String tomlString = this.toml.toToml();
tempFileWriter.write(tomlString);
}
// Compare the new configuration with the previous one
TomlParseResult newToml = Toml.parse(Path.of(tempFile.toURI()));
for (Map.Entry<String, Object> entry : newToml.toMap().entrySet())
{
String key = entry.getKey();
Object newValue = entry.getValue();
Object oldValue = previousValues.get(key);
if (oldValue == null || !oldValue.equals(newValue))
{
// Value has changed, update it
this.toml.toMap().replace(key, newValue);
previousValues.put(key, newValue);
}
}
// Save the updated configuration to the original file
try (FileWriter fileWriter = new FileWriter(this.file))
{
// Convert the updated TomlTable to TOML format and write it to the original file
String tomlString = this.toml.toToml();
fileWriter.write(tomlString);
}
// Delete the temporary file and the backup file
Files.delete(Path.of(tempFile.toURI()));
Files.delete(Path.of(backup.toURI()));
}
@Override
public void load() throws IOException
{
// TODO: Implement
}
@Override
public String getFileName()
{
return null;
}
@Override
public File getConfigurationFile()
{
return null;
}
@Override
public String getString(String path)
{
return null;
}
@Override
public boolean getBoolean(String path)
{
return false;
}
@Override
public @Unmodifiable <T> List<T> getList(String path, Class<T> clazz)
{
return null;
}
@Override
public @Unmodifiable List<String> getStringList(String path)
{
return null;
}
@Override
public int getInt(String path)
{
return 0;
}
@Override
public long getLong(String path)
{
return 0;
}
@Override
public double getDouble(String path)
{
return 0;
}
@Override
public <T> void set(String path, T value)
{
// TODO: Implement
}
@Override
public <T> Optional<T> get(String path, Class<T> clazz)
{
return Optional.empty();
}
@Override
public <T> T getOrDefault(String path, Class<T> clazz, T fallback)
{
return null;
}
}

View File

@ -23,7 +23,7 @@
package fns.patchwork.event;
import fns.patchwork.api.Context;
import fns.patchwork.provider.Context;
import fns.patchwork.base.Patchwork;
import fns.patchwork.service.Service;
import java.util.HashSet;

View File

@ -23,7 +23,6 @@
package fns.patchwork.particle;
import fns.patchwork.api.Interpolator;
import fns.patchwork.utils.InterpolationUtils;
import java.util.Set;
import java.util.UUID;
@ -101,7 +100,7 @@ public interface Trail
* @see #getColor()
* @see Particle
* @see InterpolationUtils
* @see Interpolator
* @see InterpolationUtils.Interpolator
*/
@Nullable
Set<Color> getColors();

View File

@ -21,9 +21,8 @@
* SOFTWARE.
*/
package fns.patchwork.api;
package fns.patchwork.provider;
import fns.patchwork.provider.ContextProvider;
import java.util.function.Function;
import net.kyori.adventure.text.Component;
import org.bukkit.Location;

View File

@ -21,7 +21,7 @@
* SOFTWARE.
*/
package fns.patchwork.data;
package fns.patchwork.registry;
import fns.patchwork.config.Configuration;
import java.util.HashMap;

View File

@ -21,7 +21,7 @@
* SOFTWARE.
*/
package fns.patchwork.data;
package fns.patchwork.registry;
import fns.patchwork.event.FEvent;
import fns.patchwork.provider.EventProvider;

View File

@ -21,7 +21,7 @@
* SOFTWARE.
*/
package fns.patchwork.data;
package fns.patchwork.registry;
import fns.patchwork.permissible.Group;
import java.util.ArrayList;

View File

@ -21,7 +21,7 @@
* SOFTWARE.
*/
package fns.patchwork.data;
package fns.patchwork.registry;
import fns.patchwork.provider.ModuleProvider;
import java.util.ArrayList;

View File

@ -21,7 +21,7 @@
* SOFTWARE.
*/
package fns.patchwork.data;
package fns.patchwork.registry;
import fns.patchwork.service.Service;
import fns.patchwork.service.ServiceSubscription;

View File

@ -21,7 +21,7 @@
* SOFTWARE.
*/
package fns.patchwork.data;
package fns.patchwork.registry;
import fns.patchwork.user.User;
import fns.patchwork.user.UserData;

View File

@ -21,7 +21,7 @@
* SOFTWARE.
*/
package fns.patchwork.api;
package fns.patchwork.serializer;
/**
* This interface represents a Serializable object. Objects which require custom serialization and cannot simply

View File

@ -23,7 +23,6 @@
package fns.patchwork.utils;
import fns.patchwork.api.Interpolator;
import java.util.LinkedHashSet;
import java.util.Set;
import net.kyori.adventure.text.format.NamedTextColor;
@ -155,4 +154,24 @@ public final class InterpolationUtils
{
return componentRGBGradient(length, from, to, InterpolationUtils::linear);
}
/**
* Interpolates a range of values and returns the results in a {@link Double} array.
* <br>
* This is a functional interface, to allow for lambda expressions, but also for anonymous custom interpolation
* implementations.
*/
@FunctionalInterface
public static interface Interpolator
{
/**
* Interpolates a range of values and returns the results in a {@link Double} array.
*
* @param from The starting value.
* @param to The ending value.
* @param max The number of values to interpolate.
* @return The interpolated values.
*/
double[] interpolate(final double from, final double to, final int max);
}
}