net.dv8tion.jda.core.entities.Member Java Examples

The following examples show how to use net.dv8tion.jda.core.entities.Member. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogsCommand.java    From FlareBot with MIT License 7 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    int lineCount = DEFAULT_LINE_COUNT;
    if (args.length == 1) {
        lineCount = GeneralUtils.getInt(args[0], DEFAULT_LINE_COUNT);
    }

    try {
        ReversedLinesFileReader rlfr = new ReversedLinesFileReader(new File("latest.log"), Charset.forName("UTF-8"));
        StringBuilder sb = new StringBuilder();
        String line;
        for (int i = 0; i < lineCount; i++) {
            line = rlfr.readLine();
            if (line == null) break;
            sb.append(line).append("\n");
        }

        String pasteUrl = MessageUtils.paste(sb.toString());
        MessageUtils.sendPM(channel, sender, pasteUrl == null ? "null" : pasteUrl, "Could not DM you the logs! " +
                "Please make sure the privacy settings allow me :( dis is pwivate, me need to send pwivately.");
    } catch (IOException e) {
        FlareBot.LOGGER.error("Failed to read latest.log", e);
        MessageUtils.sendException("Failed to read latest.log", e, channel);
    }
}
 
Example #2
Source File: BanCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length >= 1) {
        User target = GuildUtils.getUser(args[0], guild.getGuildId());
        if (target == null) {
            MessageUtils.sendErrorMessage("We cannot find that user! Try their ID if you didn't already.", channel, sender);
            return;
        }
        String reason = null;
        if (args.length >= 2)
            reason = MessageUtils.getMessage(args, 1);

        ModlogHandler.getInstance().handleAction(guild, channel, sender, target, ModAction.BAN, reason);
    } else {
        MessageUtils.sendUsage(this, channel, sender, args);
    }
}
 
Example #3
Source File: HelpCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@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 (type.isInternal() && !GeneralUtils.canRunInternalCommand(type, sender)) {
            channel.sendMessage(MessageUtils.getEmbed(sender).setDescription("No such category!").build()).queue();
            return;
        }

        sendCommands(guild, channel, member, type);
    } else
        sendCommands(channel.getGuild(), channel, sender);
}
 
Example #4
Source File: StopCommand.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(TextChannel textChannel, Member member, Message message, List<String> arguments) {
	EmbedBuilder embedBuilder = new EmbedBuilder();
	embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl());
	embedBuilder.setColor(DiscordUtil.DEFAULT);
	
	if (DiscordBot.getInstance().getDiscord().getAudioPlayer().getPlayingTrack() == null) {
		embedBuilder.setColor(DiscordUtil.ERROR);
		embedBuilder.setTitle("Player is not playing anything!", null);
		DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
		return;
	}
	
	DiscordBot.getInstance().getDiscord().getAudioPlayer().stopTrack();
	embedBuilder.setColor(DiscordUtil.SUCCESS);
	embedBuilder.setTitle("Track stopped.", null);
	DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
}
 
Example #5
Source File: Permission.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
public boolean checkMember(Member member, String command) {
	Group group = findUserGroup(member);
	if (group == null) {
		return false;
	}
	
	if (group.isIgnoreNonVoice() && !member.getVoiceState().inVoiceChannel()) {
		return false;
	}
	
	if (!checkCommand(group, member, command)) {
		return false;
	}
	
	//TODO
	return false;
}
 
Example #6
Source File: ServerCommand.java    From DiscordBlueBot with MIT License 6 votes vote down vote up
@Override
public void action(String[] args, MessageReceivedEvent event) {
    EmbedBuilder builder = new EmbedBuilder();
    builder.setAuthor("Server Info", null, "http://i.imgur.com/880AyL6.png");
    builder.setColor(Color.decode(MainBot.getConfig().getEmbedColor()));
    builder.setThumbnail(event.getGuild().getIconUrl());
    builder.addField("Name", event.getGuild().getName(), true);
    builder.addBlankField(true);
    builder.addField("Owner", event.getGuild().getOwner().getUser().getName() + "#" + event.getGuild().getOwner().getUser().getDiscriminator() , true);
    builder.addField("Server ID", event.getGuild().getId(), true);
    builder.addField("Region", event.getGuild().getRegion().name(), true);
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy h:mm a");
    builder.addField("Creation Date", event.getGuild().getCreationTime().format(formatter), true);
    builder.addField("Total Members", String.valueOf(event.getGuild().getMembers().size()), true);
    int online = 0;
    for(Member member : event.getGuild().getMembers()) {
        if(!member.getOnlineStatus().equals(OnlineStatus.OFFLINE)) {
            ++online;
        }
    }
    builder.addField("Online Members", String.valueOf(online), true);

    event.getTextChannel().sendMessage(builder.build()).queue();
}
 
Example #7
Source File: Stats.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
private GuildStats(Guild g) {

            List<Member> l = g.getMembers();

            this.name = g.getName();
            this.id = g.getId();
            this.region = g.getRegion().getName();
            this.avatar = g.getIconUrl() == null ? "not set" : g.getIconUrl();
            this.textChans = g.getTextChannels().size();
            this.voiceChans = g.getVoiceChannels().size();
            this.categories = g.getCategories().size();
            this.rolesCount = g.getRoles().size();
            this.afk = g.getAfkChannel() == null ? "not set" : g.getAfkChannel().getName();
            this.owner = g.getOwner();

            this.all = l.size();
            this.users = l.stream().filter(m -> !m.getUser().isBot()).count();
            this.onlineUsers = l.stream().filter(m -> !m.getUser().isBot() && !m.getOnlineStatus().equals(OnlineStatus.OFFLINE)).count();
            this.bots = l.stream().filter(m -> m.getUser().isBot()).count();
            this.onlineBots = l.stream().filter(m -> m.getUser().isBot() && !m.getOnlineStatus().equals(OnlineStatus.OFFLINE)).count();

            this.roles = g.getRoles().stream()
                    .filter(r -> !r.getName().contains("everyone"))
                    .map(r -> String.format("%s (`%d`)", r.getName(), getMembsInRole(r)))
                    .collect(Collectors.joining(", "));
        }
 
Example #8
Source File: HelpCommand.java    From FlareBot with MIT License 6 votes vote down vote up
public void sendCommands(GuildWrapper guild, TextChannel channel, Member member, CommandType type) {
    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!***")
            .setColor(Color.CYAN);
    PaginationUtil.sendEmbedPagedMessage(builder.build(), 0, channel, member.getUser(), ButtonGroupConstants.HELP);
}
 
Example #9
Source File: DiscordCommand.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
public void execute(TextChannel channel, Member member, String command) {
	if (command.equalsIgnoreCase("botinfo")) {
		channel.sendMessage("DiscordBot - Bungeecord Edition, Version " + DiscordBotCore.getInstance().getConfiguration().getDiscordBotVersion() + ", Created by LX_Gaming\nJDA - " + DiscordBotCore.getInstance().getConfiguration().getJDAVersion()).queue();
		return;
	}
	
	if (command.equalsIgnoreCase("website")) {
		channel.sendMessage("``Website:`` **https://lxgaming.github.io/**\n``Source:`` **https://github.com/LXGaming/DiscordBot/**").queue();
		return;
	}
	
	DiscordBotCore.getInstance().getEventManager().onCommandReceived(new Message()
			.setChannel(channel.getId())
			.setFormat(DiscordBotCore.getInstance().getConfiguration().getCommandFormat().get(command.split(" ")[0]))
			.setName(member.getEffectiveName())
			.setNick(member.getNickname())
			.setMessage(command));
}
 
Example #10
Source File: JoinCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (member.getVoiceState().inVoiceChannel()) {
        if (channel.getGuild().getAudioManager().isAttemptingToConnect()) {
            MessageUtils.sendErrorMessage("Currently connecting to a voice channel! Try again soon!", channel);
            return;
        }
        if (channel.getGuild().getSelfMember().getVoiceState().inVoiceChannel() && !channel.getGuild()
                .getSelfMember()
                .getVoiceState()
                .getAudioChannel()
                .getId()
                .equals(member
                        .getVoiceState()
                        .getAudioChannel()
                        .getId()) && !getPermissions(channel).hasPermission(member, Permission.JOIN_OTHER)) {
            MessageUtils.sendErrorMessage("You need the permission `" + Permission.JOIN_OTHER + "` for me to join your voice channel while I'm in one!", channel);
            return;
        }
        GuildUtils.joinChannel(channel, member);
    }
}
 
Example #11
Source File: SkipCommand.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(TextChannel textChannel, Member member, Message message, List<String> arguments) {
	EmbedBuilder embedBuilder = new EmbedBuilder();
	embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl());
	embedBuilder.setColor(DiscordUtil.DEFAULT);
	
	if (DiscordBot.getInstance().getDiscord().getAudioQueue().isRepeatSong()) {
		embedBuilder.setColor(DiscordUtil.WARNING);
		DiscordBot.getInstance().getDiscord().getAudioQueue().setRepeatSong(false);
		embedBuilder.setTitle("Repeat is now off, Skipping...", null);
	} else {
		embedBuilder.setColor(DiscordUtil.SUCCESS);
		embedBuilder.setTitle("Skipping...", null);
	}
	
	DiscordBot.getInstance().getDiscord().getAudioQueue().playNext();
	DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
}
 
Example #12
Source File: VolumeCommand.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(TextChannel textChannel, Member member, Message message, List<String> arguments) {
	EmbedBuilder embedBuilder = new EmbedBuilder();
	embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl());
	embedBuilder.setColor(DiscordUtil.DEFAULT);
	
	if (arguments != null && !arguments.isEmpty()) {
		try {
			int volume = Integer.parseInt(arguments.get(0));
			if (volume > 100 || volume < 0) {
				volume = DiscordBot.getInstance().getDiscord().getAudioPlayer().getVolume();
			}
			
			DiscordBot.getInstance().getDiscord().getAudioPlayer().setVolume(volume);
			embedBuilder.setColor(DiscordUtil.SUCCESS);
		} catch (NumberFormatException ex) {
			embedBuilder.setColor(DiscordUtil.ERROR);
			embedBuilder.setTitle("Invalid volume!", null);
			DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
			return;
		}
	}
	
	embedBuilder.setTitle("Volume - " + DiscordBot.getInstance().getDiscord().getAudioPlayer().getVolume(), null);
	DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
}
 
Example #13
Source File: DeleteCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 0) {
        MessageUtils.sendUsage(this, channel, sender, args);
        return;
    }
    channel.sendTyping().complete();
    String name = MessageUtils.getMessage(args, 0);
    CassandraController.runTask(session -> {
        ResultSet set = session.execute(session
                .prepare("SELECT playlist_name FROM flarebot.playlist WHERE playlist_name = ? AND guild_id = ?")
                .bind().setString(0, name).setString(1, channel.getGuild().getId()));
        if (set.one() != null) {
            session.execute(session
                    .prepare("DELETE FROM flarebot.playlist WHERE playlist_name = ? AND guild_id = ?").bind()
                    .setString(0, name).setString(1, channel.getGuild().getId()));
            channel.sendMessage(MessageUtils.getEmbed(sender)
                    .setDescription(String
                            .format("Removed the playlist '%s'", name)).setColor(Color.green)
                    .build()).queue();
        } else {
            MessageUtils.sendErrorMessage(String.format("The playlist '%s' does not exist!", name), channel, sender);
        }
    });
}
 
Example #14
Source File: MusicAnnounceCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 1 && ARGS_PATTERN.matcher(args[0]).matches()) {
        if (args[0].equalsIgnoreCase("here")) {
            guild.setMusicAnnounceChannelId(channel.getId());
            channel.sendMessage(MessageUtils.getEmbed(sender)
                    .setDescription("Set music announcements to appear in " + channel
                            .getAsMention()).build()).queue();
        } else {
            guild.setMusicAnnounceChannelId(null);
            channel.sendMessage(MessageUtils.getEmbed(sender)
                    .setDescription(String
                            .format("Disabled announcements for `%s`", channel.getGuild()
                                    .getName()))
                    .build()).queue();
        }
    } else {
        MessageUtils.sendUsage(this, channel, sender, args);
    }
}
 
Example #15
Source File: LeaveCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (channel.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) {
        if ((!member.getVoiceState().inVoiceChannel() || !channel.getGuild().getSelfMember().getVoiceState()
                .getAudioChannel().getId()
                .equals(member.getVoiceState().getAudioChannel()
                        .getId())) && !getPermissions(channel)
                .hasPermission(member, Permission.LEAVE_OTHER)) {
            MessageUtils.sendErrorMessage("You need the permission `" + Permission.LEAVE_OTHER + "` for me to leave a different voice channel!",
                    channel, sender);
            return;
        }
        channel.getGuild().getAudioManager().closeAudioConnection();
        if (FlareBotManager.instance().getLastActive().containsKey(guild.getGuildIdLong()))
            FlareBotManager.instance().getLastActive().remove(guild.getGuildIdLong());
        MessageUtils.sendInfoMessage("Bye bye! I've left the channel for now", channel, sender);
    }
}
 
Example #16
Source File: MuteCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 0) {
        MessageUtils.sendUsage(this, channel, sender, args);
    } else {
        User user = GuildUtils.getUser(args[0], guild.getGuildId());
        if (user == null) {
            MessageUtils.sendErrorMessage("Invalid user!!", channel);
            return;
        }
        if (guild.getMutedRole() == null) {
            MessageUtils.sendErrorMessage("Error getting the \"Muted\" role! Check FlareBot has permissions to create it!", channel);
            return;
        }
        String reason = args.length > 1 ? MessageUtils.getMessage(args, 1) : null;
        ModlogHandler.getInstance().handleAction(guild, channel, sender, user, ModAction.MUTE, reason);
    }
}
 
Example #17
Source File: ShardInfoCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@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);
}
 
Example #18
Source File: BetaCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    String betaInfo =
            FormatUtils.formatCommandPrefix(guild, FlareBot.getCommandManager().getCommands()
                    .stream()
                    .filter(Command::isBetaTesterCommand)
                    .map(c -> "`{%}" + c.getCommand() + "` - " + c.getDescription())
                    .collect(Collectors.joining("\n")));
    String betaMessage = guild.hasBetaAccess() ?
            "Thank you for being apart of our beta program! Please report any bugs or give us suggestions over at the [support discord](" + Constants.INVITE_URL + ")!"
            : "Listed below are the commands you can gain access to by being a part of our beta program! To join the beta program, you will either need to win " +
            "beta access through a giveaway (Make sure you are in the [support server](" + Constants.INVITE_URL + ") to hear of these!) or you can become apart of the " +
            "Donator tier or higher on our [patreon page](https://www.patreon.com/flarebot)!";
    EmbedBuilder builder = MessageUtils.getEmbed(sender);
    builder.setColor(Color.CYAN);
    builder.setDescription(betaMessage);
    builder.addField("Beta Commands", betaInfo, false);
    channel.sendMessage(builder.build()).queue();
}
 
Example #19
Source File: SetPrefixCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 1) {
        if (args[0].equalsIgnoreCase("reset")) {
            guild.setPrefix('_');
            MessageUtils.sendInfoMessage("Reset the prefix back to `_`!", channel, sender);
        } else if (args[0].length() == 1) {
            guild.setPrefix(args[0].charAt(0));
            channel.sendMessage(MessageUtils.getEmbed(sender)
                    .setDescription(String.format("Set the prefix to `%s`", args[0])).build())
                    .queue();
        } else {
            MessageUtils.sendErrorMessage("Cannot set the prefix to be more that one character long!", channel, sender);
        }
    } else {
        channel.sendMessage(MessageUtils.getEmbed(sender)
                .setDescription(String.format("Current guild prefix is `%s`!", guild.getPrefix())).build()).queue();
    }
}
 
Example #20
Source File: SoftBanCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length >= 1) {
        User target = GuildUtils.getUser(args[0], guild.getGuildId());
        if (target == null) {
            MessageUtils.sendErrorMessage("We cannot find that user! Try their ID if you didn't already.", channel, sender);
            return;
        }
        String reason = null;
        if (args.length >= 2)
            reason = MessageUtils.getMessage(args, 1);

        ModlogHandler.getInstance().handleAction(guild, channel, sender, target, ModAction.SOFTBAN, reason);
    } else {
        MessageUtils.sendUsage(this, channel, sender, args);
    }
}
 
Example #21
Source File: AvatarCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    User user = sender;
    if (args.length > 0)
        user = GuildUtils.getUser(MessageUtils.getMessage(args, 0), guild.getGuildId());
    if (user != null) {
        if (!user.getId().equals(sender.getId()) && !getPermissions(channel).hasPermission(member, Permission.AVATAR_OTHER)) {
            MessageUtils.sendErrorMessage("You need the permission `" + Permission.AVATAR_OTHER + "` in order to do that command!",
                    channel);
            return;
        }
        channel.sendMessage(MessageUtils.getEmbed(sender).setColor(Color.cyan).setAuthor(user.getName(), null, null)
                .setImage(user.getEffectiveAvatarUrl()).build()).queue();
    } else
        MessageUtils.sendErrorMessage("Cannot find that user!", channel);
}
 
Example #22
Source File: ShuffleCommand.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(TextChannel textChannel, Member member, Message message, List<String> arguments) {
	EmbedBuilder embedBuilder = new EmbedBuilder();
	embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl());
	embedBuilder.setColor(DiscordUtil.DEFAULT);
	
	if (DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue() == null || DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue().size() < 2) {
		embedBuilder.setColor(DiscordUtil.ERROR);
		embedBuilder.setTitle("The current queue is not big enough to shuffle!", null);
		DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
		return;
	}
	
	Collections.shuffle(DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue(), new Random(System.nanoTime()));
	embedBuilder.setColor(DiscordUtil.SUCCESS);
	embedBuilder.setTitle("Current queue shuffled.", null);
	DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
}
 
Example #23
Source File: Command.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
public void execute(TextChannel textChannel, Member member, Message message) {
	List<String> arguments;
	if (message.getContent().startsWith(DiscordBot.getInstance().getConfig().getCommandPrefix())) {
		arguments = getValidArguments(DiscordUtil.filter(message.getContent().substring(DiscordBot.getInstance().getConfig().getCommandPrefix().length())).split(" "));
	} else {
		arguments = getValidArguments(DiscordUtil.filter(message.getContent().substring(1)).split(" "));
	}
	
	if (arguments == null || arguments.size() < 1) {
		return;
	}
	
	for (Iterator<ICommand> iterator = getRegisteredCommands().iterator(); iterator.hasNext();) {
		ICommand command = iterator.next();
		if (checkCommandName(arguments.get(0), command.getName()) || checkCommandAliases(arguments.get(0), command.getAliases())) {
			LogHelper.debug("Processing Command '" + message.getContent() + "' For '" + member.getEffectiveName() + "'.");
			arguments.remove(0);
			command.execute(textChannel, member, message, arguments);
			DiscordBot.getInstance().getDiscord().getMessageSender().addMessage(message);
			return;
		}
	}
}
 
Example #24
Source File: ChangelogCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message msg, String[] args, Member member) {
    if (PerGuildPermissions.isAdmin(sender)) {
        if (args.length == 0) {
            channel.sendMessage("Specify a version or PR to post about!").queue();
            return;
        }
        if (args[0].startsWith("pr:")) {
            channel.sendMessage(new MessageBuilder().setEmbed(GitHubUtils.getEmbedForPR(args[0].substring(3))
                    .build()).build()).queue();
        } else {
            String message = msg.getContentRaw();
            message = message.substring(message.indexOf(" ") + 1);
            channel.sendMessage(message).queue();
        }
    }
}
 
Example #25
Source File: TempMuteCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length < 2) {
        MessageUtils.sendUsage(this, channel, sender, args);
    } else {
        User user = GuildUtils.getUser(args[0], guild.getGuildId());
        if (user == null) {
            MessageUtils.sendErrorMessage("Invalid user!!", channel);
            return;
        }
        if (guild.getMutedRole() == null) {
            MessageUtils.sendErrorMessage("Error getting the \"Muted\" role! Check FlareBot has permissions to create it!", channel);
            return;
        }

        Period period;
        if ((period = GeneralUtils.getTimeFromInput(args[1], channel)) == null) return;
        String reason = args.length >= 3 ? MessageUtils.getMessage(args, 2) : null;

        ModlogHandler.getInstance().handleAction(guild, channel, sender, user, ModAction.TEMP_MUTE, reason,
                period.toStandardDuration().getMillis());
    }
}
 
Example #26
Source File: HelpCommand.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(TextChannel textChannel, Member member, Message message, List<String> arguments) {
	EmbedBuilder embedBuilder = new EmbedBuilder();
	embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl());
	embedBuilder.setColor(DiscordUtil.DEFAULT);
	embedBuilder.setTitle("Commands", null);
	
	for (Iterator<ICommand> iterator = DiscordBot.getInstance().getDiscord().getCommand().getRegisteredCommands().iterator(); iterator.hasNext();) {
		ICommand command = iterator.next();
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append("Description - " + command.getDescription() + "\n");
		stringBuilder.append("Usage - " + command.getUsage() + "\n");
		
		if (command.getAliases() != null && !command.getAliases().isEmpty()) {
			stringBuilder.append("Aliases - " + String.join(", ", command.getAliases()));
		}
		embedBuilder.addField(command.getName(), stringBuilder.toString(), false);
	}
	
	embedBuilder.setFooter("<> = Required Argument, [] = Optional Argument", null);
	DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
}
 
Example #27
Source File: UnmuteCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length >= 1) {
        User target = GuildUtils.getUser(args[0]);
        if (target == null) {
            MessageUtils.sendErrorMessage("We cannot find that user! Try their ID if you didn't already.", channel, sender);
            return;
        }
        String reason = null;
        if (args.length >= 2)
            reason = MessageUtils.getMessage(args, 1);

        ModlogHandler.getInstance().handleAction(guild, channel, sender, target, ModAction.UNMUTE, reason);
    } else {
        MessageUtils.sendUsage(this, channel, sender, args);
    }
}
 
Example #28
Source File: KickCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length >= 1) {
        User user = GuildUtils.getUser(args[0], guild.getGuildId());
        if (user == null) {
            MessageUtils.sendErrorMessage("We cannot find that user! Try their ID if you didn't already.", channel, sender);
            return;
        }
        Member target = guild.getGuild().getMember(user);
        if (target == null) {
            MessageUtils.sendErrorMessage("That user is not on this server therefore cannot be kicked!",
                    channel, sender);
            return;
        }
        String reason = null;
        if (args.length >= 2)
            reason = MessageUtils.getMessage(args, 1);
        ModlogHandler.getInstance().handleAction(guild, channel, sender, user, ModAction.KICK, reason);
    } else {
        MessageUtils.sendUsage(this, channel, sender, args);
    }
}
 
Example #29
Source File: UpdateJDACommand.java    From FlareBot with MIT License 5 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 1) {
        String version = args[0];

        try {
            File f = new File("pom.xml");
            Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(f);

            Node jdaNode = doc.getElementsByTagName("dependency").item(0);
            NodeList children = jdaNode.getChildNodes();
            for (int i = 0; i < children.getLength(); i++) {
                Node node = children.item(i);
                if (node.getNodeName().equalsIgnoreCase("version"))
                    node.setTextContent(version);
            }

            DOMSource source = new DOMSource(doc);
            TransformerFactory.newInstance().newTransformer().transform(source, new StreamResult(f));
            channel.sendMessage("Updated to JDA version `" + version + "`\n" +
                    "I will now restart in 10 minutes and apply the update!").queue();
            new FlareBotTask("JDA-Update") {
                @Override
                public void run() {
                    FlareBot.instance().quit(true);
                }
            }.delay(TimeUnit.MINUTES.toMillis(10));
            // _update-jda 3.3.1_306
        } catch (SAXException | IOException | ParserConfigurationException | TransformerException e) {
            FlareBot.LOGGER.error("Failed to parse the pom file!", e);
            channel.sendMessage("Parsing failed! " + e.getMessage()).queue();
        }
    }
}
 
Example #30
Source File: Rand6.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
private void reroll(Member member, MessageReceivedEvent event) throws IOException {

        BufferedReader fr;
        Date date = new Date();

        HashMap<Member, String> rollMap = new HashMap<>();

        if (saveFile.exists()) {
            fr = new BufferedReader(new FileReader(saveFile));
            fr.lines().forEach(s -> rollMap.put(event.getGuild().getMemberById(s.split(":")[0]), s.split(":")[1]));
            fr.close();
        }

        if ((date.getTime()) < Long.parseLong((rollMap.get(member) == null) ? (date.getTime()-1) + "" : rollMap.get(member))) {
            event.getTextChannel().sendMessage(new EmbedBuilder().setColor(Color.red).setDescription("Your reroll is still consumed.\nReset in `" + timeToReset(rollMap.get(member)) + "`.").build()).queue();
            return;
        } else {
            rollMap.put(member, (date.getTime() + 12*60*60*1000) + "");
            event.getTextChannel().sendMessage(new EmbedBuilder().setColor(Color.orange).setDescription(member.getAsMention() + " USED A REROLL. (Reset in `" + timeToReset(rollMap.get(member)) + "`)\n\nYour new operator, " + member.getAsMention() + ", is `" + getRandOp() + "`").build()).queue();
        }

        FileWriter fw = new FileWriter(saveFile);

        rollMap.keySet().stream().forEach(m -> {
            try {
                fw.write(m.getUser().getId() + ":" + rollMap.get(m) + "\n");
            } catch (IOException e) {
                e.printStackTrace();
                event.getTextChannel().sendMessage(MSGS.error().setDescription("AN ERROR OCCURED WHILE WRITING SAVE FILE...").build()).queue();
            }
        });

        fw.close();

    }