Skip to content
This repository was archived by the owner on Jul 17, 2020. It is now read-only.

Commit 2d8cf0e

Browse files
author
Zirak
committed
Fixed $rand
1 parent b04e630 commit 2d8cf0e

File tree

3 files changed

+43
-21
lines changed

3 files changed

+43
-21
lines changed

master.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,10 +1703,9 @@ var macros = {
17031703

17041704
//the chat keeps a low opacity for users who remained silent for long,
17051705
// and high opacity for those who recently talked
1706-
var active = [].filter.call( presentUsers, function ( user ) {
1706+
var user = Array.filter( presentUsers, function ( user ) {
17071707
return Number( user.style.opacity ) >= 0.5;
1708-
}),
1709-
user = active[ Math.floor(Math.random() * (active.length-1)) ];
1708+
}).random();
17101709

17111710
if ( !user ) {
17121711
return 'Nobody';
@@ -1726,8 +1725,21 @@ var macros = {
17261725
//random number, min <= n <= max
17271726
//treats non-numeric inputs like they don't exist
17281727
rand : function ( msgObj, min, max ) {
1729-
min = Number( min );
1730-
max = Number( max );
1728+
// rand() === rand( 0, 10 )
1729+
if ( !min ) {
1730+
min = 0;
1731+
max = 10;
1732+
}
1733+
// rand( max ) === rand( 0, max )
1734+
else if ( !max ) {
1735+
max = min;
1736+
min = 0;
1737+
}
1738+
else {
1739+
min = Number( min );
1740+
max = Number( max );
1741+
}
1742+
17311743
return Math.rand( min, max );
17321744
}
17331745
};
@@ -1776,10 +1788,8 @@ bot.parseMacro = function parse ( source, extraVars ) {
17761788

17771789
//parse the arguments, split them into individual arguments,
17781790
// and trim'em (to cover the case of "arg,arg" and "arg, arg")
1779-
return (
1780-
[ source ].concat(
1781-
parse( macroArgs, extraVars )
1782-
.split( ',' ).invoke( 'trim' ) ) );
1791+
var parsedArgs = parse( macroArgs, extraVars );
1792+
return [ source ].concat( parsedArgs.split(',').invoke('trim') );
17831793
//this is not good code
17841794
}
17851795

@@ -4311,6 +4321,8 @@ bot.addCommand({
43114321
});
43124322
}());
43134323

4324+
;
4325+
43144326
;
43154327
(function () {
43164328
var baseURL = 'http://api.jquery.com/';
@@ -6221,7 +6233,7 @@ bot.addCommand({
62216233
return message;
62226234
}
62236235

6224-
welcome( args, args.get('roomid') );
6236+
welcome( args, args.get('room_id') );
62256237
},
62266238
permission : {
62276239
del : 'NONE'

0 commit comments

Comments
 (0)