use of net.dv8tion.jda.core.entities.Message in project Ardent by adamint.
the class ShardInfo method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
StringBuilder builder = new StringBuilder();
for (Shard shard : ShardManager.getShards()) {
builder.append(shard.jda.getShardInfo()).append(" | STATUS: ").append(shard.jda.getStatus()).append(" | " + "U: ").append(shard.jda.getUsers().size()).append(" | G: ").append(shard.jda.getGuilds().size()).append(" | MC: ").append(shard.jda.getVoiceChannels().stream().filter(voiceChannel -> voiceChannel.getMembers().contains(voiceChannel.getGuild().getSelfMember())).count()).append(" | LE: " + (System.currentTimeMillis() - shard.getLAST_EVENT()));
if (shard.jda.getShardInfo() != null && shard.jda.getShardInfo().equals(guild.getJDA().getShardInfo())) {
builder.append(" <- CURRENT");
}
builder.append("\n");
}
channel.sendMessage(String.format("```prolog\n%s```", builder.toString())).queue();
}
use of net.dv8tion.jda.core.entities.Message in project Ardent by adamint.
the class Stats method setupSubcommands.
@Override
public void setupSubcommands() throws Exception {
subcommands.add(new Subcommand("See what commands are being used", "commands", "commands") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
StringBuilder commandBars = new StringBuilder();
Map<String, Long> commandsUsed = getCommandData(ShardManager.getShards());
final int[] counter = { 0 };
final int[] totalCommandsReceived = { 0 };
commandsUsed.forEach((key, value) -> {
if (counter[0] < 7)
totalCommandsReceived[0] += value;
counter[0]++;
});
counter[0] = 0;
commandsUsed.forEach((key, value) -> {
if (counter[0] < 7) {
int percent = (int) (value * 100 / totalCommandsReceived[0]);
String bar = bar(percent);
if (bar != null) {
commandBars.append(bar + " " + percent + "% **" + key + "**\n");
}
}
counter[0]++;
});
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor("Command Statistics", getShard().url, getShard().bot.getAvatarUrl());
builder.setColor(Color.GREEN);
builder.setDescription("Command Usage\n" + commandBars.toString());
sendEmbed(builder, channel, user);
}
});
subcommands.add(new Subcommand("See how many server's I'm joining and leaving", "guilds") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor("Guild Statistics", getShard().url, getShard().bot.getAvatarUrl());
builder.setColor(Color.GREEN);
int lPH = 0;
int lPD = 0;
int lPS = 0;
long epochSecond = Instant.now().getEpochSecond();
long hBar = epochSecond - (60 * 60);
long dBar = epochSecond - (60 * 60 * 24);
long sBar = 0;
for (Instant i : Leave.botLeaveEvents) {
if (i.getEpochSecond() >= hBar)
lPH++;
if (i.getEpochSecond() >= dBar)
lPD++;
// Always true
if (i.getEpochSecond() >= sBar)
lPS++;
}
int jPH = 0;
int jPD = 0;
int jPS = 0;
for (Instant i : Join.botJoinEvents) {
if (i.getEpochSecond() >= hBar)
jPH++;
if (i.getEpochSecond() >= dBar)
jPD++;
// Always true
if (i.getEpochSecond() >= sBar)
jPS++;
}
builder.addField("Hourly", generateGuild(jPH, lPH), false);
builder.addField("Daily", generateGuild(jPD, lPD), false);
builder.addField("This Session", generateGuild(jPS, lPS), false);
builder.addField("Guilds", String.valueOf(InternalStats.collect().getGuilds()), false);
sendEmbed(builder, channel, user);
}
});
}
use of net.dv8tion.jda.core.entities.Message in project Ardent by adamint.
the class MusicConfig method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
Cursor<HashMap> settings = r.db("data").table("music_settings").filter(row -> row.g("guild_id").eq(guild.getId())).run(connection);
if (settings.hasNext()) {
MusicSettingsModel musicSettingsModel = asPojo(settings.next(), MusicSettingsModel.class);
sendTranslatedMessage("**music Settings**\n" + "Delete music play messages: " + musicSettingsModel.isRemove_addition_messages(), channel, user);
} else
sendTranslatedMessage("Your guild has no set music settings! Type **/manage** to find your portal" + " link", channel, user);
}
use of net.dv8tion.jda.core.entities.Message in project MantaroBot by Mantaro.
the class Poll method createPoll.
private Future<Void> createPoll(Message message) {
runningPoll = ReactionOperations.create(message, TimeUnit.MILLISECONDS.toSeconds(timeout), new ReactionOperation() {
@Override
public int add(MessageReactionAddEvent e) {
int i = e.getReactionEmote().getName().charAt(0) - '\u0030';
if (i < 1 || i > options.length)
return Operation.IGNORED;
// always return false anyway lul
return Operation.IGNORED;
}
@Override
public void onExpire() {
if (getChannel() == null)
return;
EmbedBuilder embedBuilder = new EmbedBuilder().setTitle("Poll results").setDescription("**Showing results for the poll started by " + MantaroBot.getInstance().getUserById(owner).getName() + "** with name: *" + name + "*").setFooter("Thanks for your vote", null);
AtomicInteger react = new AtomicInteger(0);
AtomicInteger counter = new AtomicInteger(0);
String votes = new ArrayList<>(getChannel().getMessageById(message.getIdLong()).complete().getReactions()).stream().filter(r -> react.getAndIncrement() <= options.length).map(r -> "+Registered " + (r.getCount() - 1) + " votes for option " + options[counter.getAndIncrement()]).collect(Collectors.joining("\n"));
embedBuilder.addField("Results", "```diff\n" + votes + "```", false);
getChannel().sendMessage(embedBuilder.build()).queue();
getRunningPolls().remove(getChannel().getId());
}
@Override
public void onCancel() {
getChannel().sendMessage(EmoteReference.CORRECT + "Cancelled poll").queue();
onExpire();
}
}, reactions(options.length));
return runningPoll;
}
use of net.dv8tion.jda.core.entities.Message in project MantaroBot by Mantaro.
the class AudioLoader method loadSingle.
private void loadSingle(AudioTrack audioTrack, boolean silent) {
AudioTrackInfo trackInfo = audioTrack.getInfo();
audioTrack.setUserData(event.getAuthor().getId());
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
DBUser dbUser = MantaroData.db().getUser(event.getMember());
GuildData guildData = dbGuild.getData();
String title = trackInfo.title;
long length = trackInfo.length;
long queueLimit = !Optional.ofNullable(dbGuild.getData().getMusicQueueSizeLimit()).isPresent() ? MAX_QUEUE_LENGTH : dbGuild.getData().getMusicQueueSizeLimit();
int fqSize = guildData.getMaxFairQueue();
if (musicManager.getTrackScheduler().getQueue().size() > queueLimit && !dbUser.isPremium() && !dbGuild.isPremium()) {
if (!silent)
event.getChannel().sendMessage(String.format(":warning: Could not queue %s: Surpassed queue song limit!", title)).queue(message -> message.delete().queueAfter(30, TimeUnit.SECONDS));
return;
}
if (audioTrack.getInfo().length > MAX_SONG_LENGTH && !dbUser.isPremium() && !dbGuild.isPremium()) {
event.getChannel().sendMessage(String.format(":warning: Could not queue %s: Track is longer than 32 minutes! (%s)", title, AudioUtils.getLength(length))).queue();
return;
}
// Comparing if the URLs are the same to be 100% sure they're just not spamming the same url over and over again.
if (musicManager.getTrackScheduler().getQueue().stream().filter(track -> track.getInfo().uri.equals(audioTrack.getInfo().uri)).count() > fqSize && !silent) {
event.getChannel().sendMessage(EmoteReference.ERROR + String.format("**Surpassed fair queue level of %d (Too many songs which are exactly equal)**", fqSize + 1)).queue();
return;
}
musicManager.getTrackScheduler().queue(audioTrack, insertFirst);
musicManager.getTrackScheduler().setRequestedChannel(event.getChannel().getIdLong());
if (!silent) {
event.getChannel().sendMessage(new MessageBuilder().append(String.format("\uD83D\uDCE3 Added to queue -> **%s** **(%s)**", title, AudioUtils.getLength(length))).stripMentions(event.getGuild(), Message.MentionType.EVERYONE, Message.MentionType.HERE).build()).queue();
}
MantaroBot.getInstance().getStatsClient().increment("tracks_loaded");
}
Aggregations