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
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package com.javadiscord.javabot.commands.moderation;

import com.javadiscord.javabot.other.Database;
import com.javadiscord.javabot.other.Embeds;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.javadiscord.javabot.other.Database;
import com.javadiscord.javabot.other.Embeds;
import com.javadiscord.javabot.other.TimeUtils;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.MessageChannel;

import java.awt.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Date;
import java.util.Locale;

public class Report extends Command {

Expand All @@ -25,10 +24,6 @@ protected void execute(CommandEvent event) {
Member member = null;
String reason = null;





if (event.getMessage().getReferencedMessage() == null) {

try {
Expand Down Expand Up @@ -70,8 +65,6 @@ protected void execute(CommandEvent event) {

}

DateTimeFormatter dtw = DateTimeFormatter.ofPattern("EEE',' dd/MM/yyyy',' HH:mm", new Locale("en"));
LocalDateTime now = LocalDateTime.now();
MessageChannel reportChannel = Database.configChannel(event, "report_cid");

EmbedBuilder eb = new EmbedBuilder()
Expand All @@ -81,7 +74,7 @@ protected void execute(CommandEvent event) {
.addField("ID", "```" + member.getId() + "```", true)
.addField("Reported by", "```" + event.getMessage().getAuthor().getAsTag() + "```", true)
.addField("Channel", "```#" + event.getMessage().getChannel().getName() + "```", true)
.addField("Reported on", "```" + dtw.format(now) + "```", true)
.addField("Reported on", "```" + LocalDateTime.now().format(TimeUtils.STANDARD_FORMATTER) + "```", true)
.addField("Reason", "```" + reason + "```", false)
.setFooter(event.getAuthor().getAsTag(), event.getAuthor().getEffectiveAvatarUrl())
.setTimestamp(new Date().toInstant());
Expand Down
54 changes: 20 additions & 34 deletions src/main/java/com/javadiscord/javabot/commands/other/Version.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.javadiscord.javabot.commands.other;

import com.javadiscord.javabot.other.Embeds;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.javadiscord.javabot.other.Embeds;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;
Expand Down Expand Up @@ -39,44 +39,30 @@ public Version () {
}

protected void execute(CommandEvent event) {

MongoDatabase database = mongoClient.getDatabase("other");
MongoCollection<Document> collection = database.getCollection("config");

String[] args = event.getArgs().split("\\s+");
String input;
if (args.length > 0 && args[0].equalsIgnoreCase("now")) {
input = LocalDate.now().format(DateTimeFormatter.ofPattern("YYYY-MM.dd"));
} else if (args.length > 0) {
input = args[0];
} else {
event.reply(Embeds.syntaxError("version now|Text", event));
return;
}

try {

String input;

if (args[0].equalsIgnoreCase("now")) {

LocalDate currentdate = LocalDate.now();
String currentDay = currentdate.format(DateTimeFormatter.ofPattern("dd"));
String currentMonth = currentdate.format(DateTimeFormatter.ofPattern("MM"));
String currentYear = currentdate.format(DateTimeFormatter.ofPattern("YYYY")).substring(2);

input = currentYear + "-" + currentMonth + "." + currentDay;

} else {
input = args[0];
}

event.reply(Embeds.configEmbed(event, "Version", "Version succesfully changed to", null, input, true));

Document Query = new Document();
Query.append("name", "Java#9523");
event.reply(Embeds.configEmbed(event, "Version", "Version succesfully changed to", null, input, true));

Document SetData = new Document();
SetData.append("version", input);
Document Query = new Document();
Query.append("name", "Java#9523");

Document update = new Document();
update.append("$set", SetData);
Document SetData = new Document();
SetData.append("version", input);

collection.updateOne(Query, update);
Document update = new Document();
update.append("$set", SetData);

} catch (ArrayIndexOutOfBoundsException e) {
event.reply(Embeds.syntaxError("version now|Text", event));
}
MongoDatabase database = mongoClient.getDatabase("other");
MongoCollection<Document> collection = database.getCollection("config");
collection.updateOne(Query, update);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.javadiscord.javabot.other.TimeUtils;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;

Expand Down Expand Up @@ -32,8 +33,7 @@ public static void exCommand (CommandEvent event) {
long unixTimeStampMilliseconds = Input / 4194304 + 1420070400000L;
long unixTimeStamp = unixTimeStampMilliseconds / 1000;

DateTimeFormatter dtf = DateTimeFormatter.ofPattern("EEE',' dd/MM/yyyy',' HH:mm", new Locale("en"));
String Date = Instant.ofEpochMilli(unixTimeStampMilliseconds).atZone(ZoneId.of("GMT")).format(dtf);
String Date = Instant.ofEpochMilli(unixTimeStampMilliseconds).atZone(ZoneId.of("GMT")).format(TimeUtils.STANDARD_FORMATTER);

EmbedBuilder eb = new EmbedBuilder()
.setAuthor("ID-Calculator")
Expand All @@ -51,8 +51,7 @@ public static void exCommand (SlashCommandEvent event, long id) {
long unixTimeStampMilliseconds = id / 4194304 + 1420070400000L;
long unixTimeStamp = unixTimeStampMilliseconds / 1000;

DateTimeFormatter dtf = DateTimeFormatter.ofPattern("EEE',' dd/MM/yyyy',' HH:mm", new Locale("en"));
String Date = Instant.ofEpochMilli(unixTimeStampMilliseconds).atZone(ZoneId.of("GMT")).format(dtf);
String Date = Instant.ofEpochMilli(unixTimeStampMilliseconds).atZone(ZoneId.of("GMT")).format(TimeUtils.STANDARD_FORMATTER);

EmbedBuilder eb = new EmbedBuilder()
.setAuthor("ID-Calculator")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.javadiscord.javabot.commands.user_commands;

import com.javadiscord.javabot.commands.other.qotw.Leaderboard;
import com.javadiscord.javabot.other.Database;
import com.javadiscord.javabot.other.Misc;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.javadiscord.javabot.commands.other.qotw.Leaderboard;
import com.javadiscord.javabot.other.Database;
import com.javadiscord.javabot.other.TimeUtils;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import net.dv8tion.jda.api.EmbedBuilder;
Expand All @@ -15,10 +15,9 @@
import org.bson.Document;

import java.awt.*;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Locale;

import static com.javadiscord.javabot.events.Startup.mongoClient;

Expand Down Expand Up @@ -48,8 +47,8 @@ public static void exCommand(CommandEvent event) {
highestRole = "everyone";
}

String timeJoined = member.getTimeJoined().format(DateTimeFormatter.ofPattern("EEE',' dd/MM/yyyy',' HH:mm", new Locale("en")));
String timeCreated = member.getTimeCreated().format(DateTimeFormatter.ofPattern("EEE',' dd/MM/yyyy',' HH:mm", new Locale("en")));
String timeJoined = member.getTimeJoined().format(TimeUtils.STANDARD_FORMATTER);
String timeCreated = member.getTimeCreated().format(TimeUtils.STANDARD_FORMATTER);

Color color = null;
String colorText;
Expand Down Expand Up @@ -149,9 +148,11 @@ public static void exCommand(CommandEvent event) {
int qotwCount = Database.getMemberInt(collection, member, "qotwpoints");
int warnCount = Database.getMemberInt(collection, member, "warns");

String joinDiff = " (" + Misc.getDateDiff(Date.from(member.getTimeJoined().toInstant()), Date.from(new Date().toInstant())) + " ago)";
String createDiff = " (" + Misc.getDateDiff(Date.from(member.getUser().getTimeCreated().toInstant()), Date.from(new Date().toInstant())) + " ago)";
Duration memberDuration = Duration.between(OffsetDateTime.now(member.getTimeJoined().getOffset()), member.getTimeJoined());
Duration createDuration = Duration.between(OffsetDateTime.now(member.getTimeCreated().getOffset()), member.getTimeCreated());

String joinDiff = TimeUtils.formatDuration(memberDuration);
String createDiff = TimeUtils.formatDuration(createDuration);

EmbedBuilder eb = new EmbedBuilder()
.setTitle(statusEmote + " " + member.getUser().getAsTag() + " " + botBadge + boostBadge + badges)
Expand Down Expand Up @@ -184,8 +185,8 @@ public static void exCommand(SlashCommandEvent event, Member member) {
highestRole = "everyone";
}

String timeJoined = member.getTimeJoined().format(DateTimeFormatter.ofPattern("EEE',' dd/MM/yyyy',' HH:mm", new Locale("en")));
String timeCreated = member.getTimeCreated().format(DateTimeFormatter.ofPattern("EEE',' dd/MM/yyyy',' HH:mm", new Locale("en")));
String timeJoined = member.getTimeJoined().format(TimeUtils.STANDARD_FORMATTER);
String timeCreated = member.getTimeCreated().format(TimeUtils.STANDARD_FORMATTER);

Color color = null;
String colorText;
Expand Down Expand Up @@ -285,9 +286,8 @@ public static void exCommand(SlashCommandEvent event, Member member) {
int qotwCount = Database.getMemberInt(collection, member, "qotwpoints");
int warnCount = Database.getMemberInt(collection, member, "warns");

String joinDiff = " (" + Misc.getDateDiff(Date.from(member.getTimeJoined().toInstant()), Date.from(new Date().toInstant())) + " ago)";
String createDiff = " (" + Misc.getDateDiff(Date.from(member.getUser().getTimeCreated().toInstant()), Date.from(new Date().toInstant())) + " ago)";

String joinDiff = TimeUtils.formatDurationToNow(member.getTimeJoined());
String createDiff = TimeUtils.formatDurationToNow(member.getTimeCreated());

EmbedBuilder eb = new EmbedBuilder()
.setTitle(statusEmote + " " + member.getUser().getAsTag() + " " + botBadge + boostBadge + badges)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package com.javadiscord.javabot.commands.user_commands;

import com.javadiscord.javabot.other.Constants;
import com.javadiscord.javabot.other.Misc;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.javadiscord.javabot.other.Constants;
import com.javadiscord.javabot.other.TimeUtils;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.interactions.ActionRow;
import net.dv8tion.jda.api.interactions.button.Button;

import java.awt.*;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;

public class ServerInfo extends Command {

Expand All @@ -25,8 +23,8 @@ public static void exCommand (CommandEvent event) {
long voiceChannelCount = event.getGuild().getVoiceChannels().stream().count();
long channelCount = event.getGuild().getChannels().stream().count() - catCount;

String guildDate = event.getGuild().getTimeCreated().format(DateTimeFormatter.ofPattern("EEE',' dd/MM/yyyy',' HH:mm", new Locale("en")));
String createdDiff = " (" + Misc.getDateDiff(Date.from(event.getGuild().getTimeCreated().toInstant()), Date.from(new Date().toInstant())) + " ago)";
String guildDate = event.getGuild().getTimeCreated().format(TimeUtils.STANDARD_FORMATTER);
String createdDiff = TimeUtils.formatDurationToNow(event.getGuild().getTimeCreated());

EmbedBuilder eb = new EmbedBuilder()
.setColor(new Color(0x2F3136))
Expand Down Expand Up @@ -60,8 +58,8 @@ public static void exCommand (SlashCommandEvent event) {
long voiceChannelCount = event.getGuild().getVoiceChannels().stream().count();
long channelCount = event.getGuild().getChannels().stream().count() - catCount;

String guildDate = event.getGuild().getTimeCreated().format(DateTimeFormatter.ofPattern("EEE',' dd/MM/yyyy',' HH:mm", new Locale("en")));
String createdDiff = " (" + Misc.getDateDiff(Date.from(event.getGuild().getTimeCreated().toInstant()), Date.from(new Date().toInstant())) + " ago)";
String guildDate = event.getGuild().getTimeCreated().format(TimeUtils.STANDARD_FORMATTER);
String createdDiff = TimeUtils.formatDurationToNow(event.getGuild().getTimeCreated());

EmbedBuilder eb = new EmbedBuilder()
.setColor(new Color(0x2F3136))
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/com/javadiscord/javabot/events/UserJoin.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.javadiscord.javabot.events;

import com.javadiscord.javabot.other.Database;
import com.javadiscord.javabot.other.Misc;
import com.javadiscord.javabot.other.ServerLock;
import com.javadiscord.javabot.other.StatsCategory;
import com.javadiscord.javabot.other.*;
import com.jagrosh.jdautilities.command.CommandEvent;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
Expand Down Expand Up @@ -201,7 +198,7 @@ public void onGuildMemberJoin(GuildMemberJoinEvent event) {
user.openPrivateChannel().complete().sendMessage(ServerLock.lockEmbed(event.getGuild())).queue();
event.getMember().kick().complete();

String diff = Misc.getDateDiff(Date.from(user.getTimeCreated().toInstant()), Date.from(new Date().toInstant()));
String diff = TimeUtils.formatDurationToNow(event.getMember().getTimeCreated());
welcomeChannel.sendMessage("**" + event.getMember().getUser().getAsTag() + "**" + " (" + diff + " old) tried to join this server.").queue();

}
Expand Down
41 changes: 0 additions & 41 deletions src/main/java/com/javadiscord/javabot/other/Misc.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URL;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

import static com.javadiscord.javabot.events.Startup.iae;

Expand All @@ -27,45 +25,6 @@ public static double round(double value, int places) {
return i.doubleValue();
}

public static String getDateDiff(Date date1, Date date2) {
TimeUnit timeUnit = null;
String ex = " ";
long diffInMillies = date2.getTime() - date1.getTime();

if (TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS) > 365) {
double i = TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS) / 365.0;
double yrs = round(i, 1);
ex += "years";
return yrs + ex;
}

if (TimeUnit.HOURS.convert(diffInMillies, TimeUnit.MILLISECONDS) > 48) {
timeUnit = TimeUnit.DAYS;
ex += "days";
return timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS) + ex;
}

if (TimeUnit.MINUTES.convert(diffInMillies, TimeUnit.MILLISECONDS) > 120) {
timeUnit = TimeUnit.HOURS;
ex += "hours";
return timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS) + ex;
}

if (TimeUnit.SECONDS.convert(diffInMillies, TimeUnit.MILLISECONDS) > 120) {
timeUnit = TimeUnit.MINUTES;
ex += "minutes";
return timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS) + ex;
}

if (TimeUnit.MILLISECONDS.convert(diffInMillies, TimeUnit.MILLISECONDS) > 2000) {
timeUnit = TimeUnit.SECONDS;
ex += "seconds";
return timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS) + ex;
}

return null;
}

public static int parseInt (String input) {

int i;
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/javadiscord/javabot/other/ServerLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import org.bson.Document;

import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;

import static com.javadiscord.javabot.events.Startup.mongoClient;
import static com.mongodb.client.model.Filters.eq;
Expand Down Expand Up @@ -52,8 +50,8 @@ public static void incrementLock(GuildMemberJoinEvent event, User user) {
lockCount = lockCount + 1;
Database.queryConfigInt(event.getGuild().getId(), "lockcount", lockCount);

String timeCreated = user.getTimeCreated().format(DateTimeFormatter.ofPattern("EEE',' dd/MM/yyyy',' HH:mm", new Locale("en")));
String createDiff = " (" + Misc.getDateDiff(Date.from(user.getTimeCreated().toInstant()), Date.from(new Date().toInstant())) + " ago)";
String timeCreated = user.getTimeCreated().format(TimeUtils.STANDARD_FORMATTER);
String createDiff = " (" + TimeUtils.formatDurationToNow(user.getTimeCreated()) + " ago)";

EmbedBuilder eb = new EmbedBuilder()
.setColor(Constants.GRAY)
Expand Down
Loading