WIP on role system

This commit is contained in:
Alex Stewart
2020-08-06 21:07:14 -04:00
parent 67f1e083e9
commit 20a16f2c74
5 changed files with 194 additions and 169 deletions
@@ -0,0 +1,35 @@
package commands.guildrole;
import java.util.ArrayList;
import core.Command;
import core.ObjectBuilderFactory;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.Response;
import dataStructures.UserInput;
import net.dv8tion.jda.core.JDA;
public class CommandWipeRoles extends Command
{
public CommandWipeRoles(KittyRole roleLevel, KittyRating contentRating) {super(roleLevel, contentRating);
// TODO Auto-generated constructor stub
}
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
JDA kitty = res.getKitty();
ArrayList guilds = (ArrayList) kitty.getGuilds();
KittyGuild guildx;
for(int i = 0; i < guilds.size(); i ++)
{
guildx = ObjectBuilderFactory.extractGuild
}
}
}
@@ -1,21 +0,0 @@
package commands.guildrole;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.UserInput;
public class SubCommandWipeRoles extends SubCommand
{
public SubCommandWipeRoles(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
{
return null;
}
}
+4 -1
View File
@@ -167,7 +167,8 @@ public class ObjectBuilderFactory
else
{
// Construct a new guild with defaults
guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString, new AudioUtils(event.getGuild(), playerManager), channels);
guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString,
new AudioUtils(event.getGuild(), playerManager), channels);
DatabaseManager.instance.globalRegister(guild);
guildCache.put(uid, guild);
}
@@ -176,6 +177,8 @@ public class ObjectBuilderFactory
return guild;
}
// Explicitly locks: guildCache
public static KittyRole extractRole(GuildMessageReceivedEvent event)
{
+153 -146
View File
@@ -1,146 +1,153 @@
package dataStructures;
import java.io.File;
import java.io.InputStream;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.events.message.guild.*;
import net.dv8tion.jda.core.EmbedBuilder;
import utils.GlobalLog;
import utils.LogFilter;
// This isn't constructed with the factory at this time, mostly because we need it
// to handle all the response queue behavior and everything internally. So long as
// commands aren't exposed to the GuildMessageReceivedEvent then we should be fine.
public class Response
{
// Variables
private GuildMessageReceivedEvent event;
private final int discordMessageMax = 2000;
private final int kittyMessageMax = 1950;
private JDA kitty;
// Constructor
public Response(GuildMessageReceivedEvent event, KittyCore kitty)
{
this.event = event;
this.kitty = kitty.jda;
}
// Builds a nicely formatted embedded message based on information provided
public void send(KittyEmbed embedInfo)
{
EmbedBuilder embed = new EmbedBuilder();
if(embedInfo.title != null && !embedInfo.title.isEmpty())
{
embed.setTitle(embedInfo.title);
}
else
{
// We have to set the title to at least something that's not empty.
// By defualt, this creates nothing really visible.
embed.setTitle(" ");
}
if(embedInfo.color != null)
embed.setColor(embedInfo.color);
if(embedInfo.descriptionText != null)
embed.setDescription(embedInfo.descriptionText);
if(embedInfo.footerText != null)
embed.setFooter(embedInfo.footerText, null);
if(embedInfo.authorImage != null || embedInfo.authorLink != null || embedInfo.authorText != null)
embed.setAuthor(embedInfo.authorText, embedInfo.authorLink, embedInfo.authorImage);
if(embedInfo.imageURL != null)
embed.setImage(embedInfo.imageURL);
if(embedInfo.thumbnailURL != null && embedInfo.thumbnailURL.contains("attachment://"))
{
// This is the case where you have a thumbnail image, but you want it to be a local file.
// TODO: Make this more generic. Consider message builder for the entire thing.
String thumbPath = embedInfo.thumbnailURL;
String thumbName = thumbPath.replace("attachment://", "");
// Build the message and send if the file is valid
MessageBuilder message = new MessageBuilder();
embed.setThumbnail(thumbPath);
message.setEmbed(embed.build());
File thumbImage = new File(thumbName);
if(thumbImage.exists())
{
event.getChannel().sendFile(thumbImage, thumbName, message.build()).queue();
}
}
else
{
if(embedInfo.thumbnailURL != null)
embed.setThumbnail(embedInfo.thumbnailURL);
event.getChannel().sendMessage(embed.build()).queue();
}
}
// Queues a standard text-based message response to the channel that issued the command.
public void send(String toRespondWith)
{
GlobalLog.log(LogFilter.Response, "Sending response: " + toRespondWith);
if(toRespondWith.length() > discordMessageMax)
{
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
}
else
{
event.getChannel().sendMessage(toRespondWith).queue();
}
}
// Queues a standard text-based message response to the specified channel.
public void sendToChannel(String toRespondWith, String channelID)
{
TextChannel channel;
channel = kitty.getTextChannelById(Long.parseLong(channelID));
if(toRespondWith.length() > discordMessageMax)
{
channel.sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
}
else
{
channel.sendMessage(toRespondWith).queue();
}
}
// Immediately dispatches the message to the channel that issued the command.
public void sendImmediate(String toRespondWith)
{
GlobalLog.log(LogFilter.Response, "Sending immediate response: " + toRespondWith);
if(toRespondWith.length() > discordMessageMax)
{
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!");
}
else
{
event.getChannel().sendMessage(toRespondWith).complete();
}
}
// Queues a file response to the channel that issued the command.
public void sendFile(File toRespondWith, String extension)
{
GlobalLog.log(LogFilter.Response, "Sending file response");
event.getChannel().sendFile(toRespondWith, "return." + extension).queue();
}
// Queues an input stream response to the channel that issued the command.
public void sendFile(InputStream in, String extension)
{
GlobalLog.log(LogFilter.Response, "Sending input stream response");
event.getChannel().sendFile(in, "return." + extension).queue();
}
}
package dataStructures;
import java.io.File;
import java.io.InputStream;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.events.message.guild.*;
import net.dv8tion.jda.core.EmbedBuilder;
import utils.GlobalLog;
import utils.LogFilter;
// This isn't constructed with the factory at this time, mostly because we need it
// to handle all the response queue behavior and everything internally. So long as
// commands aren't exposed to the GuildMessageReceivedEvent then we should be fine.
public class Response
{
// Variables
private GuildMessageReceivedEvent event;
private final int discordMessageMax = 2000;
private final int kittyMessageMax = 1950;
private JDA kitty;
// Constructor
public Response(GuildMessageReceivedEvent event, KittyCore kitty)
{
this.event = event;
this.kitty = kitty.jda;
}
// Builds a nicely formatted embedded message based on information provided
public void send(KittyEmbed embedInfo)
{
EmbedBuilder embed = new EmbedBuilder();
if(embedInfo.title != null && !embedInfo.title.isEmpty())
{
embed.setTitle(embedInfo.title);
}
else
{
// We have to set the title to at least something that's not empty.
// By defualt, this creates nothing really visible.
embed.setTitle(" ");
}
if(embedInfo.color != null)
embed.setColor(embedInfo.color);
if(embedInfo.descriptionText != null)
embed.setDescription(embedInfo.descriptionText);
if(embedInfo.footerText != null)
embed.setFooter(embedInfo.footerText, null);
if(embedInfo.authorImage != null || embedInfo.authorLink != null || embedInfo.authorText != null)
embed.setAuthor(embedInfo.authorText, embedInfo.authorLink, embedInfo.authorImage);
if(embedInfo.imageURL != null)
embed.setImage(embedInfo.imageURL);
if(embedInfo.thumbnailURL != null && embedInfo.thumbnailURL.contains("attachment://"))
{
// This is the case where you have a thumbnail image, but you want it to be a local file.
// TODO: Make this more generic. Consider message builder for the entire thing.
String thumbPath = embedInfo.thumbnailURL;
String thumbName = thumbPath.replace("attachment://", "");
// Build the message and send if the file is valid
MessageBuilder message = new MessageBuilder();
embed.setThumbnail(thumbPath);
message.setEmbed(embed.build());
File thumbImage = new File(thumbName);
if(thumbImage.exists())
{
event.getChannel().sendFile(thumbImage, thumbName, message.build()).queue();
}
}
else
{
if(embedInfo.thumbnailURL != null)
embed.setThumbnail(embedInfo.thumbnailURL);
event.getChannel().sendMessage(embed.build()).queue();
}
}
// Queues a standard text-based message response to the channel that issued the command.
public void send(String toRespondWith)
{
GlobalLog.log(LogFilter.Response, "Sending response: " + toRespondWith);
if(toRespondWith.length() > discordMessageMax)
{
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
}
else
{
event.getChannel().sendMessage(toRespondWith).queue();
}
}
// Queues a standard text-based message response to the specified channel.
public void sendToChannel(String toRespondWith, String channelID)
{
TextChannel channel;
channel = kitty.getTextChannelById(Long.parseLong(channelID));
if(toRespondWith.length() > discordMessageMax)
{
channel.sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
}
else
{
channel.sendMessage(toRespondWith).queue();
}
}
// Immediately dispatches the message to the channel that issued the command.
public void sendImmediate(String toRespondWith)
{
GlobalLog.log(LogFilter.Response, "Sending immediate response: " + toRespondWith);
if(toRespondWith.length() > discordMessageMax)
{
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!");
}
else
{
event.getChannel().sendMessage(toRespondWith).complete();
}
}
// Queues a file response to the channel that issued the command.
public void sendFile(File toRespondWith, String extension)
{
GlobalLog.log(LogFilter.Response, "Sending file response");
event.getChannel().sendFile(toRespondWith, "return." + extension).queue();
}
// Queues an input stream response to the channel that issued the command.
public void sendFile(InputStream in, String extension)
{
GlobalLog.log(LogFilter.Response, "Sending input stream response");
event.getChannel().sendFile(in, "return." + extension).queue();
}
//Sends Kittybot as an object
//WARNING: THIS WILL EDIT THE ENTIRE BOT, DO NOT USE LIGHTLY
public JDA getKitty()
{
return kitty;
}
}
+2 -1
View File
@@ -118,7 +118,8 @@ public class Main extends ListenerAdapter
{
if(pluginOutput.get(i).startsWith("!"))
{
commandManager.invokeOnNewThread(guild, channel, user, new UserInput(pluginOutput.get(i).substring(1), guild), response);
commandManager.invokeOnNewThread(guild, channel, user,
new UserInput(pluginOutput.get(i).substring(1), guild), response);
}
else
{