@@ -1075,9 +1075,29 @@ bot.Command = function ( cmd ) {
1075
1075
} ) ;
1076
1076
1077
1077
cmd . exec = function ( ) {
1078
+ var args = arguments ,
1079
+ self = this ,
1080
+ ret ;
1081
+
1078
1082
this . invoked += 1 ;
1079
1083
1080
- return this . fun . apply ( this . thisArg , arguments ) ;
1084
+ if ( this . format && this . logic ) {
1085
+ if ( this . async ) {
1086
+ args . push ( function ( ) {
1087
+ self . format . apply ( self , arguments ) ;
1088
+ } ) ;
1089
+
1090
+ this . logic . apply ( this , args ) ;
1091
+ }
1092
+ else {
1093
+ ret = this . format ( this . logic . apply ( this , args ) ) ;
1094
+ }
1095
+ }
1096
+ else {
1097
+ ret = this . fun . apply ( this . thisArg , arguments ) ;
1098
+ }
1099
+
1100
+ return ret ;
1081
1101
} ;
1082
1102
1083
1103
cmd . del = function ( ) {
@@ -4108,9 +4128,10 @@ var define = {
4108
4128
bot . log ( args , '/define input' ) ;
4109
4129
this . fetchData ( args . toString ( ) , finish ) ;
4110
4130
4111
- function finish ( definition , pageid ) {
4112
- bot . log ( definition , pageid , '/define result' ) ;
4113
- var res ;
4131
+ function finish ( definition ) {
4132
+ bot . log ( definition , '/define result' ) ;
4133
+ var pageid = definition . pageid ,
4134
+ res ;
4114
4135
4115
4136
if ( pageid < 0 ) {
4116
4137
res = notFoundMsgs . random ( ) ;
@@ -4153,8 +4174,9 @@ var define = {
4153
4174
}
4154
4175
else {
4155
4176
cb ( {
4156
- name : page . title ,
4157
- text : definition . text
4177
+ name : page . title ,
4178
+ text : definition . text ,
4179
+ pageid : pageid
4158
4180
} ) ;
4159
4181
}
4160
4182
} ,
@@ -6263,7 +6285,7 @@ bot.listen( re, selectStargateEpisode );
6263
6285
*/
6264
6286
6265
6287
6266
- var template = '{display_name} ({link}) ' +
6288
+ var template = '{display_name} ({link}) ' +
6267
6289
'{indicative} {reputation} reputation, ' +
6268
6290
'earned {reputation_change_day} rep today, ' +
6269
6291
'asked {question_count} questions, ' +
@@ -6368,23 +6390,31 @@ function normalize_stats ( stats ) {
6368
6390
stats . avg_rep_post = 'T͎͍̘͙̖̤̉̌̇̅ͯ͋͢͜͝H̖͙̗̗̺͚̱͕̒́͟E̫̺̯͖͎̗̒͑̅̈ ̈ͮ̽ͯ̆̋́͏͙͓͓͇̹<̩̟̳̫̪̇ͩ̑̆͗̽̇͆́ͅC̬͎ͪͩ̓̑͊ͮͪ̄̚̕Ě̯̰̤̗̜̗͓͛͝N̶̴̞͇̟̲̪̅̓ͯͅT͍̯̰͓̬͚̅͆̄E̠͇͇̬̬͕͖ͨ̔̓͞R͚̠̻̲̗̹̀>̇̏ͣ҉̳̖̟̫͕ ̧̛͈͙͇͂̓̚͡C͈̞̻̩̯̠̻ͥ̆͐̄ͦ́̀͟A̛̪̫͙̺̱̥̞̙ͦͧ̽͛̈́ͯ̅̍N̦̭͕̹̤͓͙̲̑͋̾͊ͣŅ̜̝͌͟O̡̝͍͚̲̝ͣ̔́͝Ť͈͢ ̪̘̳͔̂̒̋ͭ͆̽͠H̢͈̤͚̬̪̭͗ͧͬ̈́̈̀͌͒͡Ơ̮͍͇̝̰͍͚͖̿ͮ̀̍́L͐̆ͨ̏̎͡҉̧̱̯̤̹͓̗̻̭ͅḐ̲̰͙͑̂̒̐́̊' ;
6369
6391
}
6370
6392
6393
+ stats . ratio = calc_qa_ratio ( stats . question_count , stats . answer_count ) ;
6394
+
6395
+ bot . log ( stats , '/stat normalized' ) ;
6396
+ return stats ;
6397
+ }
6398
+
6399
+ function calc_qa_ratio ( questions , answers ) {
6371
6400
//for teh lulz
6372
- if ( ! stats . question_count && stats . answer_count ) {
6373
- stats . ratio = "H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ" ;
6401
+ if ( ! questions && answer ) {
6402
+ return "H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ" ;
6374
6403
}
6375
- else if ( ! stats . answer_count && stats . question_count ) {
6376
- stats . ratio = "TO͇̹̺ͅƝ̴ȳ̳ TH̘Ë͖́̉ ͠P̯͍̭O̚N̐Y̡" ;
6404
+ else if ( ! answer && questions ) {
6405
+ return "TO͇̹̺ͅƝ̴ȳ̳ TH̘Ë͖́̉ ͠P̯͍̭O̚N̐Y̡" ;
6377
6406
}
6378
- else if ( ! stats . answer_count && ! stats . question_count ) {
6379
- stats . ratio = 'http://i.imgur.com/F79hP.png' ;
6380
- }
6381
- else {
6382
- stats . ratio =
6383
- Math . ratio ( stats . question_count , stats . answer_count ) ;
6407
+ else if ( ! answer && ! questions ) {
6408
+ return 'http://i.imgur.com/F79hP.png' ;
6384
6409
}
6385
6410
6386
- bot . log ( stats , '/stat normalized' ) ;
6387
- return stats ;
6411
+ // #196:
6412
+ // 1. GCD of 1.
6413
+ // 2. Either the antecedent or the consequent are 1
6414
+ //(in A:B, A is the antecedent, B is the consequent)
6415
+ var gcd = Math . gcd ( questions , answers ) ;
6416
+
6417
+ return Math . ratio ( questions , answers ) ;
6388
6418
}
6389
6419
6390
6420
var cmd = {
0 commit comments