Search in sources :

Example 1 with ReportMessage

use of stream.flarebot.flarebot.objects.ReportMessage in project FlareBot by FlareBot.

the class GeneralUtils method getReportEmbed.

/**
 * Gets the {@link Report} embed with all of the info on the report.
 *
 * @param sender The {@link User} who requested the embed
 * @param report The {@link Report} to get the embed of.
 * @return an {@link EmbedBuilder} that contains all the report data
 */
public static EmbedBuilder getReportEmbed(User sender, Report report) {
    EmbedBuilder eb = MessageUtils.getEmbed(sender);
    User reporter = Getters.getUserById(report.getReporterId());
    User reported = Getters.getUserById(report.getReportedId());
    eb.addField("Report ID", String.valueOf(report.getId()), true);
    eb.addField("Reporter", reporter != null ? MessageUtils.getTag(reporter) : "Unknown", true);
    eb.addField("Reported", reported != null ? MessageUtils.getTag(reported) : "Unknown", true);
    // eb.addField("Time", report.getTime().toLocalDateTime().atOffset(ZoneOffset.UTC).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + " GMT/BST", true);
    eb.setTimestamp(report.getTime().toLocalDateTime());
    eb.addField("Status", report.getStatus().getMessage(), true);
    eb.addField("Message", "```" + report.getMessage() + "```", false);
    StringBuilder builder = new StringBuilder("The last 5 messages by the reported user: ```\n");
    for (ReportMessage m : report.getMessages()) {
        builder.append("[").append(m.getTime().toLocalDateTime().format(DateTimeFormatter.ofPattern("HH:mm:ss"))).append(" GMT/BST] ").append(FormatUtils.truncate(100, m.getMessage())).append("\n");
    }
    builder.append("```");
    eb.addField("Messages from reported user", builder.toString(), false);
    return eb;
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ReportMessage(stream.flarebot.flarebot.objects.ReportMessage)

Example 2 with ReportMessage

use of stream.flarebot.flarebot.objects.ReportMessage in project FlareBot by FlareBot.

the class ReportCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length >= 2) {
        User user = GuildUtils.getUser(args[0], channel.getGuild().getId());
        if (user == null) {
            MessageUtils.sendErrorMessage("Invalid user: " + args[0], channel);
            return;
        }
        Report report = new Report((guild.getReportManager().getLastId() + 1), MessageUtils.getMessage(args, 1), sender.getId(), user.getId(), new Timestamp(System.currentTimeMillis()), ReportStatus.OPEN);
        List<Message> messages = channel.getHistory().retrievePast(100).complete().stream().filter(m -> m.getAuthor().equals(user)).collect(Collectors.toList());
        if (messages.size() > 0) {
            messages = messages.subList(0, Math.min(5, messages.size() - 1));
            List<ReportMessage> reportMessages = new ArrayList<>();
            for (Message userMessage : messages) {
                reportMessages.add(new ReportMessage(userMessage.getContentDisplay(), Timestamp.valueOf(userMessage.getCreationTime().atZoneSameInstant(ZoneOffset.UTC).toLocalDateTime())));
            }
            report.setMessages(reportMessages);
        }
        guild.getReportManager().report(report);
        ModlogHandler.getInstance().postToModlog(guild, ModlogEvent.REPORT_SUBMITTED, user, null, MessageUtils.getMessage(args, 1), new MessageEmbed.Field("Reported By", MessageUtils.getTag(sender), true));
        MessageUtils.sendPM(channel, sender, GeneralUtils.getReportEmbed(sender, report).setDescription("Successfully reported the user"));
    } else {
        MessageUtils.sendUsage(this, channel, sender, args);
    }
}
Also used : ReportStatus(stream.flarebot.flarebot.objects.ReportStatus) Report(stream.flarebot.flarebot.objects.Report) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) Timestamp(java.sql.Timestamp) ModlogHandler(stream.flarebot.flarebot.mod.modlog.ModlogHandler) ModlogEvent(stream.flarebot.flarebot.mod.modlog.ModlogEvent) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) GeneralUtils(stream.flarebot.flarebot.util.general.GeneralUtils) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ReportMessage(stream.flarebot.flarebot.objects.ReportMessage) List(java.util.List) Permission(stream.flarebot.flarebot.permissions.Permission) Command(stream.flarebot.flarebot.commands.Command) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) ZoneOffset(java.time.ZoneOffset) CommandType(stream.flarebot.flarebot.commands.CommandType) GuildUtils(stream.flarebot.flarebot.util.general.GuildUtils) ReportMessage(stream.flarebot.flarebot.objects.ReportMessage) Report(stream.flarebot.flarebot.objects.Report) ArrayList(java.util.ArrayList) ReportMessage(stream.flarebot.flarebot.objects.ReportMessage) Timestamp(java.sql.Timestamp)

Aggregations

ReportMessage (stream.flarebot.flarebot.objects.ReportMessage)2 Timestamp (java.sql.Timestamp)1 ZoneOffset (java.time.ZoneOffset)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)1 net.dv8tion.jda.core.entities (net.dv8tion.jda.core.entities)1 Command (stream.flarebot.flarebot.commands.Command)1 CommandType (stream.flarebot.flarebot.commands.CommandType)1 ModlogEvent (stream.flarebot.flarebot.mod.modlog.ModlogEvent)1 ModlogHandler (stream.flarebot.flarebot.mod.modlog.ModlogHandler)1 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)1 Report (stream.flarebot.flarebot.objects.Report)1 ReportStatus (stream.flarebot.flarebot.objects.ReportStatus)1 Permission (stream.flarebot.flarebot.permissions.Permission)1 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)1 GeneralUtils (stream.flarebot.flarebot.util.general.GeneralUtils)1 GuildUtils (stream.flarebot.flarebot.util.general.GuildUtils)1