• 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 Befehl nur X Mal benutzbar + Beschreibung ändern

Hallo,
hat jemand eventuell einen Ansatz oder eine Idee für mich wie man einen Befehl nur X Mal verwenden kann? Ebenfalls habe ich probleme dabei die Beschreibung von jemandem zu ändern, auch hier bin ich offen für ideen.
Danke im Vorraus!
~ Kuschel

PS: Ich bin noch recht neu beim Sinusbot Scripts Schreiben
 

DrWarpMan

Well-Known Member
Contributor
Insider
Hallo,
hat jemand eventuell einen Ansatz oder eine Idee für mich wie man einen Befehl nur X Mal verwenden kann? Ebenfalls habe ich probleme dabei die Beschreibung von jemandem zu ändern, auch hier bin ich offen für ideen.
Danke im Vorraus!
~ Kuschel

PS: Ich bin noch recht neu beim Sinusbot Scripts Schreiben
Depends whether you want to disable commands coming from Sinusbot itself (!play, !yt, !stop) or you want to disable commands coming from your own script.
 

DrWarpMan

Well-Known Member
Contributor
Insider
So you want to have a command blocked, when used more than 10 times for example?
Then I'd do something like storing the UID + the command(s) to an object variable (possibly in a database) and set value to 0, increase it each time a command is used, and add a check for whether the number is > X..
 
Last edited:

DrWarpMan

Well-Known Member
Contributor
Insider
JavaScript:
registerPlugin({
    name: "Demo Script",
    version: "0.1",
    description: "Demo Script",
    author: "DrWarpMan <[email protected]>",
    backends: ["ts3"],
    engine: ">= 1.0",
    autorun: false,
    enableWeb: false,
    hidden: false,
    requiredModules: [],
    vars: [],
    voiceCommands: []
}, (_, config, meta) => {

    const backend = require("backend");
    const engine = require("engine");
    const event = require("event");
    const store = require("store");

    /*

        Amount => the amount of how many times you have used that command, I could not find any better word for this,
        so just that you know that what amount is :D

        I have not tested it, it may have typos, and it may not even start, or work - give me feedback

    */

    event.on("chat", ev => {
        // This is my way how to make command and arguments from text message
        let message = ev.text.split(" ").filter(i => /\s/.test(i) === false && i.length > 0); // Get text from event, split the text ( message ), remove multiple spaces
        let command = message[0].toLowerCase(); // Get command from the message
        let args = message.slice(1).join(" "); // Get args from message (after first space) - IGNORE THIS
        let client = ev.client; // Get client from event

        if (command === "!mycmd") {
            if (getCommandAmount(client, command) < 10) // If command was used less than 10 times
            {
                addCommandAmount(client, command); // Add command amount
            } else {
                client.chat("Nope, you can not write this command anymore!"); // If reached max. (10 times)
            }
        }
    });

    function getCommandAmount(client, command) {
        return store.get(client.uid() + " " + command) || 0; // Get current amount from store, if undefined - return 0
    }

    function addCommandAmount(client, command) {
        let currentAmount = getCommandAmount(client, command); // Get current amount
        currentAmount++; // Increase current amount
        store.set(client.uid() + " " + command, currentAmount); // Store current amount
        client.chat("Command amount added!"); // Message that command amount was added succesfully!;
    }

    // SCRIPT LOADED SUCCCESFULLY - this is what I use in every single script of mine, (inspired by irgendwr)
    engine.log("[Script] \"" + meta.name + "\" [Version] \"" + meta.version + "\" [Author] \"" + meta.author + "\"");
});
 
JavaScript:
registerPlugin({
    name: "Demo Script",
    version: "0.1",
    description: "Demo Script",
    author: "DrWarpMan <[email protected]>",
    backends: ["ts3"],
    engine: ">= 1.0",
    autorun: false,
    enableWeb: false,
    hidden: false,
    requiredModules: [],
    vars: [],
    voiceCommands: []
}, (_, config, meta) => {

    const backend = require("backend");
    const engine = require("engine");
    const event = require("event");
    const store = require("store");

    /*

        Amount => the amount of how many times you have used that command, I could not find any better word for this,
        so just that you know that what amount is :D

        I have not tested it, it may have typos, and it may not even start, or work - give me feedback

    */

    event.on("chat", ev => {
        // This is my way how to make command and arguments from text message
        let message = ev.text.split(" ").filter(i => /\s/.test(i) === false && i.length > 0); // Get text from event, split the text ( message ), remove multiple spaces
        let command = message[0].toLowerCase(); // Get command from the message
        let args = message.slice(1).join(" "); // Get args from message (after first space) - IGNORE THIS
        let client = ev.client; // Get client from event

        if (command === "!mycmd") {
            if (getCommandAmount(client, command) < 10) // If command was used less than 10 times
            {
                addCommandAmount(client, command); // Add command amount
            } else {
                client.chat("Nope, you can not write this command anymore!"); // If reached max. (10 times)
            }
        }
    });

    function getCommandAmount(client, command) {
        return store.get(client.uid() + " " + command) || 0; // Get current amount from store, if undefined - return 0
    }

    function addCommandAmount(client, command) {
        let currentAmount = getCommandAmount(client, command); // Get current amount
        currentAmount++; // Increase current amount
        store.set(client.uid() + " " + command, currentAmount); // Store current amount
        client.chat("Command amount added!"); // Message that command amount was added succesfully!;
    }

    // SCRIPT LOADED SUCCCESFULLY - this is what I use in every single script of mine, (inspired by irgendwr)
    engine.log("[Script] \"" + meta.name + "\" [Version] \"" + meta.version + "\" [Author] \"" + meta.author + "\"");
});
tanks, works fine <3
A idear for description change?
 

DrWarpMan

Well-Known Member
Contributor
Insider
I am not sure what do you want exactly.

Change description of command executor client / Change description of bot upon command from client / ... / ... ?
 
Das ich nicht so spamme frage ich einfach hier nach, gibt es eine möglichkeit zu überprüfen ob ein benutzer eine Gruppe hat? Er kann beliebig viele andere haben, jedoch möchte ich überprüfen ob diese dabei ist. Wie mache ich das?
 

TwentyFour

BinusSot Junkie
V.I.P.
Contributor
Insider
Das ich nicht so spamme frage ich einfach hier nach, gibt es eine möglichkeit zu überprüfen ob ein benutzer eine Gruppe hat? Er kann beliebig viele andere haben, jedoch möchte ich überprüfen ob diese dabei ist. Wie mache ich das?
Du würdest getServerGroups() auf den Benutzer anwenden. Das zurückgegebene Array aller zugewiesenen Servergroups durchläufst du dann, und schaust, ob die gewünschte dabei ist.
Ein Beispiel wäre dieses Skript von @DrWarpMan (die Funktion checkUsers):
https://forum.sinusbot.com/resources/group-checker.390/

Wenn du viele solcher Abfragen benötigst, gibts da die OKlib, da sind schon viele hilfreiche Funktionen zusammengefasst, die dir etwas Code-Arbeit abnehmen. Ein Beispiel für ein Skript, das die OKlib nutzt, wäre hier:
https://forum.sinusbot.com/resources/rlnt-move-on-connect.424/
 
So und ich hoffe nun ein letztes mal mit diesem Skript dass ich hier um hilfe bitten muss, das ist mein derzeitiges Skript, jedoch bekomme ich immer folgende Log nachricht.
JavaScript:
registerPlugin({
    name: "Vanish",
    version: "0.1",
    description: "Diese Einstellungen dürfen NICHT geändert werden.",
    author: "Kuschel",
    backends: ["ts3"],
    engine: ">= 1.0",
    autorun: false,
    enableWeb: false,
    hidden: false,
    requiredModules: [],
    vars: [{

      
    
            name: 'pm',
            title: 'Erlaubte Gruppen',
            type: 'strings'
    
    
    }],
    voiceCommands: []
}, (_, config, meta) => {

    const backend = require("backend");
    const engine = require("engine");
    const event = require("event");
    const store = require("store");

 

    

    event.on("chat", ev => {
        let client = ev.client;

        if (ev.text == "!vanish") {
            if (hasRights(client)) {
                
                if (hasServerGroupWithID(client, 33)) {
                store.set("vanish" + client.uid(), 33);
                client.removeFromServerGroup(33);
                client.addToServerGroup(9);
                client.chat("[color=#b700ff]Rangsystem ×[/color] Du hast nun den Vanishmodus betreten, nutze [color=red]!vanish[/color] um diesen wieder zu verlassen.");
                engine.log("[Vanish] Der Nutzer" + client.name + "hat den Vanishmodus betreten.");
                }
                
                                
                
            } else

                {

                    if (store.get("vanish" + client.uid()) === undefined) {
                        
                    }
                    else {
                    client.chat("[color=#b700ff]Rangsystem ×[/color] Du hast nun den Vanishmodus verlassen, nutze [color=red]!vanish[/color] um diesen wieder zu betreten.");
                engine.log("[Vanish] Der Nutzer" + client.name + "hat den Vanishmodus verlassen.");   
                client.addToServerGroup(makeback(client));
                client.removeFromServerGroup(9);
            } }
    }});
function hasRights(client) {
        if (config.pm === undefined)
            return false;
        else return checkArrays(client.getServerGroups().map(group => group.id()), config.pm);
    }

    function hasServerGroupWithID(client, id) {
        return client.getServerGroups().some(function(group) {
            return group.id() == id;
        });
    }

  
function makeback(client) {
    return store.get("vanish" + client.uid())
}
    function checkArrays(arr1, arr2) {
        if (arr1 === undefined || arr2 === undefined)
            return false;

        return arr2.some(item => arr1.includes(item));
    }
});

Lognachricht: "< vanish > Command ignored, user unknown. "
 

flyth

is reticulating splines
Staff member
Developer
Contributor
Lognachricht: "< vanish > Command ignored, user unknown. "
Die Logmeldung kommt, weil der Bot selbst den Befehl nicht kennt, aber denselben Präfix nutzt. Kannst du also ignorieren.

Bitte formatiere das Script ordentlich, bevor du es hier postest. Das mag sonst echt niemand lesen (verstehen) und hilft auch dir selbst nicht gerade beim basteln ;)
 
JavaScript:
registerPlugin({
    name: "Vanish",
    version: "0.1",
    description: "Diese Einstellungen dürfen NICHT geändert werden.",
    author: "Kuschel",
    backends: ["ts3"],
    engine: ">= 1.0",
    autorun: false,
    enableWeb: false,
    hidden: false,
    requiredModules: [],
    vars: [{
        name: 'pm',
        title: 'Erlaubte Gruppen',
        type: 'strings'
    }],
    voiceCommands: []
}, (_, config, meta) => {
    const backend = require("backend");
    const engine = require("engine");
    const event = require("event");
    const store = require("store");
    event.on("chat", ev => {
        let client = ev.client;
        if (ev.text == "!vanish") {
            if (hasRights(client)) {   
                if (hasServerGroupWithID(client, 33)) {
                store.set("vanish" + client.uid(), 33);
                client.removeFromServerGroup(33);
                client.addToServerGroup(9);
                client.chat("[color=#b700ff]Rangsystem ×[/color] Du hast nun den Vanishmodus betreten, nutze [color=red]!vanish[/color] um diesen wieder zu verlassen.");
                engine.log("[Vanish] Der Nutzer" + client.name + "hat den Vanishmodus betreten.");
                }
            } else
                {
                    if (store.get("vanish" + client.uid()) === undefined) {
                    }
                    else {
                    client.chat("[color=#b700ff]Rangsystem ×[/color] Du hast nun den Vanishmodus verlassen, nutze [color=red]!vanish[/color] um diesen wieder zu betreten.");
                engine.log("[Vanish] Der Nutzer" + client.name + "hat den Vanishmodus verlassen.");   
                client.addToServerGroup(makeback(client));
                client.removeFromServerGroup(9);
            } }
    }});
function hasRights(client) {
        if (config.pm === undefined)
            return false;
        else return checkArrays(client.getServerGroups().map(group => group.id()), config.pm);
    }
    function hasServerGroupWithID(client, id) {
        return client.getServerGroups().some(function(group) {
            return group.id() == id;
        });
    }

function makeback(client) {
    return store.get("vanish" + client.uid())
}
function checkArrays(arr1, arr2) {
    if (arr1 === undefined || arr2 === undefined)
        return false;
    return arr2.some(item => arr1.includes(item));
    }
});

So dann hier nochmal der ordentliche Code :D
 
Top