Skip to content
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.egg.papertrail</groupId>
<artifactId>paper-trail-bot</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<name>PaperTrail</name>
<description>A simple bot for logging all user actions</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.papertrail.listeners.customlisteners;

import java.awt.Color;
import java.util.EnumMap;
import java.util.Map;

import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.SelfUser;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

public class RequiredPermissionCheckListener extends ListenerAdapter {

@Override
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {

if (event.getName().equals("permcheck")) {

Guild guild = event.getGuild();

SelfUser botAsUser = event.getJDA().getSelfUser();
Role botIntegrationRole = guild.getRoleByBot(botAsUser);
Member botMember = guild.getMember(botAsUser);

EmbedBuilder eb = new EmbedBuilder();
eb.setTitle("PaperTrail Permissions Checker");
eb.setDescription("Helps determine whether the required permissions are granted for PaperTrail to function properly");
eb.setColor(Color.MAGENTA);

eb.addField("Bot Integration Role Specific Permission", (botIntegrationRole.hasPermission(Permission.VIEW_AUDIT_LOGS) ? "✅" : "❌")+Permission.VIEW_AUDIT_LOGS.getName(), false);

// create a map of required permissions and set all their statuses to false
Map<Permission, Boolean> requiredPermissions = new EnumMap<>(Permission.class);
requiredPermissions.putAll(Map.of(
Permission.MESSAGE_EMBED_LINKS, false,
Permission.MESSAGE_HISTORY, false,
Permission.MESSAGE_SEND, false,
Permission.MESSAGE_SEND_IN_THREADS, false,
Permission.VIEW_CHANNEL, false));


GuildChannel currentChannel = guild.getGuildChannelById(event.getChannelIdLong());

if(currentChannel==null || botMember == null) {
eb.addField("Channel Specific Permissions","ERROR: Could not determine bot permissions for the given channel. Channel possibly not supported", false);
} else {
botMember.getPermissions(currentChannel).forEach(permission ->{
if(requiredPermissions.containsKey(permission)) {
requiredPermissions.replace(permission, true);
}
});

StringBuilder finalPermissions = new StringBuilder();
requiredPermissions.entrySet().forEach(permission -> {
finalPermissions.append(Boolean.TRUE.equals(permission.getValue()) ? "✅" : "❌");
finalPermissions.append(permission.getKey().getName()+System.lineSeparator());
});


eb.addField("Channel Specific Permissions: "+currentChannel.getAsMention(), finalPermissions.toString(), false);
}


MessageEmbed mb = eb.build();
event.replyEmbeds(mb).queue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void onGuildMemberUpdateBoostTime(GuildMemberUpdateBoostTimeEvent event)
eb.addField("🪫 Booster Lost", "╰┈➤"+mentionableMember+" has removed their boost from your server", false);
eb.addField("📉 Remaining Boosts In The Server", "╰┈➤"+guild.getBoostCount(), false);
eb.addField("🎖️ Current Boost Tier", "╰┈➤"+guild.getBoostTier().toString(), false);
eb.addField("Notice", "Boosts remain active for a period even after a member stops boosting, so the server's boost count doesn't update immediately.", false);
}

eb.setFooter("Server Boost Detection");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/papertrail/main/FireRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.papertrail.listeners.customlisteners.BotInfoListener;
import org.papertrail.listeners.customlisteners.ServerStatListener;
import org.papertrail.listeners.customlisteners.BotSetupListener;
import org.papertrail.listeners.customlisteners.RequiredPermissionCheckListener;
import org.papertrail.listeners.guildlisteners.ServerBoostListener;
import org.papertrail.listeners.loglisteners.AuditLogListener;
import org.papertrail.listeners.loglisteners.AuditLogCommandListener;
Expand Down Expand Up @@ -59,6 +60,7 @@ public static void main(String[] args) throws IOException, SQLException {
ci.getManager().addEventListener(new BotInfoListener());
ci.getManager().addEventListener(new BotSetupListener());
ci.getManager().addEventListener(new AnnouncementListener(dc));
ci.getManager().addEventListener(new RequiredPermissionCheckListener());

/*
* This is required only to set up a cron-job to periodically ping this end-point so that
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/papertrail/main/SlashCommandRegistrar.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ private void setAuditLogCommands(JDA jda) {
.addOption(OptionType.STRING, "detail", "Detailed Information", true)
.addOption(OptionType.STRING, "extra", "Extra Notes", false);

CommandData permCheck = Commands.slash("permcheck", "Checks if the bot has the necessary permissions to operate");

jda.updateCommands()
.addCommands(auditLogChannelRegistration,
auditLogChannelFetch,
Expand All @@ -57,7 +59,8 @@ private void setAuditLogCommands(JDA jda) {
serverStats,
botInfo,
setup,
announcement)
announcement,
permCheck)
.queue();
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/papertrail/version/ProjectInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ private ProjectInfo() {
}

public static final String APPNAME = "PaperTrail";
public static final String VERSION = "v1.1.0";
public static final String VERSION = "v1.2.0";
public static final String PROJECT_LINK = "https://github.com/Egg-03/PaperTrailBot";
public static final String PROJECT_ISSUE_LINK="https://github.com/Egg-03/PaperTrailBot/issues";

Expand Down
Loading