use of io.discloader.discloader.entity.channel.IGuildTextChannel in project DiscLoader by R3alCl0ud.
the class Guild method setup.
/**
* Sets up a guild with data from the gateway
*
* @param data
* The guild's data
*/
@Override
public void setup(GuildJSON data) {
try {
name = data.name;
icon = data.icon != null ? data.icon : null;
iconURL = icon != null ? Endpoints.guildIcon(getID(), icon) : null;
ownerID = SnowflakeUtil.parse(data.owner_id);
memberCount = data.member_count;
voiceRegion = new VoiceRegion(data.region);
splashHash = data.splash;
if (data.roles.length > 0) {
roles.clear();
for (RoleJSON role : data.roles) {
IRole r = gfac.buildRole(this, role);
roles.put(r.getID(), r);
}
}
if (data.members != null && data.members.length > 0) {
members.clear();
for (MemberJSON member : data.members) {
IGuildMember m = gfac.buildMember(this, member);
members.put(m.getID(), m);
}
}
if (data.channels != null && data.channels.length > 0) {
for (ChannelJSON channelData : data.channels) {
IGuildChannel chan = (IGuildChannel) EntityRegistry.addChannel(channelData, getLoader(), this);
if (chan instanceof IGuildTextChannel)
textChannels.put(chan.getID(), (IGuildTextChannel) chan);
else if (chan instanceof IGuildVoiceChannel)
voiceChannels.put(chan.getID(), (IGuildVoiceChannel) chan);
}
}
if (data.presences != null && data.presences.length > 0) {
presences.clear();
for (PresenceJSON presence : data.presences) {
this.setPresence(presence);
}
}
if (data.emojis != null && data.emojis.length > 0) {
this.guildEmojis.clear();
for (EmojiJSON e : data.emojis) {
this.guildEmojis.put(SnowflakeUtil.parse(e.id), new GuildEmoji(e, this));
}
}
if (data.voice_states != null && data.voice_states.length > 0) {
this.rawStates.clear();
for (VoiceStateJSON v : data.voice_states) {
this.rawStates.put(SnowflakeUtil.parse(v.user_id), new VoiceState(v, this));
}
}
this.available = data.unavailable == true ? false : true;
} catch (Exception e) {
e.printStackTrace();
}
}
use of io.discloader.discloader.entity.channel.IGuildTextChannel in project DiscLoader by R3alCl0ud.
the class ChannelCategory method createTextChannel.
@Override
public CompletableFuture<IGuildTextChannel> createTextChannel(String name) {
CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
JSONObject data = new JSONObject().put("parent_id", SnowflakeUtil.asString(this)).put("name", name).put("type", 0);
// System.out.println(data.toString());
CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.POST, Endpoints.guildChannels(getGuild().getID()), new RESTOptions(data), ChannelJSON.class);
cf.thenAcceptAsync(channelJSON -> {
if (channelJSON != null) {
IGuildTextChannel channel = (IGuildTextChannel) EntityBuilder.getChannelFactory().buildChannel(channelJSON, getLoader(), getGuild(), false);
if (channel != null)
future.complete(channel);
}
});
cf.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
use of io.discloader.discloader.entity.channel.IGuildTextChannel in project DiscLoader by R3alCl0ud.
the class TextChannel method setTopic.
public CompletableFuture<IGuildTextChannel> setTopic(String topic) {
if (!this.permissionsOf(guild.getCurrentMember()).hasAny(Permissions.MANAGE_CHANNELS, Permissions.ADMINISTRATOR) && !guild.isOwner()) {
throw new PermissionsException("Insufficient Permissions");
}
if (topic.length() > 1024) {
throw new RuntimeException("topic length [" + topic.length() + "] > 1024");
}
CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
JSONObject payload = new JSONObject().put("topic", topic);
CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.PATCH, Endpoints.channel(getID()), new RESTOptions(payload), ChannelJSON.class);
cf.thenAcceptAsync(data -> {
IGuildTextChannel channel = (IGuildTextChannel) EntityBuilder.getChannelFactory().buildChannel(data, getLoader(), getGuild(), false);
future.complete(channel);
});
cf.exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
use of io.discloader.discloader.entity.channel.IGuildTextChannel in project DiscLoader by R3alCl0ud.
the class CommandHandler method handleMessageCreate.
public static void handleMessageCreate(MessageCreateEvent e) {
try {
IMessage message = e.getMessage();
if (!handleCommands || e.loader.user == null || message.getAuthor() == null || message.getAuthor().isBot() || ((!e.loader.user.isBot() && selfBot) && message.getAuthor().getID() != e.loader.user.getID()) || message.getContent().length() < prefix.length()) {
return;
}
String[] Args = e.args;
String label = Args[0];
String rest = "";
if (label.length() < message.getContent().length())
rest = message.getContent().substring(label.length() + 1);
int argc = Args.length > 1 ? Args.length - 1 : 0;
if (label.length() < prefix.length() || !label.substring(0, prefix.length()).equals(prefix)) {
return;
}
try {
label = label.substring(prefix.length());
} catch (Exception ex) {
ex.printStackTrace();
}
Command command = getCommand(label, message);
if (command != null) {
if (message.getChannel() instanceof IGuildTextChannel && !command.shouldExecute(message.getMember(), (IGuildTextChannel) message.getChannel()))
return;
String[] args = new String[argc];
Matcher argM = command.getArgsPattern().matcher(rest);
int n = 0;
while (argM.find()) {
for (int i = 0; i < argM.groupCount() && i < args.length; i++) {
try {
args[n] = argM.group(i);
} catch (Exception ex) {
ex.printStackTrace();
}
}
n++;
}
command.execute(e, args);
return;
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
Aggregations