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;
}
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);
}
}
Aggregations