use of tk.ardentbot.rethink.models.AntiAdvertisingSettings in project Ardent by adamint.
the class AdBlock method setupSubcommands.
@Override
public void setupSubcommands() throws Exception {
subcommands.add(new Subcommand("View the Adblock settings for this server", "settings", "settings") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
AntiAdvertisingSettings settings = asPojo(r.table("anti_advertising_settings").get(guild.getId()).run(connection), AntiAdvertisingSettings.class);
if (settings == null) {
settings = new AntiAdvertisingSettings(guild.getId(), true, false);
r.table("anti_advertising_settings").insert(r.json(gson.toJson(settings))).run(connection);
}
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
String adblockSettings = "Adblock Settings";
builder.setAuthor(adblockSettings, guild.getIconUrl(), guild.getIconUrl());
StringBuilder description = new StringBuilder();
description.append("**" + adblockSettings + "**");
description.append("\nAllow users to post server invites: *" + settings.isAllow_discord_server_links() + "*");
description.append("\nBan users after they advertise twice: *" + settings.isBan_after_two_infractions() + "*");
sendEmbed(builder.setDescription(description), channel, user);
}
});
subcommands.add(new Subcommand("Allow or block users from sending server invites", "serverinvites [true/false]", "serverinvites") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
try {
AntiAdvertisingSettings settings = asPojo(r.table("anti_advertising_settings").get(guild.getId()).run(connection), AntiAdvertisingSettings.class);
boolean allow = Boolean.parseBoolean(args[2]);
if (allow) {
if (settings == null)
r.table("anti_advertising_settings").insert(r.json(gson.toJson(new AntiAdvertisingSettings(guild.getId(), true, false)))).run(connection);
else
r.table("anti_advertising_settings").get(guild.getId()).update(r.hashMap("allow_discord_server_links", true)).run(connection);
sendTranslatedMessage("People can now post Discord server invite links", channel, user);
} else {
if (settings == null)
r.table("anti_advertising_settings").insert(r.json(gson.toJson(new AntiAdvertisingSettings(guild.getId(), false, false)))).run(connection);
else
r.table("anti_advertising_settings").get(guild.getId()).update(r.hashMap("allow_discord_server_links", false)).run(connection);
sendTranslatedMessage("People now **cannot** post Discord server invite links", channel, user);
}
} catch (Exception ex) {
sendTranslatedMessage("You need to specify true or false!", channel, user);
}
}
});
subcommands.add(new Subcommand("Ban users who advertise more than twice", "banafter2ads [true/false]", "banafter2ads") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
try {
AntiAdvertisingSettings settings = asPojo(r.table("anti_advertising_settings").get(guild.getId()).run(connection), AntiAdvertisingSettings.class);
boolean yes = Boolean.parseBoolean(args[2]);
if (yes) {
if (settings == null)
r.table("anti_advertising_settings").insert(r.json(gson.toJson(new AntiAdvertisingSettings(guild.getId(), false, true)))).run(connection);
else
r.table("anti_advertising_settings").get(guild.getId()).update(r.hashMap("ban_after_two_infractions", true)).run(connection);
sendTranslatedMessage("I will now ban users if they advertise more than twice", channel, user);
} else {
if (settings == null)
r.table("anti_advertising_settings").insert(r.json(gson.toJson(new AntiAdvertisingSettings(guild.getId(), true, false)))).run(connection);
else
r.table("anti_advertising_settings").get(guild.getId()).update(r.hashMap("ban_after_two_infractions", false)).run(connection);
sendTranslatedMessage("I won't ban members after 2 advertising infractions", channel, user);
}
} catch (Exception ex) {
sendTranslatedMessage("You need to specify true or false!", channel, user);
}
}
});
}
use of tk.ardentbot.rethink.models.AntiAdvertisingSettings in project Ardent by adamint.
the class OnMessage method onMessage.
@SubscribeEvent
public void onMessage(MessageReceivedEvent event) {
if (!Ardent.started)
return;
if (event.getAuthor().isBot())
return;
try {
switch(event.getChannel().getType()) {
case TEXT:
TriviaChecker.check(event);
Guild guild = event.getGuild();
Shard shard = GuildUtils.getShard(guild);
shard.factory.incrementMessagesReceived();
if (event.getGuild() == null)
// This one will never be executed. But just in case to avoid NPE.
return;
AntiAdvertisingSettings antiAdvertisingSettings = BaseCommand.asPojo(r.table("anti_advertising_settings").get(guild.getId()).run(connection), AntiAdvertisingSettings.class);
if (antiAdvertisingSettings != null && !antiAdvertisingSettings.isAllow_discord_server_links()) {
if (!event.getMember().hasPermission(Permission.MANAGE_SERVER)) {
if (event.getMessage().getRawContent().contains("discordapp.com/invite") || event.getMessage().getRawContent().contains("discord.gg")) {
event.getMessage().delete().queue();
ArrayList<AdvertisingInfraction> infractions = BaseCommand.queryAsArrayList(AdvertisingInfraction.class, r.table("advertising_infractions").filter(row -> row.g("guild_id").eq(guild.getId()).and(row.g("user_id").eq(event.getAuthor().getId()))).run(connection));
if (infractions.size() > 2 && antiAdvertisingSettings.isBan_after_two_infractions()) {
guild.getController().ban(event.getAuthor(), 1).queue();
shard.help.sendEditedTranslation("Banned {0} for advertising.", event.getAuthor(), event.getChannel(), UserUtils.getNameWithDiscriminator(event.getAuthor().getId()));
event.getAuthor().openPrivateChannel().queue(privateChannel -> {
privateChannel.sendMessage("You were banned from " + guild.getName() + " for advertising.").queue();
});
r.table("advertising_infractions").filter(row -> row.g("guild_id").eq(guild.getId()).and(row.g("user_id").eq(event.getAuthor().getId()))).delete().run(connection);
} else {
r.table("advertising_infractions").insert(r.json(BaseCommand.getStaticGson().toJson(new AdvertisingInfraction(event.getAuthor().getId(), guild.getId())))).run(connection);
shard.help.sendEditedTranslation("{0}, you can't advertise Discord servers here!", event.getAuthor(), event.getChannel(), event.getAuthor().getAsMention());
}
return;
}
}
}
if (guild.getId().equalsIgnoreCase("260841592070340609")) {
UserUtils.addMoney(event.getAuthor(), 0.10);
}
Member ardentMember = event.getGuild().getMember(event.getJDA().getSelfUser());
Member userMember = event.getMember();
if (ardentMember == null || userMember == null || userMember.hasPermission(Permission.MANAGE_SERVER) || !ardentMember.hasPermission(Permission.MESSAGE_MANAGE)) {
shard.factory.pass(event, GuildUtils.getPrefix(guild));
// The event will be handled and musn't be resumed here.
return;
}
if (!shard.botMuteData.isMuted(event.getMember())) {
shard.factory.pass(event, GuildUtils.getPrefix(guild));
// The event will be handled and musn't be resumed here.
return;
}
event.getMessage().delete().queue();
String reply = "Sorry, but you're muted in {0} until {1}".replace("{0}", event.getGuild().getName()).replace("{1}", Date.from(Instant.ofEpochSecond(shard.botMuteData.getUnmuteTime(event.getMember()) / 1000)).toLocaleString());
event.getAuthor().openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage(reply).queue());
break;
case PRIVATE:
event.getChannel().sendMessage("Please use Ardent commands inside of a guild!").queue();
shard0.factory.incrementMessagesReceived();
break;
}
} catch (Exception ex) {
new BotException(ex);
}
}
Aggregations