Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -1,95 +1,95 @@
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord;

import com.mashape.unirest.http.Unirest;
import de.btobastian.javacord.utils.ThreadPool;

/**
* This class is used to get a new api instance.
*/
public class Javacord {

/**
* The current javacord version.
*/
public static final String VERSION = "2.0.14";

/**
* The github url of javacord.
*/
public static final String GITHUB_URL = "https://github.com/BtoBastian/Javacord";

/**
* The user agent used for requests.
*/
public static final String USER_AGENT = "Javacord DiscordBot (" + GITHUB_URL + ", v" + VERSION + ")";

static {
Unirest.setDefaultHeader("User-Agent", USER_AGENT);
}

private Javacord() { }

/**
* Gets a new instance of DiscordAPI.
*
* You can use different instances to connect to more than one account.
*
* @return A new instance of DiscordAPI.
* @see #getApi(String, String)
*/
public static DiscordAPI getApi() {
return new ImplDiscordAPI(new ThreadPool());
}

/**
* Gets a new instance of DiscordAPI.
*
* You can use different instances to connect to more than one account.
*
* @param email The email address which should be used to connect to the account.
* @param password The password which should be used to connect to the account.
* @return A new instance of DiscordAPI.
* @see DiscordAPI#setEmail(String)
* @see DiscordAPI#setPassword(String)
*/
public static DiscordAPI getApi(String email, String password) {
DiscordAPI api = getApi();
api.setEmail(email);
api.setPassword(password);
return api;
}

/**
* Gets a new instance of DiscordAPI.
*
* The only way to login to a bot is by using the token.
*
* @param token The token which is required to login.
* @param bot Whether the token is the token of a bot account or a normal account.
* @return A new instance of DiscordAPI.
*/
public static DiscordAPI getApi(String token, boolean bot) {
DiscordAPI api = getApi();
api.setToken(token, bot);
return api;
}

}
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord;

import com.mashape.unirest.http.Unirest;
import de.btobastian.javacord.utils.ThreadPool;

/**
* This class is used to get a new api instance.
*/
public class Javacord {

/**
* The current javacord version.
*/
public static final String VERSION = "2.0.14";

/**
* The github url of javacord.
*/
public static final String GITHUB_URL = "https://github.com/BtoBastian/Javacord";

/**
* The user agent used for requests.
*/
public static final String USER_AGENT = "Javacord DiscordBot (" + GITHUB_URL + ", v" + VERSION + ")";

static {
Unirest.setDefaultHeader("User-Agent", USER_AGENT);
}

private Javacord() { }

/**
* Gets a new instance of DiscordAPI.
*
* You can use different instances to connect to more than one account.
*
* @return A new instance of DiscordAPI.
* @see #getApi(String, String)
*/
public static DiscordAPI getApi() {
return new ImplDiscordAPI(new ThreadPool());
}

/**
* Gets a new instance of DiscordAPI.
*
* You can use different instances to connect to more than one account.
*
* @param email The email address which should be used to connect to the account.
* @param password The password which should be used to connect to the account.
* @return A new instance of DiscordAPI.
* @see DiscordAPI#setEmail(String)
* @see DiscordAPI#setPassword(String)
*/
public static DiscordAPI getApi(String email, String password) {
DiscordAPI api = getApi();
api.setEmail(email);
api.setPassword(password);
return api;
}

/**
* Gets a new instance of DiscordAPI.
*
* The only way to login to a bot is by using the token.
*
* @param token The token which is required to login.
* @param bot Whether the token is the token of a bot account or a normal account.
* @return A new instance of DiscordAPI.
*/
public static DiscordAPI getApi(String token, boolean bot) {
DiscordAPI api = getApi();
api.setToken(token, bot);
return api;
}

}
@@ -1,187 +1,187 @@
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

import de.btobastian.javacord.entities.message.Message;
import de.btobastian.javacord.entities.message.MessageReceiver;
import de.btobastian.javacord.entities.permissions.Permissions;
import de.btobastian.javacord.entities.permissions.Role;

import java.util.concurrent.Future;

/**
* This interface represents a channel.
*/
public interface Channel extends MessageReceiver {

/**
* Gets the id of the channel.
*
* @return The id of the channel.
*/
public String getId();

/**
* Gets the name of the channel.
*
* @return The name of the channel.
*/
public String getName();

/**
* Gets the topic of the channel.
*
* @return The topic of the channel.
*/
public String getTopic();

/**
* Gets the position of the channel.
*
* @return The position of the channel.
*/
public int getPosition();

/**
* Gets the server of the channel.
*
* @return The server of the channel.
*/
public Server getServer();

/**
* Deletes the channel.
*
* @return A future which tells us if the deletion was successful or not.
*/
public Future<Void> delete();

/**
* Gets an invite builder.
* An invite builder is used to easily create invites.
*
* @return An invite builder.
*/
public InviteBuilder getInviteBuilder();

/**
* Gets the overwritten permissions of an user in this channel.
*
* @param user The user which overwrites the permissions.
* @return The overwritten permissions of the user.
*/
public Permissions getOverwrittenPermissions(User user);

/**
* Gets the overwritten permissions of a role in this channel.
*
* @param role The role which overwrites the permissions.
* @return The overwritten permissions of the role.
*/
public Permissions getOverwrittenPermissions(Role role);

/**
* Updates the permissions of the given role.
*
* @param role The role to update.
* @param permissions The permissions to set.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateOverwrittenPermissions(Role role, Permissions permissions);

/**
* Updates the permissions of the given user.
*
* @param user The user to update.
* @param permissions The permissions to set.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateOverwrittenPermissions(User user, Permissions permissions);

/**
* Deletes the overwritten permissions of the given role.
*
* @param role The role to delete.
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> deleteOverwrittenPermissions(Role role);

/**
* Deletes the overwritten permissions of the given user.
*
* @param user The user to delete.
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> deleteOverwrittenPermissions(User user);

/**
* Updates the name of the channel.
* If you want to update the topic, too, use {@link #update(String, String)}.
* Otherwise the first update will be overridden (except you wait for it to finish using {@link Future#get()}).
*
* @param newName The new name of the channel.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateName(String newName);

/**
* Updates the topic of the channel.
* If you want to update the name, too, use {@link #update(String, String)}.
* Otherwise the first update will be overridden (except you wait for it to finish using {@link Future#get()}).
*
* @param newTopic The new topic of the channel.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateTopic(String newTopic);

/**
* Updates the channel.
*
* @param newName The new name of the channel.
* @param newTopic The new topic of the channel.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> update(String newName, String newTopic);

/**
* Gets the tag which is used to mention the channel.
*
* @return Gets the tag which is used to mention the channel.
*/
public String getMentionTag();

/**
* Deletes multiple messages at once.
*
* @param messages The messages to delete.
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> bulkDelete(String... messages);

/**
* Deletes multiple messages at once.
* <p>
* Note: You can only bulk delete 2-100 messages.
*
* @param messages The messages to delete.
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> bulkDelete(Message... messages);

}
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

import de.btobastian.javacord.entities.message.Message;
import de.btobastian.javacord.entities.message.MessageReceiver;
import de.btobastian.javacord.entities.permissions.Permissions;
import de.btobastian.javacord.entities.permissions.Role;

import java.util.concurrent.Future;

/**
* This interface represents a channel.
*/
public interface Channel extends MessageReceiver {

/**
* Gets the id of the channel.
*
* @return The id of the channel.
*/
public String getId();

/**
* Gets the name of the channel.
*
* @return The name of the channel.
*/
public String getName();

/**
* Gets the topic of the channel.
*
* @return The topic of the channel.
*/
public String getTopic();

/**
* Gets the position of the channel.
*
* @return The position of the channel.
*/
public int getPosition();

/**
* Gets the server of the channel.
*
* @return The server of the channel.
*/
public Server getServer();

/**
* Deletes the channel.
*
* @return A future which tells us if the deletion was successful or not.
*/
public Future<Void> delete();

/**
* Gets an invite builder.
* An invite builder is used to easily create invites.
*
* @return An invite builder.
*/
public InviteBuilder getInviteBuilder();

/**
* Gets the overwritten permissions of an user in this channel.
*
* @param user The user which overwrites the permissions.
* @return The overwritten permissions of the user.
*/
public Permissions getOverwrittenPermissions(User user);

/**
* Gets the overwritten permissions of a role in this channel.
*
* @param role The role which overwrites the permissions.
* @return The overwritten permissions of the role.
*/
public Permissions getOverwrittenPermissions(Role role);

/**
* Updates the permissions of the given role.
*
* @param role The role to update.
* @param permissions The permissions to set.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateOverwrittenPermissions(Role role, Permissions permissions);

/**
* Updates the permissions of the given user.
*
* @param user The user to update.
* @param permissions The permissions to set.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateOverwrittenPermissions(User user, Permissions permissions);

/**
* Deletes the overwritten permissions of the given role.
*
* @param role The role to delete.
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> deleteOverwrittenPermissions(Role role);

/**
* Deletes the overwritten permissions of the given user.
*
* @param user The user to delete.
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> deleteOverwrittenPermissions(User user);

/**
* Updates the name of the channel.
* If you want to update the topic, too, use {@link #update(String, String)}.
* Otherwise the first update will be overridden (except you wait for it to finish using {@link Future#get()}).
*
* @param newName The new name of the channel.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateName(String newName);

/**
* Updates the topic of the channel.
* If you want to update the name, too, use {@link #update(String, String)}.
* Otherwise the first update will be overridden (except you wait for it to finish using {@link Future#get()}).
*
* @param newTopic The new topic of the channel.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateTopic(String newTopic);

/**
* Updates the channel.
*
* @param newName The new name of the channel.
* @param newTopic The new topic of the channel.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> update(String newName, String newTopic);

/**
* Gets the tag which is used to mention the channel.
*
* @return Gets the tag which is used to mention the channel.
*/
public String getMentionTag();

/**
* Deletes multiple messages at once.
*
* @param messages The messages to delete.
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> bulkDelete(String... messages);

/**
* Deletes multiple messages at once.
* <p>
* Note: You can only bulk delete 2-100 messages.
*
* @param messages The messages to delete.
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> bulkDelete(Message... messages);

}
@@ -1,128 +1,128 @@
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

import com.google.common.util.concurrent.FutureCallback;
import de.btobastian.javacord.entities.permissions.Role;

import java.awt.image.BufferedImage;
import java.net.URL;
import java.util.Collection;
import java.util.concurrent.Future;

/**
* This interface represents a custom emoji.
*/
public interface CustomEmoji {

/**
* Gets the id of the emoji.
*
* @return The id of the emoji.
*/
public String getId();

/**
* Gets the name of the emoji.
*
* @return The name of the emoji.
*/
public String getName();

/**
* Gets the server of the emoji.
*
* @return The server of the emoji.
*/
public Server getServer();

/**
* Gets whether the emoji is managed.
*
* @return Whether the emoji is managed.
*/
public boolean isManaged();

/**
* Gets whether the emoji must be wrapped in colons.
*
* @return Whether the emoji must be wrapped in colons.
*/
public boolean requiresColons();

/**
* Gets the roles this emoji is active for.
*
* @return The roles this emoji is active for.
*/
public Collection<Role> getRoles();

/**
* Gets the tag which is used to display the emoji.
*
* @return The tag which is used to display the emoji.
*/
public String getMentionTag();

/**
* Gets the emoji as byte array.
*
* @return The png-image of the emoji.
*/
public Future<byte[]> getEmojiAsByteArray();

/**
* Gets the emoji as byte array.
*
* @param callback The callback which will be informed when the emoji was downloaded.
* The array is the png-image of the emoji.
* @return The png-image of the emoji.
*/
public Future<byte[]> getEmojiAsByteArray(FutureCallback<byte[]> callback);

/**
* Gets the emoji.
*
* @return The png-image of the emoji.
*/
public Future<BufferedImage> getEmoji();

/**
* Gets the emoji.
*
* @param callback The callback which will be informed when the emoji was downloaded.
* @return The png-image of the emoji.
*/
public Future<BufferedImage> getEmoji(FutureCallback<BufferedImage> callback);

/**
* Gets the url of the emoji image.
*
* @return The url of the emoji image.
*/
public URL getImageUrl();

/**
* Deletes the emoji.
*
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> delete();

}
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

import com.google.common.util.concurrent.FutureCallback;
import de.btobastian.javacord.entities.permissions.Role;

import java.awt.image.BufferedImage;
import java.net.URL;
import java.util.Collection;
import java.util.concurrent.Future;

/**
* This interface represents a custom emoji.
*/
public interface CustomEmoji {

/**
* Gets the id of the emoji.
*
* @return The id of the emoji.
*/
public String getId();

/**
* Gets the name of the emoji.
*
* @return The name of the emoji.
*/
public String getName();

/**
* Gets the server of the emoji.
*
* @return The server of the emoji.
*/
public Server getServer();

/**
* Gets whether the emoji is managed.
*
* @return Whether the emoji is managed.
*/
public boolean isManaged();

/**
* Gets whether the emoji must be wrapped in colons.
*
* @return Whether the emoji must be wrapped in colons.
*/
public boolean requiresColons();

/**
* Gets the roles this emoji is active for.
*
* @return The roles this emoji is active for.
*/
public Collection<Role> getRoles();

/**
* Gets the tag which is used to display the emoji.
*
* @return The tag which is used to display the emoji.
*/
public String getMentionTag();

/**
* Gets the emoji as byte array.
*
* @return The png-image of the emoji.
*/
public Future<byte[]> getEmojiAsByteArray();

/**
* Gets the emoji as byte array.
*
* @param callback The callback which will be informed when the emoji was downloaded.
* The array is the png-image of the emoji.
* @return The png-image of the emoji.
*/
public Future<byte[]> getEmojiAsByteArray(FutureCallback<byte[]> callback);

/**
* Gets the emoji.
*
* @return The png-image of the emoji.
*/
public Future<BufferedImage> getEmoji();

/**
* Gets the emoji.
*
* @param callback The callback which will be informed when the emoji was downloaded.
* @return The png-image of the emoji.
*/
public Future<BufferedImage> getEmoji(FutureCallback<BufferedImage> callback);

/**
* Gets the url of the emoji image.
*
* @return The url of the emoji image.
*/
public URL getImageUrl();

/**
* Deletes the emoji.
*
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> delete();

}
@@ -1,184 +1,184 @@
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

import com.google.common.util.concurrent.FutureCallback;

import java.net.URL;
import java.util.Calendar;
import java.util.concurrent.Future;

/**
* This interface represents an invite.
*
* Note: Unlike the other classes there may be more invite instances for one invite.
* Invites won't be updated (e.g. uses).
*/
public interface Invite {

/**
* Gets the invite code.
*
* @return The invite code.
*/
public String getCode();

/**
* Gets the url of the invite.
*
* @return The url of the invite.
*/
public URL getInviteUrl();

/**
* Gets the server id of the invite.
*
* @return The server id of the invite.
*/
public String getServerId();

/**
* Gets the server name of the invite.
*
* @return The server name of the invite.
*/
public String getServerName();

/**
* Gets the server of the invite. May be <code>null</code>!
*
* @return Get's the server of the invite. <code>Null</code> if you are not member of the invite's server.
*/
public Server getServer();

/**
* Gets the channel id of the invite.
*
* @return The channel id of the invite.
*/
public String getChannelId();

/**
* Gets the channel name of the invite.
*
* @return The channel name of the invite.
*/
public String getChannelName();

/**
* Gets the channel of the invite. May be <code>null</code>!
*
* @return Get's the channel of the invite.
* <code>Null</code> if you are not member of the invite's server or it's a voice channel.
*/
public Channel getChannel();

/**
* Gets the voice channel of the invite. May be <code>null</code>!
*
* @return Get's the voice channel of the invite.
* <code>Null</code> if you are not member of the invite's server or it's a text channel.
*/
public VoiceChannel getVoiceChannel();

/**
* Checks whether the channel is a voice or text channel.
*
* @return Whether the channel is a voice channel or not.
*/
public boolean isVoiceChannel();

/**
* Gets the maximum age of the invite.
*
* @return The maximum age of the invite. <code>-1</code> if the invite has no max age
* or you are not allowed to get this information.
*/
public int getMaxAge();

/**
* Checks if the invite is revoked.
*
* @return Whether the invite is revoked or not. May be also <code>true</code> if
* you are not allowed to get this information.
*/
public boolean isRevoked();

/**
* Gets the date of creation. May be <code>null</code>.
*
* @return The date of creation. May be <code>null</code>if you are not allowed to get this information.
*/
public Calendar getCreationDate();

/**
* Gets the uses of the invite.
*
* @return The uses of the invite. <code>-1</code> if you are not allowed to get this information.
*/
public int getUses();

/**
* Gets the maximum uses of the invite.
*
* @return The maximum uses of the invite. <code>-1</code> if the invite has no limit
* or you are not allowed to get this information.
*/
public int getMaxUses();

/**
* Checks if the invite is temporary.
*
* @return Whether the invite is temporary or not. May be also <code>false</code> if
* you are not allowed to get this information.
*/
public boolean isTemporary();

/**
* Gets the creator of the invite.
*
* @return The creator of the invite. <code>Null</code> if you are not allowed to get this information.
*/
public User getCreator();

/**
* Accepts the invite.
*
* @return The server.
* @see de.btobastian.javacord.DiscordAPI#acceptInvite(String)
*/
public Future<Server> acceptInvite();

/**
* Accepts the invite.
*
* @param callback The callback which will be informed when you joined the server or joining failed.
* @return The server.
* @see de.btobastian.javacord.DiscordAPI#acceptInvite(String, FutureCallback)
*/
public Future<Server> acceptInvite(FutureCallback<Server> callback);

/**
* Deletes the invite.
*
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> delete();

}
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

import com.google.common.util.concurrent.FutureCallback;

import java.net.URL;
import java.util.Calendar;
import java.util.concurrent.Future;

/**
* This interface represents an invite.
*
* Note: Unlike the other classes there may be more invite instances for one invite.
* Invites won't be updated (e.g. uses).
*/
public interface Invite {

/**
* Gets the invite code.
*
* @return The invite code.
*/
public String getCode();

/**
* Gets the url of the invite.
*
* @return The url of the invite.
*/
public URL getInviteUrl();

/**
* Gets the server id of the invite.
*
* @return The server id of the invite.
*/
public String getServerId();

/**
* Gets the server name of the invite.
*
* @return The server name of the invite.
*/
public String getServerName();

/**
* Gets the server of the invite. May be <code>null</code>!
*
* @return Get's the server of the invite. <code>Null</code> if you are not member of the invite's server.
*/
public Server getServer();

/**
* Gets the channel id of the invite.
*
* @return The channel id of the invite.
*/
public String getChannelId();

/**
* Gets the channel name of the invite.
*
* @return The channel name of the invite.
*/
public String getChannelName();

/**
* Gets the channel of the invite. May be <code>null</code>!
*
* @return Get's the channel of the invite.
* <code>Null</code> if you are not member of the invite's server or it's a voice channel.
*/
public Channel getChannel();

/**
* Gets the voice channel of the invite. May be <code>null</code>!
*
* @return Get's the voice channel of the invite.
* <code>Null</code> if you are not member of the invite's server or it's a text channel.
*/
public VoiceChannel getVoiceChannel();

/**
* Checks whether the channel is a voice or text channel.
*
* @return Whether the channel is a voice channel or not.
*/
public boolean isVoiceChannel();

/**
* Gets the maximum age of the invite.
*
* @return The maximum age of the invite. <code>-1</code> if the invite has no max age
* or you are not allowed to get this information.
*/
public int getMaxAge();

/**
* Checks if the invite is revoked.
*
* @return Whether the invite is revoked or not. May be also <code>true</code> if
* you are not allowed to get this information.
*/
public boolean isRevoked();

/**
* Gets the date of creation. May be <code>null</code>.
*
* @return The date of creation. May be <code>null</code>if you are not allowed to get this information.
*/
public Calendar getCreationDate();

/**
* Gets the uses of the invite.
*
* @return The uses of the invite. <code>-1</code> if you are not allowed to get this information.
*/
public int getUses();

/**
* Gets the maximum uses of the invite.
*
* @return The maximum uses of the invite. <code>-1</code> if the invite has no limit
* or you are not allowed to get this information.
*/
public int getMaxUses();

/**
* Checks if the invite is temporary.
*
* @return Whether the invite is temporary or not. May be also <code>false</code> if
* you are not allowed to get this information.
*/
public boolean isTemporary();

/**
* Gets the creator of the invite.
*
* @return The creator of the invite. <code>Null</code> if you are not allowed to get this information.
*/
public User getCreator();

/**
* Accepts the invite.
*
* @return The server.
* @see de.btobastian.javacord.DiscordAPI#acceptInvite(String)
*/
public Future<Server> acceptInvite();

/**
* Accepts the invite.
*
* @param callback The callback which will be informed when you joined the server or joining failed.
* @return The server.
* @see de.btobastian.javacord.DiscordAPI#acceptInvite(String, FutureCallback)
*/
public Future<Server> acceptInvite(FutureCallback<Server> callback);

/**
* Deletes the invite.
*
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> delete();

}
@@ -1,69 +1,69 @@
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

import com.google.common.util.concurrent.FutureCallback;

import java.util.concurrent.Future;

/**
* This interfaces helps to create invites.
*/
public interface InviteBuilder {

/**
* Sets the max uses of the invite.
*
* @param maxUses The max uses of the invite.
* @return This object.
*/
public InviteBuilder setMaxUses(int maxUses);

/**
* Sets if the invite is temporary.
*
* @param temporary Whether the invite should be temporary or not.
* @return This object.
*/
public InviteBuilder setTemporary(boolean temporary);

/**
* Sets the max age of the invite.
*
* @param maxAge The max age of the invite in seconds.
* @return This object.
*/
public InviteBuilder setMaxAge(int maxAge);

/**
* Creates the invite.
*
* @return The invite.
*/
public Future<Invite> create();

/**
* Creates the invite.
*
* @param callback The callback which will be informed when the invite was created or creation failed.
* @return The invite.
*/
public Future<Invite> create(FutureCallback<Invite> callback);

}
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

import com.google.common.util.concurrent.FutureCallback;

import java.util.concurrent.Future;

/**
* This interfaces helps to create invites.
*/
public interface InviteBuilder {

/**
* Sets the max uses of the invite.
*
* @param maxUses The max uses of the invite.
* @return This object.
*/
public InviteBuilder setMaxUses(int maxUses);

/**
* Sets if the invite is temporary.
*
* @param temporary Whether the invite should be temporary or not.
* @return This object.
*/
public InviteBuilder setTemporary(boolean temporary);

/**
* Sets the max age of the invite.
*
* @param maxAge The max age of the invite in seconds.
* @return This object.
*/
public InviteBuilder setMaxAge(int maxAge);

/**
* Creates the invite.
*
* @return The invite.
*/
public Future<Invite> create();

/**
* Creates the invite.
*
* @param callback The callback which will be informed when the invite was created or creation failed.
* @return The invite.
*/
public Future<Invite> create(FutureCallback<Invite> callback);

}
@@ -1,90 +1,90 @@
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

/**
* This enum represents a valid region for a server.
*/
public enum Region {

AMSTERDAM("amsterdam", "Amsterdam"),
BRAZIL("brazil", "Brazil"),
EU_CENTRAL("eu-central", "EU Central"),
EU_WEST("eu-west", "EU West"),
FRANKFURT("frankfurt", "Frankfurt"),
LONDON("london", "London"),
SINGAPORE("singapore", "Singapore"),
SYDNEY("sydney", "Sydney"),
US_CENTRAL("us-central", "US Central"),
US_EAST("us-east", "US East"),
US_SOUTH("us-south", "US South"),
US_WEST("us-west", "US West"),
/**
* An unknown region, most likely because discord added new regions.
*/
UNKNOWN("us-west", "Unknown");

private final String key;
private final String name;

/**
* Class constructor.
*
* @param key The key of the region.
* @param name The name of the region.
*/
private Region(String key, String name) {
this.key = key;
this.name = name;
}

/**
* Gets the key of the region which is used for REST-request.
*
* @return The key of the region.
*/
public String getKey() {
return key;
}

/**
* Gets the name of the region (which looks nicer than the key :-) ).
*
* @return The name of the region.
*/
public String getName() {
return name;
}

/**
* Gets a region by its key.
*
* @param key The key of the region.
* @return The region with the given key. {@link Region#UNKNOWN} if no region for the given key was found.
*/
public static Region getRegionByKey(String key) {
for (Region region : values()) {
if (region.getKey().equalsIgnoreCase(key) && region != UNKNOWN) {
return region;
}
}
return UNKNOWN;
}

}
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

/**
* This enum represents a valid region for a server.
*/
public enum Region {

AMSTERDAM("amsterdam", "Amsterdam"),
BRAZIL("brazil", "Brazil"),
EU_CENTRAL("eu-central", "EU Central"),
EU_WEST("eu-west", "EU West"),
FRANKFURT("frankfurt", "Frankfurt"),
LONDON("london", "London"),
SINGAPORE("singapore", "Singapore"),
SYDNEY("sydney", "Sydney"),
US_CENTRAL("us-central", "US Central"),
US_EAST("us-east", "US East"),
US_SOUTH("us-south", "US South"),
US_WEST("us-west", "US West"),
/**
* An unknown region, most likely because discord added new regions.
*/
UNKNOWN("us-west", "Unknown");

private final String key;
private final String name;

/**
* Class constructor.
*
* @param key The key of the region.
* @param name The name of the region.
*/
private Region(String key, String name) {
this.key = key;
this.name = name;
}

/**
* Gets the key of the region which is used for REST-request.
*
* @return The key of the region.
*/
public String getKey() {
return key;
}

/**
* Gets the name of the region (which looks nicer than the key :-) ).
*
* @return The name of the region.
*/
public String getName() {
return name;
}

/**
* Gets a region by its key.
*
* @param key The key of the region.
* @return The region with the given key. {@link Region#UNKNOWN} if no region for the given key was found.
*/
public static Region getRegionByKey(String key) {
for (Region region : values()) {
if (region.getKey().equalsIgnoreCase(key) && region != UNKNOWN) {
return region;
}
}
return UNKNOWN;
}

}

Large diffs are not rendered by default.

@@ -1,170 +1,170 @@
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

import com.google.common.util.concurrent.FutureCallback;
import de.btobastian.javacord.entities.message.MessageReceiver;
import de.btobastian.javacord.entities.permissions.Role;

import java.awt.image.BufferedImage;
import java.net.URL;
import java.util.Collection;
import java.util.concurrent.Future;

/**
* This interface represents an user.
*/
public interface User extends MessageReceiver {

/**
* Gets the id of the user.
*
* @return The id of the user.
*/
public String getId();

/**
* Gets the name of the user.
*
* @return The name of the user.
*/
public String getName();

/**
* Gets the nickname of the user on the given server.
*
* @param server The server.
* @return The nickname of the user on the server or <code>null</code> if the user has no nick.
*/
public String getNickname(Server server);

/**
* Checks if the user has a nickname on the given server.
*
* @param server The server to check.
* @return Whether the user has a nickname on the server or not.
*/
public boolean hasNickname(Server server);

/**
* Updates the nickname of a user.
*
* @param server The server.
* @param nickname The nickname to set.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateNickname(Server server, String nickname);

/**
* Checks if the user is the account you logged in.
*
* @return Whether the user is you or not.
*/
public boolean isYourself();

/**
* Gets the avatar of the user as byte array.
*
* @return The jpg-avatar of the user. The array is empty if the user has no avatar.
*/
public Future<byte[]> getAvatarAsByteArray();

/**
* Gets the avatar of the user as byte array.
*
* @param callback The callback which will be informed when the avatar was downloaded.
* The array is the jpg-avatar of the user. The array is empty if the user has no avatar.
* @return The jpg-avatar of the user. The array is empty if the user has no avatar.
*/
public Future<byte[]> getAvatarAsByteArray(FutureCallback<byte[]> callback);

/**
* Gets the avatar of the user.
*
* @return The jpg-avatar of the user. Canceled if the user has no avatar.
*/
public Future<BufferedImage> getAvatar();

/**
* Gets the avatar of the user.
*
* @param callback The callback which will be informed when the avatar was downloaded.
* The image will be <code>null</code> if the user has no avatar.
* @return The jpg-avatar of the user. Canceled if the user has no avatar.
*/
public Future<BufferedImage> getAvatar(FutureCallback<BufferedImage> callback);

/**
* Gets the url of the users avatar.
*
* @return The url of the users avatar. <code>Null</code> if the user has no avatar.
*/
public URL getAvatarUrl();

/**
* Gets the id of the users avatar.
*
* @return The id of the users avatar. <code>Null</code> if the user has no avatar.
*/
public String getAvatarId();

/**
* Gets the roles of the user on the given server.
*
* @param server The server.
* @return The roles of the user on the given server.
*/
public Collection<Role> getRoles(Server server);

/**
* Gets the game the user is currently playing.
*
* @return The game the user is currently playing. May be <code>null</code>.
*/
public String getGame();

/**
* Gets the tag which is used to mention the user.
*
* @return Gets the tag which is used to mention the user.
*/
public String getMentionTag();

/**
* Gets the discriminator of the user.
*
* @return The discriminator of the user.
*/
public String getDiscriminator();

/**
* Checks whether the user is a bot or not.
*
* @return Whether the user is a bot or not.
*/
public boolean isBot();

/**
* Gets the status of the user.
*
* @return The status of the user.
*/
public UserStatus getStatus();

}
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

import com.google.common.util.concurrent.FutureCallback;
import de.btobastian.javacord.entities.message.MessageReceiver;
import de.btobastian.javacord.entities.permissions.Role;

import java.awt.image.BufferedImage;
import java.net.URL;
import java.util.Collection;
import java.util.concurrent.Future;

/**
* This interface represents an user.
*/
public interface User extends MessageReceiver {

/**
* Gets the id of the user.
*
* @return The id of the user.
*/
public String getId();

/**
* Gets the name of the user.
*
* @return The name of the user.
*/
public String getName();

/**
* Gets the nickname of the user on the given server.
*
* @param server The server.
* @return The nickname of the user on the server or <code>null</code> if the user has no nick.
*/
public String getNickname(Server server);

/**
* Checks if the user has a nickname on the given server.
*
* @param server The server to check.
* @return Whether the user has a nickname on the server or not.
*/
public boolean hasNickname(Server server);

/**
* Updates the nickname of a user.
*
* @param server The server.
* @param nickname The nickname to set.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateNickname(Server server, String nickname);

/**
* Checks if the user is the account you logged in.
*
* @return Whether the user is you or not.
*/
public boolean isYourself();

/**
* Gets the avatar of the user as byte array.
*
* @return The jpg-avatar of the user. The array is empty if the user has no avatar.
*/
public Future<byte[]> getAvatarAsByteArray();

/**
* Gets the avatar of the user as byte array.
*
* @param callback The callback which will be informed when the avatar was downloaded.
* The array is the jpg-avatar of the user. The array is empty if the user has no avatar.
* @return The jpg-avatar of the user. The array is empty if the user has no avatar.
*/
public Future<byte[]> getAvatarAsByteArray(FutureCallback<byte[]> callback);

/**
* Gets the avatar of the user.
*
* @return The jpg-avatar of the user. Canceled if the user has no avatar.
*/
public Future<BufferedImage> getAvatar();

/**
* Gets the avatar of the user.
*
* @param callback The callback which will be informed when the avatar was downloaded.
* The image will be <code>null</code> if the user has no avatar.
* @return The jpg-avatar of the user. Canceled if the user has no avatar.
*/
public Future<BufferedImage> getAvatar(FutureCallback<BufferedImage> callback);

/**
* Gets the url of the users avatar.
*
* @return The url of the users avatar. <code>Null</code> if the user has no avatar.
*/
public URL getAvatarUrl();

/**
* Gets the id of the users avatar.
*
* @return The id of the users avatar. <code>Null</code> if the user has no avatar.
*/
public String getAvatarId();

/**
* Gets the roles of the user on the given server.
*
* @param server The server.
* @return The roles of the user on the given server.
*/
public Collection<Role> getRoles(Server server);

/**
* Gets the game the user is currently playing.
*
* @return The game the user is currently playing. May be <code>null</code>.
*/
public String getGame();

/**
* Gets the tag which is used to mention the user.
*
* @return Gets the tag which is used to mention the user.
*/
public String getMentionTag();

/**
* Gets the discriminator of the user.
*
* @return The discriminator of the user.
*/
public String getDiscriminator();

/**
* Checks whether the user is a bot or not.
*
* @return Whether the user is a bot or not.
*/
public boolean isBot();

/**
* Gets the status of the user.
*
* @return The status of the user.
*/
public UserStatus getStatus();

}
@@ -1,59 +1,59 @@
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

/**
* An enum which contains all statuses.
*/
public enum UserStatus {

/**
* The user is online.
*/
ONLINE(),

/**
* The user is idle.
*/
IDLE(),

/**
* Ths user is offline.
*/
OFFLINE();

/**
* Gets the status from the given String.
*
* @param str The string, e.g. "online".
*
* @return The status.
*/
public static UserStatus fromString(String str) {
switch (str) {
case "online":
return ONLINE;
case "idle":
return IDLE;
default:
return OFFLINE;
}
}

}
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

/**
* An enum which contains all statuses.
*/
public enum UserStatus {

/**
* The user is online.
*/
ONLINE(),

/**
* The user is idle.
*/
IDLE(),

/**
* Ths user is offline.
*/
OFFLINE();

/**
* Gets the status from the given String.
*
* @param str The string, e.g. "online".
*
* @return The status.
*/
public static UserStatus fromString(String str) {
switch (str) {
case "online":
return ONLINE;
case "idle":
return IDLE;
default:
return OFFLINE;
}
}

}
@@ -1,132 +1,132 @@
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

import de.btobastian.javacord.entities.permissions.Permissions;
import de.btobastian.javacord.entities.permissions.Role;

import java.util.concurrent.Future;

/**
* This interface represents a voice channel.
*/
public interface VoiceChannel {

/**
* Gets the id of the channel.
*
* @return The id of the channel.
*/
public String getId();

/**
* Gets the name of the channel.
*
* @return The name of the channel.
*/
public String getName();

/**
* Gets the position of the channel.
*
* @return The position of the channel.
*/
public int getPosition();

/**
* Gets the server of the channel.
*
* @return The server of the channel.
*/
public Server getServer();

/**
* Deletes the channel.
*
* @return A future which tells us if the deletion was successful or not.
*/
public Future<Void> delete();

/**
* Gets an invite builder.
* An invite builder is used to easily create invites.
*
* @return An invite builder.
*/
public InviteBuilder getInviteBuilder();

/**
* Gets the overwritten permissions of an user in this channel.
*
* @param user The user which overwrites the permissions.
* @return The overwritten permissions of the user.
*/
public Permissions getOverwrittenPermissions(User user);

/**
* Gets the overwritten permissions of a role in this channel.
*
* @param role The role which overwrites the permissions.
* @return The overwritten permissions of the role.
*/
public Permissions getOverwrittenPermissions(Role role);

/**
* Updates the permissions of the given role.
*
* @param role The role to update.
* @param permissions The permissions to set.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateOverwrittenPermissions(Role role, Permissions permissions);

/**
* Updates the permissions of the given user.
*
* @param user The user to update.
* @param permissions The permissions to set.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateOverwrittenPermissions(User user, Permissions permissions);

/**
* Deletes the overwritten permissions of the given role.
*
* @param role The role to delete.
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> deleteOverwrittenPermissions(Role role);

/**
* Deletes the overwritten permissions of the given user.
*
* @param user The user to delete.
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> deleteOverwrittenPermissions(User user);

/**
* Updates the name of the channel.
*
* @param newName The new name of the channel.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateName(String newName);

}
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities;

import de.btobastian.javacord.entities.permissions.Permissions;
import de.btobastian.javacord.entities.permissions.Role;

import java.util.concurrent.Future;

/**
* This interface represents a voice channel.
*/
public interface VoiceChannel {

/**
* Gets the id of the channel.
*
* @return The id of the channel.
*/
public String getId();

/**
* Gets the name of the channel.
*
* @return The name of the channel.
*/
public String getName();

/**
* Gets the position of the channel.
*
* @return The position of the channel.
*/
public int getPosition();

/**
* Gets the server of the channel.
*
* @return The server of the channel.
*/
public Server getServer();

/**
* Deletes the channel.
*
* @return A future which tells us if the deletion was successful or not.
*/
public Future<Void> delete();

/**
* Gets an invite builder.
* An invite builder is used to easily create invites.
*
* @return An invite builder.
*/
public InviteBuilder getInviteBuilder();

/**
* Gets the overwritten permissions of an user in this channel.
*
* @param user The user which overwrites the permissions.
* @return The overwritten permissions of the user.
*/
public Permissions getOverwrittenPermissions(User user);

/**
* Gets the overwritten permissions of a role in this channel.
*
* @param role The role which overwrites the permissions.
* @return The overwritten permissions of the role.
*/
public Permissions getOverwrittenPermissions(Role role);

/**
* Updates the permissions of the given role.
*
* @param role The role to update.
* @param permissions The permissions to set.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateOverwrittenPermissions(Role role, Permissions permissions);

/**
* Updates the permissions of the given user.
*
* @param user The user to update.
* @param permissions The permissions to set.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateOverwrittenPermissions(User user, Permissions permissions);

/**
* Deletes the overwritten permissions of the given role.
*
* @param role The role to delete.
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> deleteOverwrittenPermissions(Role role);

/**
* Deletes the overwritten permissions of the given user.
*
* @param user The user to delete.
* @return A future which tells us whether the deletion was successful or not.
*/
public Future<Void> deleteOverwrittenPermissions(User user);

/**
* Updates the name of the channel.
*
* @param newName The new name of the channel.
* @return A future which tells us whether the update was successful or not.
*/
public Future<Void> updateName(String newName);

}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -1,131 +1,131 @@
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities.impl;

import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import de.btobastian.javacord.ImplDiscordAPI;
import de.btobastian.javacord.entities.Invite;
import de.btobastian.javacord.entities.InviteBuilder;
import de.btobastian.javacord.utils.LoggerUtil;
import de.btobastian.javacord.utils.ratelimits.RateLimitType;
import org.json.JSONObject;
import org.slf4j.Logger;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;

/**
* The implementation of the invite builder interface.
*/
public class ImplInviteBuilder implements InviteBuilder {

/**
* The logger of this class.
*/
private static final Logger logger = LoggerUtil.getLogger(ImplInviteBuilder.class);

private final ImplDiscordAPI api;
private final ImplChannel textChannel;
private final ImplVoiceChannel voiceChannel;

private int maxUses = -1;
private byte temporary = -1;
private int maxAge = -1;

public ImplInviteBuilder(ImplChannel textChannel, ImplDiscordAPI api) {
this.textChannel = textChannel;
this.voiceChannel = null;
this.api = api;
}

public ImplInviteBuilder(ImplVoiceChannel voiceChannel, ImplDiscordAPI api) {
this.textChannel = null;
this.voiceChannel = voiceChannel;
this.api = api;
}

@Override
public InviteBuilder setMaxUses(int maxUses) {
this.maxUses = maxUses;
return this;
}

@Override
public InviteBuilder setTemporary(boolean temporary) {
this.temporary = temporary ? (byte) 1 : 0;
return this;
}

@Override
public InviteBuilder setMaxAge(int maxAge) {
this.maxAge = maxAge;
return this;
}

@Override
public Future<Invite> create() {
return create(null);
}

@Override
public Future<Invite> create(FutureCallback<Invite> callback) {
ListenableFuture<Invite> future =
api.getThreadPool().getListeningExecutorService().submit(new Callable<Invite>() {
@Override
public Invite call() throws Exception {
logger.debug("Trying to create invite for channel {} (max uses: {}, temporary: {}, max age: {}",
textChannel == null ? voiceChannel : textChannel, maxUses, temporary, maxAge);
JSONObject jsonParam = new JSONObject();
if (maxUses > 0) {
jsonParam.put("max_uses", maxUses);
}
if (temporary > -1) {
jsonParam.put("temporary", temporary == 1);
}
if (maxAge > 0) {
jsonParam.put("max_age", maxAge);
}
String channelId = textChannel == null ? voiceChannel.getId() : textChannel.getId();
HttpResponse<JsonNode> response = Unirest
.post("https://discordapp.com/api/channels/" + channelId + "/invites")
.header("authorization", api.getToken())
.header("Content-Type", "application/json")
.body(jsonParam.toString())
.asJson();
api.checkResponse(response);
api.checkRateLimit(response, RateLimitType.UNKNOWN, null, null);
JSONObject data = response.getBody().getObject();
logger.debug("Created invite for channel {} (max uses: {}, temporary: {}, max age: {}",
textChannel == null ? voiceChannel : textChannel, maxUses, temporary,
data.has("max_age") ? data.getInt("max_age") : -1);
return new ImplInvite(api, data);
}
});
if (callback != null) {
Futures.addCallback(future, callback);
}
return future;
}

}
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities.impl;

import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import de.btobastian.javacord.ImplDiscordAPI;
import de.btobastian.javacord.entities.Invite;
import de.btobastian.javacord.entities.InviteBuilder;
import de.btobastian.javacord.utils.LoggerUtil;
import de.btobastian.javacord.utils.ratelimits.RateLimitType;
import org.json.JSONObject;
import org.slf4j.Logger;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;

/**
* The implementation of the invite builder interface.
*/
public class ImplInviteBuilder implements InviteBuilder {

/**
* The logger of this class.
*/
private static final Logger logger = LoggerUtil.getLogger(ImplInviteBuilder.class);

private final ImplDiscordAPI api;
private final ImplChannel textChannel;
private final ImplVoiceChannel voiceChannel;

private int maxUses = -1;
private byte temporary = -1;
private int maxAge = -1;

public ImplInviteBuilder(ImplChannel textChannel, ImplDiscordAPI api) {
this.textChannel = textChannel;
this.voiceChannel = null;
this.api = api;
}

public ImplInviteBuilder(ImplVoiceChannel voiceChannel, ImplDiscordAPI api) {
this.textChannel = null;
this.voiceChannel = voiceChannel;
this.api = api;
}

@Override
public InviteBuilder setMaxUses(int maxUses) {
this.maxUses = maxUses;
return this;
}

@Override
public InviteBuilder setTemporary(boolean temporary) {
this.temporary = temporary ? (byte) 1 : 0;
return this;
}

@Override
public InviteBuilder setMaxAge(int maxAge) {
this.maxAge = maxAge;
return this;
}

@Override
public Future<Invite> create() {
return create(null);
}

@Override
public Future<Invite> create(FutureCallback<Invite> callback) {
ListenableFuture<Invite> future =
api.getThreadPool().getListeningExecutorService().submit(new Callable<Invite>() {
@Override
public Invite call() throws Exception {
logger.debug("Trying to create invite for channel {} (max uses: {}, temporary: {}, max age: {}",
textChannel == null ? voiceChannel : textChannel, maxUses, temporary, maxAge);
JSONObject jsonParam = new JSONObject();
if (maxUses > 0) {
jsonParam.put("max_uses", maxUses);
}
if (temporary > -1) {
jsonParam.put("temporary", temporary == 1);
}
if (maxAge > 0) {
jsonParam.put("max_age", maxAge);
}
String channelId = textChannel == null ? voiceChannel.getId() : textChannel.getId();
HttpResponse<JsonNode> response = Unirest
.post("https://discordapp.com/api/channels/" + channelId + "/invites")
.header("authorization", api.getToken())
.header("Content-Type", "application/json")
.body(jsonParam.toString())
.asJson();
api.checkResponse(response);
api.checkRateLimit(response, RateLimitType.UNKNOWN, null, null);
JSONObject data = response.getBody().getObject();
logger.debug("Created invite for channel {} (max uses: {}, temporary: {}, max age: {}",
textChannel == null ? voiceChannel : textChannel, maxUses, temporary,
data.has("max_age") ? data.getInt("max_age") : -1);
return new ImplInvite(api, data);
}
});
if (callback != null) {
Futures.addCallback(future, callback);
}
return future;
}

}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -1,63 +1,63 @@
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities.message;

import java.net.URL;

/**
* This interface represents a message attachment.
*/
public interface MessageAttachment {

/**
* Gets the url of the attachment.
*
* @return The url of the attachment.
*/
public URL getUrl();

/**
* Gets the proxy url of the attachment.
*
* @return The proxy url of the attachment.
*/
public URL getProxyUrl();

/**
* Gets the size of the attachment in bytes.
*
* @return The size of the attachment in bytes.
*/
public int getSize();

/**
* Gets the id of the attachment.
*
* @return The id of the attachment.
*/
public String getId();

/**
* Gets the file name of the attachment.
*
* @return The file name of the attachment.
*/
public String getFileName();

}
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities.message;

import java.net.URL;

/**
* This interface represents a message attachment.
*/
public interface MessageAttachment {

/**
* Gets the url of the attachment.
*
* @return The url of the attachment.
*/
public URL getUrl();

/**
* Gets the proxy url of the attachment.
*
* @return The proxy url of the attachment.
*/
public URL getProxyUrl();

/**
* Gets the size of the attachment in bytes.
*
* @return The size of the attachment in bytes.
*/
public int getSize();

/**
* Gets the id of the attachment.
*
* @return The id of the attachment.
*/
public String getId();

/**
* Gets the file name of the attachment.
*
* @return The file name of the attachment.
*/
public String getFileName();

}
@@ -1,163 +1,163 @@
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities.message;

import de.btobastian.javacord.entities.Channel;
import de.btobastian.javacord.entities.User;
import de.btobastian.javacord.entities.permissions.Role;

/**
* This class helps to build messages with decorations.
*/
public class MessageBuilder {

private final StringBuilder strBuilder;

/**
* Creates a new instance of this class.
*/
public MessageBuilder() {
strBuilder = new StringBuilder();
}

/**
* Appends the given message to the text (without decorations).
*
* @param message The message.
* @return This object to reuse it.
*/
public MessageBuilder append(String message) {
strBuilder.append(message);
return this;
}

/**
* Appends the decoration to the text.
*
* @param message The message.
* @param decorations The decorations/style.
* @return This object to reuse it.
*/
public MessageBuilder appendDecoration(String message, MessageDecoration... decorations) {
for (MessageDecoration decoration : decorations) {
strBuilder.append(decoration.getPrefix());
}
strBuilder.append(message);
for (MessageDecoration decoration : decorations) {
strBuilder.append(decoration.getSuffix());
}
return this;
}

/**
* Appends code to the text.
*
* @param language The language, e.g. "java".
* @param message The message.
* @return This object to reuse it.
*/
public MessageBuilder appendCode(String language, String message) {
strBuilder.append(MessageDecoration.CODE_LONG.getPrefix()).append(language).append("\n")
.append(message).append(MessageDecoration.CODE_LONG.getSuffix());
return this;
}

/**
* Appends an user (@user).
*
* @param user The user to append.
* @return This object to reuse it.
* @see #appendUser(User)
*/
public MessageBuilder appendMention(User user) {
strBuilder.append(user.getMentionTag());
return this;
}

/**
* Appends an user (@user).
*
* @param user The user to append.
* @return This object to reuse it.
* @see #appendMention(User)
*/
public MessageBuilder appendUser(User user) {
return appendMention(user);
}

/**
* Appends a new line.
*
* @return This object to reuse it.
*/
public MessageBuilder appendNewLine() {
strBuilder.append("\n");
return this;
}

/**
* Appends a channel (@channel).
*
* @param channel The channel to append.
* @return This object to reuse it.
*/
public MessageBuilder appendChannel(Channel channel) {
strBuilder.append(channel.getMentionTag());
return this;
}

/**
* Appends a role (@role).
*
* @param role The role to append.
* @return This object to reuse it.
*/
public MessageBuilder appendRole(Role role) {
strBuilder.append(role.getMentionTag());
return this;
}

/**
* Gets the {@link StringBuilder} which is used to build the message.
*
* @return The StringBuilder which is used to build the message.
*/
public StringBuilder getStringBuilder() {
return strBuilder;
}

/**
* Generates the String to send.
*
* @return The String to send.
*/
public String build() {
return strBuilder.toString();
}

/**
* Generates the String to send.
*
* @return The String to send.
*/
@Override
public String toString() {
return build();
}
/*
* Copyright (C) 2017 Bastian Oppermann
*
* This file is part of Javacord.
*
* Javacord is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* Javacord is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
package de.btobastian.javacord.entities.message;

import de.btobastian.javacord.entities.Channel;
import de.btobastian.javacord.entities.User;
import de.btobastian.javacord.entities.permissions.Role;

/**
* This class helps to build messages with decorations.
*/
public class MessageBuilder {

private final StringBuilder strBuilder;

/**
* Creates a new instance of this class.
*/
public MessageBuilder() {
strBuilder = new StringBuilder();
}

/**
* Appends the given message to the text (without decorations).
*
* @param message The message.
* @return This object to reuse it.
*/
public MessageBuilder append(String message) {
strBuilder.append(message);
return this;
}

/**
* Appends the decoration to the text.
*
* @param message The message.
* @param decorations The decorations/style.
* @return This object to reuse it.
*/
public MessageBuilder appendDecoration(String message, MessageDecoration... decorations) {
for (MessageDecoration decoration : decorations) {
strBuilder.append(decoration.getPrefix());
}
strBuilder.append(message);
for (MessageDecoration decoration : decorations) {
strBuilder.append(decoration.getSuffix());
}
return this;
}

/**
* Appends code to the text.
*
* @param language The language, e.g. "java".
* @param message The message.
* @return This object to reuse it.
*/
public MessageBuilder appendCode(String language, String message) {
strBuilder.append(MessageDecoration.CODE_LONG.getPrefix()).append(language).append("\n")
.append(message).append(MessageDecoration.CODE_LONG.getSuffix());
return this;
}

/**
* Appends an user (@user).
*
* @param user The user to append.
* @return This object to reuse it.
* @see #appendUser(User)
*/
public MessageBuilder appendMention(User user) {
strBuilder.append(user.getMentionTag());
return this;
}

/**
* Appends an user (@user).
*
* @param user The user to append.
* @return This object to reuse it.
* @see #appendMention(User)
*/
public MessageBuilder appendUser(User user) {
return appendMention(user);
}

/**
* Appends a new line.
*
* @return This object to reuse it.
*/
public MessageBuilder appendNewLine() {
strBuilder.append("\n");
return this;
}

/**
* Appends a channel (@channel).
*
* @param channel The channel to append.
* @return This object to reuse it.
*/
public MessageBuilder appendChannel(Channel channel) {
strBuilder.append(channel.getMentionTag());
return this;
}

/**
* Appends a role (@role).
*
* @param role The role to append.
* @return This object to reuse it.
*/
public MessageBuilder appendRole(Role role) {
strBuilder.append(role.getMentionTag());
return this;
}

/**
* Gets the {@link StringBuilder} which is used to build the message.
*
* @return The StringBuilder which is used to build the message.
*/
public StringBuilder getStringBuilder() {
return strBuilder;
}

/**
* Generates the String to send.
*
* @return The String to send.
*/
public String build() {
return strBuilder.toString();
}

/**
* Generates the String to send.
*
* @return The String to send.
*/
@Override
public String toString() {
return build();
}
}