use of net.dv8tion.jda.core.entities.Member in project Frost by woojiahao.
the class FrostRoles method autoAssignRole.
public static void autoAssignRole(Guild guild) {
List<Member> members = guild.getMembers();
for (Member m : members) {
DiscordSet set = new DiscordSet(m.getUser(), guild);
assignRole(set, RolesID.MEMBER);
if (m.isOwner())
assignRole(set, RolesID.OWNER);
if (m.getUser().isBot())
assignRole(set, RolesID.SLAVE);
}
}
use of net.dv8tion.jda.core.entities.Member in project c0debaseBot by Biospheere.
the class LeaderboardCommand method execute.
@Override
public void execute(String[] args, Message msg) {
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setColor(msg.getGuild().getSelfMember().getColor());
embedBuilder.setTitle("Leaderboard: " + msg.getGuild().getName());
CodebaseBot.getInstance().getLeaderboardPagination().updateList(CodebaseBot.getInstance().getLevelManager().getLevelUsersSorted());
int count = 1;
for (LevelUser levelUser : CodebaseBot.getInstance().getLeaderboardPagination().getPage(1)) {
Member member = msg.getGuild().getMemberById(Long.valueOf(levelUser.getId()));
if (member != null) {
embedBuilder.appendDescription("`" + count + ")` " + StringUtils.replaceCharacter(member.getEffectiveName()) + "#" + member.getUser().getDiscriminator() + " (Lvl." + levelUser.getLevel() + ")\n");
}
count++;
}
embedBuilder.setFooter("Seite: (1/" + ((CodebaseBot.getInstance().getLevelManager().getLevelUsersSorted().size() / 10) + 1) + ")", msg.getGuild().getIconUrl());
msg.getTextChannel().sendMessage(embedBuilder.build()).queue((Message success) -> {
success.addReaction(EmojiManager.getForAlias("arrow_left").getUnicode()).queue();
success.addReaction(EmojiManager.getForAlias("arrow_right").getUnicode()).queue();
});
}
use of net.dv8tion.jda.core.entities.Member in project MantaroBot by Mantaro.
the class GameCmds method game.
@Subscribe
public void game(CommandRegistry cr) {
final NewRateLimiter rateLimiter = new NewRateLimiter(Executors.newSingleThreadScheduledExecutor(), 4, 6, TimeUnit.SECONDS, 450, true) {
@Override
protected void onSpamDetected(String key, int times) {
log.warn("[Game] Spam detected for {} ({} times)!", key, times);
}
};
SimpleTreeCommand gameCommand = (SimpleTreeCommand) cr.register("game", new SimpleTreeCommand(Category.GAMES) {
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Guessing games.").addField("Games", "`~>game character` - **Starts an instance of Guess the character (anime)**.\n" + "`~>game pokemon` - **Starts an instance of who's that pokemon?**\n" + "`~>game number` - **Starts an instance of Guess The Number**`\n" + "`~>game lobby` - **Starts a chunk of different games, for example `~>game lobby pokemon, trivia` will start pokemon and then trivia.**\n" + "`~>game multiple` - **Starts multiple instances of one game, for example `~>game multiple trivia 5` will start trivia 5 times.**\n" + "`~>game wins` - **Shows how many times you've won in games**", false).addField("Considerations", "The pokemon guessing game has around *900 different pokemon* to guess, " + "where the anime guessing game has around 60. The number in the number guessing game is a random number between 0 and 150.\n" + "To start multiple trivia sessions please use `~>game trivia multiple`, not `~>trivia multiple`", false).build();
}
}.addSubCommand("character", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
startGame(new Character(), event);
}
}).addSubCommand("pokemon", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
startGame(new Pokemon(), event);
}
}).addSubCommand("number", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
startGame(new GuessTheNumber(), event);
}
}));
gameCommand.setPredicate(event -> Utils.handleDefaultNewRatelimit(rateLimiter, event.getAuthor(), event));
gameCommand.createSubCommandAlias("pokemon", "pokémon");
gameCommand.createSubCommandAlias("number", "guessthatnumber");
gameCommand.addSubCommand("wins", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
Member member = Utils.findMember(event, event.getMember(), content);
if (member == null)
return;
event.getChannel().sendMessage(EmoteReference.POPPER + member.getEffectiveName() + " has won " + MantaroData.db().getPlayer(member).getData().getGamesWon() + " games").queue();
}
});
gameCommand.addSubCommand("lobby", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
if (content.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You didn't specify anything to play!").queue();
return;
}
// Stripe all mentions from this.
String[] split = mentionPattern.matcher(content).replaceAll("").split(", ");
if (split.length < 1 || split.length == 1) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify two games at least!").queue();
return;
}
LinkedList<Game> gameList = new LinkedList<>();
for (String s : split) {
switch(s.replace(" ", "")) {
case "pokemon":
gameList.add(new Pokemon());
break;
case "trivia":
gameList.add(new Trivia(null));
break;
case "number":
gameList.add(new GuessTheNumber());
break;
case "character":
gameList.add(new Character());
break;
}
}
if (gameList.isEmpty() || gameList.size() == 1) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify two games at least (Valid games: character, pokemon, number, trivia)!").queue();
return;
}
startMultipleGames(gameList, event);
}
});
gameCommand.addSubCommand("multiple", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
String[] values = SPLIT_PATTERN.split(content, 2);
if (values.length < 2) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify the game and the number of times to run it").queue();
return;
}
int number;
try {
number = Integer.parseInt(values[1]);
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Invalid number of times!").queue();
return;
}
if (number > 10) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You can only start a maximum of 10 games of the same type at a time!").queue();
return;
}
LinkedList<Game> gameList = new LinkedList<>();
for (int i = 0; i < number; i++) {
switch(values[0].replace(" ", "")) {
case "pokemon":
gameList.add(new Pokemon());
break;
case "trivia":
gameList.add(new Trivia(null));
break;
case "number":
gameList.add(new GuessTheNumber());
break;
case "character":
gameList.add(new Character());
break;
}
}
if (gameList.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify a valid game! (Valid games: character, pokemon, number, trivia)").queue();
return;
}
startMultipleGames(gameList, event);
}
});
}
use of net.dv8tion.jda.core.entities.Member in project MantaroBot by Mantaro.
the class MuteCmds method mute.
@Subscribe
public void mute(CommandRegistry registry) {
Command mute = registry.register("mute", new SimpleCommand(Category.MODERATION) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (!event.getMember().hasPermission(Permission.KICK_MEMBERS) || !event.getMember().hasPermission(Permission.BAN_MEMBERS)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to have either ban or kick members permission to mute!").queue();
return;
}
ManagedDatabase db = MantaroData.db();
DBGuild dbGuild = db.getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
String reason = "Not specified";
Map<String, Optional<String>> opts = br.com.brjdevs.java.utils.texts.StringUtils.parse(args);
if (guildData.getMutedRole() == null) {
event.getChannel().sendMessage(EmoteReference.ERROR + "The mute role is not set in this server, you can set it by doing `~>opts muterole set <role>`").queue();
return;
}
Role mutedRole = event.getGuild().getRoleById(guildData.getMutedRole());
if (mutedRole == null) {
event.getChannel().sendMessage(EmoteReference.ERROR + "The previously configured mute role on this server is now non-existent!").queue();
return;
}
if (args.length > 1) {
reason = StringUtils.splitArgs(content, 2)[1];
}
if (event.getMessage().getMentionedUsers().isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to mention at least one user to mute.").queue();
return;
}
if (!event.getGuild().getSelfMember().hasPermission(event.getChannel(), Permission.MANAGE_ROLES)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "I don't have permissions to administrate roles on this server!").queue();
return;
}
// Regex from: Fabricio20
final String finalReason = timePattern.matcher(reason).replaceAll("");
MantaroObj data = db.getMantaroData();
event.getMessage().getMentionedUsers().forEach(user -> {
Member m = event.getGuild().getMember(user);
long time = guildData.getSetModTimeout() > 0 ? System.currentTimeMillis() + guildData.getSetModTimeout() : 0L;
if (opts.containsKey("time")) {
if (!opts.get("time").isPresent() || opts.get("time").get().isEmpty()) {
event.getChannel().sendMessage(EmoteReference.WARNING + "You wanted time but didn't specify for how long!").queue();
return;
}
time = System.currentTimeMillis() + Utils.parseTime(opts.get("time").get());
if (time > System.currentTimeMillis() + TimeUnit.DAYS.toMillis(10)) {
// smh smh smfh god fuck rethinkdb just
// dont
event.getChannel().sendMessage(EmoteReference.ERROR + "Too long...").queue();
// smh
return;
}
if (time < 0) {
event.getChannel().sendMessage("You cannot mute someone for negative time!").queue();
return;
}
data.getMutes().put(user.getIdLong(), Pair.of(event.getGuild().getId(), time));
data.save();
dbGuild.save();
} else {
if (time > 0) {
if (time > System.currentTimeMillis() + TimeUnit.DAYS.toMillis(10)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "The default mute timeout length is too long (Maximum: 10 days)...").queue();
return;
}
data.getMutes().put(user.getIdLong(), Pair.of(event.getGuild().getId(), time));
data.save();
dbGuild.save();
} else {
event.getChannel().sendMessage(EmoteReference.ERROR + "You didn't specify any time!").queue();
return;
}
}
if (m.getRoles().contains(mutedRole)) {
event.getChannel().sendMessage(EmoteReference.WARNING + "This user already has a mute role assigned. Please do `~>unmute` to unmute them.").queue();
return;
}
if (!event.getGuild().getSelfMember().canInteract(m)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "I cannot assign the mute role to this user because they're in a higher hierarchy than me, or the role is in a higher hierarchy!").queue();
return;
}
if (!event.getMember().canInteract(m)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "I cannot assign the mute role to this user because they're in a higher hierarchy than me, or the role is in a higher hierarchy than you!").queue();
return;
}
final DBGuild dbg = db.getGuild(event.getGuild());
event.getGuild().getController().addSingleRoleToMember(m, mutedRole).reason(String.format("Muted by %#s for %s: %s", event.getAuthor(), Utils.formatDuration(time - System.currentTimeMillis()), finalReason)).queue();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Added mute role to **" + m.getEffectiveName() + (time > 0 ? "** for around " + Utils.getHumanizedTime(time - System.currentTimeMillis()) : "**")).queue();
dbg.getData().setCases(dbg.getData().getCases() + 1);
dbg.saveAsync();
ModLog.log(event.getMember(), user, finalReason, ModLog.ModAction.MUTE, dbg.getData().getCases());
});
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Mute").setDescription("**Mutes the specified users**").addField("Usage", "`~>mute <user> <reason> [-time <time>]` - Mutes the specified users.", false).addField("Parameters", "`users` - The users to mute. Needs to be mentions.\n" + "`[-time <time>]` - The time to mute an user for. For example `~>mute @Natan#1289 wew, nice -time 1m20s` will mute Natan for 1 minute and 20 seconds.", false).addField("Considerations", "To unmute an user, do `~>unmute`.", false).addField("Extended usage", "`time` - can be used with the following parameters: " + "d (days), s (second), m (minutes), h (hour). **For example -time 1d1h will mute for one day and one hour.**", false).build();
}
});
mute.addOption("defaultmutetimeout:set", new Option("Default mute timeout", "Sets the default mute timeout for ~>mute.\n" + "This command will set the timeout of ~>mute to a fixed value **unless you specify another time in the command**\n" + "**Example:** `~>opts defaultmutetimeout set 1m20s`\n" + "**Considerations:** Time is in 1m20s or 1h10m3s format, for example.", OptionType.GUILD).setAction(((event, args) -> {
if (args.length == 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You have to specify a timeout in the format of 1m20s, for example.").queue();
return;
}
if (!(args[0]).matches("(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+)s)?")) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Wrong time format. You have to specify a timeout in the format of 1m20s, for example.").queue();
return;
}
long timeoutToSet = Utils.parseTime(args[0]);
long time = System.currentTimeMillis() + timeoutToSet;
if (time > System.currentTimeMillis() + TimeUnit.DAYS.toMillis(10)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Too long...").queue();
return;
}
if (time < 0) {
event.getChannel().sendMessage("You cannot mute someone for negative time!").queue();
return;
}
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
guildData.setSetModTimeout(timeoutToSet);
dbGuild.save();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Successfully set mod action timeout to `" + args[0] + "` (" + timeoutToSet + "ms)").queue();
})).setShortDescription("Sets the default timeout for the ~>mute command"));
mute.addOption("defaultmutetimeout:reset", new Option("Default mute timeout reset", "Resets the default mute timeout which was set previously with `defaultmusictimeout set`", OptionType.GUILD).setAction((event -> {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
guildData.setSetModTimeout(0L);
dbGuild.save();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Successfully reset timeout.").queue();
})).setShortDescription("Resets the default mute timeout."));
mute.addOption("muterole:set", new Option("Mute role set", "Sets this guilds mute role to apply on the ~>mute command.\n" + "To use this command you need to specify a role name. *In case the name contains spaces, the name should" + " be wrapped in quotation marks", OptionType.COMMAND).setAction((event, args) -> {
if (args.length < 1) {
OptsCmd.onHelp(event);
return;
}
String roleName = String.join(" ", args);
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
List<Role> roleList = event.getGuild().getRolesByName(roleName, true);
if (roleList.size() == 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "I didn't find a role with that name!").queue();
} else if (roleList.size() == 1) {
Role role = roleList.get(0);
guildData.setMutedRole(role.getId());
dbGuild.saveAsync();
event.getChannel().sendMessage(EmoteReference.OK + "Set mute role to **" + roleName + "**").queue();
} else {
DiscordUtils.selectList(event, roleList, role -> String.format("%s (ID: %s) | Position: %s", role.getName(), role.getId(), role.getPosition()), s -> OptsCmd.getOpts().baseEmbed(event, "Select the Mute Role:").setDescription(s).build(), role -> {
guildData.setMutedRole(role.getId());
dbGuild.saveAsync();
event.getChannel().sendMessage(EmoteReference.OK + "Set mute role to **" + roleName + "**").queue();
});
}
}).setShortDescription("Sets this guilds mute role to apply on the ~>mute command"));
mute.addOption("muterole:unbind", new Option("Mute Role unbind", "Resets the current value set for the mute role", OptionType.GENERAL).setAction(event -> {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
guildData.setMutedRole(null);
dbGuild.saveAsync();
event.getChannel().sendMessage(EmoteReference.OK + "Correctly reset the mute role.").queue();
}).setShortDescription("Resets the current value set for the mute role."));
}
use of net.dv8tion.jda.core.entities.Member 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();
}
Aggregations