From 65627d43a84b24f64d564d297fa854167bd31c71 Mon Sep 17 00:00:00 2001 From: stephen Date: Tue, 7 Dec 2021 16:43:46 -0500 Subject: [PATCH] 0.1.2 ready! Removed chalk, d2d, and express --- index.js | 75 +++++++++++++++++++++++++++------------------------- package.json | 3 --- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/index.js b/index.js index 6dd9b55..ac30e9a 100755 --- a/index.js +++ b/index.js @@ -1,7 +1,3 @@ -const chalk = require('chalk'); -const d2d = require('degrees-to-direction'); -const express = require('express') -const app = express(); const fs = require('fs'); const ini = require('ini'); const mastodon = require('mastodon'); @@ -51,6 +47,13 @@ const vfc_url = config.vfc_url; const weather_api_key = config.weather_api_key; const weather_units = config.weather_units; +// thx: https://stackoverflow.com/questions/48750528/get-direction-from-degrees +function getDirection(angle) { + var directions = ['North', 'North-East', 'East', 'South-East', 'South', 'South-West', 'West', 'North-West']; + var index = Math.round(((angle %= 360) < 0 ? angle + 360 : angle) / 45) % 8; + return directions[index]; +} + var ami = new require('asterisk-manager')(asterisk_port, asterisk_host, asterisk_user, asterisk_password, false); let weather_url = `https://api.openweathermap.org/data/2.5/weather?id=${city_code}&appid=${weather_api_key}&units=${weather_units}` var client = mqtt.connect('tcp://' + mqtt_user + ':' + mqtt_password + '@' + mqtt_server); @@ -65,8 +68,6 @@ xmpp.on('online', function(data, to) { xmpp.send(user_jid, "[ONLINE]", false); client.publish(mqtt_topic, mqtt_message); M.post('statuses', { status: `${mastodon_toot}` }); - app.get('/', (req, res) => res.send("Bot Online!

Bot Online!

")); - app.listen(app_port, () => console.log(`Listening on ${app_port}!`)); }); xmpp.on('chat', function(from, message) { @@ -74,7 +75,7 @@ xmpp.on('chat', function(from, message) { // HELP if (message === 'help' || message === 'Help') { xmpp.send(from, 'https://wiki.vanderwarker.family/doku.php?id=code:vxmppb:commands'); - console.log(chalk.blue('help')); + console.log('help'); } // UNLOCKS @@ -92,7 +93,7 @@ xmpp.on('chat', function(from, message) { request(api_url + "?columns=" + n, (error, res, body) => { if (error) { - return chalk.red(console.log(error)) + return console.log(error) }; if (!error && res.statusCode == 200) { @@ -100,22 +101,22 @@ xmpp.on('chat', function(from, message) { var ule = body.match(ulb); const ur = user_name + " has " + ule[1] + " unlocks for " + n; xmpp.send(from, ur); - console.log(chalk.yellow(ur)); + console.log(ur); } if (!error && res.statusCode == 401) { - console.log(chalk.red('Invalid credentials')); + console.log('Invalid credentials'); xmpp.send(from, 'Invalid credentials'); } if (!error && res.statusCode == 404) { - console.log(chalk.red('Record not found')); + console.log('Record not found'); xmpp.send(from, 'Record not found'); } if (!error && res.statusCode == 500) { - console.log(chalk.red('Server error.')); + console.log('Server error.'); xmpp.send(from, 'Server error. Please ping admin'); } }); - console.log(chalk.blue('unlocks')); + console.log('unlocks'); } // Check VFC balance @@ -130,16 +131,16 @@ xmpp.on('chat', function(from, message) { }); request(vfc_url, (error, res, body) => { if (error) { - return chalk.red(console.log(error)) + return console.log(error) }; if (!error && res.statusCode == 200) { const balance = user_name + " has " + res.body + " VFC"; xmpp.send(from, balance); - console.log(chalk.yellow(balance)); + console.log(balance); } }); - console.log(chalk.blue('vfc')); + console.log('vfc'); } // Get latest RSS item from feed @@ -168,12 +169,12 @@ xmpp.on('chat', function(from, message) { 'data': 'googletts.agi, \"hello. ' + from + ' has pinged you!\"', 'application': 'agi' }); - console.log(chalk.blue('ping')); + console.log('ping'); let guf = `${gotify_url}/message?token=${gotify_api_key}&message=${from} ${gotify_message}&title=${gotify_title}&priority=${gotify_priority}`; let gufe = encodeURI(guf); request.post(gufe, function (err, response, body) { if(err){ - console.log(chalk.red('error:', err)); + console.log('error:', err); } }); } @@ -183,18 +184,18 @@ xmpp.on('chat', function(from, message) { xmpp.send(from, "Checking weather. Please hold...\r\n \r\n"); request(weather_url, function (err, response, body) { if(err){ - console.log(chalk.red('error:', err)); + console.log('error:', err); } else { let w = JSON.parse(body); let wm = city_name + " Weather: \r\n Tempature: " + w.main.temp + " degrees. \r\n Conditions: " + w.weather[0].main + "\r\n Pressure: " + - w.main.pressure + " \r\n Wind Direction: " + d2d(w.wind.deg) + "\r\n Wind Speed: " + w.wind.speed + " m.p.h. \r\n"; + w.main.pressure + " \r\n Wind Direction: " + getDirection(w.wind.deg) + "\r\n Wind Speed: " + w.wind.speed + " m.p.h. \r\n"; let wmc = city_name + " Weather: Tempature: " + w.main.temp + " degrees. Conditions: " + w.weather[0].main + ". Pressure: " + - w.main.pressure + ". Wind Direction: " + d2d(w.wind.deg) + ". Wind Speed: " + w.wind.speed + " miles per hour \r\n"; - console.log(chalk.yellow(wm)); + w.main.pressure + ". Wind Direction: " + getDirection(w.wind.deg) + ". Wind Speed: " + w.wind.speed + " miles per hour \r\n"; + console.log(wm); client.publish('weather/temp', 'w.main.temp'); client.publish('weather/conditions', 'w.weather[0].main'); client.publish('weather/pressure', 'w.main.pressure'); - client.publish('weather/wind/direction', 'd2d(w.wind.deg)'); + client.publish('weather/wind/direction', 'getDirection(w.wind.deg)'); client.publish('weather/wind/speed', 'w.wind.speed'); xmpp.send(from, wm); /* @@ -209,31 +210,33 @@ xmpp.on('chat', function(from, message) { */ } }); - console.log(chalk.blue('weather')); + console.log('weather'); } - // BYE - else if (message === 'bye' || message === "Bye" && from != user_jid) { + // Sends a nice goodbye message + else if (message === 'bye' || message === "Bye"){ xmpp.send(from, "Bye, have a beautiful time!"); - if (from === user_jid || message === "!bye") { + console.log('bye'); + + } + // Shutsdown bot if admin messages "goodbye" + else if (message === "goodbye" || from === user_jid){ xmpp.send(from, "Alrighty, shutting down. Goodbye!"); - console.log(chalk.red('Admin shutdown.')); - process.exit(1) - } - console.log(chalk.blue('bye')); + console.log('Admin shutdown.'); + process.exit(1); } // Get users vCard (WIP) else if (message === 'vcard' && from === user_jid){ xmpp.getVCard(from, function (vcard) { xmpp.send(from, vcard); - console.log(chalk.yellow(vcard)) + console.log(vcard) }) } // If the user sends something we don't have logic for, send them info about the project else { xmpp.send(from, "This is an auto replying bot. Reply \"help\" for more info, or https://wiki.vanderwarker.family/doku.php?id=code:vxmppb:start"); - console.log(chalk.blue('autoreply')); + console.log('autoreply'); } }); @@ -245,11 +248,11 @@ console.error(err); // EXTENDING XEPS (WIP) /* xmpp.on('chatstate', function(from, state) { -console.log(chalk.yellow(state)); +console.log(state); }); xmpp.on('buddy', function(jid, state, statusText, resource) { -console.log(chalk.yellow(state + statusText + resource)); +console.log(state + statusText + resource); }); */ @@ -262,4 +265,4 @@ xmpp.connect({ }); // Checks the XMPP server for new 'friend' requests -console.log(chalk.yellow(xmpp.getRoster())); +console.log(xmpp.getRoster()); diff --git a/package.json b/package.json index 0792ba0..2eb22a9 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,6 @@ ], "dependencies": { "asterisk-manager": "0.1.16", - "chalk": "2.4.2", - "degrees-to-direction": "1.1.1", - "express": "4.17.1", "ini": "2.0.0", "mastodon": "1.2.2", "mqtt": "4.2.6",