Scrypt: The Luky ONE's


#1

Die script is to choose random Viewer/s from your Chat. The reson to do this is up to you :wink:

Copy just the Code below in Texteditor and save to: phantombot\scripts\commands…

Use in Chat !lucky (amount optional) -
exemple:
!lucky = "The Lucky ONE is RANDOMNAME"
or
!lucky 3 = ‚ÄúThe Lucky ONE‚Äôs are RANDOMNAME - RANDOMNAME - RANDOMNAME‚ÄĚ
!! No Admin, Mod, Bot or Owner will be choosen !!

If something not working like expected feel free to Reply to this post.

//Autoload function
(function() {
	//command setup
	$.bind('command', function(event){
		var command = event.getCommand();
        var sender = event.getSender();
        var arguments = event.getArguments();
        var args = event.getArgs();
		
		
		//!lucky command settings
		if(command.equalsIgnoreCase('lucky')){
			var name;
			var check = true;
			var message;
			var choosenArray = [];
			var amount = args[0];
			
			if(amount == undefined){
				amount = 1;
			}
			for(var i = 0; i < amount; i++){
				var count = 20; //Set trys befor break
				do{
					name = $.username.resolve($.randElement($.users)[0]);
					switch(true){
							//No Admin, Mod, Bot or Owner will be choosen
							case $.isAdmin(name):
							case $.isMod(name):
							case $.isBot(name):
							case $.isOwner(name):
								break;
							default:
								//make sure a Chatuser exists only once in Array list.
								var index = choosenArray.findIndex(function(nameExist){
									return nameExist == name;
								});
								if(index == -1){
									choosenArray.push(name);
								}
								else{
									break;
								}
								check = false;
								break;
					}
					
					//Break while if trys (count) reach 0
					//This happens if just Admin, Mod, Bot or Owner will be in chat
					count--;
					if(count == 0){
						break;
					}
				}while(check)
			}
			
			if(choosenArray.length == 0){
				message = "No Lucky ONE chosen!"; 
			}
			else{
				for(var i = 0; i < choosenArray.length; i++){
					if(i == 0){
						message = " - "+choosenArray[i];
					}
					else{
						message += " & "+choosenArray[i];
					}
					
				}
				
				var messageStart;
				switch(choosenArray.length){
					case 1:
						messageStart = "The Lucky ONE is ";
						break;
					default:
						messageStart = "The Lucky ONE's are ";
						break;
				}
				
				message = messageStart+message;
			}
			
			$.say(message);
		}
	});

	//register chat command
	$.bind('initReady', function(){
		$.registerChatCommand('./commands/lucky.js', 'lucky', 1);
	});
})();

#3

Hello Rain,
first thanks for your feedback.
And about discorde… i have never looked to code somethinge for it. May be i don’t use discord. An other point is: i code at moment a TwitchChatHelperForStreamer witch shows you easy your Chat, Dashboard, current Viewers and so on and this all without open a browser.
:wink: