Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
SeveralCircles committed Mar 29, 2024
1 parent ebec0dc commit a9b615e
Show file tree
Hide file tree
Showing 26 changed files with 44 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public class SparkConversation extends Conversation {
private final List<String> alreadyVoted = new LinkedList<>();
private final Map<Message, Integer> messageList;
private final String question;
Timer t = new Timer();
Timer t2 = new Timer();
final Timer t = new Timer();
final Timer t2 = new Timer();
int votes = 0;
MessageChannelUnion channel;
final MessageChannelUnion channel;
public SparkConversation(MessageChannelUnion channel, String question, int minutes) {
super((GuildMessageChannel) channel);
this.channel = channel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
import java.util.Properties;

public class UserConfig implements FlamesData {
private Locale locale = Locale.getDefault();
private Locale locale;

{

Check warning on line 15 in src/main/java/com/severalcircles/flames/data/user/UserConfig.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Class initializer may be 'static'

Class initializer may be 'static'
Locale.getDefault();
}

private boolean qotdAllowed;
private boolean favQuoteAllowed;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public List<UserEntity> getTopAndBottom() {
topAndBottom.add(lowCandidates.get(2));
return topAndBottom;
}
private Map<String, UserEntity> entities = new HashMap<>();
private Map<String, UserEntity> entities;

public Map<String, UserEntity> getEntities() {
return entities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.severalcircles.flames.frontend.conversations.SparkVoteMessageContext;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) {
// Bots don't get processed by Flames, simply because it's easier on everyone.
if (user.isBot()) return;
if (user.getName().toUpperCase(Locale.ROOT).contains("GOLDLEWIS")) event.getMessage().reply("https://media.discordapp.net/attachments/543162982536970240/943936840015159336/SpottedGoldlewis.gif").complete();
String nick = "";
String nick;
try {
nick = Objects.requireNonNull(event.getGuild().getMemberById(Flames.api.getSelfUser().getId())).getNickname();
} catch (NullPointerException e) {nick = "";}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class FlamesHandlerEmbed implements FlamesEmbed {
private final String causedByImage;
final ResourceBundle rsc;
final String causedBy;
Color color;
final Color color;
public FlamesHandlerEmbed(FlamesException e) {
StackTraceElement[] st = Thread.currentThread().getStackTrace();
String className = st[3].getClassName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import net.dv8tion.jda.api.entities.MessageEmbed;

public class FlamesExceptionHandler extends ThrowableHandler {
FlamesException e;
final FlamesException e;
public FlamesExceptionHandler(FlamesException e) {
this.e = e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import net.dv8tion.jda.api.entities.MessageEmbed;

public class FlamesRuntimeExceptionHandler extends ThrowableHandler {
FlamesRuntimeException e;
String cause;
final FlamesRuntimeException e;
final String cause;
public FlamesRuntimeExceptionHandler(FlamesRuntimeException e, Class cls) {
this.e = e;
if (Flames.runningDebug) this.cause = cls.getName() + "(" + e.getStackTrace()[0].getLineNumber() + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static String searchImage(String q) throws IOException {
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Authorization", "Authorization: Client-ID 5BgyDJn2wiCT7SNM8kVyKeFFCWsnBvXM8F1jCEti-t8");
StringBuffer content = new StringBuffer();
StringBuffer content;
try {
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
import net.dv8tion.jda.api.entities.MessageEmbed;

public interface FlamesEmbed {
public MessageEmbed get();
MessageEmbed get();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
import net.dv8tion.jda.api.interactions.commands.context.MessageContextInteraction;

public interface FlamesMessageContext {
public void execute(MessageContextInteraction event);
void execute(MessageContextInteraction event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class SparkCommand implements FlamesCommand {
@Override
public void execute(SlashCommandInteractionEvent event, FlamesUser sender) throws ConsentException, IOException {
public void execute(SlashCommandInteractionEvent event, FlamesUser sender) {
if (!SparkConversation.sparkConversations.isEmpty()) {
event.reply("There is already a Spark conversation in progress!").setEphemeral(true).complete();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
import java.util.ResourceBundle;

public class SparkResultsEmbed implements FlamesEmbed {
String question;
String answer;
int votes;
final String question;
final String answer;
final int votes;
public SparkResultsEmbed(String question, String answer, int votes) {
this.question = question;
this.answer = answer;
this.votes = votes;
}
ResourceBundle local = Flames.local();
final ResourceBundle local = Flames.local();
@Override
public MessageEmbed get() {
MessageEmbed embed = null;
MessageEmbed embed;
try {
embed = new EmbedBuilder()
.setTitle(question)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,27 @@
import java.util.ResourceBundle;

public class SparkStartEmbed implements FlamesEmbed {
ResourceBundle local;
FlamesUser fluser;
User user;
String question;
int minutes;
final ResourceBundle local;
final FlamesUser fluser;
final User user;
final String question;
final int minutes;
public SparkStartEmbed(FlamesUser fluser, User user, String question, int minutes) {
local = Flames.local();
this.fluser = fluser;
this.user = user;
this.question = question;
this.minutes = minutes;
if (minutes > 5) minutes = 5;
if (minutes > 5) {

Check warning on line 33 in src/main/java/com/severalcircles/flames/frontend/conversations/SparkStartEmbed.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Statement with empty body

`if` statement has empty body
}
}

@Override
public MessageEmbed get() {
String eS = "<t:" + (Instant.now().plus(minutes, ChronoUnit.MINUTES).toEpochMilli() / 1000) + ":R>";
eS = eS.replace(" ", "");
System.out.println(eS);
MessageEmbed embed = null;
MessageEmbed embed;
try {
embed = new EmbedBuilder()
.setColor(Color.CYAN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.dv8tion.jda.api.interactions.commands.context.MessageContextInteraction;

import java.util.Objects;
import java.util.ResourceBundle;

public class SparkVoteMessageContext implements FlamesMessageContext {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.severalcircles.flames.Flames;
import com.severalcircles.flames.data.global.GlobalData;
import com.severalcircles.flames.data.user.FlamesUser;
import com.severalcircles.flames.util.Ranking;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.User;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
import com.severalcircles.flames.data.user.UserFunFacts;
import com.severalcircles.flames.external.FlamesAssets;
import com.severalcircles.flames.frontend.FlamesEmbed;
import com.severalcircles.flames.util.Emotion;
import com.severalcircles.flames.util.Ranking;
import com.severalcircles.flames.util.StringUtil;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.User;

import java.awt.*;
import java.util.List;
import java.util.ResourceBundle;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.severalcircles.flames.Flames;
import com.severalcircles.flames.data.user.FlamesUser;
import com.severalcircles.flames.frontend.FlamesEmbed;
import com.severalcircles.flames.frontend.today.Today;
import com.severalcircles.flames.util.StringUtil;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void execute(UserContextInteractionEvent event) {
FlamesUser flt;
try {
flt = FlamesDataManager.readUser(thanked);
sender = FlamesDataManager.readUser(event.getUser());
FlamesDataManager.readUser(event.getUser());
} catch (IOException e) {
e.printStackTrace();

Check warning on line 35 in src/main/java/com/severalcircles/flames/frontend/thanks/ThanksContext.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Call to 'printStackTrace()'

Call to `printStackTrace()` should probably be replaced with more robust logging
event.replyEmbeds(new ExceptionHandler(e).handleThenGetFrontend()).complete();
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/severalcircles/flames/util/Ranking.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

package com.severalcircles.flames.util;

import com.severalcircles.flames.data.global.GlobalData;

import java.io.IOException;
import java.util.Arrays;
import java.util.Locale;
import java.util.ResourceBundle;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/json/Cookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static JSONObject toJSONObject(String string) {

name = unescape(x.nextTo('=').trim());
//per RFC6265, if the name is blank, the cookie should be ignored.
if("".equals(name)) {
if(name.isEmpty()) {
throw new JSONException("Cookies must have a 'name'");
}
jo.put("name", name);
Expand Down Expand Up @@ -124,7 +124,7 @@ public static JSONObject toJSONObject(String string) {
x.next();
}
// only store non-blank attributes
if(!"".equals(name) && !"".equals(value)) {
if(!name.isEmpty() && !"".equals(value)) {
jo.put(name, value);
}
}
Expand Down Expand Up @@ -160,7 +160,7 @@ public static String toString(JSONObject jo) throws JSONException {
}
}

if(name == null || "".equals(name.trim())) {
if(name == null || name.trim().isEmpty()) {
throw new JSONException("Cookie does not have a name");
}
if(value == null) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/json/JSONPointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public JSONPointer(final String pointer) {
}
this.refTokens = new ArrayList<String>();
int slashIdx = -1;
int prevSlashIdx = 0;
int prevSlashIdx;
do {
prevSlashIdx = slashIdx + 1;
slashIdx = refs.indexOf('/', prevSlashIdx);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/json/JSONTokener.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public Object nextValue() throws JSONException {
}

string = sb.toString().trim();
if ("".equals(string)) {
if (string.isEmpty()) {
throw this.syntaxError("Missing value");
}
return JSONObject.stringToValue(string);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/json/JSONWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class JSONWriter {
/**
* The writer that will receive the output.
*/
protected Appendable writer;
protected final Appendable writer;

/**
* Make a fresh JSONWriter. It can be used to build one JSON text.
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/json/XML.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

import org.jetbrains.annotations.NotNull;

import java.io.Reader;
import java.io.StringReader;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Iterator;
Expand Down Expand Up @@ -89,6 +90,7 @@ public class XML {
*/
private static Iterable<Integer> codePointIterator(final String string) {
return new Iterable<Integer>() {
@NotNull
@Override
public Iterator<Integer> iterator() {
return new Iterator<Integer>() {
Expand Down Expand Up @@ -256,7 +258,7 @@ private static boolean parse(XMLTokener x, JSONObject context, String name, XMLP
throws JSONException {
char c;
int i;
JSONObject jsonObject = null;
JSONObject jsonObject;
String string;
String tagName;
Object token;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#
# Copyright (c) 2022 Several Circles.
#

io.grpc.internal.PickFirstLoadBalancerProvider
io.grpc.util.SecretRoundRobinLoadBalancerProvider$Provider
#

0 comments on commit a9b615e

Please sign in to comment.