|
| 1 | +const Discord = require('discord.js'); |
| 2 | +const five = require('johnny-five'); |
| 3 | +const client = new Discord.Client(); |
| 4 | +const { Board, Thermometer } = require("johnny-five"); |
| 5 | +const AsciiTable = require("ascii-table"); |
| 6 | +const board = new Board(); |
| 7 | +board.on("ready", () => { |
| 8 | + const led = new five.Led(13); |
| 9 | + const piezo = new five.Piezo(3); |
| 10 | + const thermometer = new Thermometer({ |
| 11 | + controller: "LM35", |
| 12 | + pin: "A0" |
| 13 | + }); |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + client.on('message', msg => { |
| 18 | + if (msg.content === "led-open") led.on() |
| 19 | + else if (msg.content === "led-close") led.off() |
| 20 | + }); |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + client.on('message', msg => { |
| 25 | + const {celsius, fahrenheit, kelvin} = thermometer; |
| 26 | + if (msg.content === "weather-degrees") { |
| 27 | + var table = new AsciiTable() |
| 28 | + table |
| 29 | + .addRow('°C:', celsius) |
| 30 | + .addRow('°F:', fahrenheit) |
| 31 | + .addRow('K:', kelvin) |
| 32 | + let embed = new Discord.RichEmbed() |
| 33 | + .setDescription(`\`\`\`${table.toString()}\`\`\``) |
| 34 | + msg.channel.send(embed) |
| 35 | + } |
| 36 | + }); |
| 37 | + |
| 38 | + client.on('message', msg => { |
| 39 | + if (msg.content === "music") { |
| 40 | + led.blink(); |
| 41 | + board.repl.inject({ |
| 42 | + piezo: piezo |
| 43 | + }); |
| 44 | + piezo.play({ |
| 45 | + song: "E D F D A - A A A A G G G G - - C D F D G - G G G G F F F F - -", |
| 46 | + beats: 1 / 4, |
| 47 | + tempo: 100 |
| 48 | + }); |
| 49 | + } else if (msg.content == "music-close") { |
| 50 | + led.stop() |
| 51 | + } |
| 52 | + }) |
| 53 | + |
| 54 | +}) |
| 55 | + |
| 56 | + |
| 57 | +client.login('Token'); //Token Here |
0 commit comments