I would like to build a command , in Node.js with Visual Studio Code, which will take data from FiveM and will show in a message how many players are online and if there is a Queue !
I will post an image and I will show what i mean:
I am using a code that logs in console and the code is :
const Gamedig = require('gamedig');
Gamedig.query({
type: 'fivem',
host: 'fivem.example.com'
}).then((state) => {
console.log(state);
}).catch((error) => {
console.log("Server is offline");
});
I would like to ask if there is a way to set as command and display "image" view!
According to the gamedig documentation, the state param that is going in the callback function have not that much predefined properties. You can retrieve directly how many players are online by the players.length property, accessing it by state.players.length inside the callback function in the then() method. But there's too a raw property which seems to return all the info the server gives you back, so you can try to parse it and retrieve any other relevant info.
Use the FiveM package to get server info.
You can get the players like this:
const FiveM = require("fivem") // Import the npm package.
const srv = new FiveM.Server('IP:PORT') // Set the IP with port.
srv.getPlayers().then(data => console.log(data)) // Get & log the data!
or the whole server object:
srv.getServer().then(data => console.log(data)) // Get & log the data!
Enjoy.
Related
Im using the puppeteer package , in order to scrap a web page data that is fetched by clicking a button in this page
this are the presetting that I'm using:
const puppeteer = require('puppeteer-extra')
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
puppeteer.use(StealthPlugin())
// Add adblocker plugin to block all ads and trackers (saves bandwidth)
const AdblockerPlugin = require('puppeteer-extra-plugin-adblocker')
puppeteer.use(AdblockerPlugin({ blockTrackers: true }))
those setting are made in order that I will not be detected as a robot.
here what I'm doing :
(basically , creating a request by clicking a button , then this request return a json with a data that fill up some text info in a label , then I'm reading the data from that label
here's how im clicking the button :
const box = await btn.boundingBox();
const x = box.x + (box.width/2);
const y = box.y + (box.height/2);
console.log(x, y);
page.mouse.move(x,y,{step:1});
page.mouse.click(x,y)
await page.waitForTimeout(4000);
then afterwards ---> I'm getting the data from the data:
const [result] = await page.$x('//*[#id="content"]/div[1]/div[1]/div/div[2]/div');
// const txt = await result.evaluate.toString
let value = await page.evaluate(el => el.textContent, result);
console.log(value);
console.log('done?');
await browser.close();
const dic = {};
dic['status'] = 200;
dic['data'] = {"message": value};
response.send(dic);
I'm also using the 'on' method in order to see if the im getting a response from the action of clicking the button , like so:
await page.on('response', async response =>{
try {
console.succ(await response.json());
} catch (error) {
//
// console.error(error);
}
});
and it sure get one.
the problem is ---> that when I'm deploying it to the firebase cloud functions server,
firebase deploy --only functions
and then triggering the function -->
I'm getting a json that look like this :
{ success: false, message: 'You look like a robot.' }
But when deploying the same code to my local host like so
firebase serve --only functions
and then triggering the function -->
I'm not detected as a robot
and getting the json with a successful result --> and with that data that the clicking of a button supposed to fetch.
this is so weird , I'm trying to think that there's a connections between the firebase cloud functions and reCAPTCHA , because both are a google services
but, its not seem's reasonable for it to be true .
that being said, what could be the reason for this?
all that change is the environment that the code runs from.
do you have any idea why this is happening ?
and how to solve it of course .
Since your function runs properly locally, it's almost certainly not the function itself.
Sites take a variety of different approaches to detect bots, one of which is blocking traffic from known data centers like Google Cloud's. Using a residential IP proxy like those provided by BrightData will probably circumvent this.
I'm facing the same issue while using Puppeteer in Firebase Cloud Functions.
I'm using a residential IP proxy with the following set of packages puppeteer-extra, puppeteer-extra-plugin-stealth, puppeteer-extra-plugin-anonymize-ua', and user-agents`.
On localhost, all is working as expected while running Puppeteer in firebase Cloud Functions I'm getting a 404 response from the requested URL. So there must be some difference.
I am trying to send a message from one connected node server to the other using the following code in server.js and server1.js:
const hyperswarm = require('hyperswarm')
const crypto = require('crypto')
const swarm = hyperswarm()
// look for peers listed under this topic
const topic = crypto.createHash('sha256')
.update('mycoolstuff')
.digest()
swarm.join(topic, {
lookup: true, // find & connect to peers
announce: true // optional- announce self as a connection target
})
swarm.on('connection', (socket, details) => {
//console.log('new connection!', details)
// you can now use the socket as a stream, eg:
process.stdin.pipe(socket).pipe(process.stdout)
})
The problem is the message from one terminal is duplicated on the other.
For example, if I type the following in server.js's terminal:
test 123
I get the following in server1.js's:
test 123
test 123
. . . and vice versa
I can work around this by setting one of the two servers to not announce:
swarm.join(topic, {
lookup: true, // find & connect to peers
announce: false // <--------- don't announce, stops duplicates
})
But I would prefer that both servers announce.
What am I misunderstanding about sockets, stdin, or hyperswarm here?
Well, I found my own answer inside the node module folder for hyperswarm in the file called example.js
I added the following:
const {
priority,
status,
retries,
peer,
client
} = details
if (client) process.stdin.pipe(socket)
else socket.pipe(process.stdout)
Which solved my problem.
I'm trying to integrate Twilio into a triggered Firestore function. The problem I'm having is when I add this code, I am unable to deploy ANY functions. As far as I know this is how to use twilio inside a cloud function. At the top I have this and I think firebase doesn't like something here because ALL functions stop deploying with this code.
// Used to send text messages
const twilio = require('twilio')
// const accountSid = functions.config().twilio.sid
// const authToken = functions.config().twilio.token
/* eslint new-cap: ["error", { "newIsCap": false }] */
const client = new twilio('ACblahblahblah', 'ccblahblahblah') // sid and token
const twilioNumber = '+13344714571' // your twilio phone number
Within the triggered function I have this. But I don't think the issue is here:
return client.messages.create({
to: someNumber,
from: twilioNumber,
body: 'Some message.'
}).then((data) => {
console.log(data)
}).catch((error) => {
console.log(error)
})
I have a valid Twilio account set up. The function logs don't tell me much other than that the function cannot be initialized. What am I missing? Seems like this has worked for others.
Figured it out about 5 minutes after posting the question. I had not installed twilio in the functions folder but rather the root of the project. Once I executed
npm install twilio
in the functions folder, the functions started deploying. Too bad there was no error in the logs that said something like "required package is missing" or something like that.
For some reason documents created on my app are not showing up on my remote couchdb database.
I am using the following
import PouchDB from 'pouchdb-react-native'
let company_id = await AsyncStorage.getItem('company_id');
let device_db = new PouchDB(company_id, {auto_compaction: true});
let remote_db = new PouchDB('https://'+API_KEY+'#'+SERVER+'/'+company_id, {ajax: {timeout: 180000}});
device_db.replicate.to(remote_db).then((resp) => {
console.log(JSON.stringify(resp));
console.log("Device to Remote Server - Success");
return resp;
}, (error) => {
console.log("Device to Remote Server - Error");
return false;
});
I get a successful response the response:
{
"ok":true,
"start_time":"2018-05-17T15:19:05.179Z",
"docs_read":0,
"docs_written":0,
"doc_write_failures":0,
"errors":[
],
"last_seq":355,
"status":"complete",
"end_time":"2018-05-17T15:19:05.555Z"
}
When I go to my remote database, document_id's that am able to search and grab on the application do not show up.
Is there something I am not taking into account?
Is there anything I can do to check why this might be happening?
This worked when I used the same scripting method in Ionic and when I switched to React-Native I noticed this is the case.
NOTE: When I do .from() and get data from remote to the device, I get the data. For some reason it just isn't pushing data out
"Is there anything I can do to check why this might be happening?"
I would try switching on debugging as outlined here.
PouchDB.debug.enable('*');
This should allow you to view debug messages in your browser's JavaScript console.
I have been working on a simple chat bot using the slack-node web api and botkit, but am having some trouble using the chat.delete functionality. I am able to list out all of my channels properly, seeing their channel Id's and names, but when I try to send along the message channel with the chat.delete function, it returns "channel_not_found".
I have also tried to send along the channel name, testing with "general" and the actual channel name that I am targeting, both of which return the same error.
My bot is using a token of the admin user, which should allow deletion of any message. My bot has scope access for chat:write:bot and chat:write:user as well.
Below is a snippet of my code - I have also tried this in other places for deleting messages sent directly from the bot and get the same error, so I don't believe it has to do with permissions. I've looked into the docs and the usage seems to be correct for what I have below, but I may be missing a piece.
controller.on('ambient', function(bot, message) {
web.channels.list().then((res) => {
console.log(res); // this prints out all of the channels
// listed channels show a match for the channel ID given in message.channel
});
// this call returns an error "error: Response not OK: channel_not_found"
web.chat.delete(message.channel, message.ts).then((res) => {
console.log(res + " was deleted bc it was not tagged");
}).catch((err) => { console.log(err) });
});
The docs are a bit confusing on this, but the chat.delete method of the official #slack/client library take the parameters in a different order:
You'll want to change your code to be:
web.chat.delete(message.ts, message.chanel).then(...)
See here:
https://slackapi.github.io/node-slack-sdk/reference/ChatFacet#ChatFacet+delete