How to handle action state "INCOMPLETE" - salesforce

The example https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm has
if (state === "SUCCESS") {
.......
}
else if (state === "INCOMPLETE") {
// do something
}
else if (state === "ERROR") {
......
What should "do something" be?
I've seen so many examples with "do something", including the code I wrote, that I'd thought I should stop doing this (copy and paste) and do something about it, pun intended.

Related

Discord.js V.13 collect once with Collector

I'm making a suggest system for my bot which starts of with the user pressing a button in a channel which then prompts them to say what they want to suggest and then their suggestion gets sent to a different channel where others can vote on it. So what I want to make it do is I want it to create a createMessageComponentCollector and then register all the good/bad votes under a a period of 24h, if the suggestion got 10 good votes it's approved, otherwise it's not. Here is my code for it so far but what I'm having issue with is to start the ComponentCollector one time and then make it register the votes for each suggestion. this is the part of my code that I'm having trouble with
client.channels.cache.get("909420357285474334").send({ embeds:[embed], components:[row] })
const filter1 = m => m.customId === "Yes" && i.messageId === interaction.messageId
collector1 = interaction.channel.createMessageComponentCollector({filter: filter1, time: 86400000});
const filter2 = m => m.customId === "No" && i.messageId === interaction.messageId
collector2 = interaction.channel.createMessageComponentCollector({filter: filter2, time: 86400000});
if (interaction.customId === "Yes") {
collector1.on('collect', async i => {
client.logger("collector1 collected")
});
collector1.on('end', collected => {
client.logger(collected.size)
// if (collected.size < 10) {
// }
});
}
if (interaction.customId === "No") {
collector2.on('collect', async i => {
client.logger("collector2 collected")
});
collector2.on('end', collected => {
client.logger(collected.size)
// if (collected.size < 10) {
// }
});
}
your question is a little bit unclear but I think I get what your looking for, if you want to check if a user already has pressed a button you could add them to a Set() constructor, now you need to set a new Set() which you can define in your startup file like this:
client.alreadyPressed = new Set()
and when you've done that one possible way to do it in your suggestion code could be like this:
collector1.on('collect', async i => {
client.logger("collector1 collected")
if (client.alreadyPressed.has(interaction.user.id)) {
i.reply({ content: `You've already voted ${i.user.username}!`, ephemeral: true })
return;
} else {
i.reply({ content: `Thank you for your vote ${i.user.username}!`, ephemeral: true });
}
client.alreadyPressed.add(i.user.id)
});
collector1.on('end', collected => {
client.logger(collected.size)
// if (collected.size < 10) {
// }
});
collector2.on('collect', async i => {
client.logger("collector2 collected")
if (client.alreadyPressed.has(interaction.user.id)) {
i.reply({ content: `You've already voted ${i.user.username}!`, ephemeral: true })
return;
} else {
i.reply({ content: `Thank you for your vote ${i.user.username}!`, ephemeral: true });
}
client.alreadyPressed.add(i.user.id)
});
collector2.on('end', collected => {
client.logger(collected.size)
// if (collected.size < 10) {
// }
});
one problem with this is that they only can vote once in the whole channel which im not sure if that's what you wanted

Discord await messages timing out | Discord V12

I am stuck on a problem. When "Player 2" (player[1]) types !yes in the channel then reason it times out. I'm not sure what I am doing wrong. player[1] is defined as msg.mentions.members.first();
let answer = true;
if (players[1].user.bot) {
return;
} else {
answer = await msg.channel.awaitMessages((msg) => {
console.log(msg.author.id === players[1].id && msg.content === `!yes`) // returns true
if (msg.author.id === players[1].id && msg.content === `!yes`) {
console.log("Player has accepted") // The console does print "Player has accepted"
return true;
}
return false;
}, {maxMatches: 1, time: 30000, errors: ['time']})
.catch(() => {
console.log("Timed out!") // The console does print "Timed Out as well"
return false;
});
}
// if user refuses to play
if (!answer) {
return channel.send(`${players[1]} preferred to run away.`);
}
You have incorrect syntax for awaitMessages() - the first argument should be a CollectorFilter (see here), not a callback.
Consider using createMessageCollector() instead. It reads much more nicely than awaitMessages() and makes more sense than forcing async/await into a collector. Should look something like this:
const filter = m => (m.author.id===players[1].id && m.content==="!yes");
const collector = msg.channel.createMessageCollector(filter, {max: 1, time: 30000});
collector.on("collect", (m) => {
// Player has accepted... do whatever
});
collector.on("end", (reason) => {
if(reason === "time") {
// Ran out of time
}
});

Changing variables with commands discord.js

How can I toggle between false/true a variable's value with a command
my code
var tagdetect = true;
const command = args.shift().toLowerCase();
if (command === 'tagdetect'){
if (args[1] === 'true'){
}
}
if (tagdetect){
if (message.mentions.users.has('id')){
client.TagİDAlgılayıcı.get('nick').execute(message, args);
}
i am using a command handler, i want to do something like {prefix}tagdetect true/false
Assuming tagdetect is the variable you want to switch, you can use two if statements to switch the boolean's state based on user input.
if (args[1] === 'true'){
tagdetect = true;
} else if (args[1] === 'false'){
tagdetect = false;
} else {
// User has given an invalid setting, let them know by sending an error message.
}
The comment is just there to let you know what you should add.

How to iterate through an enmap?

I'm trying to iterate through an enmap for my discord.js bot, I've managed to set and get values from a single entry but I'm trying to set up a command that adds people to a newsletter like DM about minor major updates.
if (args[0] === 'minor') {
if (devlog.updates === 'minor') return message.channel.send('You are already recieving minor updates.').then(m => m.delete(5000))
await client.devlog.set(userID, "yes", 'subscribed');
await client.devlog.set(userID, "minor", 'updates');
return message.channel.send('You will now recieve minor and major updates.').then(m => m.delete(5000))
}
if (args[0] === 'major') {
if (devlog.updates === 'major') return message.channel.send('You are already recieving major updates.').then(m => m.delete(5000))
await client.devlog.set(userID, "yes", 'subscribed');
await client.devlog.set(userID, "major", 'updates');
return message.channel.send('You will now recieve only major updates.').then(m => m.delete(5000))
}
if (!args[0]) {
if (devlog.subscribed === 'yes') {
await client.devlog.set(userID, "no", 'subscribed');
await client.devlog.set(userID, "none", 'updates');
return message.channel.send('You will stop recieving updates about RoboTurtle all together').then(m => m.delete(5000))
}
if (devlog.subscribed === 'no') {
return message.channel.send(`Please choose wether you\'d like to recieve minor or major updates! (minor has both) **devlog minor/major**`).then(m => m.delete(10000))
}
}
It kind of works but it won't trigger the message if they already are subscribed to the same type of update and if they do just !devlog it's meant to either set them to not receive updates if they already are, or tell them to choose between the two if they aren't, however it just sends the last message either way.
I tried setting up my enmap iteration for DMing all subscribed people with a for...of function based off the .map related docs (since they're meant to be just "fancier" maps) but to no avail, since they don't really show discord style use cases.
if (args[0] === 'minor') {
for (let entry of client.devlog) {
if (entry.updates === 'minor') {
let user = client.users.get(entry)
user.send(`**[Minor Update]\n${args.slice(1)}`)
}
}
}
if (args[0] === 'major') {
for (let entry of client.devlog) {
if (entry.subscribed === 'yes') {
let user = client.users.get(entry)
user.send(`**[Major Update!]\n${args.slice(1)}`)
}
}
}
In case anyone wanted to look at the full code to get a better idea of what Im trying to do here ya go: https://pastebin.com/bCML6EQ5
Since they are just an extension of the normal Map class, I would iterate through them with Map.forEach():
let yourEnmap = new Enmap();
yourEnmap.set('user_id', 'your_values');
yourEnmap.forEach((value, key, map) => {
...
});
In your case it would be something like:
client.devlog.forEach((values, user_id) => {
// you can check your subscription here, the use the user_id to send the DM
client.users.get(user_id).send("Your message.");
});

php for loops how to start again after else

I want to do something like this. Do you have ideas for this?
=== a ===
if( Something ){
=== b ===
{
else
{
go back to === a ===
}
Thanks.
It is usual while loop.
$something = false;
while (!$something) {
//here are ====a==== actions
}
//here are b actions
You want something like this:
while (true) {
if( Something ){
=== b ===
}
else
{
=== a ===
}
if (we're done) {
break;
}
}
Alternatively, you could use a proper condition in your while loop to exit.

Resources