Added the Embed module V1

This commit is contained in:
Mathias Wagner 2022-09-06 16:30:52 +02:00
parent be825e7281
commit 526dba12b8
7 changed files with 185 additions and 0 deletions

3
SheepstarModules/EmbedV1/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Project exclude paths
/target/
.idea

View File

@ -0,0 +1,2 @@
# SheepstarModule-Embed
The official sheepstar embed module

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xyz.sheepstar</groupId>
<artifactId>SheepstarModule-Embed</artifactId>
<version>pre1.0.0</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>xyz.sheepstar</groupId>
<artifactId>SheepstarCore</artifactId>
<version>beta1.0.2</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,75 @@
package xyz.sheepstar.embed.commands;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import xyz.sheepstar.util.bot.builder.message.DefaultEmbedBuilder;
import xyz.sheepstar.util.bot.command.Arguments;
import xyz.sheepstar.util.bot.command.GuildCommand;
import xyz.sheepstar.util.bot.command.GuildEventController;
import xyz.sheepstar.util.bot.command.PublicCommandException;
import xyz.sheepstar.util.bot.command.annotations.CommandMeta;
import xyz.sheepstar.util.bot.permission.PermissionNode;
import java.awt.*;
import java.util.Date;
@CommandMeta(aliases = "embed", subAliases = "custom", permission = PermissionNode.ADMINISTRATOR, description = "Creates a fully customizable embed")
public class CustomEmbedCommand extends GuildCommand {
@Override
public void usage() {
usage("title", "The title of the embed").required(true).add();
usage("description", "The description of the embed").add();
usage("author_name", "The name of the author field").add();
usage("author_url", "The url of the author field (needs author_name to work)").add();
usage("footer_text", "The text of the footer field").add();
usage("footer_icon", "The icon of the footer field (needs footer_text to work)").add();
usage("thumbnail_url", "The url of the thumbnail").add();
usage("image_url", "The url of the image").add();
usage(OptionType.BOOLEAN, "enable_timestamp", "Shows a timestamp below the embed").add();
usage("color", "The color of the embed (hex-code)").add();
}
@Override
public void execute(GuildEventController event, Arguments args) throws Exception {
DefaultEmbedBuilder builder = new DefaultEmbedBuilder();
try {
builder.setTitle(args.getString("title"));
if (args.exists("description")) builder.setDescription(args.getString("description").replace("\\n", "\n"));
if (args.exists("author_name")) builder.setAuthor(args.getString("author_name"));
if (args.exists("author_name") && args.exists("author_url"))
builder.setAuthor(args.getString("author_name"), null, args.getString("author_url"));
if (args.exists("footer_text")) builder.setFooter(args.getString("footer_text"));
if (args.exists("footer_text") && args.exists("footer_icon"))
builder.setFooter(args.getString("footer_text"), args.getString("footer_icon"));
if (args.exists("thumbnail_url")) builder.setThumbnail(args.getString("thumbnail_url"));
if (args.exists("image_url")) builder.setImage(args.getString("image_url"));
if (args.exists("enable_timestamp") && args.getBoolean("enable_timestamp"))
builder.setTimestamp(new Date().toInstant());
if (args.exists("color")) builder.setColor(Color.decode(args.getString("color")));
event.getChannel().sendMessage(builder.toMessage()).complete();
event.success("embed.success");
} catch (Exception e) {
throw new PublicCommandException("embed.error", e.getMessage());
}
}
}

View File

@ -0,0 +1,57 @@
package xyz.sheepstar.embed.commands;
import xyz.sheepstar.util.bot.builder.message.DefaultEmbedBuilder;
import xyz.sheepstar.util.bot.command.Arguments;
import xyz.sheepstar.util.bot.command.GuildCommand;
import xyz.sheepstar.util.bot.command.GuildEventController;
import xyz.sheepstar.util.bot.command.annotations.CommandMeta;
import xyz.sheepstar.util.bot.permission.PermissionNode;
import java.awt.*;
import static xyz.sheepstar.util.bot.builder.message.MessageType.*;
@CommandMeta(aliases = "embed", subAliases = "simple", permission = PermissionNode.ADMINISTRATOR, description = "Creates a simple embed")
public class SimpleEmbedCommand extends GuildCommand {
@Override
public void usage() {
usage("title", "The title of the embed").required(true).add();
usage("description", "The description of the embed").required(true).add();
usage("color", "The color of the embed")
.addChoice("blue", getHex(PRIMARY.getColor()))
.addChoice("red", getHex(ERROR.getColor()))
.addChoice("green", getHex(SUCCESS.getColor()))
.addChoice("orange", getHex(WARNING.getColor()))
.addChoice("gray", getHex(SECONDARY.getColor()))
.addChoice("white", getHex(WHITE.getColor()))
.addChoice("black", getHex(BLACK.getColor()))
.add();
}
/**
* Gets the hex code of a color
* @param color The color you want to translate
* @return the color as a hex string
*/
public String getHex(Color color) {
return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue());
}
@Override
public void execute(GuildEventController event, Arguments args) throws Exception {
DefaultEmbedBuilder builder = new DefaultEmbedBuilder();
builder.setTitle(args.getString("title"));
builder.setDescription(args.getString("description").replace("\\n", "\n"));
builder.setColor(args.exists("color") ? Color.decode(args.getString("color")) : PRIMARY.getColor());
event.getChannel().sendMessage(builder.toMessage()).queue();
event.success("embed.embed_created");
}
}

View File

@ -0,0 +1,21 @@
package xyz.sheepstar.embed.core;
import xyz.sheepstar.embed.commands.CustomEmbedCommand;
import xyz.sheepstar.embed.commands.SimpleEmbedCommand;
import xyz.sheepstar.util.bot.manager.ImportManager;
import xyz.sheepstar.util.module.SheepstarModule;
public class EmbedCore extends SheepstarModule {
// TODO: Embed channels
private ImportManager importManager;
@Override
public void onEnable() {
importManager = new ImportManager(getAPI(), "embed");
importManager.registerCommand(new SimpleEmbedCommand());
importManager.registerCommand(new CustomEmbedCommand());
}
}

View File

@ -0,0 +1,3 @@
main: xyz.sheepstar.embed.core.EmbedCore
name: embed
author: Mathias Wagner