use of net.dv8tion.jda.core.entities.TextChannel in project FlareBot by FlareBot.
the class ModlogCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
if (args.length >= 1) {
if (args[0].equalsIgnoreCase("list")) {
int page = 1;
if (args.length == 2) {
page = GeneralUtils.getInt(args[1], 1);
}
Set<ModlogAction> actions = guild.getModeration().getEnabledActions();
List<ModlogAction> events = new ArrayList<>(actions);
if (events.isEmpty()) {
MessageUtils.sendErrorMessage("No Events are enabled", channel);
return;
}
PagedTableBuilder tb = new PagedTableBuilder();
tb.addColumn("Event");
tb.addColumn("Compact");
tb.addColumn("Channel");
tb.setRowCount(10);
for (ModlogAction modlogAction : events) {
if (guild.getModeration().isEventEnabled(guild, modlogAction.getEvent())) {
List<String> part = new ArrayList<>();
part.add(modlogAction.getEvent().getName());
part.add(String.valueOf(modlogAction.isCompacted()));
part.add(modlogAction.getModlogChannel(guild.getGuild()).getName());
tb.addRow(part);
}
}
PaginationUtil.sendPagedMessage(channel, tb.build(), page - 1, sender, ButtonGroupConstants.MODLOG_LIST);
return;
}
if (args[0].equalsIgnoreCase("features")) {
int page = 1;
if (args.length == 2) {
page = GeneralUtils.getInt(args[1], 1);
}
listEvents(channel, page, sender);
return;
}
}
if (args.length >= 2) {
String eventArgument = MessageUtils.getMessage(args, 1, args[0].equalsIgnoreCase("enable") ? Math.max(2, args.length - 1) : args.length);
ModlogEvent event = ModlogEvent.getEvent(eventArgument);
boolean all = false;
boolean defaultEvents = false;
if (event == null) {
if (eventArgument.equalsIgnoreCase("all"))
all = true;
else if (eventArgument.equalsIgnoreCase("default"))
defaultEvents = true;
else {
MessageUtils.sendErrorMessage("Invalid Event: `" + eventArgument + "`\n" + "For a list of all events do `{%}modlog features`, " + "for a list of all enabled events do `{%}modlog list`.", channel);
return;
}
}
Moderation moderation = guild.getModeration();
if (args[0].equalsIgnoreCase("enable")) {
TextChannel tc = GuildUtils.getChannel(args[args.length - 1], guild);
if (tc == null) {
MessageUtils.sendErrorMessage("I cannot find the channel `" + args[args.length - 1] + "` try to mention the channel " + "or use the channel ID", channel);
return;
}
long channelId = tc.getIdLong();
if (!guild.getGuild().getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) {
MessageUtils.sendErrorMessage("I don't have permission to view audit logs so you can't use Modlog events!", channel);
return;
}
if (all) {
moderation.enableAllEvents(guild, channelId);
MessageUtils.sendSuccessMessage("Successfully enabled **all** events in " + tc.getAsMention(), channel, sender);
return;
} else if (defaultEvents) {
moderation.enableDefaultEvents(guild, channelId);
MessageUtils.sendSuccessMessage("Successfully enabled **default** events in " + tc.getAsMention(), channel, sender);
return;
} else {
if (moderation.enableEvent(guild, channelId, event)) {
MessageUtils.sendSuccessMessage("Successfully enabled event `" + WordUtils.capitalize(event.getTitle().toLowerCase().replaceAll("_", " ")) + "`\nThis event will be displayed in the " + tc.getAsMention() + " channel.", channel, sender);
return;
} else {
MessageUtils.sendErrorMessage("Error enabling event, I couldn't find that channel!", channel, sender);
return;
}
}
}
if (args[0].equalsIgnoreCase("disable")) {
if (all) {
moderation.disableAllEvents();
MessageUtils.sendSuccessMessage("Successfully disabled **all** events", channel, sender);
return;
} else if (defaultEvents) {
moderation.disableDefaultEvents();
MessageUtils.sendSuccessMessage("Successfully disabled all **default** events", channel, sender);
return;
} else {
if (moderation.isEventEnabled(guild, event)) {
moderation.disableEvent(event);
MessageUtils.sendSuccessMessage("Successfully disabled event `" + WordUtils.capitalize(event.getTitle()) + "`", channel, sender);
return;
} else {
MessageUtils.sendErrorMessage("Error disabling event (Probably already disabled)", channel, sender);
return;
}
}
}
if (args[0].equalsIgnoreCase("compact")) {
if (all) {
int compact = 0;
int uncompact = 0;
for (ModlogEvent modlogEvent : ModlogEvent.values) {
if (moderation.isEventEnabled(guild, modlogEvent)) {
if (moderation.isEventCompacted(modlogEvent)) {
compact++;
} else {
uncompact++;
}
}
}
for (ModlogEvent modlogEvents : ModlogEvent.values) {
moderation.setEventCompact(modlogEvents, uncompact >= compact);
}
MessageUtils.sendSuccessMessage((uncompact >= compact ? "Compacted" : "Un-compacted") + " all the modlog events", channel, sender);
return;
} else if (defaultEvents) {
int compact = 0;
int uncompact = 0;
for (ModlogEvent modlogEvent : ModlogEvent.values) {
if (modlogEvent.isDefaultEvent() && moderation.isEventEnabled(guild, modlogEvent)) {
if (moderation.isEventCompacted(modlogEvent))
compact++;
else
uncompact++;
}
}
for (ModlogEvent modlogEvent : ModlogEvent.values) {
if (modlogEvent.isDefaultEvent())
moderation.setEventCompact(modlogEvent, compact >= uncompact);
}
MessageUtils.sendSuccessMessage((compact >= uncompact ? "Un-compacted" : "Compacted") + " all the default modlog events", channel, sender);
} else {
if (moderation.isEventEnabled(guild, event)) {
boolean compact = moderation.setEventCompact(event, !moderation.isEventCompacted(event));
if (compact) {
MessageUtils.sendSuccessMessage("Compacted event `" + WordUtils.capitalize(event.getTitle()) + "`", channel, sender);
return;
} else {
MessageUtils.sendSuccessMessage("Un-compacted event `" + WordUtils.capitalize(event.getTitle()) + "`", channel, sender);
return;
}
} else {
MessageUtils.sendErrorMessage("You can't compact an event that isn't enabled!", channel);
return;
}
}
}
}
MessageUtils.sendUsage(this, channel, member.getUser(), args);
}
use of net.dv8tion.jda.core.entities.TextChannel in project FlareBot by FlareBot.
the class Events method onGuildMemberJoin.
@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
if (event.getMember().getUser().isBot() || event.getMember().getUser().isFake())
return;
PlayerCache cache = flareBot.getPlayerCache(event.getMember().getUser().getId());
cache.setLastSeen(LocalDateTime.now());
GuildWrapper wrapper = FlareBotManager.instance().getGuild(event.getGuild().getId());
if (wrapper == null)
return;
if (wrapper.isBlocked())
return;
if (flareBot.getManager().getGuild(event.getGuild().getId()).getWelcome() != null) {
Welcome welcome = wrapper.getWelcome();
if ((welcome.getChannelId() != null && Getters.getChannelById(welcome.getChannelId()) != null) || welcome.isDmEnabled()) {
if (welcome.getChannelId() != null && Getters.getChannelById(welcome.getChannelId()) != null && welcome.isGuildEnabled()) {
TextChannel channel = Getters.getChannelById(welcome.getChannelId());
if (channel == null || !channel.canTalk()) {
welcome.setGuildEnabled(false);
MessageUtils.sendPM(event.getGuild().getOwner().getUser(), "Cannot send welcome messages in " + (channel == null ? welcome.getChannelId() : channel.getAsMention()) + " due to this, welcomes have been disabled!");
return;
}
if (welcome.isGuildEnabled()) {
String guildMsg = VariableUtils.parseVariables(welcome.getRandomGuildMessage(), wrapper, null, event.getUser());
// Deprecated values
guildMsg = guildMsg.replace("%user%", event.getMember().getUser().getName()).replace("%guild%", event.getGuild().getName()).replace("%mention%", event.getMember().getUser().getAsMention());
channel.sendMessage(guildMsg).queue();
if (guildMsg.contains("%user%") || guildMsg.contains("%guild%") || guildMsg.contains("%mention%")) {
MessageUtils.sendPM(event.getGuild().getOwner().getUser(), "Your guild welcome message contains deprecated variables! " + "Please check the docs at the link below for a list of all the " + "variables you can use!\n" + "https://docs.flarebot.stream/variables");
}
}
}
if (welcome.isDmEnabled()) {
// We can't DM other bots.
if (event.getMember().getUser().isBot())
return;
String dmMsg = VariableUtils.parseVariables(welcome.getRandomDmMessage(), wrapper, null, event.getUser());
// Deprecated values
dmMsg = dmMsg.replace("%user%", event.getMember().getUser().getName()).replace("%guild%", event.getGuild().getName()).replace("%mention%", event.getMember().getUser().getAsMention());
MessageUtils.sendPM(event.getMember().getUser(), dmMsg);
if (dmMsg.contains("%user%") || dmMsg.contains("%guild%") || dmMsg.contains("%mention%")) {
MessageUtils.sendPM(event.getGuild().getOwner().getUser(), "Your DM welcome message contains deprecated variables! " + "Please check the docs at the link below for a list of all the " + "variables you can use!\n" + "https://docs.flarebot.stream/variables");
}
}
} else
welcome.setGuildEnabled(false);
}
if (event.getMember().getUser().isBot())
return;
if (!wrapper.getAutoAssignRoles().isEmpty()) {
Set<String> autoAssignRoles = wrapper.getAutoAssignRoles();
List<Role> roles = new ArrayList<>();
for (String s : autoAssignRoles) {
Role role = event.getGuild().getRoleById(s);
if (role != null) {
roles.add(role);
} else
autoAssignRoles.remove(s);
}
try {
event.getGuild().getController().addRolesToMember(event.getMember(), roles).queue((n) -> {
}, e1 -> handle(e1, event, roles));
StringBuilder sb = new StringBuilder("```\n");
for (Role role : roles) {
sb.append(role.getName()).append(" (").append(role.getId()).append(")\n");
}
sb.append("```");
ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.FLAREBOT_AUTOASSIGN_ROLE, event.getUser(), new MessageEmbed.Field("Roles", sb.toString(), false));
} catch (Exception e1) {
handle(e1, event, roles);
}
}
}
use of net.dv8tion.jda.core.entities.TextChannel in project TheLighterBot by PhotonBursted.
the class FileController method retrievePermChannels.
private void retrievePermChannels() throws SQLException {
retrieveData("SELECT *\n" + "FROM \"PermChannels\"", result -> {
try {
TextChannel tc = l.getBot().getTextChannelById(result.getLong("tc_id"));
VoiceChannel vc = l.getBot().getVoiceChannelById(result.getLong("vc_id"));
if (tc != null && vc != null) {
l.getChannelController().getPermChannels().putStoring(tc, vc);
}
} catch (SQLException ex) {
log.error("Something went wrong retrieving the permanent channels", ex);
}
});
}
use of net.dv8tion.jda.core.entities.TextChannel in project TheLighterBot by PhotonBursted.
the class UnlinkChannelCommand method execute.
@Override
protected void execute() {
if (!ev.getMember().getVoiceState().inVoiceChannel()) {
handleError(MessageContent.NOT_IN_VOICE_CHANNEL);
}
VoiceChannel vc = ev.getMember().getVoiceState().getChannel();
if (!l.getChannelController().isLinked(vc)) {
handleError(MessageContent.CHANNEL_NOT_LINKED);
}
TextChannel tc = l.getChannelController().getLinkedChannels().getForVoiceChannel(vc);
l.getChannelController().getLinkedChannels().removeByValueStoring(vc);
if (l.getChannelController().isPermanent(vc)) {
l.getChannelController().getPermChannels().removeByValueStoring(vc);
}
LoggerUtils.logAndDelete(log, String.format("A link has been removed:\n" + " - VC: %s (%s)\n" + " - TC: %s (%s)", vc.getName(), vc.getId(), tc.getName(), tc.getId()));
l.getDiscordController().sendMessage(ev, String.format("Successfully unlinked **%s** from **%s**!", vc.getName(), tc.getAsMention()), DiscordController.AUTOMATIC_REMOVAL_INTERVAL);
}
use of net.dv8tion.jda.core.entities.TextChannel in project Ardent by adamint.
the class GuildUtils method getChannelNames.
public static ArrayList<String> getChannelNames(ArrayList<String> ids, Guild guild) {
ArrayList<String> names = new ArrayList<>();
ids.forEach(id -> {
TextChannel channel = guild.getTextChannelById(id);
if (channel != null)
names.add(channel.getName());
});
return names;
}
Aggregations