• 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.

DE [Solved]User von ServerGruppe auslesen

Kamikaze

Well-Known Member
Contributor
Hallou!

Schreibe aktuell wieder ein Skript bei dem user die in einer bestimmten Servergruppe einen definierten channel joinen eine nachricht bekommen. dies ist ja kein problem, nun möchte ich aber hinzufügen, das wenn so ein client joint das user aus bestimmten servergruppen eine nachricht bekommen das der user in den channel gejoint ist.

Wie kann ich aus einer Servergruppe die User auslesen?
Hier ein auszug des Skripts (wird nachher noch optimiert^^)
JavaScript:
event.on('clientMove', function(ev) {

[...]

var ActiveGuestSupport = config.a_ActiveGuestSupport // 0|yes ; 1|no
var guestGroupID = config.b_guestGroupID
var guestMsg = config.bm_guestMessage
var supportGroupID = config.c_supportGroupID
var supportMsg = config.cm_supportMessage

if (ev.toChannel !== undefined) {
    engine.log(ev.toChanel)
    if (ev.toChannel.id() == 1) {
        if (ActiveGuestSupport == 0) {
            // Get ServerGroupId of moved user
            ev.client.getServerGroups().forEach(function(svg) {
                svgid = svg.id()
                guestGroupID.forEach(function(gugID) {
                    // If moved user is in guestGroups send msg
                    if (svgid == gugID) {
                        ev.client.chat(guestMsg) // User is in guestGroupID
                        
                        //Notify Support Group
                        supportGroupID.forEach(function(sugID) {
                            // Get User foreach Servergroup
                        })
                    }
                })
            })
        }
    }
}
 

irgendwr

no longer active, "retired" staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
Wie kann ich aus einer Servergruppe die User auslesen?
Sollte so in der art gehen (kann's gerade nicht testen):
JavaScript:
var backend = require('backend')
var clients = backend.getClients()

// get clients with matching group
var clientsWithGroup = getClientsWithGroup(clients, yourServergroupIdHere)

/**
 * Returns all clients with a specified group
 * @param {Client[]} clients
 * @param {(string|number)} groupId
 * @returns {Client[]}
 */
function getClientsWithGroup(clients, groupId) {
    // filter clients
    return clients.filter(function(client) {
        // check if clients has matching group
        return client.getServerGroups().some(function(clGroup) {
            return clGroup.id() == groupId
        })
    })
}

Docs:
https://sinusbot.github.io/scripting-docs/
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some
 

Kamikaze

Well-Known Member
Contributor
Sollte so in der art gehen (kann's gerade nicht testen):
JavaScript:
var backend = require('backend')
var clients = backend.getClients()

// get clients with matching group
var clientsWithGroup = getClientsWithGroup(clients, yourServergroupIdHere)

/**
* Returns all clients with a specified group
* @param {Client[]} clients
* @param {(string|number)} groupId
* @returns {Client[]}
*/
function getClientsWithGroup(clients, groupId) {
    // filter clients
    return clients.filter(function(client) {
        // check if clients has matching group
        return client.getServerGroups().some(function(clGroup) {
            return clGroup.id() == groupId
        })
    })
}

Docs:
https://sinusbot.github.io/scripting-docs/
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some
Danke, klappt :D
 
Top