multiple embed into one message - javascript

i really need help.
How can i multiple embed into one message instead of sending 1 by 1?
if (msg.content.startsWith(prefix + "find")) {
const item = game.data.members;
const GQ = msg.content.split(' ').slice(1);
let ign;
let gq;
for (var i = 0; i < item.length; i++) {
if (item[i].task_finished_week < GQ) {
ign = item[i].name;
gq = item[i].task_finished_week;
const embed = new Discord.RichEmbed()
.setTitle(ign)
.addField('Weekly GQ', gq);
msg.channel.send({ embed });
}
}

Related

improving home grown closed captioning

this may get closed as request for software, or opinion based but I'm hopeful it might not.
I wrote a JS web page for our church that uses speech recognition to transcribe the pastor's speech and display it as closed captions on a monitor. The accuracy is around 90%. I was wondering if anyone had suggestions to improve it or if using an API like Google Translate would help.
you can try it here. https://bryandellinger.github.io/voicetotext/
here it is in github
warning this version has a large list of profanities in it
https://github.com/bryandellinger/voicetotext/blob/main/index.html
below is the relevant code.
const badWords = ['apple', 'banana', 'orange', 'grape', 'pear']
window.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition;
let finalTranscript = '';
let recognition = new window.SpeechRecognition();
recognition.interimResults = true;
recognition.maxAlternatives = 10;
recognition.continuous = true;
recognition.addEventListener('end', () => {
recognition.start();
});
recognition.onresult = (event) => {
let interimTranscript = '';
for (let i = event.resultIndex, len = event.results.length; i < len; i++) {
let transcript = (event.results[i][0].transcript);
const words = transcript.split(" ");
const words2 = [];
words.forEach(element => {
if (element.indexOf('*') < 0){
words2.push(element);
}
});
const filteredWords = words2.filter(word => !badWords.includes(word.toLowerCase()));
if (event.results[i].isFinal) {
finalTranscript += filteredWords.join(' ');
} else {
interimTranscript += filteredWords.join(' ');
}
}
interimTranscript = interimTranscript.length > 1000 ? interimTranscript.substring(1000) : interimTranscript;
finalTranscript = finalTranscript.length > 1000 ? finalTranscript.substring(1000) : finalTranscript;
document.querySelector('div').innerHTML = finalTranscript + '<i style="color:#FFFFFF;">' + interimTranscript + '</>';
const myDiv = document.getElementById('container');
myDiv.scrollTop = myDiv.scrollHeight;
}
recognition.start();

React Native AsyncStorage Error when I want store data

I'm doing an operation inside my function and I want to store my JSON data with AsyncStorage and use it elsewhere, but I'm getting an error in react native
this is my code block;
onPress={() => {
press = item.id;
// console.warn(press);
ars = options;
dd = JSON.stringify(ars);
cc = JSON.parse(dd);
for (var i = 0; i < cc.length; i++) {
if (cc[i].id == press) {
// console.warn(cc[i]);
var productData = cc[i];
var stri = JSON.stringify(cc[i]);
AsyncStorage.setItem('ProductData', stri);
var abc = AsyncStorage.getItem('ProductData');
console.warn(stri);
console.warn(abc);
}
}
}}>
how can i solve that problem?
thanks.
var abc = await AsyncStorage.getItem('ProductData');
add await as it is promise that all
so whole code will look like this
onPress={async () => {
press = item.id;
// console.warn(press);
ars = options;
dd = JSON.stringify(ars);
cc = JSON.parse(dd);
for (var i = 0; i < cc.length; i++) {
if (cc[i].id == press) {
// console.warn(cc[i]);
var productData = cc[i];
var stri = JSON.stringify(cc[i]);
AsyncStorage.setItem('ProductData', stri);
var abc =await AsyncStorage.getItem('ProductData');
console.warn(stri);
console.warn(abc);
}
}
}}>
add async to function and add await

how to export all contact by API in hubspot to google spredsheet with app script

I try to export all contacts from hubspot to spreadsheet,
but I do not know how I can do it
You would be wise to use the people api since the Contact API will begin to be shut down after June 15. I've provided a function that I use.
You welcome to it.
Use what you wish. Modify as needed.
function displayCurrentContacts() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName('Contacts');
sh.clearContents();
const vs = [['Name', 'Emails']];
const resp = People.People.Connections.list('people/me', { personFields: "emailAddresses,names,organizations" });
//Logger.log(resp);
const data = JSON.parse(resp);
let m = 0;
let n = 0;
data.connections.forEach((ob1, i) => {
if (ob1.emailAddresses && ob1.emailAddresses.length > 0) {
let emails = [... new Set(ob1.emailAddresses.map(ob2 => ob2.value))];//used set to insure I get unique list
//let emails = ob1.emailAddresses.map(ob2 => ob2.value);
let name;
m += emails.length;
if (ob1.names && ob1.organizations) {
name = ob1.names[0].displayName + '\n' + ob1.organizations[0].name;
++n;
} else if (ob1.names) {
name = ob1.names[0].displayName;
++n;
} else if (ob1.organizations) {
name = ob1.organizations[0].name;
++n;
}
vs.push([name, emails.sort().join('\n')])
}
});
vs.push([n, m])
sh.getRange(1, 1, vs.length, vs[0].length).setValues(vs)
sh.getRange(2, 1, sh.getLastRow() - 2, sh.getLastColumn()).sort({ column: 1, sortAscending: true });
}

Incorrect loading order from local storage

I'm having problem with loading from local storage.
Here's a part of the code
const getTerminus = () => {
let terminus;
if (localStorage.getItem("terminus") === null) {
terminus = [];
} else {
terminus = JSON.parse(localStorage.getItem("terminus"));
}
let directions;
if (localStorage.getItem("directions") === null) {
directions = [];
} else {
directions = JSON.parse(localStorage.getItem("directions"));
}
terminus.forEach(async(stop) => {
let API_URL =
"https://ckan.multimediagdansk.pl/dataset/c24aa637-3619-4dc2-a171-a23eec8f2172/resource/d3e96eb6-25ad-4d6c-8651-b1eb39155945/download/stopsingdansk.json";
let response = await fetch(API_URL);
let data = await response.json();
const {
stops,
stopId,
stopName,
stopCode,
zoneId
} = data;
let input = stop;
let ID;
let dataArr = [];
for (let i = 0; i < stops.length; i++) {
if (
stops[i].stopName === input &&
stops[i].stopCode === directions[terminus.indexOf(input)] &&
stops[i].zoneId === 1
) {
ID = stops[i].stopId;
dataArr = [ID, stops[i].stopName];
}
}
API_URL = `https://ckan2.multimediagdansk.pl/delays?stopId=${ID}`;
response = await fetch(API_URL);
data = await response.json();
const {
delay,
estimatedTime,
routeId,
headsign
} = data;
let times = [];
let routeIds = [];
let headsigns = [];
for (let i = 0; i < delay.length; i++) {
times.push(delay[i].estimatedTime);
routeIds.push(delay[i].routeId);
headsigns.push(delay[i].headsign);
}
routeIds.push(" ");
times.push(" ");
const cardDiv = document.createElement("div");
cardDiv.classList.add("card");
const stopNameDiv = document.createElement("div");
stopNameDiv.classList.add("stop-name-div");
cardDiv.appendChild(stopNameDiv);
const stopNameSpan = document.createElement("span");
stopNameSpan.innerText = dataArr[1];
stopNameSpan.classList.add("stop-name-span");
stopNameDiv.appendChild(stopNameSpan);
const scheduleDiv = document.createElement("div");
scheduleDiv.classList.add("schedule-div");
cardDiv.appendChild(scheduleDiv);
if (headsigns.length !== 0) {
routeIds.unshift("Line");
headsigns.unshift("Direction");
times.unshift("Departure");
}
const lineSpan = document.createElement("span");
lineSpan.innerText = routeIds.join("\n");
lineSpan.classList.add("line-span");
scheduleDiv.appendChild(lineSpan);
const dirSpan = document.createElement("span");
dirSpan.innerText = headsigns.join("\n");
dirSpan.classList.add("dir-span");
scheduleDiv.appendChild(dirSpan);
const timeSpan = document.createElement("span");
timeSpan.innerText = times.join("\n");
timeSpan.classList.add("time-span");
scheduleDiv.appendChild(timeSpan);
const buttonsDiv = document.createElement("div");
buttonsDiv.classList.add("buttons-div");
cardDiv.appendChild(buttonsDiv);
const deleteButton = document.createElement("button");
deleteButton.innerHTML = '<i class="fas fa-trash"></i>';
deleteButton.classList.add("delete-button");
buttonsDiv.appendChild(deleteButton);
const dirButton = document.createElement("button");
dirButton.innerHTML = '<i class="fas fa-retweet"></i>';
dirButton.classList.add("reverse-button");
buttonsDiv.appendChild(dirButton);
stopList.appendChild(cardDiv);
});
};
document.addEventListener("DOMContentLoaded", getTerminus);
Terminus contains stop names, and directions contains direction codes.
On refresh, it fetches data from API based on stop name and direction, and displays a card with departure time etc.
The problem is, on closing and re-opening the page cards are sometimes displayed in a wrong order. I have found out, that as time between closing and opening lengthens, the probability of this occurring gets higher. After simple refresh everything is in correct order.
Does it have something to do with browser cache? Has anyone had similar issue or knows what's going on?
Alright, as #Yoshi stated, it was insequential promise error. I managed to fix it by using reduce().
Here are the threads that helped me
Resolve promises one after another (i.e. in sequence)?
Why Using reduce() to Sequentially Resolve Promises Works

Get all users who have added a reaction to a message (discord.js)

In discord.js, how do I get all the users who have added a reaction to a message? (And then do something with their ID and tag etc.)
Below is what I thought it would be but it doesn't work, and I can't find anything to help me on the internet with what I'm searching.
var users = msg.reactions.resolve(messageID).users.cache;
var userIDs = [];
var userTags = [];
users.forEach(user => {
userIDs.push(user.id);
userTags.push(user.tag);
}
Thanks.
This is not the nicest way to do it:
let channel = await bot.channels.fetch(channelId)
let message = await channel.messages.fetch(messageId)
let reactions = await message.reactions.cache.first().users.fetch()
reactions = reactions.toJSON()
for(i = 0; i < reactions.length; i ++) console.log(reactions[i].id)
Hopefully, this is enough to help you out. However, this will now target a message with a specific string (aka, an old message)
var targetedMessage = "Whatever the string is of that specific old message";
var userIDs = [];
var userTags = [];
client.on("message", message => {
//Alternate targeting technique
/*if(message.content == "reactMe") {
targetedMessage = message.id;
}*/
if(message.content == "whoReacted" && targetedMessage != null) {
var theReactors = "Everyone who reacted was:";
for(var i = 0; i < userIDs.length; i++) {
theReactors = theReactors + ` <#${userIDs[i]}>`;
}
message.channel.send(theReactors);
}
}
client.on("messageReactionAdd", (reaction, user) => {
if(reaction.message.content == targetedMessage) {
var reacted = false;
for(var i = 0; i < userIDs.length; i++) {
if(user.id == userIDs[i]) {
reacted = true;
}
}
if(!reacted) {
userIDs.push(user.id);
userTags.push(user.tag);
}
}
});

Categories