Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Rules with custom emotes #137

Merged
merged 3 commits into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions example-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@
"Owners":
[],
"Database":{"IP":"",
"Port":6775,
"DBName":"",
"Username":"",
"Password":""},
"Tokens":{
"BotToken":"",
"Giphy":"",
"Port": 6775,
"DBName": "",
"Username": "",
"Password": ""},
"Tokens": {
"BotToken": "",
"Giphy": "",
"GitHub": "",
"MythicalBotList":"",
"BotsForDiscord":"",
"DiscordBotList":"",
"DiscordBestBots":"",
"MythicalBotList": "",
"BotsForDiscord": "",
"DiscordBotList": "",
"DiscordBestBots": "",
"DiscordBoats": "",
"YetAnotherBotList": "",
"DiscordExtremeList": "",
"DiscordBotReviews": "",
"DiscordBots": ""
"DiscordBots": "",
"BotListSpace": ""
}
}
12 changes: 11 additions & 1 deletion src/main/java/com/bbn/hadder/Rethink.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ public void insertUser(String id) {
this.insert("user", r.hashMap("id", id).with("prefix", "h."));
}

public void updateRules(String guild_id, String message_id, String role_id) {
public void updateRules(String guild_id, String message_id, String role_id, String accept_emote, String decline_emote) {
this.update("server", guild_id, "message_id", message_id);
this.update("server", guild_id, "role_id", role_id);
this.update("server", guild_id, "accept_emote", accept_emote);
this.update("server", guild_id, "decline_emote", decline_emote);
}

public String getRulesMID(String guild_id) {
Expand All @@ -163,6 +165,14 @@ public String getRulesRID(String guild_id) {
return (String) this.get("server", "id", guild_id, "role_id");
}

public String getRulesAEmote(String guild_id) {
return (String) this.get("server", "id", guild_id, "accept_emote");
}

public String getRulesDEmote(String guild_id) {
return (String) this.get("server", "id", guild_id, "decline_emote");
}

public void setInviteDetection(String guild_id, boolean b) {
try {
r.table("server").get(guild_id).update(r.hashMap("invite_detect", b)).run(conn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class InviteDetectCommand implements Command {
@Override
public void executed(String[] args, CommandEvent event) {
if (args.length == 1) {
if (event.getMember().hasPermission(Permission.MANAGE_SERVER)) {
if (event.getMember().hasPermission(Permission.MANAGE_SERVER) || event.getConfig().getOwners().toString().contains(event.getAuthor().getId())) {
String opinion = args[0].toLowerCase();
switch (opinion) {
case "on":
Expand Down
239 changes: 123 additions & 116 deletions src/main/java/com/bbn/hadder/commands/moderation/RulesCommand.java

Large diffs are not rendered by default.

27 changes: 12 additions & 15 deletions src/main/java/com/bbn/hadder/listener/InviteLinkListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import com.bbn.hadder.Rethink;
import com.bbn.hadder.utils.MessageEditor;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
Expand Down Expand Up @@ -45,21 +44,19 @@ public void onMessageReceived(@Nonnull MessageReceivedEvent event) {
e.printStackTrace();
}
}
} else if (event.getMessage().getContentRaw().contains("discordapp.com/invite")) {
if (!event.getMember().hasPermission(Permission.ADMINISTRATOR) && rethink.getInviteDetection(event.getGuild().getId())) {
String split = event.getMessage().getContentRaw().split("discordapp.com/invite/", 10)[1];
String invite = split.split(" ")[0];
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url("https://canary.discordapp.com/api/v6/invites/" + invite).build();
try {
Response response = client.newCall(request).execute();
JSONObject json = new JSONObject(response.body().string());
if (!json.toString().contains("\"message\":")) {
event.getMessage().delete().reason("Invite Link detected").queue();
}
} catch (Exception e) {
e.printStackTrace();
} else if (event.getMessage().getContentRaw().contains("discordapp.com/invite") && !event.getMember().hasPermission(Permission.ADMINISTRATOR) && rethink.getInviteDetection(event.getGuild().getId())) {
String split = event.getMessage().getContentRaw().split("discordapp.com/invite/", 10)[1];
String invite = split.split(" ")[0];
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url("https://canary.discordapp.com/api/v6/invites/" + invite).build();
try {
Response response = client.newCall(request).execute();
JSONObject json = new JSONObject(response.body().string());
if (!json.toString().contains("\"message\":")) {
event.getMessage().delete().reason("Invite Link detected").queue();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Expand Down
25 changes: 19 additions & 6 deletions src/main/java/com/bbn/hadder/listener/RulesListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,31 @@ public RulesListener(Rethink rethink) {
@Override
public void onMessageReactionAdd(MessageReactionAddEvent event) {
if (event.getMessageId().equals(rethink.getRulesMID(event.getGuild().getId())) && !event.getMember().getUser().isBot()) {
if (event.getReactionEmote().getEmoji().equals("✅")) {
event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(rethink.getRulesRID(event.getGuild().getId()))).reason("Accepted rules").queue();
} else if (event.getReactionEmote().getEmoji().equals("❌") && event.getGuild().getSelfMember().canInteract(event.getMember())) {
event.getReaction().removeReaction().queue();
event.getMember().kick().reason("Declined the rules");
if (event.getReactionEmote().isEmote()) {
if (rethink.getRulesAEmote(event.getGuild().getId()).contains(event.getReactionEmote().getId())) {
event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(rethink.getRulesRID(event.getGuild().getId()))).reason("Accepted rules").queue();
} else if (rethink.getRulesDEmote(event.getGuild().getId()).contains(event.getReactionEmote().getId())) {
event.getReaction().removeReaction(event.getUser()).queue();
if (event.getGuild().getSelfMember().canInteract(event.getMember())) {
event.getMember().kick().reason("Declined the rules");
}
}
} else {
if (event.getReactionEmote().getEmoji().equals(rethink.getRulesAEmote(event.getGuild().getId()))) {
event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(rethink.getRulesRID(event.getGuild().getId()))).reason("Accepted rules").queue();
} else if (event.getReactionEmote().getEmoji().equals(rethink.getRulesDEmote(event.getGuild().getId()))) {
event.getReaction().removeReaction(event.getUser()).queue();
if (event.getGuild().getSelfMember().canInteract(event.getMember())) {
event.getMember().kick().reason("Declined the rules");
}
}
}
}
}

@Override
public void onMessageReactionRemove(MessageReactionRemoveEvent event) {
if (event.getMessageId().equals(rethink.getRulesMID(event.getGuild().getId())) && !event.getMember().getUser().isBot() && event.getReactionEmote().getEmoji().equals("✅")) {
if (event.getMessageId().equals(rethink.getRulesMID(event.getGuild().getId())) && !event.getMember().getUser().isBot()) {
event.getGuild().removeRoleFromMember(event.getMember(), event.getGuild().getRoleById(rethink.getRulesRID(event.getGuild().getId()))).reason("Withdrawal of the acceptance of the rules").queue();
}
}
Expand Down
29 changes: 24 additions & 5 deletions src/main/java/com/bbn/hadder/utils/MessageEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,42 @@ public EmbedBuilder setDefaultSettings(MessageType type) {
EmbedBuilder builder = new EmbedBuilder();
switch (type) {
case INFO:
builder.setColor(new Color(47, 94, 105)).setTimestamp(Instant.now());
builder
.setColor(new Color(47, 94, 105))
.setFooter("Hadder", "https://bigbotnetwork.com/images/Hadder.png")
.setTimestamp(Instant.now());
break;

case ERROR:
builder.setColor(Color.RED).setTimestamp(Instant.now());
builder
.setColor(Color.RED)
.setFooter("Hadder", "https://bigbotnetwork.com/images/Hadder.png")
.setTimestamp(Instant.now());
break;

case WARNING:
builder.setColor(Color.ORANGE).setTimestamp(Instant.now());
builder
.setColor(Color.ORANGE)
.setFooter("Hadder", "https://bigbotnetwork.com/images/Hadder.png")
.setTimestamp(Instant.now());
break;

case NO_PERMISSION:
builder.setTitle("⛔ No Permission ⛔").setDescription("You are not authorized to execute this command!").setColor(Color.RED).setTimestamp(Instant.now());
builder
.setTitle("⛔ No Permission ⛔")
.setDescription("You are not authorized to execute this command!")
.setColor(Color.RED)
.setFooter("Hadder", "https://bigbotnetwork.com/images/Hadder.png")
.setTimestamp(Instant.now());
break;

case NO_SELF_PERMISSION:
builder.setTitle("⛔ No Permission ⛔").setDescription("Unfortunately, I do not have the required rights to perform this action").setColor(Color.RED).setTimestamp(Instant.now());
builder
.setTitle("⛔ No Permission ⛔")
.setDescription("Unfortunately, I do not have the required rights to perform this action")
.setColor(Color.RED)
.setFooter("Hadder", "https://bigbotnetwork.com/images/Hadder.png")
.setTimestamp(Instant.now());
break;
}
return builder;
Expand Down