This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

i'm going to burn in hell for this aren't i

  • Loading branch information...
damianb committed Jun 23, 2012
1 parent 86e95fc commit 4fafb16b611601e6b212292ba1dcad9eeae4c739
Showing with 74 additions and 29 deletions.
  1. +28 −24 bot.js
  2. +46 −5 command/dice.js
View
52 bot.js
@@ -110,8 +110,8 @@ client.addListener('message' + nconf.get('bot:primarychannel'), function (nick,
var command = split.shift()
if(command in yukari.message_hooked) {
for(var c in yukari.message_hooked) {
if(yukari.commands[yukari.message_hooked[command][c]].validate(command, split)) {
yukari.commands[yukari.message_hooked[command][c]].process(
if(yukari.commands[yukari.message_hooked[command][c]].validateMessage(victim, split)) {
yukari.commands[yukari.message_hooked[command][c]].processMessage(
function(message){
if(message == false) {
client.action(nconf.get('bot:primarychannel'), 'hiccups')
@@ -120,43 +120,47 @@ client.addListener('message' + nconf.get('bot:primarychannel'), function (nick,
}
},
nick,
command,
split
)
}
}
} else {
// @todo - magic commands / factoids
}
yukari.parseCommand(client, nconf.get('bot:primarychannel'), nick, command, split)
//yukari.parseCommand(client, nconf.get('bot:primarychannel'), nick, command, split)
}
})
/**
* YouTube URI Eavesdropping
*/
* non-command eavesdropping...
*
client.addListener('message' + nconf.get('bot:primarychannel'), function (nick, text) {
youtube = text.match(/http:\/\/(?:(?:www\.)?youtube\.com|youtu\.be)(?:\/watch\?v=|\/)([\w\-\_]+)/ig)
if(youtube != null) {
for(i in youtube) {
var videoid = false
var params = url.parse(youtube[i],true)
if(params['query']['v'] != null) {
videoid = params['query']['v']
} else if(params['hostname'] == 'youtu.be' && params['path'] != null) {
videoid = params['path'].split('/')[1]
}
if(text.charAt(0) != nconf.get('bot:command')) {
youtube = text.match(/http:\/\/(?:(?:www\.)?youtube\.com|youtu\.be)(?:\/watch\?v=|\/)([\w\-\_]+)/ig)
if(youtube != null) {
for(i in youtube) {
var videoid = false
var params = url.parse(youtube[i],true)
if(params['query']['v'] != null) {
videoid = params['query']['v']
} else if(params['hostname'] == 'youtu.be' && params['path'] != null) {
videoid = params['path'].split('/')[1]
}
if(videoid != false) {
yukari.grabYoutube(videoid, function(ret) {
if(ret !== false) {
client.say(nconf.get('bot:primarychannel'), ret.replace('[YouTube]', '[' + irc.colors.wrap('light_red', 'You') + irc.colors.wrap('white', 'Tube') + ']'))
} else {
client.action(nconf.get('bot:primarychannel'), 'hiccups')
}
})
if(videoid != false) {
yukari.grabYoutube(videoid, function(ret) {
if(ret !== false) {
client.say(nconf.get('bot:primarychannel'), ret.replace('[YouTube]', '[' + irc.colors.wrap('light_red', 'You') + irc.colors.wrap('white', 'Tube') + ']'))
} else {
client.action(nconf.get('bot:primarychannel'), 'hiccups')
}
})
}
}
}
}
})
*/
/**
* runtime
View
@@ -1,4 +1,3 @@
// oh god what am i doing
module.exports = {
name:"dice",
@@ -11,11 +10,53 @@ module.exports = {
yukari.register('message', 'dice', 'roll')
},
validate:function(command, args) {
// asdf
validateMessage:function(victim, args) {
var match = args.match(/(\d+)\s*d\s*(\d+)(\s*[-+]\s*\d+)?(.*)/i)
if(match != null || match.length < 2) {
return true
}
return false
},
process:function(callback, victim, command, args) {
// asdf
processMessage:function(callback, victim, args) {
var match = args.match(/(\d+)\s*d\s*(\d+)(\s*[-+]\s*\d+)?(.*)/i)
var number, sides, additional, rest
match.shift()
number = match.shift()
sides = match.shift()
if(match.length > 0) {
additional = match.shift()
}
if(match.length > 0) {
rest = _s.trim(match.join(''))
}
if(additional) {
additional = _s.trim(additional).replace(' ', '')
if(additional.charAt(0) == '-') {
additional = parseInt(additional) * -1
} else {
additional = parseInt(additional)
}
}
var roll = 0, rolls = []
for(i = 0; i < number; i++) {
var t = 0
if(sides >= 1) {
t = Math.floor(Math.random() * sides) + 1
rolls.push(t)
roll += t
}
}
if(additional) {
roll += additional
result = number + 'd' + sides + (rest ? ' ' + rest : '') + ', got [' + rolls.join(',') + ']' + ((additional > 0) ? ' +' : ' -') + ' ' + additional + ' totaling ' + roll
} else {
result = number + 'd' + sides + (rest ? ' ' + rest : '') + ', got [' + rolls.join(',') + '] totaling ' + roll
}
callback(victim + ' rolls ' + result)
}
}

0 comments on commit 4fafb16

Please sign in to comment.