Warning System Script


#11

Yeah that’s fine, but the command path also needs to match it.


#12

@IllusionaryOne on my side it don’t work:


what i’m doing wrong ?


#13

Change the registerChatCommand to ./custom/WarnSys.js. That is how I had it working at least.


#14

and again i don’t know where the wrong thing is:

    $.bind('command', function(event) {
        var command = event.getCommand();
		var sender = event.getSender();
		var args = event.getArgs();
		var reason = "";

        if (command.equalsIgnoreCase('warn')) {
            $.say(args[0] + ' dies ist deine erste Verwarnung!');
			for(var i = 1; i < args.length; i++){
				reason += args[1];
				if(i != args.length - 1){
					reason += " ";
				}
			}
			$.say("./timeout " + args[0] + " 5 " + reason);
			$.consoleLn('Warn');
        }
    });

i hope someone of you can see the failure


#15

I am not sure what isn’t working, but, ./timeout is not a Twitch command. .timeout is.


#16

yeah it should output the command as test reason


#17
[07-25-2017 @ 22:22:56.663 GMT] [ERROR] [loadScript()@ScriptManager.java:46] Failed to load module: custom/warnSys.js: JavaScript Error: missing ; before statement (warnSys.js#12)
[07-25-2017 @ 22:22:56.664 GMT] [ERROR] [loadScript()@ScriptManager.java:49] Terminating PhantomBot due to Bad JavaScript File

#18

It is telling you that Line 12 has an error. Can you paste the whole script? Or just check on line 12 to make sure you terminated the line with a semi-colon.?


#19
/**
 * warnSys.js
 *
 * A command that randomly picks a random message from the the randoms stack and post it in the chat.
 */
(function() {
	var 
	
    /**
     * @event command
     */
    $.bind('command', function(event) {
        var command = event.getCommand();
		var sender = event.getSender();
		var args = event.getArgs();
		var reason;

        /**
         * @commandpath random - Something random will happen
         */
        if (command.equalsIgnoreCase('warn')) {
            $.say(args[0] + ' dies ist deine erste Verwarnung!');
			for(var i = 1; i < args.length; i++){
				reason += args[1];
				if(i != args.length - 1){
					reason += " ";
				}
			}
			$.say("./timeout " + args[0] + " 5 " + reason);
			$.consoleLn('Warn');
        }
    });

    /**
     * @event initReady
     */
    $.bind('initReady', function() {
        if ($.bot.isModuleEnabled('./custom/warnSys.js')) {
            $.registerChatCommand('./custom/warnSys.js', 'warn', 3);
        }
    });
})();

#20

You have a var just hanging out there messing things up.


#21

its to late i think i should go sleep :laughing:


#22

Hey me again :joy:
now i want to test if db entry exist and if not i want to create it.
How can i check if an db entry exist (Number)?
I tried:

if ($.getSetIniDbNumber('my_db_table', 'test') == undefined){
	$.say("I have it");
}

#23

Describes all of the API calls for the INIDB, including what they do and what they return.


#24

i asked nothing :zipper_mouth_face:


#25

I spent a while on that particular page, is why I referenced it :slight_smile:

The $.getSetIniDBNumber() you are calling retrieves a value or sets it if it doesn’t exist. That would probably do what you want, but if you want to check to see if it was set prior (for displaying in chat I suppose) you would use:

boolean $.inidb.exists(String table_name, String key)
Returns true is the key exists in table_name.

You do need an additional parameter though for:
int $.getSetIniDbNumber(String table_name, String key, int defaultValue)

The above is what we use in many instances when setting initial values in the database in modules.


#26

Many thanks @IllusionaryOne that you spent your time on that. :smiley:

Maybe you can answer my last question.

The last thing i not know how to do that.
I want to reset the keys when the streamer went offline.
I know that i can ask if the streamer is offline but that didn’t help i think or can i solve it some this way ?

Or do i can use any change event to check if “variable” changed ?


#27

I want to perform an value search for an int value.
I tried:

  • At first
    if (command.equalsIgnoreCase('delwarnall')){
    var warnsys_test = $.inidb.searchByValue('warnSystem', 1);
    $.say(warnsys_test);
    }
    
    The error:
    [07-26-2017 @ 01:39:00.107 GMT] [ERROR] [init.js:318] (hook.call, command, ./custom/warnSys.js) InternalError: Java class "[Ljava.lang.String;" has no public instance field or method named "startsWith". (misc.js#116)
    

  • And after that:
    if (command.equalsIgnoreCase('delwarnall')){
    	var warnsys_test = $.inidb.searchByValue('warnSystem', '1');
    	$.say(warnsys_test);
    }
    
    With this error:
    [07-26-2017 @ 01:40:41.761 GMT] [ERROR] [init.js:318] (hook.call, command, ./custom/warnSys.js) InternalError: Java class "[Ljava.lang.String;" has no public instance field or method named "startsWith". (misc.js#116)
    

What am i doing wrong ?


#28

You’re not sending a string to $.say, you’re sending an array. Please read more about the functions that you are using and Rhino.

As stated in the docs, $.inidb.searchByValue() returns a string array (String[]).


#29

Is this finished ?? Id love this system on my bot


#30

Not completely I still didn’t build in that when the streamer went offline it automatically clear the Database.
And the Language files I didn’t managed to build in