Skip to content

ClaireLang - Multi-language support and placeholders #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
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
22 changes: 17 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@ jar {
}

group 'com.sidpatchy'
version '3.3.3'
version '3.4.0-SNAPSHOT'

processResources {
filesMatching('**/build.properties') {
expand(
version: project.version,
buildDate: new Date().format("yyyy-MM-dd HH:mm:ss")
)
}
}

sourceCompatibility = 17
targetCompatibility = 17
kotlin {
jvmToolchain(17)
}

repositories {
mavenLocal()
mavenCentral()
maven { url 'https://m2.dv8tion.net/releases' }
maven { url 'https://jitpack.io' }
Expand All @@ -27,7 +38,7 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1'

implementation 'com.github.Sidpatchy:Robin:2.0.0'
implementation 'com.github.Sidpatchy:Robin:2.2.4'

implementation 'org.javacord:javacord:3.8.0'

Expand All @@ -40,7 +51,8 @@ dependencies {

implementation 'org.yaml:snakeyaml:2.0'
implementation 'org.json:json:20231013'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.16.1'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.18.0'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.18.0'

}

Expand Down
134 changes: 134 additions & 0 deletions code_of_conduct.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@

# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or advances of
any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address,
without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official email address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
`[email protected]` or `@sidpatchy` on the Discord.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series of
actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within the
community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.1, available at
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].

Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].

For answers to common questions about this code of conduct, see the FAQ at
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
[https://www.contributor-covenant.org/translations][translations].

[homepage]: https://www.contributor-covenant.org
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations

89 changes: 44 additions & 45 deletions src/main/java/com/sidpatchy/clairebot/API/APIUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class APIUser {
private final String userID;
Expand Down Expand Up @@ -72,72 +72,67 @@ public String getLanguage() {
*
* @return the value of pointsGuildID
*/
public ArrayList<String> getPointsGuildID() {
return (ArrayList<String>) user.getList("pointsGuildID")
.stream()
.map(Object::toString)
.collect(Collectors.toList());
public List<String> getPointsGuildID() {
return user.getList("pointsGuildID", String.class);
}

/**
*
* @return
*/
public ArrayList<Integer> getPointsMessages() {
return (ArrayList<Integer>) user.getList("pointsMessages")
.stream()
.filter(Integer.class::isInstance)
.map(Integer.class::cast)
.collect(Collectors.toList());
public List<Integer> getPointsMessages() {
return user.getList("pointsMessages", Integer.class);
}

public ArrayList<Integer> getPointsVoiceChat() {
return (ArrayList<Integer>) user.getList("pointsVoiceChat")
.stream()
.filter(Integer.class::isInstance)
.map(Integer.class::cast)
.collect(Collectors.toList());
public List<Integer> getPointsVoiceChat() {
return user.getList("pointsVoiceChat", Integer.class);
}

public void createUser(String accentColour,
String language,
ArrayList<String> pointsGuildID,
ArrayList<Integer> pointsMessages,
ArrayList<Integer> pointsVoiceChat) throws IOException {
List<String> pointsGuildID,
List<Integer> pointsMessages,
List<Integer> pointsVoiceChat) throws IOException {
POST post = new POST();
post.postToURL(Main.getApiPath() + "api/v1/user/", userConstructor(accentColour, language, pointsGuildID, pointsMessages, pointsVoiceChat));
}

public void createUserWithDefaults() {
Map<String, Object> defaults = Main.getUserDefaults();
RobinConfiguration.RobinSection defaults = new RobinConfiguration.RobinSection(Main.getUserDefaults());

try {
createUser(
(String) defaults.get("accentColour"),
(String) defaults.get("language"),
(ArrayList<String>) defaults.get("pointsGuildID"),
(ArrayList<Integer>) defaults.get("pointsMessages"),
(ArrayList<Integer>) defaults.get("pointsVoiceChat")
defaults.getString("accentColour"),
defaults.getString("language"),
defaults.getList("pointsGuildID", String.class),
defaults.getList("pointsMessages", Integer.class),
defaults.getList("pointsVoiceChat", Integer.class)
);
}
// top 10 bad ideas #1
catch (Exception ignored) {
ignored.printStackTrace();
Main.getLogger().error("Unable to create user with defaults.");
catch (Exception e) {
Main.getLogger().error("Unable to create user with defaults.", e);
}
createNewWithDefaults = false; // prevent recursion if ClaireData goes down.
}

public void updateUser(String accentColour,
String language,
ArrayList<String> pointsGuildID,
ArrayList<Integer> pointsMessages,
ArrayList<Integer> pointsVoiceChat) throws IOException {
List<String> pointsGuildID,
List<Integer> pointsMessages,
List<Integer> pointsVoiceChat) throws IOException {
// Add null check and fallback for language
if (language == null) {
new Exception("Language null origin trace").printStackTrace();
}

PUT put = new PUT();
put.putToURL(Main.getApiPath() + "api/v1/user/" + userID, userConstructor(accentColour, language, pointsGuildID, pointsMessages, pointsVoiceChat));
put.putToURL(Main.getApiPath() + "api/v1/user/" + userID,
userConstructor(accentColour, language, pointsGuildID, pointsMessages, pointsVoiceChat));
}

public void updateUserColour(String accentColour) throws IOException {
// Ensure that the values for the getters below are populated before querying.
getUser();
updateUser(accentColour,
getLanguage(),
getPointsGuildID(),
Expand All @@ -147,6 +142,8 @@ public void updateUserColour(String accentColour) throws IOException {
}

public void updateUserLanguage(String languageString) throws IOException {
// Ensure that the values for the getters below are populated before querying.
getUser();
updateUser(getAccentColour(),
languageString,
getPointsGuildID(),
Expand All @@ -155,14 +152,16 @@ public void updateUserLanguage(String languageString) throws IOException {
}

public void updateUserPointsGuildID(String guildID, Integer newPoints) throws IOException {
updateUserPointsGuildID((ArrayList<String>) LevelingTools.updateUserPoints(userID, guildID, newPoints));
updateUserPointsGuildID(LevelingTools.updateUserPoints(userID, guildID, newPoints));
}

public void updateUserPointsGuildID(Map<String, Integer> guildPointsToUpdate) throws IOException {
updateUserPointsGuildID((ArrayList<String>) LevelingTools.updateUserPoints(userID, guildPointsToUpdate));
updateUserPointsGuildID(LevelingTools.updateUserPoints(userID, guildPointsToUpdate));
}

public void updateUserPointsGuildID(ArrayList<String> pointsGuildID) throws IOException {
public void updateUserPointsGuildID(List<String> pointsGuildID) throws IOException {
// Ensure that the values for the getters below are populated before querying.
getUser();
updateUser(getAccentColour(),
getLanguage(),
pointsGuildID,
Expand All @@ -187,18 +186,18 @@ public void deleteUser() throws IOException {
*/
public String userConstructor(String accentColour,
String language,
ArrayList<String> pointsGuildID,
ArrayList<Integer> pointsMessages,
ArrayList<Integer> pointsVoiceChat) {
List<String> pointsGuildID,
List<Integer> pointsMessages,
List<Integer> pointsVoiceChat) {
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode userNode = objectMapper.createObjectNode();

userNode.put("userID", userID);
userNode.put("accentColour", accentColour);
userNode.put("language", language);
userNode.put("pointsGuildID", objectMapper.valueToTree(pointsGuildID));
userNode.put("pointsMessages", objectMapper.valueToTree(pointsMessages));
userNode.put("pointsVoiceChat", objectMapper.valueToTree(pointsVoiceChat));
userNode.set("pointsGuildID", objectMapper.valueToTree(pointsGuildID));
userNode.set("pointsMessages", objectMapper.valueToTree(pointsMessages));
userNode.set("pointsVoiceChat", objectMapper.valueToTree(pointsVoiceChat));

return userNode.toString();
}
Expand Down Expand Up @@ -235,4 +234,4 @@ private void fixUserPointsGuildID() throws IOException {
updateUserPointsGuildID((ArrayList<String>) defaults.get("pointsGuildID"));
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/sidpatchy/clairebot/Clockwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Helper extends TimerTask {
public void run() {
try {
config.loadFromURL("https://raw.githubusercontent.com/nikolaischunk/discord-phishing-links/main/domain-list.json");
Clockwork.setPhishingDomains(config.getList("domains")
Clockwork.setPhishingDomains(config.getList("domains", String.class)
.stream()
.map(Object::toString)
.collect(Collectors.toList()));
Expand Down
Loading