Commit 8d95ad9e authored by samuel.hobman's avatar samuel.hobman

Update humidity.js

parent 63780dfd
const Discord = require("Discord.js"); const Discord = require("Discord.js");
const config = require('./config.json'); const config = require('./config.json'); // This includes the discord Token. Which is required to lock on.
const client = new Discord.Client; const client = new Discord.Client;
const fs = require("fs"); const fs = require("fs");
const MongoClient = require('mongodb').MongoClient; const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://Sam:assignment@cluster0.issnm.mongodb.net/enclosure?retryWrites=true&w=majority"; const uri = "mongodb+srv://Sam:assignment@cluster0.issnm.mongodb.net/enclosure?retryWrites=true&w=majority"; // this contains the password to the cluster specifically.
const mongoClient = new MongoClient(uri, { useNewUrlParser: true }); const mongoClient = new MongoClient(uri, { useNewUrlParser: true });
const currentTime = new Date(); const currentTime = new Date(); // date in unix epoch time.
var intervalID = setInterval(checkData, 60000); var intervalID = setInterval(checkData, 60000);
client.once('ready', () => { client.once('ready', () => {
console.log("I'm logged on!"); console.log("I'm logged on!");
}); });
client.on('message', async message => { client.on('message', async message => {
if (!message.content.startsWith('!') || message.author.bot) return if (!message.content.startsWith('!') || message.author.bot) return // otherwise, a bot might constantly message itself.
const command = message.content.toLowerCase(); const command = message.content.toLowerCase();
switch(command) { switch(command) {
case "!report": case "!report":
...@@ -83,7 +83,7 @@ async function checkData(flag){ // if flagged, the code simply sends the current ...@@ -83,7 +83,7 @@ async function checkData(flag){ // if flagged, the code simply sends the current
function sendToUser(person, temperature, humidity){ function sendToUser(person, temperature, humidity){
person.send("Temperature of the enclosure is currently " + temperature + "C, humidity is: " + humidity + "%"); person.send("Temperature of the enclosure is currently " + temperature + "C, humidity is: " + humidity + "%");
} }
function alertHumidity(person, humidity, tooHumid) { function alertHumidity(person, humidity, tooHumid) { // tooHumid defaults to false.
if (tooHumid) { if (tooHumid) {
person.send("Sir, your enclosure is too humid. It is currently " + humidity + "%"); person.send("Sir, your enclosure is too humid. It is currently " + humidity + "%");
} }
...@@ -100,7 +100,7 @@ else { ...@@ -100,7 +100,7 @@ else {
} }
} }
async function insertIntoMongo(enclosureData){ async function insertIntoMongo(enclosureData){
const user = await client.users.fetch("226082168294735872"); const user = await client.users.fetch("226082168294735872"); // this is my own Discord ID, required to make it contact me directly.
try { try {
const thisSession = await mongoClient.connect(); // returns a promise to connect const thisSession = await mongoClient.connect(); // returns a promise to connect
const database = thisSession.db("enclosure"); const database = thisSession.db("enclosure");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment