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

Commit 5bf997d

Browse files
author
Zirak
committed
define now actually delivers a correct link, instead of a pageid of undefined.
1 parent fc133b5 commit 5bf997d

File tree

5 files changed

+116
-57
lines changed

5 files changed

+116
-57
lines changed

master.js

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,9 +1075,29 @@ bot.Command = function ( cmd ) {
10751075
});
10761076

10771077
cmd.exec = function () {
1078+
var args = arguments,
1079+
self = this,
1080+
ret;
1081+
10781082
this.invoked += 1;
10791083

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;
10811101
};
10821102

10831103
cmd.del = function () {
@@ -4108,9 +4128,10 @@ var define = {
41084128
bot.log( args, '/define input' );
41094129
this.fetchData( args.toString(), finish );
41104130

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;
41144135

41154136
if ( pageid < 0 ) {
41164137
res = notFoundMsgs.random();
@@ -4153,8 +4174,9 @@ var define = {
41534174
}
41544175
else {
41554176
cb({
4156-
name : page.title,
4157-
text : definition.text
4177+
name : page.title,
4178+
text : definition.text,
4179+
pageid : pageid
41584180
});
41594181
}
41604182
},
@@ -6263,7 +6285,7 @@ bot.listen( re, selectStargateEpisode );
62636285
*/
62646286

62656287

6266-
var template = '{display_name} ({link}) ' +
6288+
var template = '{display_name} ({link}) ' +
62676289
'{indicative} {reputation} reputation, ' +
62686290
'earned {reputation_change_day} rep today, ' +
62696291
'asked {question_count} questions, ' +
@@ -6368,23 +6390,31 @@ function normalize_stats ( stats ) {
63686390
stats.avg_rep_post = 'T͎͍̘͙̖̤̉̌̇̅ͯ͋͢͜͝H̖͙̗̗̺͚̱͕̒́͟E̫̺̯͖͎̗̒͑̅̈ ̈ͮ̽ͯ̆̋́͏͙͓͓͇̹<̩̟̳̫̪̇ͩ̑̆͗̽̇͆́ͅC̬͎ͪͩ̓̑͊ͮͪ̄̚̕Ě̯̰̤̗̜̗͓͛͝N̶̴̞͇̟̲̪̅̓ͯͅT͍̯̰͓̬͚̅͆̄E̠͇͇̬̬͕͖ͨ̔̓͞R͚̠̻̲̗̹̀>̇̏ͣ҉̳̖̟̫͕ ̧̛͈͙͇͂̓̚͡C͈̞̻̩̯̠̻ͥ̆͐̄ͦ́̀͟A̛̪̫͙̺̱̥̞̙ͦͧ̽͛̈́ͯ̅̍N̦̭͕̹̤͓͙̲̑͋̾͊ͣŅ̜̝͌͟O̡̝͍͚̲̝ͣ̔́͝Ť͈͢ ̪̘̳͔̂̒̋ͭ͆̽͠H̢͈̤͚̬̪̭͗ͧͬ̈́̈̀͌͒͡Ơ̮͍͇̝̰͍͚͖̿ͮ̀̍́L͐̆ͨ̏̎͡҉̧̱̯̤̹͓̗̻̭ͅḐ̲̰͙͑̂̒̐́̊';
63696391
}
63706392

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 ) {
63716400
//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̨̥̫͎̭ͯ̿̔̀ͅ";
63746403
}
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̡";
63776406
}
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';
63846409
}
63856410

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 );
63886418
}
63896419

63906420
var cmd = {

0 commit comments

Comments
 (0)