Warning System Script


#1

Hello i want to realise a Warning System but I’m new to this type of JS development and I not really know how to start.

I have two main question before starting:

  • How can I get an stream stop?
  • And how can I create 2 args, the first arg should be only one word (a Username), and the second arg should get everything after arg 1.

Thanks for helping


#2

Can you explain further what you mean by “stream stop?” Do you want to know when Twitch tells PhantomBot that the stream has stopped?

Regarding the arguments, this is for a custom command (!addcom) or you are wanting to write a script for something more specialized based on the ‘stream stop’ question?


#3

yeah i want to clear the warnings when Twitch tells PhantomBot that the stream has stopped

yeah like that but within the script i want to do that.


#4

if ya know how to use the twitch API you could just run ya script to check when the streams stopped rather than getting a responce from phantombot (not recommended but its stil an option)


#5

i think phantombot have included somthing that tell if the stream is stopped


#6

$.isOnline($.channelName);

This reports that status of the stream from the Twitch API. It returns true if the stream is online and false if offline.

Remember that the Twitch API caching in PhantomBot runs every 30 seconds and that Twitch generally takes 2-5 minutes to report the status of a stream being up/down (which is why we do not constantly hammer the Twitch API).


#7

What i’m doing wrong?
It output nothing:

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


        if (command.equalsIgnoreCase('warn')){
            $.say("Test Warn");
            $.consoleLn("Warn");
			return;
        }
    });
    $.bind('initReady', function () {
        $.registerChatCommand('./custom/WarnSys.js', 'warn', 7);
    });
})();

#8

Works for me (running from Console, bot in Mute Mode):

warn
[07-24-2017 @ 16:39:22.462 MDT] [MUTED] Test Warn
[07-24-2017 @ 16:39:22.464 MDT] Warn

#9

Change the script location to ./scripts/custom and change this $.registerChatCommand('./custom/WarnSys.js', 'warn', 7); to this $.registerChatCommand('./scripts/custom/WarnSys.js', 'warn', 7);

All scripts have to be in the scripts folder.

Edited the guide, sorry about that.


#10

I thought that they Need to ne in the Script Folder so I put it in ./scripts/custom/WarnSys.js will test the changes later


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