use of net.kodehawa.mantarobot.data.entities.DBGuild in project MantaroBot by Mantaro.
the class ModerationCmds method onPostLoad.
@Command
public static void onPostLoad(PostLoadEvent e) {
OptsCmd.registerOption("modlog:blacklist", event -> {
List<User> mentioned = event.getMessage().getMentionedUsers();
if (mentioned.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "**You need to specify the users to locally blacklist from mod logs.**").queue();
return;
}
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
List<String> toBlackList = mentioned.stream().map(ISnowflake::getId).collect(Collectors.toList());
String blacklisted = mentioned.stream().map(user -> user.getName() + "#" + user.getDiscriminator()).collect(Collectors.joining(","));
guildData.getModlogBlacklistedPeople().addAll(toBlackList);
dbGuild.save();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Locally blacklisted users from mod-log: **" + blacklisted + "**").queue();
});
OptsCmd.registerOption("modlog:whitelist", event -> {
List<User> mentioned = event.getMessage().getMentionedUsers();
if (mentioned.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "**You need to specify the users to locally un-blacklist from mod logs.**").queue();
return;
}
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
List<String> toUnBlacklist = mentioned.stream().map(ISnowflake::getId).collect(Collectors.toList());
String unBlacklisted = mentioned.stream().map(user -> user.getName() + "#" + user.getDiscriminator()).collect(Collectors.joining(","));
guildData.getModlogBlacklistedPeople().removeAll(toUnBlacklist);
dbGuild.save();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Locally un-blacklisted users from mod-log: **" + unBlacklisted + "**").queue();
});
OptsCmd.registerOption("linkprotection:toggle", event -> {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
boolean toggler = guildData.isLinkProtection();
guildData.setLinkProtection(!toggler);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Set link protection to " + "`" + !toggler + "`").queue();
dbGuild.save();
});
OptsCmd.registerOption("slowmode:toggle", event -> {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
boolean toggler = guildData.isSlowMode();
guildData.setSlowMode(!toggler);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Set slowmode chat to " + "`" + !toggler + "`").queue();
dbGuild.save();
});
OptsCmd.registerOption("antispam:toggle", event -> {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
boolean toggler = guildData.isAntiSpam();
guildData.setAntiSpam(!toggler);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Set anti-spam chat mode to " + "`" + !toggler + "`").queue();
dbGuild.save();
});
OptsCmd.registerOption("linkprotection:channel:allow", (event, args) -> {
if (args.length == 0) {
OptsCmd.onHelp(event);
return;
}
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
String channelName = args[0];
List<TextChannel> textChannels = event.getGuild().getTextChannels().stream().filter(textChannel -> textChannel.getName().contains(channelName)).collect(Collectors.toList());
if (textChannels.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "There were no channels matching your search.").queue();
}
if (textChannels.size() <= 1) {
guildData.getLinkProtectionAllowedChannels().add(textChannels.get(0).getId());
dbGuild.save();
event.getChannel().sendMessage(EmoteReference.CORRECT + textChannels.get(0).getAsMention() + " can now be used to post discord invites.").queue();
return;
}
DiscordUtils.selectList(event, textChannels, textChannel -> String.format("%s (ID: %s)", textChannel.getName(), textChannel.getId()), s -> OptsCmd.getOpts().baseEmbed(event, "Select the Channel:").setDescription(s).build(), textChannel -> {
guildData.getLinkProtectionAllowedChannels().add(textChannel.getId());
dbGuild.save();
event.getChannel().sendMessage(EmoteReference.OK + textChannel.getAsMention() + " can now be used to send discord invites.").queue();
});
});
OptsCmd.registerOption("linkprotection:channel:disallow", (event, args) -> {
if (args.length == 0) {
OptsCmd.onHelp(event);
return;
}
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
String channelName = args[0];
List<TextChannel> textChannels = event.getGuild().getTextChannels().stream().filter(textChannel -> textChannel.getName().contains(channelName)).collect(Collectors.toList());
if (textChannels.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "There were no channels matching your search.").queue();
}
if (textChannels.size() <= 1) {
guildData.getLinkProtectionAllowedChannels().remove(textChannels.get(0).getId());
dbGuild.save();
event.getChannel().sendMessage(EmoteReference.CORRECT + textChannels.get(0).getAsMention() + " cannot longer be used to post discord invites.").queue();
return;
}
DiscordUtils.selectList(event, textChannels, textChannel -> String.format("%s (ID: %s)", textChannel.getName(), textChannel.getId()), s -> OptsCmd.getOpts().baseEmbed(event, "Select the Channel:").setDescription(s).build(), textChannel -> {
guildData.getLinkProtectionAllowedChannels().remove(textChannel.getId());
dbGuild.save();
event.getChannel().sendMessage(EmoteReference.OK + textChannel.getAsMention() + " cannot longer be used to send discord invites.").queue();
});
});
}
use of net.kodehawa.mantarobot.data.entities.DBGuild in project MantaroBot by Mantaro.
the class ModerationCmds method tempban.
@Command
public static void tempban(CommandRegistry cr) {
cr.register("tempban", new SimpleCommand(Category.MODERATION) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
String reason = content;
Guild guild = event.getGuild();
User author = event.getAuthor();
TextChannel channel = event.getChannel();
Message receivedMessage = event.getMessage();
if (!guild.getMember(author).hasPermission(net.dv8tion.jda.core.Permission.BAN_MEMBERS)) {
channel.sendMessage(EmoteReference.ERROR + "Cannot ban: You have no Ban Members permission.").queue();
return;
}
if (event.getMessage().getMentionedUsers().isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to mention an user!").queue();
return;
}
for (User user : event.getMessage().getMentionedUsers()) {
reason = reason.replaceAll("(\\s+)?<@!?" + user.getId() + ">(\\s+)?", "");
}
int index = reason.indexOf("time:");
if (index < 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot temp ban an user without giving me the time!").queue();
return;
}
String time = reason.substring(index);
reason = reason.replace(time, "").trim();
time = time.replaceAll("time:(\\s+)?", "");
if (reason.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot temp ban someone without a reason.!").queue();
return;
}
if (time.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot temp ban someone without giving me the time!").queue();
return;
}
final DBGuild db = MantaroData.db().getGuild(event.getGuild());
long l = AudioCmdUtils.parseTime(time);
String finalReason = reason;
String sTime = StringUtils.parseTime(l);
receivedMessage.getMentionedUsers().forEach(user -> guild.getController().ban(user, 7).queue(success -> {
user.openPrivateChannel().complete().sendMessage(EmoteReference.MEGA + "You were **temporarly banned** by " + event.getAuthor().getName() + "#" + event.getAuthor().getDiscriminator() + " with reason: " + finalReason + ".").queue();
db.getData().setCases(db.getData().getCases() + 1);
db.saveAsync();
channel.sendMessage(EmoteReference.ZAP + "You will be missed... or not " + user.getName()).queue();
ModLog.log(event.getMember(), user, finalReason, ModLog.ModAction.TEMP_BAN, db.getData().getCases(), sTime);
MantaroBot.getTempBanManager().addTempban(guild.getId() + ":" + user.getId(), l + System.currentTimeMillis());
TextChannelGround.of(event).dropItemWithChance(1, 2);
}, error -> {
if (error instanceof PermissionException) {
channel.sendMessage(EmoteReference.ERROR + "Error banning " + user.getName() + ": " + "(I need the permission " + ((PermissionException) error).getPermission() + ")").queue();
} else {
channel.sendMessage(EmoteReference.ERROR + "I encountered an unknown error while banning " + user.getName() + ": " + "<" + error.getClass().getSimpleName() + ">: " + error.getMessage()).queue();
log.warn("Encountered an unexpected error while trying to ban someone.", error);
}
}));
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Tempban Command").setDescription("**Temporarily bans an user**").addField("Usage", "`~>tempban <user> <reason> time:<time>`", false).addField("Example", "`~>tempban @Kodehawa example time:1d`", 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 give a day and an hour.**", false).build();
}
});
}
use of net.kodehawa.mantarobot.data.entities.DBGuild in project MantaroBot by Mantaro.
the class UtilsCmds method dateGMT.
static String dateGMT(Guild guild, String tz) {
DateFormat format = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
DBGuild dbGuild = MantaroData.db().getGuild(guild.getId());
GuildData guildData = dbGuild.getData();
if (guildData.getTimeDisplay() == 1) {
format = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss a");
}
System.out.println(TimeZone.getTimeZone(tz));
return format.format(new Date());
}
use of net.kodehawa.mantarobot.data.entities.DBGuild in project MantaroBot by Mantaro.
the class UtilsCmds method onPostLoad.
@Command
public static void onPostLoad(PostLoadEvent e) {
OptsCmd.registerOption("birthday:enable", (event, args) -> {
if (args.length < 2) {
OptsCmd.onHelp(event);
return;
}
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
try {
String channel = args[0];
String role = args[1];
boolean isId = channel.matches("^[0-9]*$");
String channelId = isId ? channel : event.getGuild().getTextChannelsByName(channel, true).get(0).getId();
String roleId = event.getGuild().getRolesByName(role.replace(channelId, ""), true).get(0).getId();
guildData.setBirthdayChannel(channelId);
guildData.setBirthdayRole(roleId);
dbGuild.save();
event.getChannel().sendMessage(String.format(EmoteReference.MEGA + "Birthday logging enabled on this server with parameters -> " + "Channel: ``#%s (%s)`` and role: ``%s (%s)``", channel, channelId, role, roleId)).queue();
} catch (Exception ex) {
if (ex instanceof IndexOutOfBoundsException) {
event.getChannel().sendMessage(EmoteReference.ERROR + "I didn't find a channel or role!\n " + "**Remember, you don't have to mention neither the role or the channel, rather just type its " + "name, order is <channel> <role>, without the leading \"<>\".**").queue();
return;
}
event.getChannel().sendMessage(EmoteReference.ERROR + "You supplied invalid arguments for this command " + EmoteReference.SAD).queue();
OptsCmd.onHelp(event);
}
});
OptsCmd.registerOption("birthday:disable", (event) -> {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
guildData.setBirthdayChannel(null);
guildData.setBirthdayRole(null);
dbGuild.save();
event.getChannel().sendMessage(EmoteReference.MEGA + "Birthday logging has been disabled on this server").queue();
});
}
use of net.kodehawa.mantarobot.data.entities.DBGuild in project MantaroBot by Mantaro.
the class ImageActionCmd method call.
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
String random = random(images);
try {
if (mentions(event).isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to mention a user").queue();
return;
}
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
MessageBuilder toSend = new MessageBuilder().append(String.format(format, mentions(event), event.getAuthor().getAsMention()));
if (!guildData.isNoMentionsAction() && swapNames) {
toSend = new MessageBuilder().append(String.format(format, event.getAuthor().getAsMention(), mentions(event)));
}
if (guildData.isNoMentionsAction() && swapNames) {
toSend = new MessageBuilder().append(String.format(format, "**" + noMentions(event) + "**", "**" + event.getMember().getEffectiveName() + "**"));
}
if (swapNames && guildData.isNoMentionsAction()) {
toSend = new MessageBuilder().append(String.format(format, "**" + event.getMember().getEffectiveName() + "**", "**" + noMentions(event) + "**"));
}
if (isLonely(event)) {
toSend = new MessageBuilder().append("**").append(lonelyLine).append("**");
}
event.getChannel().sendFile(CACHE.getInput(random), imageName, toSend.build()).queue();
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "I'd like to know what happened, but I couldn't send the image.").queue();
log.error("Error while performing Action Command ``" + name + "``. The image ``" + random + "`` threw an Exception.", e);
}
}
Aggregations