WIP on role system
This commit is contained in:
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -167,7 +167,8 @@ public class ObjectBuilderFactory
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Construct a new guild with defaults
|
// 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);
|
DatabaseManager.instance.globalRegister(guild);
|
||||||
guildCache.put(uid, guild);
|
guildCache.put(uid, guild);
|
||||||
}
|
}
|
||||||
@@ -176,6 +177,8 @@ public class ObjectBuilderFactory
|
|||||||
return guild;
|
return guild;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Explicitly locks: guildCache
|
// Explicitly locks: guildCache
|
||||||
public static KittyRole extractRole(GuildMessageReceivedEvent event)
|
public static KittyRole extractRole(GuildMessageReceivedEvent event)
|
||||||
{
|
{
|
||||||
|
|||||||
+153
-146
@@ -1,146 +1,153 @@
|
|||||||
package dataStructures;
|
package dataStructures;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import net.dv8tion.jda.core.JDA;
|
import net.dv8tion.jda.core.JDA;
|
||||||
import net.dv8tion.jda.core.MessageBuilder;
|
import net.dv8tion.jda.core.MessageBuilder;
|
||||||
import net.dv8tion.jda.core.entities.TextChannel;
|
import net.dv8tion.jda.core.entities.TextChannel;
|
||||||
import net.dv8tion.jda.core.events.message.guild.*;
|
import net.dv8tion.jda.core.events.message.guild.*;
|
||||||
import net.dv8tion.jda.core.EmbedBuilder;
|
import net.dv8tion.jda.core.EmbedBuilder;
|
||||||
import utils.GlobalLog;
|
import utils.GlobalLog;
|
||||||
import utils.LogFilter;
|
import utils.LogFilter;
|
||||||
|
|
||||||
// This isn't constructed with the factory at this time, mostly because we need it
|
// 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
|
// 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.
|
// commands aren't exposed to the GuildMessageReceivedEvent then we should be fine.
|
||||||
public class Response
|
public class Response
|
||||||
{
|
{
|
||||||
// Variables
|
// Variables
|
||||||
private GuildMessageReceivedEvent event;
|
private GuildMessageReceivedEvent event;
|
||||||
private final int discordMessageMax = 2000;
|
private final int discordMessageMax = 2000;
|
||||||
private final int kittyMessageMax = 1950;
|
private final int kittyMessageMax = 1950;
|
||||||
private JDA kitty;
|
private JDA kitty;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
public Response(GuildMessageReceivedEvent event, KittyCore kitty)
|
public Response(GuildMessageReceivedEvent event, KittyCore kitty)
|
||||||
{
|
{
|
||||||
this.event = event;
|
this.event = event;
|
||||||
this.kitty = kitty.jda;
|
this.kitty = kitty.jda;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Builds a nicely formatted embedded message based on information provided
|
// Builds a nicely formatted embedded message based on information provided
|
||||||
public void send(KittyEmbed embedInfo)
|
public void send(KittyEmbed embedInfo)
|
||||||
{
|
{
|
||||||
EmbedBuilder embed = new EmbedBuilder();
|
EmbedBuilder embed = new EmbedBuilder();
|
||||||
|
|
||||||
if(embedInfo.title != null && !embedInfo.title.isEmpty())
|
if(embedInfo.title != null && !embedInfo.title.isEmpty())
|
||||||
{
|
{
|
||||||
embed.setTitle(embedInfo.title);
|
embed.setTitle(embedInfo.title);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// We have to set the title to at least something that's not empty.
|
// We have to set the title to at least something that's not empty.
|
||||||
// By defualt, this creates nothing really visible.
|
// By defualt, this creates nothing really visible.
|
||||||
embed.setTitle(" ");
|
embed.setTitle(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(embedInfo.color != null)
|
if(embedInfo.color != null)
|
||||||
embed.setColor(embedInfo.color);
|
embed.setColor(embedInfo.color);
|
||||||
|
|
||||||
if(embedInfo.descriptionText != null)
|
if(embedInfo.descriptionText != null)
|
||||||
embed.setDescription(embedInfo.descriptionText);
|
embed.setDescription(embedInfo.descriptionText);
|
||||||
|
|
||||||
if(embedInfo.footerText != null)
|
if(embedInfo.footerText != null)
|
||||||
embed.setFooter(embedInfo.footerText, null);
|
embed.setFooter(embedInfo.footerText, null);
|
||||||
|
|
||||||
if(embedInfo.authorImage != null || embedInfo.authorLink != null || embedInfo.authorText != null)
|
if(embedInfo.authorImage != null || embedInfo.authorLink != null || embedInfo.authorText != null)
|
||||||
embed.setAuthor(embedInfo.authorText, embedInfo.authorLink, embedInfo.authorImage);
|
embed.setAuthor(embedInfo.authorText, embedInfo.authorLink, embedInfo.authorImage);
|
||||||
|
|
||||||
if(embedInfo.imageURL != null)
|
if(embedInfo.imageURL != null)
|
||||||
embed.setImage(embedInfo.imageURL);
|
embed.setImage(embedInfo.imageURL);
|
||||||
|
|
||||||
if(embedInfo.thumbnailURL != null && embedInfo.thumbnailURL.contains("attachment://"))
|
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.
|
// 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.
|
// TODO: Make this more generic. Consider message builder for the entire thing.
|
||||||
String thumbPath = embedInfo.thumbnailURL;
|
String thumbPath = embedInfo.thumbnailURL;
|
||||||
String thumbName = thumbPath.replace("attachment://", "");
|
String thumbName = thumbPath.replace("attachment://", "");
|
||||||
|
|
||||||
// Build the message and send if the file is valid
|
// Build the message and send if the file is valid
|
||||||
MessageBuilder message = new MessageBuilder();
|
MessageBuilder message = new MessageBuilder();
|
||||||
embed.setThumbnail(thumbPath);
|
embed.setThumbnail(thumbPath);
|
||||||
message.setEmbed(embed.build());
|
message.setEmbed(embed.build());
|
||||||
|
|
||||||
File thumbImage = new File(thumbName);
|
File thumbImage = new File(thumbName);
|
||||||
if(thumbImage.exists())
|
if(thumbImage.exists())
|
||||||
{
|
{
|
||||||
event.getChannel().sendFile(thumbImage, thumbName, message.build()).queue();
|
event.getChannel().sendFile(thumbImage, thumbName, message.build()).queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(embedInfo.thumbnailURL != null)
|
if(embedInfo.thumbnailURL != null)
|
||||||
embed.setThumbnail(embedInfo.thumbnailURL);
|
embed.setThumbnail(embedInfo.thumbnailURL);
|
||||||
|
|
||||||
event.getChannel().sendMessage(embed.build()).queue();
|
event.getChannel().sendMessage(embed.build()).queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Queues a standard text-based message response to the channel that issued the command.
|
// Queues a standard text-based message response to the channel that issued the command.
|
||||||
public void send(String toRespondWith)
|
public void send(String toRespondWith)
|
||||||
{
|
{
|
||||||
GlobalLog.log(LogFilter.Response, "Sending response: " + toRespondWith);
|
GlobalLog.log(LogFilter.Response, "Sending response: " + toRespondWith);
|
||||||
if(toRespondWith.length() > discordMessageMax)
|
if(toRespondWith.length() > discordMessageMax)
|
||||||
{
|
{
|
||||||
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
|
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
event.getChannel().sendMessage(toRespondWith).queue();
|
event.getChannel().sendMessage(toRespondWith).queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Queues a standard text-based message response to the specified channel.
|
// Queues a standard text-based message response to the specified channel.
|
||||||
public void sendToChannel(String toRespondWith, String channelID)
|
public void sendToChannel(String toRespondWith, String channelID)
|
||||||
{
|
{
|
||||||
TextChannel channel;
|
TextChannel channel;
|
||||||
channel = kitty.getTextChannelById(Long.parseLong(channelID));
|
channel = kitty.getTextChannelById(Long.parseLong(channelID));
|
||||||
if(toRespondWith.length() > discordMessageMax)
|
if(toRespondWith.length() > discordMessageMax)
|
||||||
{
|
{
|
||||||
channel.sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
|
channel.sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
channel.sendMessage(toRespondWith).queue();
|
channel.sendMessage(toRespondWith).queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Immediately dispatches the message to the channel that issued the command.
|
// Immediately dispatches the message to the channel that issued the command.
|
||||||
public void sendImmediate(String toRespondWith)
|
public void sendImmediate(String toRespondWith)
|
||||||
{
|
{
|
||||||
GlobalLog.log(LogFilter.Response, "Sending immediate response: " + toRespondWith);
|
GlobalLog.log(LogFilter.Response, "Sending immediate response: " + toRespondWith);
|
||||||
if(toRespondWith.length() > discordMessageMax)
|
if(toRespondWith.length() > discordMessageMax)
|
||||||
{
|
{
|
||||||
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!");
|
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
event.getChannel().sendMessage(toRespondWith).complete();
|
event.getChannel().sendMessage(toRespondWith).complete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Queues a file response to the channel that issued the command.
|
// Queues a file response to the channel that issued the command.
|
||||||
public void sendFile(File toRespondWith, String extension)
|
public void sendFile(File toRespondWith, String extension)
|
||||||
{
|
{
|
||||||
GlobalLog.log(LogFilter.Response, "Sending file response");
|
GlobalLog.log(LogFilter.Response, "Sending file response");
|
||||||
event.getChannel().sendFile(toRespondWith, "return." + extension).queue();
|
event.getChannel().sendFile(toRespondWith, "return." + extension).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Queues an input stream response to the channel that issued the command.
|
// Queues an input stream response to the channel that issued the command.
|
||||||
public void sendFile(InputStream in, String extension)
|
public void sendFile(InputStream in, String extension)
|
||||||
{
|
{
|
||||||
GlobalLog.log(LogFilter.Response, "Sending input stream response");
|
GlobalLog.log(LogFilter.Response, "Sending input stream response");
|
||||||
event.getChannel().sendFile(in, "return." + extension).queue();
|
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
@@ -118,7 +118,8 @@ public class Main extends ListenerAdapter
|
|||||||
{
|
{
|
||||||
if(pluginOutput.get(i).startsWith("!"))
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user