Implement Dynamic Presence #19
## Added Dynamic Presence to Functions - Added default to startup - Added to RSS manager - Added to interaction create event - Added to message create function ## Related Work #15 ### LinkCop - Updated with new regex string and logic approved and restricted channels - Implemented new config storage ### Guild Member Add (event) - Implemented new config storage for welcome channel ### Message Create (event) - Implemented new config storage for ignored channel IDs - Improved the logic for gpt interactions to reset presence ### Mongo Config Wrappers - Updated logic in order to handle different data types the same way - Updated set functions to wrap the value in the key - Updated get functions to return the keyyed value ie `config[key]`
This commit is contained in:
@@ -8,9 +8,9 @@ const collectionName = 'configurations';
|
||||
// Function to get a configuration by key
|
||||
export const getConfig = async (key) => {
|
||||
try {
|
||||
const config = await getDocumentByField(collectionName, '_id', key);
|
||||
const config = await getDocumentByField(collectionName, 'key', key);
|
||||
log.DEBUG(`Configuration for key "${key}" retrieved:`, config);
|
||||
return config || null; // Return null if no configuration is found
|
||||
return config ? config[key] : null; // Return null if no configuration is found
|
||||
} catch (error) {
|
||||
log.ERROR('Error retrieving configuration:', error);
|
||||
throw error;
|
||||
@@ -19,8 +19,10 @@ export const getConfig = async (key) => {
|
||||
|
||||
// Function to set a configuration by key
|
||||
export const setConfig = async (key, value) => {
|
||||
// Set the config object
|
||||
value = {key : value};
|
||||
try {
|
||||
const result = await upsertDocumentByField(collectionName, '_id', key, value);
|
||||
const result = await upsertDocumentByField(collectionName, 'key', key, value);
|
||||
log.DEBUG(`Configuration for key "${key}" set:`, value, result);
|
||||
return result > 0 ? key : null; // Return key if updated successfully, otherwise null
|
||||
} catch (error) {
|
||||
@@ -32,7 +34,7 @@ export const setConfig = async (key, value) => {
|
||||
// Function to delete a configuration by key (optional)
|
||||
export const deleteConfig = async (key) => {
|
||||
try {
|
||||
const result = await deleteDocumentByField(collectionName, '_id', key);
|
||||
const result = await deleteDocumentByField(collectionName, 'key', key);
|
||||
log.DEBUG(`Configuration for key "${key}" deleted:`, result);
|
||||
return result; // Return the count of deleted documents
|
||||
} catch (error) {
|
||||
@@ -44,9 +46,9 @@ export const deleteConfig = async (key) => {
|
||||
// Function to get a configuration by key for a specific guild
|
||||
export const getGuildConfig = async (guildId, key) => {
|
||||
try {
|
||||
const config = await getDocumentByFields(collectionName, ['guildId', guildId], ['_id', key]);
|
||||
const config = await getDocumentByFields(collectionName, ['guildId', guildId], ['key', key]);
|
||||
log.DEBUG(`Guild ${guildId} configuration for key "${key}" retrieved:`, config);
|
||||
return config || null; // Return null if no configuration is found
|
||||
return config ? config[key] : null; // Return null if no configuration is found
|
||||
} catch (error) {
|
||||
log.ERROR('Error retrieving guild configuration:', error);
|
||||
throw error;
|
||||
@@ -55,8 +57,10 @@ export const getGuildConfig = async (guildId, key) => {
|
||||
|
||||
// Function to set a configuration by key for a specific guild
|
||||
export const setGuildConfig = async (guildId, key, value) => {
|
||||
// Set the config object
|
||||
value = {key : value};
|
||||
try {
|
||||
const result = await upsertDocumentByFields(collectionName, value, ['guildId', guildId], ['_id', key]);
|
||||
const result = await upsertDocumentByFields(collectionName, value, ['guildId', guildId], ['key', key]);
|
||||
log.DEBUG(`Guild ${guildId} configuration for key "${key}" set:`, value);
|
||||
return result > 0 ? key : null; // Return key if updated successfully, otherwise null
|
||||
} catch (error) {
|
||||
@@ -68,7 +72,7 @@ export const setGuildConfig = async (guildId, key, value) => {
|
||||
// Function to delete a configuration by key for a specific guild (optional)
|
||||
export const deleteGuildConfig = async (guildId, key) => {
|
||||
try {
|
||||
const result = await deleteDocumentByFields(collectionName, ['guildId', guildId], ['_id', key]);
|
||||
const result = await deleteDocumentByFields(collectionName, ['guildId', guildId], ['key', key]);
|
||||
log.DEBUG(`Guild ${guildId} configuration for key "${key}" deleted:`, result);
|
||||
return result; // Return the count of deleted documents
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user