implement logging feature base
This commit is contained in:
@ -0,0 +1,72 @@
|
||||
package cc.fascinated.bat.features.logging;
|
||||
|
||||
import cc.fascinated.bat.command.Category;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.PasteUtils;
|
||||
import cc.fascinated.bat.features.Feature;
|
||||
import cc.fascinated.bat.features.base.profile.FeatureProfile;
|
||||
import cc.fascinated.bat.features.logging.command.LogsCommand;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.service.CommandService;
|
||||
import lombok.NonNull;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
public class LogFeature extends Feature {
|
||||
@Autowired
|
||||
public LogFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
|
||||
super("Logging", false, Category.LOGS);
|
||||
|
||||
super.registerCommand(commandService, context.getBean(LogsCommand.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an embed to use for logging
|
||||
*
|
||||
* @return the embed
|
||||
*/
|
||||
public EmbedBuilder baseLogEmbed() {
|
||||
return EmbedUtils.genericEmbed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a log to the log channel
|
||||
*
|
||||
* @param guild the guild to send the log in
|
||||
* @param type the type of log
|
||||
* @param embed the embed to send
|
||||
*/
|
||||
public void sendLog(BatGuild guild, LogType type, MessageEmbed embed) {
|
||||
FeatureProfile featureProfile = guild.getFeatureProfile();
|
||||
if (featureProfile.isFeatureDisabled(this)) { // The feature is disabled
|
||||
return;
|
||||
}
|
||||
LogProfile logProfile = guild.getLogProfile();
|
||||
if (!logProfile.hasLogChannel(type)) { // The guild has no log channel for this type
|
||||
return;
|
||||
}
|
||||
TextChannel logChannel = logProfile.getLogChannel(type);
|
||||
if (logChannel == null) { // The log channel has been removed
|
||||
return;
|
||||
}
|
||||
logChannel.sendMessageEmbeds(embed).queue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the content to be sent in the log
|
||||
*
|
||||
* @param content the content to format
|
||||
* @return the formatted content
|
||||
*/
|
||||
public String formatContent(String content) {
|
||||
return content.length() > 512 ? PasteUtils.uploadPaste(content).getUrl() : "\n```\n%s\n```".formatted(content);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user