daily pastebin goal
10%
SHARE
TWEET

Untitled

Multivit4min Feb 19th, 2018 21 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. registerPlugin({
  2.     name: 'Roll',
  3.     version: '1.0',
  4.     description: 'This Script allows you to roll a random number!',
  5.     author: 'Multivitamin <david@multivitamin.wtf>',
  6.     vars: [{
  7.         name: 'max',
  8.         title: 'Default max number which should be rolled if only the command !roll has been used',
  9.         type: 'number'
  10.     }]
  11. }, function(sinusbot, config) {
  12.  
  13.     var sinusbot = null
  14.  
  15.     var event = require("event")
  16.     var backend = require("backend")
  17.  
  18.     var defaultMax = (isNaN(parseInt(config.max)) || parseInt(config.max) <= 1) ? 10 : parseInt(config.max)
  19.  
  20.     function roll(min, max) {
  21.         return Math.floor(Math.random() * (max - min + 1)) + min
  22.     }
  23.  
  24.     event.on("chat", function(ev) {
  25.         if (ev.text[0] != "!" || backend.getBotClient().uid() == ev.client.uid()) return
  26.  
  27.         if (ev.text.match(/^!help( (.+)?|$)/i)) {
  28.             ev.client.chat("This Plugin uses the Multivitamins roll Plugin! For more help use the command [b]!roll help[/b]")
  29.  
  30.         } else if (ev.text.match(/^!roll ?help ?$/i)) {
  31.             ev.client.chat("Multiple Paramateres are available, you can define minimum and maximum value by yoruself!")
  32.             ev.client.chat("[b]!roll 10[/b] Will roll a random value between 1 and 10")
  33.             ev.client.chat("[b]!roll 5 12[/b] Will roll a random value between 5 and 12")
  34.             ev.client.chat("[b]!roll[/b] Will roll a random value between 1 and "+defaultMax)
  35.  
  36.         } else if (ev.text.match(/^!roll ?(\d*) *-{0,1} *(\d*) *$/i)) {
  37.             var reply = getReplyMode(ev)
  38.             var min = 1
  39.             var max = defaultMax
  40.             var match = ev.text.match(/^!roll ?(\d*) *-{0,1} *(\d*) *$/i)
  41.             if (match[1] && match[2]) {
  42.                 if (parseInt(match[1]) >= parseInt(match[2]))
  43.                     return reply("First Number must be smaller than the second!")
  44.                 min = parseInt(match[1])
  45.                 max = parseInt(match[2])
  46.             } else if (match[1] && !match[2]) {
  47.                 if (min >= match[1])
  48.                     return reply("Number must be bigger than 1!")
  49.                 max = parseInt(match[1])
  50.             }
  51.             reply(getClientUrl(ev.client)+" rolled a [color=blue][b]"+roll(min, max)+"[/b][/color] ("+min+"-"+max+")")
  52.  
  53.         } else if (ev.text.match(/^!roll/)) {
  54.             ev.client.chat("Invalid Command usage! ([b]!roll <min> <max>[/b] or [b]!roll <max>[/b])")
  55.  
  56.         }
  57.     })
  58.  
  59.     function getReplyMode(ev) {
  60.         switch (ev.mode) {
  61.             case 3: return backend.chat
  62.             case 2: return ev.channel.chat
  63.             case 1:
  64.             default: return ev.client.chat
  65.         }
  66.     }
  67.  
  68.     function getClientUrl(c) {
  69.         return "[URL=client://"+c.id()+"/"+c.uid()+"~"+encodeURI(c.nick())+"]"+c.nick()+"[/URL]"
  70.     }
  71.  
  72.  
  73. })
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