use of stream.flarebot.flarebot.objects.GuildWrapper 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")) {
} 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());
VoiceChannel vc = (wrapper.getGuild().getSelfMember().getVoiceState() != null && wrapper.getGuild().getSelfMember().getVoiceState().getChannel() != null ? wrapper.getGuild().getSelfMember().getVoiceState().getChannel() : null);
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" + "\nVoice Channel: %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(), (vc == null ? "null" : vc.toString()), lastActive));
} else {
channel.sendMessage("Invalid debug option").queue();
return;
}
channel.sendMessage(eb.build()).queue();
}
use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.
the class HelpCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
if (args.length == 1) {
CommandType type;
try {
type = CommandType.valueOf(args[0].toUpperCase());
} catch (IllegalArgumentException ignored) {
channel.sendMessage(MessageUtils.getEmbed(sender).setDescription("No such category!").build()).queue();
return;
}
if (GeneralUtils.canRunInternalCommand(type, sender)) {
List<String> pages = new ArrayList<>();
List<String> help = type.getCommands().stream().filter(cmd -> getPermissions(channel).hasPermission(member, cmd.getPermission())).map(command -> guild.getPrefix() + command.getCommand() + " - " + command.getDescription() + '\n').collect(Collectors.toList());
StringBuilder sb = new StringBuilder();
for (String s : help) {
if (sb.length() + s.length() > 1024) {
pages.add(sb.toString());
sb.setLength(0);
}
sb.append(s);
}
pages.add(sb.toString());
PagedEmbedBuilder<String> builder = new PagedEmbedBuilder<>(new PaginationList<>(pages));
builder.setTitle("***FlareBot " + type + " commands!***");
builder.setColor(Color.CYAN);
PaginationUtil.sendEmbedPagedMessage(builder.build(), 0, channel, sender, ButtonGroupConstants.HELP);
} else {
channel.sendMessage(MessageUtils.getEmbed(sender).setDescription("No such category!").build()).queue();
}
} else {
sendCommands(channel.getGuild(), channel, sender);
}
}
use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.
the class PlayerListener method onTrackEnd.
@Override
public void onTrackEnd(AudioPlayer aplayer, AudioTrack atrack, AudioTrackEndReason reason) {
GuildWrapper wrapper = FlareBotManager.instance().getGuild(player.getGuildId());
if (wrapper == null)
return;
// No song on next
if (player.getPlaylist().isEmpty()) {
FlareBotManager.instance().getLastActive().put(Long.parseLong(player.getGuildId()), System.currentTimeMillis());
}
VoteUtil.remove(SkipCommand.getSkipUUID(), wrapper.getGuild());
if (wrapper.isSongnickEnabled()) {
if (GuildUtils.canChangeNick(player.getGuildId())) {
Guild c = wrapper.getGuild();
if (c == null) {
wrapper.setSongnick(false);
} else {
if (player.getPlaylist().isEmpty())
c.getController().setNickname(c.getSelfMember(), null).queue();
}
} else {
if (!GuildUtils.canChangeNick(player.getGuildId())) {
MessageUtils.sendPM(Getters.getGuildById(player.getGuildId()).getOwner().getUser(), "FlareBot can't change it's nickname so SongNick has been disabled!");
}
}
}
}
use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.
the class Events method handleCommand.
private void handleCommand(GuildMessageReceivedEvent event, Command cmd, String[] args) {
Metrics.commandsReceived.labels(cmd.getClass().getSimpleName()).inc();
GuildWrapper guild = flareBot.getManager().getGuild(event.getGuild().getId());
if (cmd.getType().isInternal()) {
if (GeneralUtils.canRunInternalCommand(cmd.getType(), event.getAuthor())) {
dispatchCommand(cmd, args, event, guild);
return;
} else {
GeneralUtils.sendImage("https://flarebot.stream/img/trap.jpg", "trap.jpg", event.getAuthor());
Constants.logEG("It's a trap", cmd, guild.getGuild(), event.getAuthor());
return;
}
}
if (guild.hasBetaAccess()) {
if ((guild.getSettings().getChannelBlacklist().contains(event.getChannel().getIdLong()) || guild.getSettings().getUserBlacklist().contains(event.getAuthor().getIdLong())) && !guild.getPermissions().hasPermission(event.getMember(), stream.flarebot.flarebot.permissions.Permission.BLACKLIST_BYPASS))
return;
}
if (guild.isBlocked() && System.currentTimeMillis() > guild.getUnBlockTime() && guild.getUnBlockTime() != -1)
guild.revokeBlock();
handleSpamDetection(event, guild);
if (guild.isBlocked() && !(cmd.getType() == CommandType.SECRET))
return;
if (handleMissingPermission(cmd, event))
return;
if (!guild.hasBetaAccess() && cmd.isBetaTesterCommand()) {
if (flareBot.isTestBot())
LOGGER.error("Guild " + event.getGuild().getId() + " tried to use the beta command '" + cmd.getCommand() + "'!");
return;
}
if (FlareBot.UPDATING.get()) {
event.getChannel().sendMessage("**Currently updating!**").queue();
return;
}
if (flareBot.getManager().isCommandDisabled(cmd.getCommand())) {
MessageUtils.sendErrorMessage(flareBot.getManager().getDisabledCommandReason(cmd.getCommand()), event.getChannel(), event.getAuthor());
return;
}
// Internal stuff
if (event.getGuild().getIdLong() == Constants.OFFICIAL_GUILD && !handleOfficialGuildStuff(event, cmd))
return;
if (event.getGuild().getIdLong() != Constants.OFFICIAL_GUILD && cmd.getType() == CommandType.MUSIC) {
MessageUtils.sendInfoMessage("FlareBot is closing down, as part of this we have disabled music commands, please read the announcement [here](https://docs.flarebot.stream). Please use the remaining available commands to move any data you wish over to other bots.\nBots we recommend:\nFredBoat - Music\nDyno - Moderation\nMee6 - Random stuff", event.getChannel());
return;
}
dispatchCommand(cmd, args, event, guild);
}
use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.
the class URLChecker method runTests.
public void runTests() {
List<String> tests = ImmutableList.of("Check this out https://i.go.iplogger.com/12dxzfcs.php", "http://cool.webcam", "http://www.discord.gg/b1nzy", "https://flarebot.stream", // "http://bit.ly/2Ix3h5k",
"www.iplogger.com", "http://test.iplogger.com/t?=192.0.0.1", "http://bit.ly/2FY9rJW");
GuildWrapper wrapper = new GuildWrapper("1");
wrapper.getNINO().addURLFlags(URLCheckFlag.IP_GRABBER, /*URLCheckFlag.BLACKLISTED,*/
URLCheckFlag.DISCORD_INVITE, URLCheckFlag.PHISHING, URLCheckFlag.SUSPICIOUS);
for (String url : tests) {
instance().checkMessage(wrapper, null, url, (flag, u) -> logger.info(url + " - " + flag));
}
}
Aggregations