daily pastebin goal
34%
SHARE
TWEET

Untitled

a guest Jul 24th, 2017 471 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Create a function to auto load the script.
  2. (function() {
  3.     // Command event.
  4.     $.bind('command', function(event) {
  5.         // All of the default methods are stored in the event argument. You can change `event` to anything you want.
  6.         // To access a method, in this case, you would do `event.myMethod()`.
  7.    
  8.         // We are registering all method into variables to make it easier to remember.
  9.         var command = event.getCommand();
  10.         var sender = event.getSender();
  11.         var arguments = event.getArguments();
  12.         var args = event.getArgs();
  13.    
  14.         // You do not need to add the command prefix. This is already done in the bot's core in Java.
  15.         if (command.equalsIgnoreCase('command')) {
  16.    
  17.             // You can use the `$.say('')` function to send any message to Twitch chat.
  18.             $.say('This is a response from my custom script!');
  19.    
  20.             // You can also use the `$.consoleLn('')` function to print messages in the bot's console.
  21.             $.consoleLn('My custom script works!');
  22.         }
  23.    
  24.    
  25.         // Example of using the arguments and sender method.
  26.         // This command would work as the following. `!guess [anwser]`
  27.         if (command.equalsIgnoreCase('guess')) {
  28.    
  29.             // Note that `arguments` and `sender` was used here and not `event.getSender()`.
  30.             // This is because we stored them in a variable at the top of the function.
  31.             if (arguments.equalsIgnoreCase('i love phantombot')) {
  32.                 $.say(sender + ' you guessed the correct anwser!');
  33.             }
  34.         }
  35.    
  36.    
  37.         // Alright, let's say you only want one argument. This is where you would use the `getArgs()` method.
  38.         // This command would work as the following. `!color [color argument]`
  39.         if (command.equalsIgnoreCase('color')) {
  40.             // JavaScript and most codding langs count from 0, so we want to the first argument, being 0 in the case.
  41.             // We want to make sure the user specified something, for that we can use `!==` to make sure that `args[0]` is not undefined.
  42.             if (args[0] !== undefined) {
  43.                 $.say('Your favorite colour is ' + args[0]);
  44.             } else {
  45.                 $.say('Please specify your favorite colour.');
  46.             }
  47.         }
  48.     });
  49.    
  50.     // ircChannelMessage event.
  51.     $.bind('ircChannelMessage', function(event) {
  52.         // All of the default methods are stored in the event argument. You can change `event` to anything you want.
  53.         // To access a method, in this case, you would do `event.myMethod()`.
  54.    
  55.         // We are registering all method into variables to make it easier to remember.
  56.         var message = event.getMessage();
  57.         var sender = event.getSender();
  58.         var tags = event.getTags();
  59.  
  60.         // Here the bot will only respond if the message only has `candy` in it.
  61.         if (message.equalsIgnoreCase('candy')) {
  62.             $.say(sender + ' likes candy!');
  63.         }
  64.  
  65.         // But what if you want to check the message for a specific keyword? Here's how you would do it the simple way.
  66.         if (message.contains('bot')) {
  67.             $.say(sender + ' you have to try out PhantomBot. It\'s a great bot!');
  68.         }
  69.  
  70.         // The message event does not have the fancy `getArgs()` method, but you can do it yourself like this.
  71.         var args = message.split(' '); // This will create an array and split it at each space in the message.
  72.  
  73.         // Here's how you can use it. Here you have the get the second argument, `(1)` because it is not a command, if you get the first `(0)`
  74.         // You will get `candy`.
  75.  
  76.         // The bot will only reply if there is a second argument in the message.
  77.         if (message.contains('candy')) {
  78.             if (args[1] !== undefined) {
  79.                 $.say(sender + '\'s candy is ' + args[1]);
  80.             }
  81.         }
  82.     });
  83.    
  84.     // initReady event to register commands.
  85.     $.bind('initReady', function() {
  86.         // `script` is the script location. IT HAS TO BE IN SCRIPTS
  87.         // `command` is the command name without the `!` prefix.
  88.         // `permission` is the group number. 0, 1, 2, 3, 4, 5, 6 and 7.
  89.         // These are also used for the permcom command.
  90.         $.registerChatCommand('script', 'command', 'permission');
  91.    
  92.    
  93.         // Here's what it looks like.
  94.         $.registerChatCommand('./scripts/custom/funCommand.js', 'fun', 7);
  95.     });
  96. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top