I am having issues posting an image of a Pokémon when command is used
const { Message, Client, MessageEmbed, MessageAttachment } = require("discord.js");
const {Ecolor} = require("../../embeds.js")
pokemon = require('../../db/pokemon.js')
module.exports = {
name: "pokeinfo",
description: "Shares Information about specified Pokemon of the game",
run: async (client, message, args) => {
let pkmn = message.content.toLowerCase().split("!pokeinfo ")[1]
for(var i=0;i<pokemon.length;i++){
if(pkmn == pokemon[i]._engName.toLowerCase()){
let Embed = new MessageEmbed()
.setColor(`${Ecolor.pink}`)
.setTitle(`Details about ${pokemon[i]._engName} :`)
.setDescription(`Dex number - ${pokemon[i]._nb}`)
.setThumbnail('https://imgur.com/Q6WZOoU.png')//https://imgur.com/Q6WZOoU.png
.addFields(
{name: 'Rarity:', value:`${pokemon[i]._rare}`, inline: true },
{name: 'Evolution Chart:', value:`${pokemon[i]._evo}`, inline: true },
{name: 'Location:', value:`${pokemon[i]._loc}`, inline: false },
{name: 'Ev Yield:', value:`${pokemon[i]._ev}`, inline: true },
{name: 'Ability:', value:`${pokemon[i]._ability}`, inline: true },
{name: '__Base Stats__:', value:
`
**HP** : ${pokemon[i]._baseStats._hp}
**Atk** : ${pokemon[i]._baseStats._atk}
**Def** : ${pokemon[i]._baseStats._def}
**S. Atk** : ${pokemon[i]._baseStats._sAtk}
**S. Def** : ${pokemon[i]._baseStats._sDef}
**Speed** : ${pokemon[i]._baseStats._spd}
**Total** : ${pokemon[i]._baseStats._total}
**Growth Rate** : ${pokemon[i]._gr}
**Type** : ${pokemon[i]._ty}
`, inline: false },
);
message.channel.send({ embeds: [Embed] });
}
}
},
};
if simplisty were just gonna use 1 pokemon below is the info being called
{
_nb:1,_engName:"Bulbasaur",_rare:"N/A",
_evo:"Bulbasaur lvl 16 | Ivysaur lvl 36 | Venusaur | Mega",
_loc:"Starter ",
_ev:"1 SpA",
_ability:"Overgrow, *Chlorophyll(HA)",
_baseStats: {_total:318,_hp:45, _atk:49, _def:49, _sAtk:65, _sDef:65, _spd:45},
_gr:"Medium Slow",_ty:"Grass/Poison"
_pho: "bulbasaur.png"
i have changed .setThumbnail('https://www.pokemon.com/us/pokedex/' + ${pokemon[i]._pho}) and in the second file added _pho: bulbasaur.png
as when that is all together is will take you to https://www.pokemon.com/us/pokedex/bulbasaur.png.
I'm just trying to set a thumbnail to display the Pokémon that is being searched for. and I'm not able to figure it out.
when I use the pokemon.com..... and hover over the image after I call the command it displays the link but not the image, if click on the thumbnail image (which is a pile of poo) it will take me to the correct page, but again the image on the bot command is not showing.
If you are looking to display the Pokémon in the Thumbnail, the URL you should give is the URL that takes you to the image and not the URL where you see the Pokémon information.
The direct URL of the image can be obtained by right clicking -> Copy address/image link.
In the case of Bulbasaur, the URL of its image is: https://assets.pokemon.com/assets/cms2/img/pokedex/full/001.png and not https://www.pokemon.com/us/pokedex/bulbasaur.png
A quick and probably functional solution would be to dynamically obtain the URL of the Pokémon images according to their number in the pokedex, as it seems that in the assets they are stored/differentiated by number and not by names.
.setThumbnail(`https://assets.pokemon.com/assets/cms2/img/pokedex/full/${pokemon[i]._nb}.png`)
Related
I have a message extension running in MS Teams.
The search list displays the Hero Card.
On selecting one of them it displays something like below in the chat.
Part of code that displays the button:
...
heroCard.content.buttons = [{
type: 'invoke',
title: 'Open Attachment',
value: {
type: "task/fetch",
messageId: "12345",
}
}];
I am looking to run my angular app on clicking Open Attachment which displays the documents.
I figured out the way to proceed using Microsoft Docs: Use task modules from bots
First I need to tweak the hero card button to pass my data.
...
heroCard.content.buttons = [{
type: 'invoke',
title: 'Open Attachment',
value: {
type: "task/fetch",
messageId: "12345",
data: attachments
}
}];
The second thing is to handle the fetch request:
async handleTeamsTaskModuleFetch(context, action) {
var attachments = action.data.data
return {
task: {
type: 'continue',
value: {
height: 400,
width: 400,
title: 'View Documents',
url: `https://example.io?data=${attachments}`
}
}
};
}
Note: the URL must be in the valid domain of the manifest - otherwise you'll see the blank page.
The below is the final output:
I want to index through a list of items stored in a json file and call to each API and bring back data. The below code shows indexing/map working by building an API link, but how do I get the whole API call and message to be inside the indexing so each list item is called and returned by the API:
// {"342671641006047252":["MSFT","AMZN","CVNA","TEAM"]}
console.log(list);
// This is indexing through the list and bulding the link
const tickers = list
.map((ticker, index) => `https://financialmodelingprep.com/api/v3/quote/${ticker}?apikey=6c7ee1f3c7a666228979fa0678fa22a3`)
return message.channel.send(tickers)
// This is going to the api for list[0]
axios.get('https://financialmodelingprep.com/api/v3/quote/'+list[0]+'?apikey=6c7ee1f3c7a666228979fa0678fa22a3').then(resp => {
console.log(resp.data);
let symbol = resp.data[0].symbol;
let price = resp.data[0].price;
let changesPercentage = resp.data[0].changesPercentage;
return message.channel.send({embed: {
color: 8311585,
fields: [{
name: "Ticker",
value: `${symbol}`,
inline: "true"
},
{
name: "Price",
value: `${price}`,
inline: "true"
},
{
name: "Change %",
value: `${changesPercentage}`,
inline: "true"
},
Nevermind on this one! I used forEach instead of .map and got it working!
I create a chat bot using dialogflow and actions on google library. In the back-end code I have created function including if else. I added new suggestions in the "else if". That are not display in the actions on google simulator.Another suggestions are working. Only that time it is not displayed. Please give me some instructions for fixed that.
this is my code:
'use strict';
const functions = require('firebase-functions');
const {
dialogflow,
Suggestions,
Carousel,
Image,
Table,
List,
} = require('actions-on-google');
const app = dialogflow({debug: true});
// Constants for list and carousel selection
const Order_Food = 'order food';
const Extra_Product = 'extra product';
const Spa_Reservation = 'spa reservation';
const Restaurant_Booking = 'restaurant booking';
app.intent('user.provide_room_number', (conv) => {
conv.ask('Great! I can help you with the following. Please select
from the options below.');
//conv.ask(new Suggestions('Order Food', 'Extra Product',
'Restaurant', 'Spa'));
// Create a carousel
conv.ask(new Carousel({
items: {
// Add the first item to the carousel
[Order_Food]: {
synonyms: [
'order food',
'food',
],
title: 'Food',
description: 'Can order some food',
image: new Image({
url: 'http://www.restauranteelpalacete.com/wp-content/uploads/2018/01/Online-Food-Ordering.jpg',
alt: 'Food',
}),
},
// Add third item to the carousel
[Spa_Reservation]: {
synonyms: [
'spa',
'spa reservation',
],
title: 'Spa Reservation',
description: 'Can put the reservation on the spa.',
image: new Image({
url: 'https://res.klook.com/images/fl_lossy.progressive,q_65/c_fill,w_1295,h_720,f_auto/w_80,x_15,y_15,g_south_west,l_klook_water/activities/kykzulvt1t71kwhnmkik/OasisSpa.jpg',
alt: 'Spa',
}),
},
// Add fourth item to the carousel
[Restaurant_Booking]: {
synonyms: [
'restaurant',
'restaurant booking',
],
title: 'Restaurant',
description: 'Can put the reservation on the Restaurant.',
image: new Image({
url: 'https://cdn-image.foodandwine.com/sites/default/files/1501607996/opentable-scenic-restaurants-marine-room-FT-BLOG0818.jpg',
alt: 'Restaurant',
}),
},
},
}));
});
app.intent('actions_intent_OPTION-handler', (conv, params, option) => {
// Get the user's selection
// Compare the user's selections to each of the item's keys
if (!option) {
conv.ask('You did not select any item from the list or carousel');
} else if (option === 'order food') {
conv.ask(new SimpleResponse({speech:"Absolutely, have you decided what you like or you could go through the in room dinning menu. \n Do you need order Food.?",text:"Absolutely, have you decided what you like or you could go through the in room dinning menu. Do you need order Food.?"}));
conv.ask(new Suggestions(["Ok", "Done", "Thanks"]));
} else if (option === 'spa reservation') {
conv.ask(new Suggestions('Yes I need Spa.'));
conv.ask(`We have an excellent Spa that offer exquisite treatment packages. You can select one of the options. We have quite a few free slots today. Do you need information about that.`);
} else if (option === 'restaurant booking') {
conv.ask(`We have some dining options for you today. Do you want more information. `);
conv.ask(new Suggestions('I need restaurant.'));
} else {
conv.ask('You selected an unknown item from the list, or carousel');
}
});
You should design your conversation bot more efficiently.In second elseif condition, after a suggestion no further conversation should happen in an intent.Suggestion are for triggering intent. For your case best scenario would be to create a follow up intent.
Suggestion is not appearing in conversation because, in every rich response at least one simple response should be present. Try below code. Hope this helps you.
conv.ask(new SimpleResponse({speech:"Absolutely, have you decided what you like or you could go through the in room dinning menu. \n Do you need order Food.?",text:"Absolutely, have you decided what you like or you could go through the in room dinning menu. Do you need order Food.?"}));
conv.ask(new Suggestions(["Ok", "Done", "Thanks"]));
we're testing out CB and part of our requirements is sending messages to Slack.
This tutorial works great, but it'd be helpful if we could specify the source of the build, so we don't have to click in to the message to see what repo/trigger failed/succeeded.
Is there a variable we can pass to the cloud function in the tutorial? I couldn't find helpful documentation.
Ideally, it would be great if CB had an integration/slack GUI that made these options configurable but c'est la vie.
You can add source information to the slack message by adding a new item to the fields list within the createSlackMessage function. You need to make sure title and value are strings.
// createSlackMessage create a message from a build object.
const createSlackMessage = (build) => {
let message = {
text: `Build \`${build.id}\``,
mrkdwn: true,
attachments: [
{
title: 'Build logs',
title_link: build.logUrl,
fields: [{
title: 'Status',
value: build.status
},{
title: 'Source',
value: JSON.stringify(build.source, null, 2)
}]
}
]
};
return message
}
You can find more information on build object here.
I'm using x-ray to extract some data from a web site but when I get to the point to crawl to another page using the built-in functionality, it simply doesn't work.
UnitPrice is the parameter I want to extract but I get "undefined" all the time.
As you can see, I'm passing the href value previously extracted on the url property.
var Xray = require('x-ray');
var x = Xray();
var x = Xray({
filters: {
cleanPrice: function (value) {
return typeof value === 'string' ? value.replace(/\r|\t|\n|€/g, "").trim() : value
},
whiteSpaces: function (value) {
return typeof value === 'string' ? value.replace(/ +/g, ' ').trim() : value
}
}
});
x('https://www.simply.es/compra-online/aceite-vinagre-y-sal.html',
'#content > ul',
[{
name: '.descripcionProducto | whiteSpaces',
categoryId: 'input[name="idCategoria"]#value',
productId: 'input[name="idProducto"]#value',
url: 'li a#href',
price: 'span | cleanPrice',
image: '.miniaturaProducto#src',
unitPrice: x('li a#href', '.precioKilo')
}])
.paginate('.link#href')
.limit(1)
// .delay(500, 1000)
// .throttle(2, 1000)
.write('results.json')
There's a pull request to fix this. Meanwhile you can use the solution which is just one line of code. See this:
https://github.com/lapwinglabs/x-ray/pull/181