Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- registerPlugin({
- name: 'Roll',
- version: '1.0',
- description: 'This Script allows you to roll a random number!',
- author: 'Multivitamin <david@multivitamin.wtf>',
- vars: [{
- name: 'max',
- title: 'Default max number which should be rolled if only the command !roll has been used',
- type: 'number'
- }]
- }, function(sinusbot, config) {
- var sinusbot = null
- var event = require("event")
- var backend = require("backend")
- var defaultMax = (isNaN(parseInt(config.max)) || parseInt(config.max) <= 1) ? 10 : parseInt(config.max)
- function roll(min, max) {
- return Math.floor(Math.random() * (max - min + 1)) + min
- }
- event.on("chat", function(ev) {
- if (ev.text[0] != "!" || backend.getBotClient().uid() == ev.client.uid()) return
- if (ev.text.match(/^!help( (.+)?|$)/i)) {
- ev.client.chat("This Plugin uses the Multivitamins roll Plugin! For more help use the command [b]!roll help[/b]")
- } else if (ev.text.match(/^!roll ?help ?$/i)) {
- ev.client.chat("Multiple Paramateres are available, you can define minimum and maximum value by yoruself!")
- ev.client.chat("[b]!roll 10[/b] Will roll a random value between 1 and 10")
- ev.client.chat("[b]!roll 5 12[/b] Will roll a random value between 5 and 12")
- ev.client.chat("[b]!roll[/b] Will roll a random value between 1 and "+defaultMax)
- } else if (ev.text.match(/^!roll ?(\d*) *-{0,1} *(\d*) *$/i)) {
- var reply = getReplyMode(ev)
- var min = 1
- var max = defaultMax
- var match = ev.text.match(/^!roll ?(\d*) *-{0,1} *(\d*) *$/i)
- if (match[1] && match[2]) {
- if (parseInt(match[1]) >= parseInt(match[2]))
- return reply("First Number must be smaller than the second!")
- min = parseInt(match[1])
- max = parseInt(match[2])
- } else if (match[1] && !match[2]) {
- if (min >= match[1])
- return reply("Number must be bigger than 1!")
- max = parseInt(match[1])
- }
- reply(getClientUrl(ev.client)+" rolled a [color=blue][b]"+roll(min, max)+"[/b][/color] ("+min+"-"+max+")")
- } else if (ev.text.match(/^!roll/)) {
- ev.client.chat("Invalid Command usage! ([b]!roll <min> <max>[/b] or [b]!roll <max>[/b])")
- }
- })
- function getReplyMode(ev) {
- switch (ev.mode) {
- case 3: return backend.chat
- case 2: return ev.channel.chat
- case 1:
- default: return ev.client.chat
- }
- }
- function getClientUrl(c) {
- return "[URL=client://"+c.id()+"/"+c.uid()+"~"+encodeURI(c.nick())+"]"+c.nick()+"[/URL]"
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement