Skip to content

Commit

Permalink
Merge pull request #3 from quark-bot-discord/development
Browse files Browse the repository at this point in the history
25th June Update
  • Loading branch information
Starman3787 authored Jun 22, 2024
2 parents d403332 + d7c292a commit 32cf0fa
Show file tree
Hide file tree
Showing 63 changed files with 1,487 additions and 89 deletions.
9 changes: 5 additions & 4 deletions .github/scripts/validate-slash_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ try {
console.error(`Validation error: ${directory}/${file}: Description exceeds 100 characters at '${currentPath}'`);
foundErrors = true;
}
if (currentPath.endsWith('.name') && value.includes(' ')) {
console.error(`Validation error: ${directory}/${file}: Name contains space at '${currentPath}'`);

if (currentPath.endsWith('.name') && value.match(/^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$/gu) == null) {
console.error(`Validation error: ${directory}/${file}: Name does not match regex at '${currentPath}', VALUE: ${value}`);
foundErrors = true;
}
if (value !== value.toLowerCase() && currentPath.endsWith('name')) {
Expand All @@ -62,8 +63,8 @@ try {

checkFields(jsonData);

if (jsonData.name && jsonData.name.includes(' ')) {
console.error(`Validation error: ${directory}/${file}: Name contains space at 'name'`);
if (jsonData.name && jsonData.name.match(/^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$/gu) == null) {
console.error(`Validation error: ${directory}/${file}: Name does not match regex, VALUE: ${jsonData.name}`);
foundErrors = true;
} else if (jsonData.description && jsonData.description.length > 100) {
console.error(`Validation error: ${directory}/${file}: Description exceeds 100 characters at 'description'`);
Expand Down
131 changes: 75 additions & 56 deletions activate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,93 @@ const path = require('path');
const fallbackLanguage = "en_us";

const baseDirectory = "bot";
const baseDirectoryActive = "active/bot";
const languages = require('./bot/languages.json');

const languagesLocation = path.join(process.cwd(), "language", baseDirectory);
const activeLanguagesLocation = path.join(process.cwd(), "language", "active", baseDirectory);

// relative file path is the path after the locale directory
function loadFile(locale, relativeFilePath) {

const filePath = path.join(languagesLocation, locale, relativeFilePath);

try {
let data;
if (!fs.existsSync(filePath))
data = "{}";
else
data = fs.readFileSync(filePath, 'utf8');
const jsonData = JSON.parse(data);
const fallbackLanguageData = JSON.parse(fs.readFileSync(path.join(languagesLocation, fallbackLanguage, relativeFilePath), 'utf8'));
function checkFields(obj, path = '') {
Object.keys(obj).forEach(key => {
const value = obj[key];
const currentPath = path ? `${path}.${key}` : key;

if (typeof value === 'string') {
let pointer = fallbackLanguageData;
const structPath = currentPath.split(".");
for (let i = 0; i < structPath.length - 1; i++) {
pointer = pointer[structPath[i]];
}
pointer[structPath[structPath.length - 1]] = value;
} else if (typeof value === 'object' && value !== null) {
checkFields(value, currentPath);
}
});
}

checkFields(jsonData);

const absolutePathToActiveSubdirectory = path.join(activeLanguagesLocation, locale, relativeFilePath);

if (!fs.existsSync(path.dirname(absolutePathToActiveSubdirectory)))
fs.mkdirSync(path.dirname(absolutePathToActiveSubdirectory), { recursive: true });

fs.writeFileSync(absolutePathToActiveSubdirectory, JSON.stringify(fallbackLanguageData), { recursive: true });

} catch (err) {
console.error(`Error processing ${filePath}:`, err);
foundErrors = true;
}

}

function loadSubdirectory(locale, relativePath) {
const absolutePath = path.join(languagesLocation, fallbackLanguage, relativePath);
const subdirectories = fs.readdirSync(absolutePath, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
const subfiles = fs.readdirSync(absolutePath, { withFileTypes: true })
.filter(dirent => !dirent.isDirectory())
.map(dirent => dirent.name);
for (let i = 0; i < subdirectories.length; i++) {
const subdirectoryPath = path.join(relativePath, subdirectories[i]);
loadSubdirectory(locale, subdirectoryPath);
}
for (let i = 0; i < subfiles.length; i++) {
const filePath = path.join(relativePath, subfiles[i]);
loadFile(locale, filePath);
}
}

function activate() {
Object.entries(languages).forEach(([key, value]) => {
const directory = path.join(process.cwd(), "languages", baseDirectory, value, "standard");

const directory = path.join(process.cwd(), baseDirectory, value);
console.log(`Processing language code ${key}...`);
if (!fs.existsSync(directory)) {
console.log(`Skipping non-existent directory: ${directory} for language code ${key}`);
return;
}

const files = fs.readdirSync(directory);
if (files.length === 0) {
console.log(`No JSON files found in ${directory}.`);
return;
}

const activeLanguageBotStandardDirectory = path.join(process.cwd(), "languages", baseDirectoryActive, value, "standard");

if (!fs.existsSync(activeLanguageBotStandardDirectory))
fs.mkdirSync(activeLanguageBotStandardDirectory, { recursive: true });

files.forEach(file => {
if (!file.endsWith('.json')) {
console.log(`Skipping non-JSON file: ${file}`);
return;
}

console.log(`Copying ${value}/${file}...`);
const filePath = path.join(directory, file);
try {
const data = fs.readFileSync(filePath, 'utf8');
const jsonData = JSON.parse(data);
const fallbackLanguageData = require(`./${baseDirectory}/${fallbackLanguage}/standard/${file}`);
function checkFields(obj, path = '') {
Object.keys(obj).forEach(key => {
const value = obj[key];
const currentPath = path ? `${path}.${key}` : key;

if (typeof value === 'string') {
let pointer = fallbackLanguageData;
const structPath = currentPath.split(".");
for (let i = 0; i < structPath.length - 1; i++) {
pointer = pointer[structPath[i]];
}
pointer[structPath[structPath.length - 1]] = value;
} else if (typeof value === 'object' && value !== null) {
checkFields(value, currentPath);
}
});
}

checkFields(jsonData);

if (!fs.existsSync(activeLanguageBotStandardDirectory))
fs.mkdirSync(activeLanguageBotStandardDirectory, { recursive: true });

fs.writeFileSync(path.join(activeLanguageBotStandardDirectory, file), JSON.stringify(fallbackLanguageData));
if (!fs.existsSync(activeLanguagesLocation))
fs.mkdirSync(activeLanguagesLocation, { recursive: true });

} catch (err) {
console.error(`Error processing ${file}:`, err);
foundErrors = true;
}
});
console.log(`Copying ${directory}...`);
loadSubdirectory(value, "/");

});

}

module.exports = activate;
module.exports = activate;
3 changes: 3 additions & 0 deletions bot/en_gb/channel_update_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"none": "none"
}
4 changes: 4 additions & 0 deletions bot/en_gb/command_responses.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
"setserverlog-enable-status-updates": "Enable Status Updates!",
"setserverlog-enable-status-updates-desc": "Get notified of all the latest updates, downtime, and other important communications from the developers!",
"setserverlog-enable-status-updates-desc-1": "We highly recommend you enable this in one of your channels!",
"setserverlog-check-permissions": "Please ensure Quark has permission to send messages in this channel, or the channel will be unset.",

"festive-title": "Free Festive Gift!",
"festive-claim": "Claim your free gift!",

"help-overview-website-description": "Easily set up and manage Quark from the [web dashboard]!",
"help-overview-inventory-description": "Manage your subscriptions or get some [Quark Pro] features for free!",
Expand Down
3 changes: 3 additions & 0 deletions bot/en_gb/emoji_update_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"none": "none"
}
12 changes: 6 additions & 6 deletions bot/en_gb/standard/channelEvents.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"channelCreated": {
"title": "Channel Created",
"title": "{type} Channel Created",
"description": "{channel} was created by {executor}",
"descriptionWithCategory": "{channel} was created by {executor} under the {category} category."
},
"channelDeleted": {
"title": "Channel Deleted",
"title": "{type} Channel Deleted",
"description": "{channel_name} was deleted by {executor}",
"channel": "Channel"
},
"channelUpdated": {
"title": "Channel Modified",
"title": "{type} Channel Modified",
"description": "{channel} was modified by {executor}"
},
"channelOverwriteCreate": {
"title": "Channel Permissions Added",
"title": "{type} Channel Permissions Added",
"description": "{executor} added permissions to {channel} for {special}"
},
"channelOverwriteDelete": {
"title": "Channel Permissions Removed",
"title": "{type} Channel Permissions Removed",
"description": "{executor} removed permissions from {channel} for {special}"
},
"channelOverwriteUpdate": {
"title": "Channel Permissions Updated",
"title": "{type} Channel Permissions Updated",
"description": "{executor} updated permissions for {channel} for {special}",
"newPermissions": "New Permissions",
"viewFullNewPermissions": "View Full New Permissions"
Expand Down
24 changes: 23 additions & 1 deletion bot/en_gb/standard/serverActions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"description_withoutInviter": "An invite {invite} was created for {channel}",
"expires": "Expires",
"never": "Never",
"maxUses": "Max Uses"
"maxUses": "Max Uses",
"none": "none"
},
"inviteDelete": {
"title": "Invite Deleted",
Expand All @@ -27,5 +28,26 @@
"emojiUpdated": {
"title": "Emoji Edited",
"description": "{emoji} was edited by {executor}"
},
"serverEventCreate": {
"title": "Event Created",
"description_withChannel": "{executor} created an event {name} in {channel}",
"description_withoutChannel": "{executor} created an event {name}",
"eventDescription": "Description",
"location": "Location",
"starts": "Starts"
},
"serverEventDelete": {
"title": "Event Deleted",
"description": "{executor} deleted the event {name}",
"linkToEventImage": "Link to event image"
},
"serverEventUpdate": {
"title": "Event Updated",
"description": "{executor} updated the event {name}",
"newEventDescription": "New Description",
"newLocation": "New Location",
"newChannel": "New Channel",
"linkToEventImage": "Link to old event image"
}
}
35 changes: 34 additions & 1 deletion bot/en_gb/standard/voiceEvents.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
},
"voiceLeave": {
"title": "Left Channel",
"description": "{user} left the {channel} voice channel"
"description": "{user} left the {channel} voice channel",
"joined": "Joined",
"joinedValue": "{relative} for {relative_fixed}"
},
"voiceDisconnect": {
"title": "Disconnected",
Expand Down Expand Up @@ -67,5 +69,36 @@
"description": "{executor} set the status for {channel}",
"status": "Status",
"linksToEmojis": "Links to emojis"
},
"stageStarted": {
"title": "Stage Started",
"description": "{executor} started a stage in {channel}",
"topic": "Topic"
},
"stageEnded": {
"title": "Stage Ended",
"description": "The stage in {channel} was ended by {executor}",
"description_noExecutor": "The stage in {channel} was ended",
"topic": "Topic",
"none": "none"
},
"stageUpdated": {
"title": "Stage Updated",
"description": "The stage in {channel} was updated by {executor}",
"oldTopic": "Old Topic",
"newTopic": "New Topic"
},
"stageSpeakerAdd": {
"title": "New Stage Speaker",
"description": "{user} became a speaker in the {channel} stage channel",
"description_inviteAccepted": "{user} accepted the invite to become a speaker in the {channel} stage channel"
},
"stageSpeakerRemove": {
"title": "Stopped Speaking",
"description": "{user} is no longer a speaker in the {channel} stage channel"
},
"stageSpeakerInvited": {
"title": "Speaker Invited",
"description": "{user} was invited to speak in the {channel} stage channel"
}
}
16 changes: 16 additions & 0 deletions bot/en_gb/time.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"second": "{time} second",
"second-plural": "{time} seconds",
"minute": "{time} minute",
"minute-plural": "{time} minutes",
"hour": "{time} hour",
"hour-plural": "{time} hours",
"day": "{time} day",
"day-plural": "{time} days",
"week": "{time} week",
"week-plural": "{time} weeks",
"month": "{time} month",
"month-plural": "{time} months",
"year": "{time} year",
"year-plural": "{time} years"
}
3 changes: 3 additions & 0 deletions bot/en_pr/channel_update_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"none": "none"
}
4 changes: 4 additions & 0 deletions bot/en_pr/command_responses.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
"setserverlog-enable-status-updates": "Enable Status Updates!",
"setserverlog-enable-status-updates-desc": "Get notified of all the latest updates, downtime, and other important communications from the developers!",
"setserverlog-enable-status-updates-desc-1": "We highly recommend you enable this in one of your channels!",
"setserverlog-check-permissions": "Please ensure Quark has permission to send messages in this channel, or the channel will be unset.",

"festive-title": "Free Festive Gift!",
"festive-claim": "Claim your free gift!",

"help-overview-website-description": "Easily set up and manage Quark from the [web dashboard]!",
"help-overview-inventory-description": "Manage your subscriptions or get some [Quark Pro] features for free!",
Expand Down
3 changes: 3 additions & 0 deletions bot/en_pr/emoji_update_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"none": "none"
}
12 changes: 6 additions & 6 deletions bot/en_pr/standard/channelEvents.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"channelCreated": {
"title": "Channel Created",
"title": "{type} Channel Created",
"description": "{channel} was created by {executor}",
"descriptionWithCategory": "{channel} was created by {executor} under the {category} category."
},
"channelDeleted": {
"title": "Channel Deleted",
"title": "{type} Channel Deleted",
"description": "{channel_name} was deleted by {executor}",
"channel": "Channel"
},
"channelUpdated": {
"title": "Channel Modified",
"title": "{type} Channel Modified",
"description": "{channel} was modified by {executor}"
},
"channelOverwriteCreate": {
"title": "Channel Permissions Added",
"title": "{type} Channel Permissions Added",
"description": "{executor} added permissions to {channel} for {special}"
},
"channelOverwriteDelete": {
"title": "Channel Permissions Removed",
"title": "{type} Channel Permissions Removed",
"description": "{executor} removed permissions from {channel} for {special}"
},
"channelOverwriteUpdate": {
"title": "Channel Permissions Updated",
"title": "{type} Channel Permissions Updated",
"description": "{executor} updated permissions for {channel} for {special}",
"newPermissions": "New Permissions",
"viewFullNewPermissions": "View Full New Permissions"
Expand Down
Loading

0 comments on commit 32cf0fa

Please sign in to comment.