Added new ShowGalleries command
This commit is contained in:
parent
29308afaed
commit
d18d791fc4
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020. Aleksei Gryczewski
|
||||||
|
* All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dev.salmonllama.fsbot.commands.staff;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.javacord.api.entity.channel.ServerTextChannel;
|
||||||
|
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||||
|
import org.javacord.api.entity.server.Server;
|
||||||
|
|
||||||
|
import dev.salmonllama.fsbot.config.BotConfig;
|
||||||
|
import dev.salmonllama.fsbot.database.controllers.GalleryController;
|
||||||
|
import dev.salmonllama.fsbot.database.models.GalleryChannel;
|
||||||
|
import dev.salmonllama.fsbot.guthix.Command;
|
||||||
|
import dev.salmonllama.fsbot.guthix.CommandContext;
|
||||||
|
import dev.salmonllama.fsbot.guthix.CommandPermission;
|
||||||
|
import dev.salmonllama.fsbot.guthix.PermissionType;
|
||||||
|
|
||||||
|
public class ShowGalleriesCommand extends Command {
|
||||||
|
@Override public String name() { return "Show Galleries"; }
|
||||||
|
@Override public String description() { return "Shows registered gallery channels in the current server"; }
|
||||||
|
@Override public String usage() { return "showgalleries"; }
|
||||||
|
@Override public String category() { return "Staff"; }
|
||||||
|
@Override public CommandPermission permission() { return new CommandPermission(PermissionType.ROLE, BotConfig.STAFF_ROLE); }
|
||||||
|
@Override public Collection<String> aliases() { return new ArrayList<>(Arrays.asList("showgalleries", "listgalleries")); }
|
||||||
|
|
||||||
|
@Override public void onCommand(CommandContext ctx) {
|
||||||
|
if (ctx.isPrivateMessage()) {
|
||||||
|
ctx.reply("This command can only be used within a server"); // TODO: Preset embeds again, yeah
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.getServer().ifPresent(server -> {
|
||||||
|
try {
|
||||||
|
Collection<GalleryChannel> galleries = GalleryController.getGalleriesByServer(server.getIdAsString());
|
||||||
|
ctx.reply(galleryEmbed(galleries, server));
|
||||||
|
} catch (SQLException e) {
|
||||||
|
ctx.reply("An exception has occurred: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
EmbedBuilder galleryEmbed(Collection<GalleryChannel> galleries, Server server) { // TODO: Base FSBot embed.
|
||||||
|
EmbedBuilder embed = new EmbedBuilder()
|
||||||
|
.setTitle("Server Gallery Channels");
|
||||||
|
|
||||||
|
Collection<String> mentionTags = galleries.stream().map(
|
||||||
|
galleryChannel -> server.getChannelById(
|
||||||
|
galleryChannel.getChannelId()).get() // Can call get safely -> The channel is not stored if it is not a valid ServerTextChannel
|
||||||
|
.asServerTextChannel().get()) // Same as above
|
||||||
|
.map(ServerTextChannel::getMentionTag).collect(Collectors.toList());
|
||||||
|
|
||||||
|
Collection<String> tags = galleries.stream().map(GalleryChannel::getTag).collect(Collectors.toList());
|
||||||
|
|
||||||
|
embed.addField("Channels", String.join("\n", mentionTags), true);
|
||||||
|
embed.addField("Tags", String.join("\n", tags), true);
|
||||||
|
|
||||||
|
return embed;
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,26 @@ public class GalleryChannel extends DatabaseModel {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getServerId() {
|
||||||
|
return serverId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerName() {
|
||||||
|
return serverName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getChannelId() {
|
||||||
|
return channelId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getChannelName() {
|
||||||
|
return channelName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTag() {
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
public static String schema() {
|
public static String schema() {
|
||||||
return "CREATE TABLE IF NOT EXISTS galleries (" +
|
return "CREATE TABLE IF NOT EXISTS galleries (" +
|
||||||
"server_id TEXT," +
|
"server_id TEXT," +
|
||||||
|
@ -68,6 +68,7 @@ public class Guthix implements MessageCreateListener {
|
|||||||
addCommand(new OutfitInfoCommand(db));
|
addCommand(new OutfitInfoCommand(db));
|
||||||
addCommand(new SetStatusCommand());
|
addCommand(new SetStatusCommand());
|
||||||
addCommand(new WelcomeMessageCommand());
|
addCommand(new WelcomeMessageCommand());
|
||||||
|
addCommand(new ShowGalleriesCommand());
|
||||||
|
|
||||||
// General Commands
|
// General Commands
|
||||||
addCommand(new PingCommand());
|
addCommand(new PingCommand());
|
||||||
|
Loading…
Reference in New Issue
Block a user