-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Response style #3
Comments
Could you please add the raw response of the server? I can't test it myself right now since I'm in the process of reinstalling Windows. As for the issue, I was thinking of letting users pass custom parsers for certain commands. function myParser(str) {
// Do some parsing
return data;
}
const TeamspeakQuery = require('teamspeak-query');
const query = new TeamspeakQuery('127.0.0.1', 10011);
query.send('login', 'serveradmin', 'changeme')
.then(() => query.send(myParser, 'serverlist'))
.then(console.log); If one needs to run a command with a specific parser frequently, some javascript-magic could be applied: const niceSend = query.send.bind(query, myParser);
// use it
query.send('login', 'serveradmin', 'changeme')
.then(() => niceSend('serverlist'))
.then(() => niceSend('some other command'))
.then(() => niceSend('some other other command')); Common parsers for a case like yours could be added to the library. |
or privilegekeylist command
Thank you for fast answer Edit (schroffl): I removed the output of the two commands, just in case it contained any confidential data. |
Hey, I am currently not really sure why I parse responses as if it had this syntax: |
Hi, I think command |
const TeamspeakQuery = require('teamspeak-query');
const query = new TeamspeakQuery('127.0.0.1', 10011);
function parseList(data) {
return data.raw()
.split('|')
.map(TeamspeakQuery.parse)
.map(entry => entry.params);
}
query.send('login', 'serveradmin', 'changeme')
.then(() => query.send('use', 1))
.then(() => query.send('clientdblist'))
.then(parseList)
.then(console.log)
.catch(console.error); and if you use that pattern a few times you can create a small helper function function sendList() {
return query.send.apply(query, Array.from(arguments)).then(parseList);
}
query.send('login', 'serveradmin', 'changeme')
.then(() => query.send('use', 1))
.then(() => sendList('clientdblist'))
.then(() => sendList('clientlist'))
.then(console.log)
.catch(console.error); I would prefer to keep the core library as concise as possible and only expose a simple and clean API. |
Oh, check the bug, if output will parse by custom function in every element have raw data of server response. |
This is a result of mapping function parseList(data) {
return data.raw()
.split('|')
.map(TeamspeakQuery.parse)
.map(entry => entry.params)
.map(entry => {
delete entry.raw;
return entry;
});
} or if you want to keep it small function parseList(data) {
return data.raw()
.split('|')
.map(TeamspeakQuery.parse)
.map(entry => entry.params)
.map(entry => (delete entry.raw, entry));
} |
Ok, I have the last question when I try to connect to several instances by getting a list of servers from the api (returning object with data of every server instance), then there is a problem that connects only to one server. |
Could you add a small example? I'm not really sure what you mean. |
Hi, @schroffl. |
I don't see any problems in your code. Do you get any network errors while trying to connect? Are you sure that you are using the correct ip and port for your servers? |
Nope, haven't any errors. In api response same object, which was write in first example. |
You can send it to this email: schroffl@users.noreply.github.com |
Heh, okay, I prepare the instances and send the data for connection. |
Doesn't seem to have worked, can you try this one: <removed> |
Successful send data about instances to <removed> |
Resolved via e-mail |
Hi, schroffl yesterday i'm met with your library, it's awesome, but have an problem.
How to get command with one mere elements (serverlist for example) output like this, because not very comfortable to work with output like this.
Last library which i was work it is
node-teamspeak
thats return response this.The text was updated successfully, but these errors were encountered: