-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #356 from Java-Discord/dynxsty/preference_improvem…
…ents Improved User Preferences by using Strings instead of Booleans
- Loading branch information
Showing
13 changed files
with
121 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/net/javadiscord/javabot/systems/user_preferences/model/BooleanPreference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package net.javadiscord.javabot.systems.user_preferences.model; | ||
|
||
import net.dv8tion.jda.api.interactions.commands.Command; | ||
|
||
/** | ||
* Represents a {@link Preference} of the {@link Boolean} type. | ||
*/ | ||
public final class BooleanPreference implements PreferenceType { | ||
@Override | ||
public String[] getAllowedChoices() { | ||
return new String[]{ | ||
"true", "false" | ||
}; | ||
} | ||
|
||
@Override | ||
public Command.Choice[] getDefaultChoices() { | ||
return new Command.Choice[]{ | ||
new Command.Choice("Enable", "true"), | ||
new Command.Choice("Disable", "false") | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/net/javadiscord/javabot/systems/user_preferences/model/PreferenceType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package net.javadiscord.javabot.systems.user_preferences.model; | ||
|
||
import net.dv8tion.jda.api.interactions.commands.Command; | ||
|
||
/** | ||
* Interface used by different Preference Types. This holds the default and allowed choices. | ||
*/ | ||
public interface PreferenceType { | ||
default String[] getAllowedChoices() { | ||
return new String[0]; | ||
} | ||
|
||
default Command.Choice[] getDefaultChoices() { | ||
return new Command.Choice[0]; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/net/javadiscord/javabot/systems/user_preferences/model/StringPreference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package net.javadiscord.javabot.systems.user_preferences.model; | ||
|
||
/** | ||
* Represents a {@link Preference} of the {@link String} type. | ||
*/ | ||
public final class StringPreference implements PreferenceType {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/resources/database/migrations/08-12-2022_better_preferences.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
TRUNCATE TABLE user_preferences; | ||
|
||
ALTER TABLE user_preferences DROP COLUMN enabled; | ||
|
||
ALTER TABLE user_preferences ADD COLUMN state VARCHAR NOT NULL DEFAULT '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters