diff --git a/src/main/java/io/discloader/discloader/common/registry/EntityRegistry.java b/src/main/java/io/discloader/discloader/common/registry/EntityRegistry.java index 1a583c5f8..ac4ab952e 100644 --- a/src/main/java/io/discloader/discloader/common/registry/EntityRegistry.java +++ b/src/main/java/io/discloader/discloader/common/registry/EntityRegistry.java @@ -15,6 +15,7 @@ import io.discloader.discloader.common.Shard; import io.discloader.discloader.core.entity.emoji.Emoji; import io.discloader.discloader.core.entity.emoji.EmojiCategory; +import io.discloader.discloader.entity.channel.ChannelTypes; import io.discloader.discloader.entity.channel.IChannel; import io.discloader.discloader.entity.channel.IGroupChannel; import io.discloader.discloader.entity.channel.IGuildChannel; @@ -86,8 +87,6 @@ public static Collection getChannels() { return channels.values(); } - - public static Collection getGroupChannels() { return groupChannels.values(); } @@ -231,13 +230,13 @@ public static void putVoiceConnection(VoiceConnection connection) { public static void removeChannel(IChannel channel) { if (channel == null) return; channels.remove(channel.getID()); - if (channel.getType() == ChannelType.TEXT) { + if (channel.getType() == ChannelTypes.TEXT) { textChannels.remove(channel.getID()); - } else if (channel.getType() == ChannelType.VOICE) { + } else if (channel.getType() == ChannelTypes.VOICE) { voiceChannels.remove(channel.getID()); - } else if (channel.getType() == ChannelType.DM) { + } else if (channel.getType() == ChannelTypes.GROUP) { groupChannels.remove(channel.getID()); - } else if (channel.getType() == ChannelType.DM) { + } else if (channel.getType() == ChannelTypes.DM) { privateChannels.remove(channel.getID()); } } diff --git a/src/main/java/io/discloader/discloader/common/registry/ModRegistry.java b/src/main/java/io/discloader/discloader/common/registry/ModRegistry.java index 5122e8f7f..4c5a80932 100644 --- a/src/main/java/io/discloader/discloader/common/registry/ModRegistry.java +++ b/src/main/java/io/discloader/discloader/common/registry/ModRegistry.java @@ -22,45 +22,48 @@ import io.discloader.discloader.util.DLUtil; public class ModRegistry { - + /** - * The mod currently being loaded in any given phase of the {@link DiscLoader loader's} startup + * The mod currently being loaded in any given phase of the + * {@link DiscLoader loader's} startup * * @author Perry Berman * @since 0.0.1 */ public static ModContainer activeMod = null; - + public static DiscLoader loader; - + /** - * A {@link HashMap} of the mods loaded by the client. Indexed by {@link Mod#modid()} + * A {@link HashMap} of the mods loaded by the client. Indexed by + * {@link Mod#modid()} * * @author Zachary Waldron * @since 0.0.1 */ public static final HashMap mods = new HashMap(); - + /** * Uninitialized mods * * @author Perry Berman */ private static final HashMap preInitMods = new HashMap(); - + /** * Contains a sensible method of figuring out what mods loaded what mod * * @author Perry Berman */ private static final Map loadMod = new HashMap(); - + private static final Logger logger = new DLLogger(ModRegistry.class).getLogger(); - + public static final CompletableFuture loaded = new CompletableFuture<>(); - + public static CompletableFuture checkCandidates(List mcs) { Thread modLoader = new Thread("ModLoader") { + public void run() { ProgressLogger.step(1, 2, "Checking candidates for @Mod annotation"); logger.info("Checking candidates for @Mod annotation"); @@ -104,7 +107,7 @@ public void run() { mc.discoverHandlers(); n++; } - + activeMod = null; ProgressLogger.phase(2, 3, "PreINIT"); logger.info("PreINIT"); @@ -121,7 +124,7 @@ public void run() { modLoader.start(); return loaded; } - + public static void preInit() { int i = 1; for (ModContainer mod : preInitMods.values()) { @@ -134,9 +137,8 @@ public static void preInit() { // activeMod = null; } DLPreInitEvent event = new DLPreInitEvent(loader); - for (IEventListener e : loader.handlers) { - e.PreInit(event); - } + logger.info("" + (loader != null)); +// loader.emit(event); ProgressLogger.phase(3, 3, "Init"); logger.info("Now swiching to the Init phase"); ProgressLogger.stage(1, 3, "Waiting to Login"); @@ -145,7 +147,7 @@ public static void preInit() { resetStep(); loaded.complete((Void) null); } - + public static CompletableFuture startMods() { ProgressLogger.stage(1, 3, "Mod Discovery"); logger.info("Beginning Mod Discovery"); @@ -155,7 +157,7 @@ public static CompletableFuture startMods() { logger.info("Discovering Mod Containers"); return checkCandidates(candidates); } - + public static void loadMod(String modid) { ModContainer mod = preInitMods.get(modid); ProgressLogger.progress(1, 3, "Checking if another mod is currently active"); @@ -166,7 +168,7 @@ public static void loadMod(String modid) { ProgressLogger.progress(2, 3, "Setting active mod"); logger.info("Setting active mod"); activeMod = mod; - + ProgressLogger.progress(3, 3, "Executing PreInit handler in: " + mod.modInfo.modid()); logger.info("Executing PreInit handler in: " + mod.modInfo.modid()); mods.put(mod.modInfo.modid(), mod); @@ -179,7 +181,7 @@ public static void loadMod(String modid) { } mod.loaded = true; } - + private static void resetStep() { if (!Main.usegui) return; LoadingPanel.setProgress(0, 0, ""); diff --git a/src/main/java/io/discloader/discloader/common/registry/factory/ChannelFactory.java b/src/main/java/io/discloader/discloader/common/registry/factory/ChannelFactory.java index 973a4ba32..a4359d3ce 100644 --- a/src/main/java/io/discloader/discloader/common/registry/factory/ChannelFactory.java +++ b/src/main/java/io/discloader/discloader/common/registry/factory/ChannelFactory.java @@ -2,11 +2,14 @@ import io.discloader.discloader.common.DiscLoader; import io.discloader.discloader.core.entity.channel.Channel; +import io.discloader.discloader.core.entity.channel.ChannelCategory; import io.discloader.discloader.core.entity.channel.PrivateChannel; import io.discloader.discloader.core.entity.channel.TextChannel; import io.discloader.discloader.core.entity.channel.VoiceChannel; import io.discloader.discloader.core.entity.message.Message; +import io.discloader.discloader.entity.channel.ChannelTypes; import io.discloader.discloader.entity.channel.IChannel; +import io.discloader.discloader.entity.channel.IChannelCategory; import io.discloader.discloader.entity.channel.ITextChannel; import io.discloader.discloader.entity.guild.IGuild; import io.discloader.discloader.entity.message.IMessage; @@ -17,6 +20,10 @@ public class ChannelFactory { public IChannel buildChannel(ChannelJSON data, IGuild guild) { + return buildChannel(data, guild, true); + } + + public IChannel buildChannel(ChannelJSON data, IGuild guild, boolean insert) { IChannel channel = null; if (data.type == DLUtil.ChannelTypes.DM) { channel = new PrivateChannel(DiscLoader.getDiscLoader(), data); @@ -26,10 +33,13 @@ public IChannel buildChannel(ChannelJSON data, IGuild guild) { if (guild != null) { if (data.type == DLUtil.ChannelTypes.text) { channel = new TextChannel(guild, data); - guild.getTextChannels().put(channel.getID(), (TextChannel) channel); + if (insert) guild.getTextChannels().put(channel.getID(), (TextChannel) channel); } else if (data.type == DLUtil.ChannelTypes.voice) { channel = new VoiceChannel(guild, data); - guild.getVoiceChannels().put(channel.getID(), (VoiceChannel) channel); + if (insert) guild.getVoiceChannels().put(channel.getID(), (VoiceChannel) channel); + } else if (ChannelTypes.fromCode(data.type) == ChannelTypes.CATEGORY) { + channel = new ChannelCategory(guild, data); + if (insert) guild.getChannelCategories().put(channel.getID(), (IChannelCategory) channel); } } } diff --git a/src/main/java/io/discloader/discloader/core/entity/channel/Channel.java b/src/main/java/io/discloader/discloader/core/entity/channel/Channel.java index 58e33aa19..3164ca7f3 100644 --- a/src/main/java/io/discloader/discloader/core/entity/channel/Channel.java +++ b/src/main/java/io/discloader/discloader/core/entity/channel/Channel.java @@ -3,10 +3,10 @@ import java.time.OffsetDateTime; import io.discloader.discloader.common.DiscLoader; +import io.discloader.discloader.entity.channel.ChannelTypes; import io.discloader.discloader.entity.channel.IChannel; import io.discloader.discloader.entity.util.SnowflakeUtil; import io.discloader.discloader.network.json.ChannelJSON; -import io.discloader.discloader.util.DLUtil.ChannelType; public class Channel implements IChannel { @@ -15,7 +15,7 @@ public class Channel implements IChannel { */ private long id; - protected ChannelType type; + protected short type; /** * The current instance of DiscLoader @@ -27,7 +27,7 @@ public Channel(DiscLoader loader, ChannelJSON data) { id = SnowflakeUtil.parse(data.id); - type = ChannelType.CHANNEL; + type = data.type; if (data != null) setup(data); } @@ -43,13 +43,13 @@ public DiscLoader getLoader() { } @Override - public ChannelType getType() { - return type; + public ChannelTypes getType() { + return ChannelTypes.fromCode(type); } @Override public boolean isPrivate() { - return type != ChannelType.TEXT && type != ChannelType.VOICE && type != ChannelType.CHANNEL; + return getType() == ChannelTypes.DM || getType() == ChannelTypes.GROUP; } public void setup(ChannelJSON data) { diff --git a/src/main/java/io/discloader/discloader/core/entity/channel/ChannelCategory.java b/src/main/java/io/discloader/discloader/core/entity/channel/ChannelCategory.java new file mode 100644 index 000000000..75ab6c896 --- /dev/null +++ b/src/main/java/io/discloader/discloader/core/entity/channel/ChannelCategory.java @@ -0,0 +1,25 @@ +package io.discloader.discloader.core.entity.channel; + +import java.util.concurrent.CompletableFuture; + +import io.discloader.discloader.entity.channel.IChannelCategory; +import io.discloader.discloader.entity.channel.IGuildChannel; +import io.discloader.discloader.entity.guild.IGuild; +import io.discloader.discloader.network.json.ChannelJSON; + +public class ChannelCategory extends GuildChannel implements IChannelCategory { + + public ChannelCategory(IGuild guild, ChannelJSON channel) { + super(guild, channel); + } + + @Override + public CompletableFuture addChannel(T guildChannel) { + return null; + } + + public void setup(ChannelJSON data) { + super.setup(data); + } + +} diff --git a/src/main/java/io/discloader/discloader/core/entity/channel/GroupChannel.java b/src/main/java/io/discloader/discloader/core/entity/channel/GroupChannel.java index f95a57af0..f69da7d35 100644 --- a/src/main/java/io/discloader/discloader/core/entity/channel/GroupChannel.java +++ b/src/main/java/io/discloader/discloader/core/entity/channel/GroupChannel.java @@ -28,7 +28,6 @@ import io.discloader.discloader.network.rest.actions.channel.pin.PinMessage; import io.discloader.discloader.network.rest.actions.channel.pin.PinnedMessages; import io.discloader.discloader.network.rest.actions.channel.pin.UnpinMessage; -import io.discloader.discloader.util.DLUtil.ChannelType; /** * Represents a GroupDMChannel on discord. GroupChannels are only available for @@ -55,7 +54,7 @@ public class GroupChannel extends Channel implements IGroupChannel, IVoiceChanne public GroupChannel(DiscLoader loader, ChannelJSON data) { super(loader, data); - type = ChannelType.GROUPDM; + // type = ChannelType.GROUPDM; messages = new HashMap<>(); typing = new HashMap<>(); @@ -225,15 +224,18 @@ public CompletableFuture> startTyping() { public CompletableFuture unpinMessage(IMessage message) { return new UnpinMessage(message).execute(); } - + /* * (non-Javadoc) - * @see io.discloader.discloader.entity.channel.ITextChannel#sendMessage(java.lang.String, - * io.discloader.discloader.core.entity.RichEmbed, io.discloader.discloader.entity.sendable.Attachment) + * @see + * io.discloader.discloader.entity.channel.ITextChannel#sendMessage(java. + * lang.String, + * io.discloader.discloader.core.entity.RichEmbed, + * io.discloader.discloader.entity.sendable.Attachment) */ @Override public CompletableFuture sendMessage(String content, RichEmbed embed, Attachment attachment) { return null; } - + } diff --git a/src/main/java/io/discloader/discloader/core/entity/channel/GuildChannel.java b/src/main/java/io/discloader/discloader/core/entity/channel/GuildChannel.java index 4a34a369c..55178c88b 100644 --- a/src/main/java/io/discloader/discloader/core/entity/channel/GuildChannel.java +++ b/src/main/java/io/discloader/discloader/core/entity/channel/GuildChannel.java @@ -6,6 +6,9 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; +import org.json.JSONObject; + +import io.discloader.discloader.common.registry.EntityBuilder; import io.discloader.discloader.core.entity.Overwrite; import io.discloader.discloader.core.entity.Permission; import io.discloader.discloader.core.entity.guild.Guild; @@ -13,15 +16,19 @@ import io.discloader.discloader.entity.IOverwrite; import io.discloader.discloader.entity.IPermission; import io.discloader.discloader.entity.channel.IGuildChannel; +import io.discloader.discloader.entity.channel.IGuildTextChannel; import io.discloader.discloader.entity.guild.IGuild; import io.discloader.discloader.entity.guild.IGuildMember; import io.discloader.discloader.entity.guild.IRole; import io.discloader.discloader.entity.invite.IInvite; import io.discloader.discloader.entity.util.Permissions; import io.discloader.discloader.network.json.ChannelJSON; +import io.discloader.discloader.network.rest.RESTOptions; import io.discloader.discloader.network.rest.actions.channel.FetchInvites; import io.discloader.discloader.network.rest.actions.channel.SetOverwrite; import io.discloader.discloader.network.rest.actions.channel.close.CloseGuildChannel; +import io.discloader.discloader.network.util.Endpoints; +import io.discloader.discloader.network.util.Methods; /** * Represents any channel in a guild @@ -59,6 +66,8 @@ public class GuildChannel extends Channel implements IGuildChannel { */ private Map overwrites; + private boolean nsfw; + public GuildChannel(IGuild guild, ChannelJSON channel) { super(guild.getLoader(), channel); @@ -77,23 +86,42 @@ public CompletableFuture delete() { return new CloseGuildChannel(this).execute(); } - /** - * Changes the channels settings - * - * @param name The new name for the channel - * @param topic The new topic for the channel - * @param position The new position for the channel - * @param bitrate The new bitrate - * @param userLimit The new userLimit - * @return A Future that completes with an IGuildChannel if successful - */ @Override - public CompletableFuture edit(String name, String topic, int position, int bitrate, int userLimit) { - CompletableFuture future = new CompletableFuture<>(); - loader.rest.modifyGuildChannel(this, name, topic, position, bitrate, userLimit).thenAcceptAsync(channel -> { - future.complete(channel); - }); - return future; + public CompletableFuture edit(String name, int position) { + return edit(name, position, nsfw); + } + + // /** + // * Changes the channels settings + // * + // * @param name The new name for the channel + // * @param topic The new topic for the channel + // * @param position The new position for the channel + // * @param bitrate The new bitrate + // * @param userLimit The new userLimit + // * @return A Future that completes with an IGuildChannel if successful + // */ + //// @Override + // public CompletableFuture edit(String name, String topic, + // int position, int bitrate, int userLimit) { + // CompletableFuture future = new CompletableFuture<>(); + // loader.rest.request(Methods.PATCH, Endpoints.channel(getID()), new + // RESTOptions, cls) + //// loader.rest.modifyGuildChannel(this, name, topic, position, bitrate, + // userLimit).thenAcceptAsync(channel -> { + //// future.complete(channel); + //// }); + // return future; + // } + + @Override + public IGuild getGuild() { + return guild; + } + + @Override + public CompletableFuture> getInvites() { + return new FetchInvites(this).execute(); } @Override @@ -105,15 +133,30 @@ public Map getMembers() { return members; } + @Override + public String getName() { + return name; + } + public Map getOverwrites() { return overwrites; } + @Override + public int getPosition() { + return position; + } + @Override public boolean isPrivate() { return false; } + @Override + public boolean isNSFW() { + return nsfw; + } + @Override public IOverwrite overwriteOf(IRole role) { return overwrites.get(role.getID()); @@ -146,8 +189,13 @@ public IPermission permissionsOf(IGuildMember member) { } @Override - public CompletableFuture setName(String name) { - return edit(name, null, position, 64000, 0); + public CompletableFuture setName(String name) { + return edit(name, position); + } + + @Override + public CompletableFuture setOverwrite(IOverwrite overwrite) { + return new SetOverwrite(this, overwrite).execute(); } @Override @@ -161,8 +209,8 @@ public CompletableFuture setPermissions(int allow, int deny, Role ro } @Override - public CompletableFuture setPosition(int position) { - return edit(name, null, position, 64000, 0); + public CompletableFuture setPosition(int position) { + return edit(name, position); } @Override @@ -173,28 +221,23 @@ public void setup(ChannelJSON data) { } @Override - public IGuild getGuild() { - return guild; + public CompletableFuture setNSFW(boolean nswf) { + return null; } @Override - public String getName() { - return name; + public CompletableFuture edit(String name, int position, boolean nsfw) { + return null; } @Override - public CompletableFuture setOverwrite(IOverwrite overwrite) { - return new SetOverwrite(this, overwrite).execute(); + public CompletableFuture edit(String name, boolean nsfw) { + return null; } @Override - public int getPosition() { - return position; - } - - @Override - public CompletableFuture> getInvites() { - return new FetchInvites(this).execute(); + public CompletableFuture edit(int position, boolean nsfw) { + return null; } } diff --git a/src/main/java/io/discloader/discloader/core/entity/channel/PrivateChannel.java b/src/main/java/io/discloader/discloader/core/entity/channel/PrivateChannel.java index 8a3dd4266..9b0ea57d0 100644 --- a/src/main/java/io/discloader/discloader/core/entity/channel/PrivateChannel.java +++ b/src/main/java/io/discloader/discloader/core/entity/channel/PrivateChannel.java @@ -26,7 +26,6 @@ import io.discloader.discloader.network.rest.actions.channel.pin.PinMessage; import io.discloader.discloader.network.rest.actions.channel.pin.PinnedMessages; import io.discloader.discloader.network.rest.actions.channel.pin.UnpinMessage; -import io.discloader.discloader.util.DLUtil.ChannelType; /** * Represents a DM Channel on discord @@ -34,29 +33,29 @@ * @author Perry Berman */ public class PrivateChannel extends Channel implements IPrivateChannel { - + private HashMap messages; - + private HashMap typing; - + /** * The user that this DM Channel was opened with * * @author Perry Berman */ private IUser recipient; - + public PrivateChannel(DiscLoader loader, ChannelJSON data) { super(loader, data); - type = ChannelType.DM; + type = 1; messages = new HashMap<>(); typing = new HashMap<>(); } - + public CompletableFuture close() { return new CloseChannel(this).execute(); } - + @Override public CompletableFuture> deleteMessages(IMessage... messages) { HashMap msgs = new HashMap<>(); @@ -65,37 +64,37 @@ public CompletableFuture> deleteMessages(IMessage... message } return deleteMessages(msgs); } - + @Override public CompletableFuture> deleteMessages(Map messages) { return new BulkDelete(this, messages).execute(); } - + @Override public CompletableFuture fetchMessage(long id) { return new FetchMessage(this, id).execute(); } - + @Override public CompletableFuture> fetchMessages() { return fetchMessages(new MessageFetchOptions()); } - + @Override public CompletableFuture> fetchMessages(MessageFetchOptions options) { return new FetchMessages(this, options).execute(); } - + @Override public CompletableFuture> fetchPinnedMessages() { return new PinnedMessages(this).execute(); } - + @Override public IMessage getLastMessage() { return getMessage(getLastMessageID()); } - + @Override public long getLastMessageID() { long lastMsgID = 0l; @@ -104,27 +103,27 @@ public long getLastMessageID() { } return lastMsgID; } - + @Override public IMessage getMessage(long messageID) { return messages.get(messageID); } - + @Override public IMessage getMessage(String id) { return getMessage(SnowflakeUtil.parse(id)); } - + @Override public Collection getMessageCollection() { return getMessages().values(); } - + @Override public HashMap getMessages() { return messages; } - + @Override public Map getPinnedMessages() { HashMap pins = new HashMap<>(); @@ -133,52 +132,52 @@ public Map getPinnedMessages() { } return pins; } - + @Override public IUser getRecipient() { return recipient; } - + @Override public HashMap getTyping() { return typing; } - + @Override public boolean isTyping(IUser user) { return typing.containsKey(user.getID()); } - + @Override public CompletableFuture pinMessage(IMessage message) { return new PinMessage(message).execute(); } - + @Override public CompletableFuture sendEmbed(RichEmbed embed) { return sendMessage(null, embed, (File) null); } - + @Override public CompletableFuture sendFile(File file) { return sendMessage(null, null, file); } - + @Override public CompletableFuture sendFile(Resource resource) { return sendMessage(null, null, resource); } - + @Override public CompletableFuture sendMessage(String content) { return sendMessage(content, null, (File) null); } - + @Override public CompletableFuture sendMessage(String content, RichEmbed embed) { return sendMessage(content, embed, (File) null); } - + @Override public CompletableFuture sendMessage(String content, RichEmbed embed, File file) { Attachment attachment = null; @@ -190,7 +189,7 @@ public CompletableFuture sendMessage(String content, RichEmbed embed, } return new SendMessage(this, content, embed, attachment, file).execute(); } - + @Override public CompletableFuture sendMessage(String content, RichEmbed embed, Resource resource) { Attachment attachment = null; @@ -201,7 +200,7 @@ public CompletableFuture sendMessage(String content, RichEmbed embed, } return new SendMessage(this, content, embed, attachment, resource).execute(); } - + @Override public void setup(ChannelJSON data) { super.setup(data); @@ -212,25 +211,28 @@ public void setup(ChannelJSON data) { } } } - + @Override public CompletableFuture> startTyping() { return new StartTyping(this).execute(); } - + @Override public CompletableFuture unpinMessage(IMessage message) { return new UnpinMessage(message).execute(); } - + /* * (non-Javadoc) - * @see io.discloader.discloader.entity.channel.ITextChannel#sendMessage(java.lang.String, - * io.discloader.discloader.core.entity.RichEmbed, io.discloader.discloader.entity.sendable.Attachment) + * @see + * io.discloader.discloader.entity.channel.ITextChannel#sendMessage(java. + * lang.String, + * io.discloader.discloader.core.entity.RichEmbed, + * io.discloader.discloader.entity.sendable.Attachment) */ @Override public CompletableFuture sendMessage(String content, RichEmbed embed, Attachment attachment) { return null; } - + } \ No newline at end of file diff --git a/src/main/java/io/discloader/discloader/core/entity/channel/TextChannel.java b/src/main/java/io/discloader/discloader/core/entity/channel/TextChannel.java index 6ba55aed5..a5a7f8b3c 100644 --- a/src/main/java/io/discloader/discloader/core/entity/channel/TextChannel.java +++ b/src/main/java/io/discloader/discloader/core/entity/channel/TextChannel.java @@ -29,7 +29,6 @@ import io.discloader.discloader.network.rest.actions.channel.pin.UnpinMessage; import io.discloader.discloader.network.util.Endpoints; import io.discloader.discloader.network.util.Methods; -import io.discloader.discloader.util.DLUtil.ChannelType; /** * Represents a TextChannel in a Guild on Discord @@ -260,9 +259,9 @@ public CompletableFuture setTopic(String topic) { public void setup(ChannelJSON data) { super.setup(data); - this.type = ChannelType.TEXT; + // type = ChannelType.TEXT; - this.topic = data.topic; + topic = data.topic; } @Override @@ -294,4 +293,24 @@ public String asMention() { return String.format("<#%d>", getID()); } + @Override + public CompletableFuture edit(String name, int position) { + return null; + } + + @Override + public CompletableFuture edit(String name, String topic) { + return null; + } + + @Override + public CompletableFuture edit(String name, String topic, int position) { + return null; + } + + @Override + public CompletableFuture setNSFW(boolean nsfw) { + return null; + } + } diff --git a/src/main/java/io/discloader/discloader/core/entity/channel/VoiceChannel.java b/src/main/java/io/discloader/discloader/core/entity/channel/VoiceChannel.java index ef1f97323..0ea446f6e 100644 --- a/src/main/java/io/discloader/discloader/core/entity/channel/VoiceChannel.java +++ b/src/main/java/io/discloader/discloader/core/entity/channel/VoiceChannel.java @@ -8,7 +8,6 @@ import io.discloader.discloader.entity.guild.IGuild; import io.discloader.discloader.entity.voice.VoiceConnection; import io.discloader.discloader.network.json.ChannelJSON; -import io.discloader.discloader.util.DLUtil.ChannelType; /** * Represents a voice channel in a guild @@ -16,29 +15,29 @@ * @author Perry Berman */ public class VoiceChannel extends GuildChannel implements IGuildVoiceChannel { - + /** * The channel's bitrate */ public int bitrate; - + /** * The limit of user that can be in this channel at one time */ public int userLimit; - + /** * @param guild The guild the channel is in * @param data The channel's data */ public VoiceChannel(IGuild guild, ChannelJSON data) { super(guild, data); - - this.type = ChannelType.VOICE; - + + // this.type = ChannelType.VOICE; + this.name = data.name; } - + /** * Changes the channels settings * @@ -49,7 +48,7 @@ public VoiceChannel(IGuild guild, ChannelJSON data) { public CompletableFuture edit(String name, int position) { return edit(name, position, bitrate, userLimit); } - + /** * Changes the channels settings * @@ -66,7 +65,7 @@ public CompletableFuture edit(String name, int position, int bitr }); return future; } - + @Override public CompletableFuture join() { if (EntityRegistry.getVoiceConnectionByID(guild.getID()) != null) { @@ -79,7 +78,7 @@ public CompletableFuture join() { EntityRegistry.putVoiceConnection(connection); return future; } - + @Override public CompletableFuture leave() { if (EntityRegistry.getVoiceConnectionByID(guild.getID()) != null) { @@ -87,30 +86,30 @@ public CompletableFuture leave() { } return null; } - + public CompletableFuture setBitrate(int bitrate) { return edit(name, position, bitrate, userLimit); } - + @Override public CompletableFuture setName(String name) { return edit(name, position, bitrate, userLimit); } - + @Override public CompletableFuture setPosition(int position) { return edit(name, position, bitrate, userLimit); } - + @Override public void setup(ChannelJSON data) { super.setup(data); - + this.bitrate = data.bitrate; - + this.userLimit = data.user_limit; } - + public CompletableFuture setUserLimit(int userLimit) { return edit(name, position, bitrate, userLimit); } diff --git a/src/main/java/io/discloader/discloader/core/entity/guild/Guild.java b/src/main/java/io/discloader/discloader/core/entity/guild/Guild.java index 231801bca..f92855405 100644 --- a/src/main/java/io/discloader/discloader/core/entity/guild/Guild.java +++ b/src/main/java/io/discloader/discloader/core/entity/guild/Guild.java @@ -38,6 +38,7 @@ import io.discloader.discloader.entity.IIcon; import io.discloader.discloader.entity.IOverwrite; import io.discloader.discloader.entity.IPresence; +import io.discloader.discloader.entity.channel.IChannelCategory; import io.discloader.discloader.entity.channel.IGuildChannel; import io.discloader.discloader.entity.channel.IGuildTextChannel; import io.discloader.discloader.entity.channel.IGuildVoiceChannel; @@ -167,6 +168,8 @@ public MemberQuery(int limit, String query) { */ private HashMap voiceChannels; + private Map categories; + /** * A HashMap of the guild's roles. Indexed by role ID. * @@ -220,6 +223,7 @@ public Guild(DiscLoader loader, GuildJSON data) { members = new HashMap<>(); textChannels = new HashMap<>(); voiceChannels = new HashMap<>(); + categories = new HashMap<>(); roles = new HashMap<>(); presences = new HashMap<>(); guildEmojis = new HashMap<>(); @@ -998,4 +1002,9 @@ public IRole getRoleByName(String name) { return null; } + @Override + public Map getChannelCategories() { + return categories; + } + } \ No newline at end of file diff --git a/src/main/java/io/discloader/discloader/entity/channel/ChannelTypes.java b/src/main/java/io/discloader/discloader/entity/channel/ChannelTypes.java new file mode 100644 index 000000000..92fd4a049 --- /dev/null +++ b/src/main/java/io/discloader/discloader/entity/channel/ChannelTypes.java @@ -0,0 +1,21 @@ +package io.discloader.discloader.entity.channel; + +public enum ChannelTypes { + TEXT(0), DM(1), VOICE(2), GROUP(3), CATEGORY(4), CHANNEL(5); + + private int identifier; + + ChannelTypes(int identifier) { + this.identifier = identifier; + } + + public static ChannelTypes fromCode(int code) { + for (ChannelTypes type : values()) { + if (type.identifier == code) return type; // if the identifier + // number is the same as + // code return the + // channel type + } + return CHANNEL; // just return text by default + } +} diff --git a/src/main/java/io/discloader/discloader/entity/channel/IChannel.java b/src/main/java/io/discloader/discloader/entity/channel/IChannel.java index 01422aea7..ad57eb4d8 100644 --- a/src/main/java/io/discloader/discloader/entity/channel/IChannel.java +++ b/src/main/java/io/discloader/discloader/entity/channel/IChannel.java @@ -6,7 +6,6 @@ import io.discloader.discloader.entity.util.ICreationTime; import io.discloader.discloader.entity.util.ISnowflake; import io.discloader.discloader.network.json.ChannelJSON; -import io.discloader.discloader.util.DLUtil.ChannelType; /** * Represents any channel on discord @@ -16,35 +15,37 @@ */ // @FunctionalInterface public interface IChannel extends ISnowflake, ICreationTime { - + /** * @return The type of the channel */ - ChannelType getType(); - + ChannelTypes getType(); + /** - * Whether or not the channel is a dm channel. Is always {@literal true} if {@link Channel#type type} is {@literal "groupDM"} or + * Whether or not the channel is a dm channel. Is always {@literal true} if + * {@link Channel#type type} is {@literal "groupDM"} or * {@literal "dm"} * * @return true if the channel is a dm/groupDM channel, false otherwise * @author Perry Berman */ boolean isPrivate(); - + // boolean isNSFW(); - + /** * Sets up the channel for use. * * @param data Channel data. */ void setup(ChannelJSON data); - + /** - * @return A string that is in the correct format for mentioning this channel in a {@link Message} + * @return A string that is in the correct format for mentioning this + * channel in a {@link Message} */ String toMention(); - + DiscLoader getLoader(); - + } diff --git a/src/main/java/io/discloader/discloader/entity/channel/IChannelCategory.java b/src/main/java/io/discloader/discloader/entity/channel/IChannelCategory.java new file mode 100644 index 000000000..002750ceb --- /dev/null +++ b/src/main/java/io/discloader/discloader/entity/channel/IChannelCategory.java @@ -0,0 +1,8 @@ +package io.discloader.discloader.entity.channel; + +import java.util.concurrent.CompletableFuture; + +public interface IChannelCategory extends IGuildChannel { + + public CompletableFuture addChannel(T guildChannel); +} diff --git a/src/main/java/io/discloader/discloader/entity/channel/IGuildChannel.java b/src/main/java/io/discloader/discloader/entity/channel/IGuildChannel.java index 528791d83..5872339d8 100644 --- a/src/main/java/io/discloader/discloader/entity/channel/IGuildChannel.java +++ b/src/main/java/io/discloader/discloader/entity/channel/IGuildChannel.java @@ -22,6 +22,14 @@ public interface IGuildChannel extends IChannel { */ CompletableFuture delete(); + CompletableFuture edit(int position, boolean nsfw); + + CompletableFuture edit(String name, boolean nsfw); + + CompletableFuture edit(String name, int position); + + CompletableFuture edit(String name, int position, boolean nsfw); + /** * Changes the channels settings * @@ -32,13 +40,16 @@ public interface IGuildChannel extends IChannel { * @param userLimit The new userLimit * @return A Future that completes with a IGuildChannel if successful */ - CompletableFuture edit(String name, String topic, int position, int bitrate, int userLimit); + // CompletableFuture edit(String name, String + // topic, int position, int bitrate, int userLimit); /** * @return */ IGuild getGuild(); + CompletableFuture> getInvites(); + /** * Gets the members that can view/join this channel * @@ -46,11 +57,11 @@ public interface IGuildChannel extends IChannel { */ Map getMembers(); - CompletableFuture> getInvites(); - String getName(); int getPosition(); + + boolean isNSFW(); IOverwrite overwriteOf(IRole role); @@ -86,6 +97,8 @@ public interface IGuildChannel extends IChannel { */ CompletableFuture setName(String name); + CompletableFuture setNSFW(boolean nswf); + CompletableFuture setOverwrite(IOverwrite overwrite); /** diff --git a/src/main/java/io/discloader/discloader/entity/channel/IGuildTextChannel.java b/src/main/java/io/discloader/discloader/entity/channel/IGuildTextChannel.java index a601897ef..d25f52711 100644 --- a/src/main/java/io/discloader/discloader/entity/channel/IGuildTextChannel.java +++ b/src/main/java/io/discloader/discloader/entity/channel/IGuildTextChannel.java @@ -8,10 +8,17 @@ * @author Perry Berman */ public interface IGuildTextChannel extends IGuildChannel, ITextChannel, IMentionable { - - CompletableFuture setTopic(String topic); - + + @Override + CompletableFuture edit(String name, int position); + + CompletableFuture edit(String name, String topic); + + CompletableFuture edit(String name, String topic, int position); + boolean isNSFW(); - - // CompletableFuture setNSFW(boolean nsfw); + + CompletableFuture setTopic(String topic); + + CompletableFuture setNSFW(boolean nsfw); } diff --git a/src/main/java/io/discloader/discloader/entity/guild/IGuild.java b/src/main/java/io/discloader/discloader/entity/guild/IGuild.java index d94ecf076..ecfb86989 100644 --- a/src/main/java/io/discloader/discloader/entity/guild/IGuild.java +++ b/src/main/java/io/discloader/discloader/entity/guild/IGuild.java @@ -20,6 +20,7 @@ import io.discloader.discloader.entity.IIcon; import io.discloader.discloader.entity.IOverwrite; import io.discloader.discloader.entity.IPresence; +import io.discloader.discloader.entity.channel.IChannelCategory; import io.discloader.discloader.entity.channel.IGuildTextChannel; import io.discloader.discloader.entity.channel.IGuildVoiceChannel; import io.discloader.discloader.entity.invite.IInvite; @@ -69,7 +70,8 @@ public interface IGuild extends ISnowflake, ICreationTime { CompletableFuture ban(IGuildMember member) throws PermissionsException; /** - * Begin a prune operation. Requires the {@link Permissions#KICK_MEMBERS KICK_MEMBERS} + * Begin a prune operation. Requires the {@link Permissions#KICK_MEMBERS + * KICK_MEMBERS} * permission. * * @return A Future that completes with the number of member kicked during @@ -80,7 +82,8 @@ public interface IGuild extends ISnowflake, ICreationTime { CompletableFuture beginPrune(); /** - * Begin a prune operation. Requires the {@link Permissions#KICK_MEMBERS KICK_MEMBERS} + * Begin a prune operation. Requires the {@link Permissions#KICK_MEMBERS + * KICK_MEMBERS} * permission. * * @param days The number of days to prune (1 or more) @@ -192,6 +195,8 @@ public interface IGuild extends ISnowflake, ICreationTime { */ CompletableFuture> fetchMembers(int limit); + Map getChannelCategories(); + /** * Returns the {@link GuildMember} object for the {@link User} you are * logged in as. diff --git a/src/main/java/io/discloader/discloader/network/json/ChannelJSON.java b/src/main/java/io/discloader/discloader/network/json/ChannelJSON.java index 8f9d5ffd8..6dfb281ba 100644 --- a/src/main/java/io/discloader/discloader/network/json/ChannelJSON.java +++ b/src/main/java/io/discloader/discloader/network/json/ChannelJSON.java @@ -7,8 +7,9 @@ public class ChannelJSON { public String topic; public String last_message_id; public String guild_id; + public String parent_id; - public int type; + public short type; public int user_limit; public int position; public int bitrate; diff --git a/src/main/java/io/discloader/discloader/network/json/GuildJSON.java b/src/main/java/io/discloader/discloader/network/json/GuildJSON.java index a0b9c0bc0..9f529e7d9 100644 --- a/src/main/java/io/discloader/discloader/network/json/GuildJSON.java +++ b/src/main/java/io/discloader/discloader/network/json/GuildJSON.java @@ -12,8 +12,9 @@ public class GuildJSON { public String owner_id; public String embed_channel_id; public String afk_channel_id; - public String[] features; public String region; + public String system_channel_id; + public String[] features; public int verification_level; public int default_message_notifications;