• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.

kamilmaj

New Member
Hey guys,

I need some help with something I am working for our Teamspeak server. I am still very new to scripting and have been reading through the scripting documentation but I'm not sure exactly how to write a script that will extract a text for example from a website and send it when a command is used. This is for a flight simulation enthusiasts ts3 server and essentially we want the command to pull the latest weather report in the form of whats called a METAR/TAF.

Here a list of websites (all have the same information) and example wether information for Warsaw airport (the airport code is EPWA:
https://www.aviationweather.gov/add...hk_tafs=on&chk_metars=on&std_trans=translated
https://www.rocketroute.com/airports/europe-eu/poland-pl/metar-warsawchopinairport-epwa.html
https://www.checkwx.com/weather/EPWA/metar
https://en.allmetsat.com/metar-taf/poland.php?icao=EPWA

Now from any of these Websites, when I type the command ( !metar EPWA ) I want this to give me this text which gets updated on the websites every hour
METAR: EPWA 151230Z 18008KT 150V210 CAVOK 06/M12 Q1029 NOSIG.

If anyone would be able to assist me on this or direct me to tutorial/script that shows something similar to this I would appreciate a lot.
 

Timo

Well-Known Member
Contributor
JavaScript:
http = {
                "method": "GET",
                "url": yourapi,
                "timeout": 60000,
                "headers": [{
                    "Content-Type": "text/plain; charset=UTF-8"
                }]
            };

            function Process(error, response) {
                LastResponse = response
                if (response.statusCode != 200) {
                    engine.log("Sorry, Your API/Website is currently not available.");
                    return;
                } else {
                    msg_g = response.data;
                    //engine.log(response.data);
                }
            }

            sinusbot.http(http, Process);
 

kamilmaj

New Member
Hey so i have this so far but not sure this will give me what i need and also if i try to see if its working and i put the javascript file into the script folder, when i start the sinusbot i cant see the script in the addons list.

registerPlugin({
name: 'Metar',
version: '1.0',
description: 'Metar Info',
author: 'Kamil Majchrzak <[email protected]>',
vars: [

{
name: 'cmd',
title: 'Command',
type: 'string',
placeholder: '!metar',
}],
autorun: true
}, sinusbot.http(http, Process); {
http = {
"method": "GET",
"url": https://en.allmetsat.com/metar-taf/poland.php?icao=EPWA,
"timeout": 60000,
"headers": [{
"Content-Type": "text/plain; charset=UTF-8"
}]
};

function Process(error, response) {
LastResponse = response
if (response.statusCode != 200) {
engine.log("Sorry, Your API/Website is currently not available.");
return;
} else {
msg_g = response.data;
//engine.log(response.data);
}
}
});
 

Multivitamin

Well-Known Member
Tier III
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
sinusbot.http is already since a few yeats deprecated and since a few months not in the builds of sinusbot
to make a http request you need this:

JavaScript:
registerPlugin({
  name: "HTTP Example",
  engine: ">= 1.0.0",
  version: "1.0.0",
  description: "example",
  author: "Multivitamin <[email protected]",
  requiredModules: ["http"],
  vars: []
}, () => {

  const http = require("http")

  http.simpleRequest({
    url: "http://example.com",
  }, (err, res) => {
    if (err) throw err
    console.log(`Got answer:`)
    console.log(res)
  })

})

eventually you will also need to reload the script via webinterface in order to get the script working
 

kamilmaj

New Member
Thanks so far for the help guys. Now what I was wondering is how I can pull text from a website by using a command. I already have an HTML version of this where using a special link it will get a text string with the METAR.

This is how the HTML simple looks.

<div class="checkwx-container" data-type="METAR" data-station="EGSS"></div>
<script src="https://api.checkwx.com/widget?key=ee56366740763e5334407e5455 " type="text/javascript"></script>

the most important from these 2 is the link and the data-station. if i run this it will open up a website that will show me this

1584293732362.png
which is a text string of the metar for the airpot with the code EGSS

how can i get this to work using javascript.

So that for example if a user on the TS3 server types in :
!metar EGSS

where !metar is the command and EGSS is the data-station

it will send a message of this to the user
EGSS METAR 151650Z AUTO 31005KT 6000 -RA SCT006 BKN016 OVC024 07/07 Q1007

Thanks again guys for the help :)
 
Top