use of net.dv8tion.jda.core.entities.TextChannel in project TheLighterBot by PhotonBursted.
the class LinkChannelCommand method execute.
@Override
protected void execute() {
if (!ev.getMember().getVoiceState().inVoiceChannel()) {
handleError(MessageContent.NOT_IN_VOICE_CHANNEL);
}
VoiceChannel vc = ev.getMember().getVoiceState().getChannel();
if (l.getChannelController().isLinked(vc)) {
handleError(MessageContent.CHANNEL_ALREADY_LINKED);
}
TextChannel tc = ev.getChannel();
l.getChannelController().getLinkedChannels().putStoring(tc, vc);
l.getChannelController().getPermChannels().putStoring(tc, vc);
LoggerUtils.logAndDelete(log, String.format("A new link has been established:\n" + " - VC: %s (%s)\n" + " - TC: %s (%s)", vc.getName(), vc.getId(), tc.getName(), tc.getId()));
l.getDiscordController().sendMessage(tc, String.format("Successfully linked **%s** to **%s**!", vc.getName(), tc.getAsMention()), DiscordController.AUTOMATIC_REMOVAL_INTERVAL);
}
use of net.dv8tion.jda.core.entities.TextChannel in project TheLighterBot by PhotonBursted.
the class TemporaryChannelSizeCommand method execute.
@Override
protected void execute() {
// Get the channels targeted by the issuer
VoiceChannel vc = ev.getMember().getVoiceState().getChannel();
TextChannel tc = l.getChannelController().getLinkedChannels().getForVoiceChannel(vc);
// If the voice channel wasn't found the user wasn't in one to start with
if (vc == null) {
handleError(MessageContent.NOT_IN_VOICE_CHANNEL);
return;
}
// The target should not be the default channel
if (vc == ev.getGuild().getAfkChannel()) {
handleError(MessageContent.AFK_CHANNEL_ACTION_NOT_PERMITTED);
return;
}
// If the target voice channel is permanent, the user requires MANAGE_CHANNEL permissions
if (l.getChannelController().isPermanent(vc) && (!l.getChannelController().isPermanent(vc) || !ev.getMember().hasPermission(Permission.MANAGE_CHANNEL))) {
handleError(MessageContent.PERMISSIONS_REQUIRED, Permission.MANAGE_CHANNEL.name(), "change the size of permanent voice channels");
return;
}
if (input.size() == 0) {
handleError("No new size for the channel was specified!");
return;
}
// If all of this is the case, getInstance the limit to be applied
String limit = input.poll();
assert limit != null;
if (limit.equals("remove")) {
limit = "0";
}
// If the input is an integer and within the limits, update the channel
if (!Utils.isInteger(limit) || Integer.parseInt(limit) < 0 || Integer.parseInt(limit) > 99) {
handleError(MessageContent.INVALID_INPUT, "Only integers between 0 (inclusive) and 99 (inclusive) are allowed!");
return;
}
int intLimit = Integer.parseInt(limit);
if (intLimit == vc.getUserLimit()) {
handleError("No action was taken as the new limit was the same as currently set.");
return;
}
// Get the user limit and set the new value
vc.getManager().setUserLimit(intLimit).reason("A command was issued from a temporary channel").queue();
// If a channel is linked, update its permissions
if (tc != null) {
// Send feedback to the logs and issuer
LoggerUtils.logAndDelete(log, String.format("Changed user limit of channel \"%s\" to %s.", vc.getName(), intLimit));
l.getDiscordController().sendMessage(ev, String.format("**%s** changed the user limit %sto **%s**.", ev.getMember().getEffectiveName(), tc.equals(ev.getChannel()) ? ("of **" + vc.getName() + "** ") : "", intLimit), DiscordController.AUTOMATIC_REMOVAL_INTERVAL);
// If the limit is 0, this means the limit was removed
if (intLimit == 0) {
l.getChannelPermissionController().changeToPublicFromPrivate(tc, vc);
} else {
l.getChannelPermissionController().changeToPrivateFromPublic(tc, vc);
}
}
}
use of net.dv8tion.jda.core.entities.TextChannel in project TheLighterBot by PhotonBursted.
the class TemporaryChannelTopicCommand method execute.
@Override
protected void execute() {
// Get the channels targeted by the issuer
VoiceChannel vc = ev.getMember().getVoiceState().getChannel();
TextChannel tc = l.getChannelController().getLinkedChannels().getForVoiceChannel(vc);
// If the voice channel wasn't found the user wasn't in one to start with
if (vc == null) {
handleError(MessageContent.NOT_IN_VOICE_CHANNEL);
return;
}
// The target should not be the default channel
if (vc == ev.getGuild().getAfkChannel()) {
handleError(MessageContent.AFK_CHANNEL_ACTION_NOT_PERMITTED);
return;
}
// If the target voice channel is permanent, the user requires MANAGE_CHANNEL permissions
if (l.getChannelController().isPermanent(vc) && (!l.getChannelController().isPermanent(vc) || !ev.getMember().hasPermission(Permission.MANAGE_CHANNEL))) {
handleError(MessageContent.PERMISSIONS_REQUIRED, Permission.MANAGE_CHANNEL.name(), "change the topic of permanent voice channels");
return;
}
String description = Utils.drainQueueToString(input);
if (tc != null) {
// Send feedback to the logs and issuer
LoggerUtils.logAndDelete(log, String.format("Changed description of channel \"%s\" to \"%s\".", tc.getName(), description));
l.getDiscordController().sendMessage(ev, String.format("**%s** changed the topic%s.", ev.getAuthor().getName(), !tc.equals(ev.getChannel()) ? ("of **" + tc.getAsMention() + "**") : ""), DiscordController.AUTOMATIC_REMOVAL_INTERVAL);
tc.getManager().setTopic(description).reason(Utils.userAsString(ev.getAuthor()) + " requested a change of topic for this channel.").queue();
}
}
use of net.dv8tion.jda.core.entities.TextChannel in project FlareBot by FlareBot.
the class DebugCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
if (args.length < 1) {
MessageUtils.sendUsage(this, channel, sender, args);
return;
}
FlareBot fb = FlareBot.instance();
EmbedBuilder eb = MessageUtils.getEmbed();
if (args[0].equalsIgnoreCase("flarebot") || args[0].equalsIgnoreCase("bot")) {
eb.setTitle("Bot Debug").setDescription(String.format("Debug for FlareBot v" + FlareBot.getVersion() + "\nUptime: %s" + "\nMemory Usage: %s" + "\nMemory Free: %s" + "\nVideo Threads: %d" + "\nCommand Threads: %d" + "\nTotal Threads: %d" + "\n\nGuilds: %d" + "\nLoaded Guilds: %d" + "\nVoice Channels: %d" + "\nActive Voice Channels: %d" + "\nCommands Executed: %d" + "\nQueued RestActions: %s", fb.getUptime(), getMB(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()), getMB(Runtime.getRuntime().freeMemory()), VideoThread.VIDEO_THREADS.activeCount(), Events.COMMAND_THREADS.activeCount(), Thread.getAllStackTraces().size(), fb.getShardManager().getGuildCache().size(), FlareBotManager.instance().getGuilds().size(), Getters.getConnectedVoiceChannels(), Getters.getActiveVoiceChannels(), fb.getEvents().getCommandCount(), getQueuedRestActions()));
StringBuilder sb = new StringBuilder();
for (DataInterceptor interceptor : DataInterceptor.getInterceptors()) sb.append(WordUtils.capitalize(interceptor.getSender().getName())).append(" - ").append(interceptor.getRequests()).append(" requests").append("\n");
eb.addField("HTTP Requests", sb.toString(), false);
} else if (args[0].equalsIgnoreCase("threads")) {
eb.setTitle("Thread Debug").setDescription(String.format("Video Threads: %d" + "\nCommand Threads: %d" + "\nTotal Threads: %d" + "\nThread list: %s", VideoThread.VIDEO_THREADS.activeCount(), Events.COMMAND_THREADS.activeCount(), Thread.getAllStackTraces().size(), MessageUtils.paste(Thread.getAllStackTraces().keySet().stream().map(th -> th.getName() + " - " + th.getState() + " (" + th.getThreadGroup().getName() + ")").collect(Collectors.joining("\n")))));
} else if (args[0].equalsIgnoreCase("server") || args[0].equalsIgnoreCase("guild")) {
GuildWrapper wrapper = guild;
if (args.length == 2)
wrapper = FlareBotManager.instance().getGuild(args[1]);
if (wrapper == null) {
channel.sendMessage("I can't find that guild!").queue();
return;
}
eb.setTitle("Server Debug").setDescription(String.format("Debug for " + wrapper.getGuildIdLong() + "\nData Ver: %s (%s)" + "\nPrefix: %s" + "\nBlocked: %b" + "\nBeta: %b" + "\nWelcomes: %b/%b" + "\nNINO: %b" + "\nSong nick: %b" + "\nPerms: %s" + "\nMute role: %s" + "\nsettings: %s" + "\n\nFor full guild data do `_guild data " + wrapper.getGuildIdLong() + "`", wrapper.dataVersion, GuildWrapper.DATA_VERSION, MessageUtils.escapeMarkdown(String.valueOf(wrapper.getPrefix())), wrapper.isBlocked(), wrapper.getBetaAccess(), wrapper.getWelcome().isGuildEnabled(), wrapper.getWelcome().isDmEnabled(), wrapper.getNINO().isEnabled(), wrapper.isSongnickEnabled(), MessageUtils.paste(FlareBot.GSON.toJson(wrapper.getPermissions())), wrapper.getMutedRole(), wrapper.getSettings().toString()));
} else if (args[0].equalsIgnoreCase("player") || args[0].equalsIgnoreCase("music")) {
GuildWrapper wrapper = guild;
if (args.length == 2)
wrapper = FlareBotManager.instance().getGuild(args[1]);
if (wrapper == null) {
channel.sendMessage("I can't find that guild!").queue();
return;
}
Player player = FlareBot.instance().getMusicManager().getPlayer(wrapper.getGuildId());
AudioManager manager = wrapper.getGuild().getAudioManager();
@Nullable VoiceChannel vc = manager.getConnectedChannel();
String lastActive = "Not tracked.";
if (VoiceChannelCleanup.VC_LAST_USED.containsKey(vc != null ? vc.getIdLong() : guild.getGuildIdLong())) {
long ms = VoiceChannelCleanup.VC_LAST_USED.get(vc != null ? vc.getIdLong() : guild.getGuildIdLong());
lastActive = String.valueOf(ms) + " (" + (System.currentTimeMillis() - ms) + "ms ago)";
}
boolean isPlaying = player.getPlayingTrack() != null;
Track track = player.getPlayingTrack();
eb.setTitle("Bot Debug").setDescription(String.format("Player Debug for `" + wrapper.getGuildId() + "`" + "\nCurrent Track: %s" + "\nCurrent Position: %s" + "\nIs Paused: %b" + "\nPlaylist Length: %s" + "\nIs Looping: %b" + "\nConnecting: %b" + "\nVoice Channel: %s" + "\nConnection State: %s" + "\nLast Active: %s", (isPlaying ? track.getTrack().getIdentifier() : "No current track"), (isPlaying ? track.getTrack().getPosition() + "/" + track.getTrack().getDuration() : "N/A"), player.getPaused(), player.getPlaylist().size(), player.getLooping(), manager.isAttemptingToConnect(), (vc == null ? "null" : vc.toString()), manager.getConnectionStatus().toString(), lastActive));
} else {
channel.sendMessage("Invalid debug option").queue();
return;
}
channel.sendMessage(eb.build()).queue();
}
use of net.dv8tion.jda.core.entities.TextChannel in project FlareBot by FlareBot.
the class ShardInfoCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
PagedTableBuilder tb = new PagedTableBuilder();
tb.addColumn("Shard ID");
tb.addColumn("Status");
tb.addColumn("Ping");
tb.addColumn("Guild Count");
tb.addColumn("Connected VCs");
List<JDA> shards = new ArrayList<>(Getters.getShards());
Collections.reverse(shards);
for (JDA jda : shards) {
List<String> row = new ArrayList<>();
row.add(ShardUtils.getDisplayShardId(jda) + (ShardUtils.getShardId(channel.getJDA()) == ShardUtils.getShardId(jda) ? " (You)" : ""));
row.add(WordUtils.capitalizeFully(jda.getStatus().toString().replace("_", " ")));
row.add(String.valueOf(jda.getPing()));
row.add(String.valueOf(jda.getGuilds().size()));
row.add(String.valueOf(jda.getVoiceChannels().stream().filter(vc -> vc.getMembers().contains(vc.getGuild().getSelfMember())).count()));
tb.addRow(row);
}
PaginationUtil.sendPagedMessage(channel, tb.build(), 0, sender, ButtonGroupConstants.SHARDINFO);
}
Aggregations