use of st.photonbur.Discord.Bot.lightbotv3.entity.bannable.BannableRole in project TheLighterBot by PhotonBursted.
the class FileController method retrieveWhitelist.
private void retrieveWhitelist() throws SQLException {
retrieveData("SELECT wl.*\n" + "FROM \"Servers\" AS s\n" + " LEFT JOIN \"Whitelists\" AS wl ON wl.server_id = s.discord_id\n" + "WHERE wl.server_id IS NOT NULL", result -> {
try {
Guild g = l.getBot().getGuildById(result.getLong("server_id"));
long entityId = result.getLong("entity_id");
String entityType = result.getString("entity_type");
switch(entityType) {
case "role":
BannableRole role = new BannableRole(entityId);
if (role.get() != null)
l.getAccesslistController().whitelist(g, new BannableRole(entityId));
break;
case "user":
BannableUser user = new BannableUser(entityId);
if (user.get() != null)
l.getAccesslistController().whitelist(g, new BannableUser(entityId));
break;
default:
}
} catch (SQLException ex) {
log.error("Something went wrong retrieving the whitelist", ex);
}
});
}
use of st.photonbur.Discord.Bot.lightbotv3.entity.bannable.BannableRole in project TheLighterBot by PhotonBursted.
the class AccesslistModificationCommand method execute.
@Override
protected void execute() {
// Check if the input actually had enough arguments
if (input.size() < 1) {
handleError(String.format("You didn't supply the ID of the entity to %s!\nPlease use `+%s <idTo%s>`.", getActionDescription("%s", "remove from the %s"), primaryCommandName, StringUtils.capitalize(targetAccesslist)));
return;
}
// Get the input after the arguments as one string representation
String target = Utils.drainQueueToString(input);
String[] targetParts = target.split(":", 2);
String targetType = targetParts[0];
String targetName = targetParts.length > 1 ? targetParts[1] : null;
// Identify what the input was targeting
switch(targetType) {
case "user":
{
// Retrieve a list of users which could be targeted by the search
List<Member> candidates = ev.getGuild().getMembersByEffectiveName(targetName, true);
// See if there were any search results
if (candidates.size() <= 0) {
handleError(String.format("No user was found in this server having name **%s**!", targetName));
return;
}
// Otherwise, generate a selector and let the user decide what the target was
if (candidates.size() == 1) {
performAccesslistModification(new BannableUser(candidates.get(0).getUser()));
} else {
LinkedHashMap<String, BannableEntity> candidateMap = new LinkedHashMap<>();
candidates.forEach(c -> candidateMap.put(Utils.userAsString(c.getUser()), new BannableUser(c.getUser())));
new SelectorBuilder<>(this).setOptionMap(candidateMap).build();
}
break;
}
case "role":
{
// Retrieve a list of roles which could be targeted by the search
List<Role> candidates = ev.getGuild().getRolesByName(targetName, true);
// See if there were any search results
if (candidates.size() <= 0) {
handleError(String.format("No role was found in this server having name **%s**!", targetName));
return;
}
// Otherwise, generate a selector and let the user decide what the target was
if (candidates.size() == 1) {
performAccesslistModification(new BannableRole(candidates.get(0)));
} else {
LinkedHashMap<String, BannableEntity> candidateMap = new LinkedHashMap<>();
candidates.forEach(c -> candidateMap.put(c.getName(), new BannableRole(c)));
new SelectorBuilder<>(this).setOptionMap(candidateMap).build();
}
break;
}
default:
BannableEntity targetEntity = null;
// Test if the id was targeting a role or user. If not, throw an error, otherwise whitelist the target
if (ev.getGuild().getRoles().stream().anyMatch(role -> role.getId().equals(target))) {
targetEntity = new BannableRole(target);
}
if (ev.getGuild().getMembers().stream().anyMatch(member -> member.getUser().getId().equals(target))) {
targetEntity = new BannableUser(target);
}
if (targetEntity == null) {
handleError(String.format("The ID you supplied (`%s`) was neither a role or user in this server!", target));
return;
}
// Detect if the id specified is already blacklisted
if (performActionCheck(ev.getGuild(), targetEntity)) {
handleError(String.format("The entity you tried to %s is already %sed for this server!", getActionDescription("%s", "remove from the %s"), targetAccesslist));
return;
}
performAccesslistModification(targetEntity);
break;
}
}
use of st.photonbur.Discord.Bot.lightbotv3.entity.bannable.BannableRole in project TheLighterBot by PhotonBursted.
the class FileController method retrieveBlacklist.
private void retrieveBlacklist() throws SQLException {
retrieveData("SELECT bl.*\n" + "FROM \"Servers\" AS s\n" + " LEFT JOIN \"Blacklists\" AS bl ON bl.server_id = s.discord_id\n" + "WHERE bl.server_id IS NOT NULL", result -> {
try {
Guild g = l.getBot().getGuildById(result.getLong("server_id"));
long entityId = result.getLong("entity_id");
String entityType = result.getString("entity_type");
switch(entityType) {
case "role":
BannableRole role = new BannableRole(entityId);
if (role.get() != null)
l.getAccesslistController().blacklist(g, role);
break;
case "user":
BannableUser user = new BannableUser(entityId);
if (user.get() != null)
l.getAccesslistController().blacklist(g, user);
break;
default:
}
} catch (SQLException ex) {
log.error("Something went wrong retrieving the blacklist", ex);
}
});
}
Aggregations