-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
154 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,7 @@ node_modules | |
tmp | ||
.env | ||
.git | ||
.gitignore | ||
.gitignore | ||
|
||
/cookies.txt | ||
/config.json |
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,2 @@ | ||
/cookies.txt | ||
/config.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { SlashCommandBuilder } = require('discord.js'); | ||
const configStore = require('../../config-store'); | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName('cfg-delete') | ||
.setDescription('Deletes a key from the config store.') | ||
.addStringOption(option => option.setName('key') | ||
.setDescription('The key to delete.') | ||
.setRequired(true)), | ||
async execute(interaction) { | ||
if (interaction.user.id !== process.env.OWNER_ID) { | ||
await interaction.reply({ content: 'You do not have permission to run this command.', ephemeral: true }); | ||
return; | ||
} | ||
configStore.delete(interaction.options.getString('key')); | ||
await interaction.reply(`Deleted \`${interaction.options.getString('key')}\`.`, { ephemeral: true }); | ||
}, | ||
}; |
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,18 @@ | ||
const { SlashCommandBuilder } = require('discord.js'); | ||
const configStore = require('../../config-store'); | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName('cfg-get') | ||
.setDescription('Gets a key from the config store.') | ||
.addStringOption(option => option.setName('key') | ||
.setDescription('The key to get.') | ||
.setRequired(true)), | ||
async execute(interaction) { | ||
if (interaction.user.id !== process.env.OWNER_ID) { | ||
await interaction.reply({ content: 'You do not have permission to run this command.', ephemeral: true }); | ||
return; | ||
} | ||
await interaction.reply(`The value of \`${interaction.options.getString('key')}\` is: \`${configStore.get(interaction.options.getString('key'))}\``, { ephemeral: true }); | ||
}, | ||
}; |
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,15 @@ | ||
const { SlashCommandBuilder } = require('discord.js'); | ||
const configStore = require('../../config-store'); | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName('cfg-list') | ||
.setDescription('Lists all the keys in the config store.'), | ||
async execute(interaction) { | ||
if (interaction.user.id !== process.env.OWNER_ID) { | ||
await interaction.reply({ content: 'You do not have permission to run this command.', ephemeral: true }); | ||
return; | ||
} | ||
await interaction.reply(`The keys in the config store are: \`${JSON.stringify(configStore.list())}\``, { ephemeral: true }); | ||
}, | ||
}; |
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,22 @@ | ||
const { SlashCommandBuilder } = require('discord.js'); | ||
const configStore = require('../../config-store'); | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName('cfg-set') | ||
.setDescription('Sets a key in the config store.') | ||
.addStringOption(option => option.setName('key') | ||
.setDescription('The key to set.') | ||
.setRequired(true)) | ||
.addStringOption(option => option.setName('value') | ||
.setDescription('The value to set.') | ||
.setRequired(true)), | ||
async execute(interaction) { | ||
if (interaction.user.id !== process.env.OWNER_ID) { | ||
await interaction.reply({ content: 'You do not have permission to run this command.', ephemeral: true }); | ||
return; | ||
} | ||
configStore.set(interaction.options.getString('key'), interaction.options.getString('value')); | ||
await interaction.reply(`Set \`${interaction.options.getString('key')}\` to \`${interaction.options.getString('value')}\`.`, { ephemeral: true }); | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const fs = require('node:fs'); | ||
|
||
class ConfigStore { | ||
/** | ||
* @param {string} fPath | ||
*/ | ||
constructor(fPath) { | ||
this.fPath = fPath; | ||
if (!fs.existsSync(this.fPath)) { | ||
fs.writeFileSync(this.fPath, '{}'); | ||
} | ||
this.config = this.readFromFile(); | ||
} | ||
|
||
readFromFile() { | ||
return JSON.parse(fs.readFileSync(this.fPath, 'utf8')); | ||
} | ||
|
||
writeToFile() { | ||
fs.writeFileSync(this.fPath, JSON.stringify(this.config, null, 2)); | ||
} | ||
|
||
list() { | ||
return Object.keys(this.config); | ||
} | ||
|
||
/** | ||
* @param {string} key | ||
*/ | ||
get(key) { | ||
return this.config[key]; | ||
} | ||
|
||
getOr(key, defaultValue) { | ||
return this.config[key] || defaultValue; | ||
} | ||
|
||
/** | ||
* @param {string} key | ||
* @param {any} value | ||
*/ | ||
set(key, value) { | ||
this.config[key] = value; | ||
this.writeToFile(); | ||
} | ||
|
||
/** | ||
* @param {string} key | ||
*/ | ||
delete(key) { | ||
delete this.config[key]; | ||
this.writeToFile(); | ||
} | ||
} | ||
|
||
module.exports = new ConfigStore('./config.json'); |