ManuelMaccou | Mosaic
ManuelMaccou | Mosaic
Explore posts from servers
RRailway
Created by ManuelMaccou | Mosaic on 2/13/2024 in #βœ‹ο½œhelp
Trying to confirm my volume implementation
I noticed that when making changes to how data is stored in volumes, then redeploying, my data was lost. From looking at other posts with similar issues, it seems the problem might be my mount path in the Railway settings, but I'm hoping to get confirmation of that. Currently, my mount path is /data This is the code for saving the data:
const DATA_DIR = path.join(__dirname, '..', 'data');

const ensureDirectoryExists = (dirPath) => {
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
};

const appendToCSV = async (filename, data) => {
ensureDirectoryExists(DATA_DIR);
const csvPath = path.join(DATA_DIR, `${filename}.csv`);

try {
await new Promise((resolve, reject) => {
fs.appendFile(csvPath, `${data}\n`, (err) => {
if (err) {
console.error('Error appending to CSV:', err);
reject(err); // Reject the promise on error
} else {
console.log('Data appended to CSV:', csvPath);
console.log('Data:', data);
resolve(); // Resolve the promise on success
}
});
});
} catch (error) {
console.error("Error appending to CSV:", error);
}
};

const logActionToCSV = async (fid, uniqueId, product, page) => {
const now = new Date().toISOString();
const productName = product.title.replace(/,/g, '');
const data = `${fid},${now},${productName},${page}`;

appendToCSV(uniqueId, data);
};
const DATA_DIR = path.join(__dirname, '..', 'data');

const ensureDirectoryExists = (dirPath) => {
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
};

const appendToCSV = async (filename, data) => {
ensureDirectoryExists(DATA_DIR);
const csvPath = path.join(DATA_DIR, `${filename}.csv`);

try {
await new Promise((resolve, reject) => {
fs.appendFile(csvPath, `${data}\n`, (err) => {
if (err) {
console.error('Error appending to CSV:', err);
reject(err); // Reject the promise on error
} else {
console.log('Data appended to CSV:', csvPath);
console.log('Data:', data);
resolve(); // Resolve the promise on success
}
});
});
} catch (error) {
console.error("Error appending to CSV:", error);
}
};

const logActionToCSV = async (fid, uniqueId, product, page) => {
const now = new Date().toISOString();
const productName = product.title.replace(/,/g, '');
const data = `${fid},${now},${productName},${page}`;

appendToCSV(uniqueId, data);
};
28 replies
RRailway
Created by ManuelMaccou | Mosaic on 2/10/2024 in #βœ‹ο½œhelp
How do I find the project directory?
This feels like a stupid question but I cant figure it out. I'm trying to append records to a CSV when the user does certain actions. I have the folder made called "data". Using the code below, in test on my local machine, the files are written successfully. And the path in the logs makes sense. But in production, I get an error saying the path doesnt exist. My root folder is "gogh-shopping". But the path where it tries to find the "data" folder is starting with "app". Is that expected? How do I point to the correct directory in prod? Here is my code:
const DATA_DIR = path.join(__dirname, 'data');

const appendToCSV = async (filename, data) => {
const csvPath = path.join(DATA_DIR, `${filename}.csv`);

try {...
const DATA_DIR = path.join(__dirname, 'data');

const appendToCSV = async (filename, data) => {
const csvPath = path.join(DATA_DIR, `${filename}.csv`);

try {...
6 replies
RRailway
Created by ManuelMaccou | Mosaic on 1/27/2024 in #βœ‹ο½œhelp
Is railway down? Getting "upstream connect error"
I'm not able to log in via github or reach the community site to report an issue. Full error showing browser: upstream connect error or disconnect/reset before headers. reset reason: connection timeout In console: Failed to load resource: the server responded with a status of 503 ()
12 replies
RRailway
Created by ManuelMaccou | Mosaic on 11/9/2023 in #βœ‹ο½œhelp
Error: "version `GLIBC_2.36' not found" with Playwright
No description
37 replies
DIAdiscord.js - Imagine a boo! πŸ‘»
Created by ManuelMaccou | Mosaic on 8/1/2023 in #djs-questions
getting partials for reactions when only ID is guaranteed
I just saw this in the d.js docs
WARNING Partial data is only ever guaranteed to contain an ID! Do not assume any property or method to work when dealing with a partial structure!
How for partial reactions, how do we make that work when regular emojis dont have an ID (unless I'm mistaken about that)
11 replies
DIAdiscord.js - Imagine a boo! πŸ‘»
Created by ManuelMaccou | Mosaic on 6/5/2023 in #djs-questions
How to completely removing an emoji, not just the reactions
In my app, the bot automatically adds different emoji reactions when a user creates a message. Afte a certain amount of time, I want that emoji removed. Not just the reactions, but the entire emoji. So far, I've only been able to figure out how to remove the reactions, which result in the default reaction count of 1, but the emoji is still there. Is there a way to remove the emoji entirely? Thanks all
5 replies
DIAdiscord.js - Imagine a boo! πŸ‘»
Created by ManuelMaccou | Mosaic on 6/2/2023 in #djs-questions
Stuck trying to create a map to track votes on messages
I'm trying to allow user to upvote/downvote messages using reactions, as well remove their previous vote. I'm using a map and a map of maps to do this. The problem is that when a user reacts to a message, the map "userMessageVotes" updates correctly, but the map of maps does not. userMessageVotes - A map of a users votes per message messageVotes - A map of maps that has all votes from all users in a message.
const messageVotes = new Map();

if (currentEmoji === 'πŸ‘' || currentEmoji === 'πŸ‘Ž') {
console.log(`Reaction is πŸ‘ or πŸ‘Ž`);
messageUserVotes.set(user.id, currentEmoji);
messageVotes.set(message.id, messageUserVotes);
console.log(`Updated vote for user ${user.id}: ${reaction.emoji.name}`);

console.log(`New messageUserVotes map for message ${message.id}: ${JSON.stringify(Array.from(messageUserVotes.entries()))}`);
console.log(`New messageVotes map for message ${message.id}: ${JSON.stringify(Array.from(messageVotes.entries()))}`);

} else {
console.log(`Reaction is not πŸ‘ or πŸ‘Ž`);
}

if (currentEmoji === 'πŸ‘' || currentEmoji === 'πŸ‘Ž') {
// Check if the opposite reaction exists
const oppositeEmoji = currentEmoji === 'πŸ‘' ? 'πŸ‘Ž' : 'πŸ‘';
const oppositeReaction = message.reactions.cache.find(r => r.emoji.name === oppositeEmoji);

// If the opposite reaction exists, remove it
if (oppositeReaction) {
await oppositeReaction.users.remove(user.id);
}

// Get previous vote
const previousVote = messageUserVotes.get(user.id) || null;
console.log(`Previous vote for user ${user.id}: ${previousVote}`);

const data = {...
const messageVotes = new Map();

if (currentEmoji === 'πŸ‘' || currentEmoji === 'πŸ‘Ž') {
console.log(`Reaction is πŸ‘ or πŸ‘Ž`);
messageUserVotes.set(user.id, currentEmoji);
messageVotes.set(message.id, messageUserVotes);
console.log(`Updated vote for user ${user.id}: ${reaction.emoji.name}`);

console.log(`New messageUserVotes map for message ${message.id}: ${JSON.stringify(Array.from(messageUserVotes.entries()))}`);
console.log(`New messageVotes map for message ${message.id}: ${JSON.stringify(Array.from(messageVotes.entries()))}`);

} else {
console.log(`Reaction is not πŸ‘ or πŸ‘Ž`);
}

if (currentEmoji === 'πŸ‘' || currentEmoji === 'πŸ‘Ž') {
// Check if the opposite reaction exists
const oppositeEmoji = currentEmoji === 'πŸ‘' ? 'πŸ‘Ž' : 'πŸ‘';
const oppositeReaction = message.reactions.cache.find(r => r.emoji.name === oppositeEmoji);

// If the opposite reaction exists, remove it
if (oppositeReaction) {
await oppositeReaction.users.remove(user.id);
}

// Get previous vote
const previousVote = messageUserVotes.get(user.id) || null;
console.log(`Previous vote for user ${user.id}: ${previousVote}`);

const data = {...
2 replies
DIAdiscord.js - Imagine a boo! πŸ‘»
Created by ManuelMaccou | Mosaic on 5/31/2023 in #djs-questions
message.channel.parent undefined in forum channel?
I'm getting an error where message.channel.parent is undefined. My intention is to cross-check the forum channel in which a user posts to make sure it's an "allowed channel". Am I not using this correctly to identify the parent forum channel of a new thread?
13 replies
DIAdiscord.js - Imagine a boo! πŸ‘»
Created by ManuelMaccou | Mosaic on 4/23/2023 in #djs-questions
Trying to get the content from the parent message in a forum post
I feel a little silly asking this because it's probably obvious. In a forum channel, I'm trying to get the content of the first message that started the forum post. The name, or title, is easy with message.channel.name But I cant figure out how to get the content.
2 replies
DIAdiscord.js - Imagine a boo! πŸ‘»
Created by ManuelMaccou | Mosaic on 4/9/2023 in #djs-questions
Sending messages from a forum channel to database, but unable to grab the tags
Everything is going through to my database from Discord, but I cant figure out how to grab the tags and the tag IDs. I've tried a few things...with the help of our AI overlords...but still no luck. Below is the section of the code where I try to grab the tag id client.on('messageCreate', async (message) => { if (message.author.bot) return; let appliedTags = []; if (message.channel.type === "GUILD_FORUM") { if (message.thread) { appliedTags = message.channel.availableTags.filter(tag => message.thread.metadata.appliedTags.includes(tag.id)); } else { console.log("No "thread" property."); } }
31 replies
DIAdiscord.js - Imagine a boo! πŸ‘»
Created by ManuelMaccou | Mosaic on 4/8/2023 in #djs-questions
How to specify the ID of a forum channel?
I have an app that sends messages to a database if they are in the pre-approved channel. I'm using the code below. This works fine when the message comes from a regular channel, but not a forum channel. Should channel.id be something else for forum channels? if (allowedChannels.some(channel => channel.channel_id === message.channel.id))
5 replies