/[sudobot]/trunk/commands/pixabay.js
ViewVC logotype

Diff of /trunk/commands/pixabay.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 21 by rakin, Mon Jul 29 17:28:12 2024 UTC revision 22 by rakin, Mon Jul 29 17:28:15 2024 UTC
# Line 16  async function image(msg, cm, type) { Line 16  async function image(msg, cm, type) {
16      if (cm.args[1] !== undefined) {      if (cm.args[1] !== undefined) {
17          let args = [...cm.args];          let args = [...cm.args];
18          args.shift();          args.shift();
19          genurl += `&q=${escape(args.join(' '))}`;          let q = new URLSearchParams({q: args.join(' ')}).toString();
20            console.log(q);
21            genurl += `&${q}`;
22      }      }
23    
24      axios.get(genurl)      axios.get(genurl)
25      .then(res => {      .then(res => {
26          if (res && res.status === 200) {          if (res && res.status === 200) {
27              //console.log(res.data);              //console.log(res.data.hits);
28                if (!res.data.hits || res.data.hits?.length < 1) {
29                  msg.reply({
30                    content: ":x: No search result found from the API."
31                  });
32                  
33                  return;
34                }
35                
36              msg.reply({              msg.reply({
37                  content: random(res.data.hits).largeImageURL                  content: random(res.data.hits).largeImageURL
38              });              });
39          }          }
40      })      })
41      .catch(err => {      .catch(err => {
42            console.log(err.message);
43          msg.reply({          msg.reply({
44              embeds: [              embeds: [
45                  new MessageEmbed()                  new MessageEmbed()

Legend:
Removed from v.21  
changed lines
  Added in v.22

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26