1
0
Fork 0

convert to my testserver setup

testserver
Dominic Reich 4 years ago
parent 95c1adbc8d
commit 18313cd432

@ -25,32 +25,42 @@ client.on("ready", () => {
client.channels.size client.channels.size
} channels of ${client.guilds.size} guilds.` } channels of ${client.guilds.size} guilds.`
); );
return client.user.setActivity("Stations", { type: "Watching" }); //return client.user.setActivity("", { type: "Watching" });
}); });
client.on("message", message => { client.on("message", message => {
if (message.author.bot) return; if (message.author.bot) return;
if (message.content.indexOf(config.prefix) !== 0) return; //if (message.content.indexOf(config.prefix) !== 0) return;
const args = message.content const args = message.content
.slice(config.prefix.length) //.slice(config.prefix.length)
.trim() .trim()
.split(/ +/g); .split(/ +/g);
const command = args.shift(); //const command = args.shift();
if (command === "loc") { /*if (command === "loc") {
let callsign = args.join("").toLowerCase(); let callsign = args.join("").toLowerCase();
getLocationInfo(callsign, message); getLocationInfo(callsign, message);
return; return;
} }*/
const command = args.shift();
if (command === "weather" || command === "wx") { if (command === "weather" || command === "wx") {
let callsign = args.join("").toLowerCase(); let callsign = args.join("").toLowerCase();
getWeather(callsign, message); getWeather(callsign, message);
return; return;
} } else if (command === "hilfe" || command === "help") {
if (command === "help") {
message.channel.send( message.channel.send(
"**Currently available commands**:\n`?loc callsign` to retrieve location information.\n`?wx callsign` to retrieve weather data." //"**Currently available commands**:\n`?loc callsign` to retrieve location information.\n`?wx callsign` to retrieve weather data."
"**Usage:**\n`help` to print this help\n`aprs_callsign` to retrieve info about *aprs_callsign*"
); );
return; return;
} else if (command === "info") {
message.channel.send(
"Hello, my name is Ron. I show the _last heard station information_ about the station that you type into the channel. Just send the callsign that you want the information about and I will see what I can do for you. If you want more information about a weather station type `wx` or `weather` before the callsign.\n\n_For example_\n**`wx OE7XEI-13`** will show the latest weather information from `OE7XEI-13`, which is a weather station from OE7AAI.\nType **`help`** or **`hilfe`** to get more information about the used commands…"
);
} else {
//let callsign = args.join("").toLowerCase();
let callsign = command.toLowerCase();
getLocationInfo(callsign, message);
return;
} }
}); });
client.login(config.token); client.login(config.token);

@ -39,26 +39,107 @@ function getLocationInfo(callsign, message) {
let lat = data.entries[0].lat; let lat = data.entries[0].lat;
let lng = data.entries[0].lng; let lng = data.entries[0].lng;
let altitude = data.entries[0].altitude let altitude = data.entries[0].altitude
? `${data.entries[0].altitude}m (${Math.round( /*? `${data.entries[0].altitude}m (${Math.round(
data.entries[0].altitude * 3.28084 data.entries[0].altitude * 3.28084
)}ft)` )}ft)`
: "Not available"; : "Not available";*/
? `${data.entries[0].altitude}m`
: "0.00m";
let speed = data.entries[0].speed
? `${data.entries[0].speed} km/h`
: "0";
let course = data.entries[0].course
? `${data.entries[0].course}`
: "0";
let comment = data.entries[0].comment
? `${data.entries[0].comment}`
: "No comment";
let status = data.entries[0].status
? `${data.entries[0].status}`
: "No status";
let path = data.entries[0].path
? `${data.entries[0].path}`
: "No path";
if (data.entries[0].status_lasttime) {
let status_last = new Date(parseInt(data.entries[0].status_lasttime, 10) * 1000);
var laststat = status_last.toLocaleString("en-US", dateOptions);
//status += `\nSent on: ${laststat}`;
}
let coords = `${lat},${lng}`; let coords = `${lat},${lng}`;
let timeUpdated = new Date(data.entries[0].time * 1000); let timeUpdated = new Date(data.entries[0].time * 1000);
let miniMapUrl = `https://maps.googleapis.com/maps/api/staticmap?center=${coords}&zoom=13&size=600x300&maptype=roadmap&markers=color:blue|${coords}&key=${ let miniMapUrl = `https://maps.googleapis.com/maps/api/staticmap?center=${coords}&zoom=17&size=600x300&maptype=terrain&markers=color:red|${coords}&key=${config.gmaps_token}`;
config.gmaps_token let title = `APRS Information for ${callsign.toUpperCase()}`;
}`;
let locationEmbed = new Discord.RichEmbed() let locationEmbed = new Discord.RichEmbed()
.setColor(config.embed_color) .setColor(config.embed_color)
.setTitle(title)
.setAuthor("APRS Bot") .setAuthor("APRS Bot")
.addField("Coordinates", coords) //.setThumbnail("https://cdn.discordapp.com/avatars/449250687868469258/1709ab4f567c56eaa731518ff621747c.png?size=2048")
.addField("Altitude", altitude) .addField("Coordinates", coords.replace(",", ", "))
.addField("Time", timeUpdated.toLocaleString("en-US", dateOptions)) .addField("Last seen", timeUpdated.toLocaleString("en-US", dateOptions));
.addField( if (speed != "0") {
"Gmaps", locationEmbed.addField("Speed", speed);
}
if (course !== "0") {
let cc = parseInt (course, 10);
let dir = "parse error";
switch(true) {
case (cc === 0):
case (cc === 365):
dir = "Heading north";
break;
case (cc === 90):
dir = "Heading east";
break;
case (cc === 180):
dir = "Heading south";
break;
case (cc === 270):
dir = "Heading west";
break;
case (cc < 90):
dir = "Heading north-east";
break;
case (cc < 180):
dir = "Heading south-east";
break;
case (cc < 270):
dir = "Heading south-west";
break;
case (cc < 365):
dir = "Heading north-west";
break;
default:
dir = "parse error";
}
dir += ` (${cc} °)`;
locationEmbed.addField("Direction", dir);
}
if (altitude !== "0.00m") {
locationEmbed.addField("Altitude", altitude);
}
if (comment !== "No comment") {
locationEmbed.addField("Comment", comment);
}
if (status !== "No status") {
locationEmbed.addField(`Status (${laststat})`, status);
}
if (path !== "No path") {
locationEmbed.addField("Path", path);
}
/*locationEmbed.addField(
"Google Maps",
`https://www.google.com/maps/search/?api=1&query=${coords}` `https://www.google.com/maps/search/?api=1&query=${coords}`
)*/
locationEmbed.addField(
"APRS.fi",
`https://aprs.fi/#!mt=roadmap&z=11&call=a%2F${callsign.toUpperCase()}&timerange=3600&tail=3600`
) )
.setImage(miniMapUrl) .setImage(miniMapUrl)
//.addField("Path",
.setTimestamp() .setTimestamp()
.setFooter("Data sourced from https://aprs.fi/"); .setFooter("Data sourced from https://aprs.fi/");
message.channel.send({ embed: locationEmbed }); message.channel.send({ embed: locationEmbed });

Loading…
Cancel
Save