diff --git a/README.md b/README.md index 5dcc2bae..a4936c2d 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,6 @@ Simply call the function with the parameters you would like to supply. bullshit-generator [theme] [length] [options] [theme] = Article/bullshit theme, as a string. [length] = Bullshit length. Must be a positive integer, or the value is ignored. -[options] = More options to the generator. If specified, must be a parsable JSON. You can also specify a "-h" or "--help" in place of anywhere to display a help message ``` diff --git a/bin/bs-gen.js b/bin/bs-gen.js index d1518697..257190da 100644 --- a/bin/bs-gen.js +++ b/bin/bs-gen.js @@ -10,7 +10,6 @@ This is a work-in-progress help document. Parameters: bullshit-generator [theme] [length] [options] [theme] = Article/bullshit theme, as a string. [length] = Bullshit length. Must be a positive integer, or the value is ignored. -[options] = More options to the generator. If specified, must be a parsable JSON. You can also specify a "-h" or "--help" in place of anywhere to display a help message (this) Source code can be found at https://github.com/Dobby233Liu/node-bullshit-generator @@ -26,10 +25,11 @@ OTHERWISE, ARISING FROM, OUT OF OR IN ANY WAY CONNECTION WITH THE LICENSED WORK OR THE USE OR OTHER DEALINGS IN THE LICENSED WORK. This is a Node.js port of https://github.com/menzi11/BullshitGenerator` -var argvClean = process.argv.map((x)=>x.trim().toLowerCase()) +var argvClean = process.argv.map((x)=>x.trim().toLowerCase()).slice(2) if(argvClean.indexOf("--help") >= 0 || argvClean.indexOf("-h") >= 0) { console.log(helpText) } else { - var 生成狗屁 = require("../lib/狗屁库.js"); - console.log(生成狗屁(process.argv[2],process.argv[3]>=0&&parseInt(process.argv[3]),require("../lib/dict/default/名人名言.js"),require("../lib/dict/default/废话.js")(process.argv[2]),require("../lib/dict/default/前面垫话.js"),require("../lib/dict/default/后面垫话.js"),process.argv[4]&&JSON.stringify(process.argv[4]))); + console.log( + require("../lib/狗屁库.js")(argvClean[0]||"学生会退会",(argvClean[1]?argvClean[1]>=0&&parseInt(process.argv[3]):undefined)) + ); } \ No newline at end of file diff --git "a/lib/\347\213\227\345\261\201\345\272\223.js" "b/lib/\347\213\227\345\261\201\345\272\223.js" index b0145126..c267d051 100644 --- "a/lib/\347\213\227\345\261\201\345\272\223.js" +++ "b/lib/\347\213\227\345\261\201\345\272\223.js" @@ -6,7 +6,7 @@ function 生成狗屁(主题 = "学生会退会", 文章长度 = 6000 * 主题.length, 名人名言 = require("./dict/default/名人名言.js"), 废话 = require("./dict/default/废话.js")(主题), 前面垫话 = require("./dict/default/前面垫话.js"), 后面垫话 = require("./dict/default/后面垫话.js"), - 选项 = { "分支大于24时加废话": false, "检测到底应该如何和又会如何产生": true, "有概率不添加后面垫话": false, "有时不加废话": true, "之前处理过废话的话不要处理名言": true, "LCG随机数机": false, "v3语法改进": true } + 选项 = { "分支大于24时加废话": false, "检测到底应该如何和又会如何产生": true, "有概率不添加后面垫话": false, "有时不加废话": true, "之前处理过废话的话不要处理名言": true, "LCG随机数机": false, "v3语法改进": true, "menzi11#175": false/**, "menzi11#175-2": true (implemented by v3语法改进)**/ } ){ var LCG; if (选项.LCG随机数机) LCG = new (require("./LCG中介.js"))(); @@ -29,15 +29,33 @@ function 生成狗屁(主题 = "学生会退会", 文章长度 = 6000 * 主题.l var 下一句废话到哪儿了 = 0; var 下一句名人名言 = 洗牌(名人名言); var 下一句名人名言到哪儿了 = 0; + if(选项["menzi11#175"]){ + var 下一句前面垫话 = 洗牌(前面垫话); + var 下一句后面垫话 = 洗牌(后面垫话); + var 下一句前面垫话到哪儿了 = 0; + var 下一句后面垫话到哪儿了 = 0; + } var 来点名人名言 = function () { let xx = 下一句名人名言[下一句名人名言到哪儿了]; - xx = xx.replace(/a/, 瞎选一个/**random.choice**/(前面垫话)); - if ((选项.有概率不添加后面垫话||false?Math.floor((选项.LCG随机数机?LCG.来个小小数():Math.random()) * 10) == 3:true)) {xx = xx.replace(/b/, 瞎选一个(后面垫话))} else {xx = xx.replace(/b/, "")} - if(下一句名人名言.length - 1 == 下一句名人名言到哪儿了) { // todo: 是否为改进? - 下一句名人名言 = 洗牌(名人名言); + xx = xx.replace(/a/, (选项["menzi11#175"]?下一句前面垫话[下一句前面垫话到哪儿了]:瞎选一个/**random.choice**/(前面垫话))); + if ((选项.有概率不添加后面垫话||false?Math.floor((选项.LCG随机数机?LCG.来个小小数():Math.random()) * 10) == 3:true)) {xx = xx.replace(/b/, (选项["menzi11#175"]?下一句后面垫话[下一句后面垫话到哪儿了]:瞎选一个(后面垫话)))} else {xx = xx.replace(/b/, "")} + if(下一句名人名言.length - 1 == 下一句名人名言到哪儿了) { + 选项.v3语法改进 && (下一句名人名言 = 洗牌(名人名言)); 下一句名人名言到哪儿了 = 0; } else 下一句名人名言到哪儿了++; + if(选项["menzi11#175"]){ + if(下一句前面垫话.length - 1 == 下一句前面垫话到哪儿了) { + 选项.v3语法改进 && (下一句前面垫话 = 洗牌(前面垫话)); + 下一句前面垫话到哪儿了 = 0; + } + else 下一句前面垫话到哪儿了++; + if(下一句后面垫话.length - 1 == 下一句后面垫话到哪儿了) { + 选项.v3语法改进 && (下一句后面垫话 = 洗牌(后面垫话)); + 下一句后面垫话到哪儿了 = 0; + } + else 下一句后面垫话到哪儿了++; + } return xx } var 另起一段 = function (以句号结束) { @@ -46,19 +64,21 @@ function 生成狗屁(主题 = "学生会退会", 文章长度 = 6000 * 主题.l var 生成 = function () { let tmp2 = ""; let tmp = " "; - var 曾处理过废话 = false; + let sctStart = tmp; + if(选项.之前处理过废话的话不要处理名言) var 曾处理过废话 = false; + // if(选项["menzi11#175-2"]) var 刚开一行 = false; var 能否以句号结束 = (tmp2) => !tmp2.endsWith("。") && !tmp2.endsWith(".") && !tmp2.endsWith(":") && !tmp2.endsWith(":") && !tmp2.endsWith("?") && !tmp2.endsWith("?") && !tmp2.endsWith("!") && !tmp2.endsWith("!") && !tmp2.endsWith(",") && !tmp2.endsWith(","); maketmp: while (tmp.length < 文章长度) { 分支 = Math.floor((选项.LCG随机数机?LCG.来个小小数():Math.random()) * 100); - if(分支 < 5 && (选项.v3语法改进 ? (!tmp.endsWith(" ") && !tmp2.endsWith(",") && !tmp2.endsWith(",")) : true)) { + if(分支 < 5 && (选项.v3语法改进 ? (!tmp.endsWith(sctStart) && !tmp2.endsWith(",") && !tmp2.endsWith(",")) : true)) { tmp2 = 另起一段((选项.v3语法改进 ? 能否以句号结束(tmp2.trim()) : true)); - 曾处理过废话 = false; + if(选项.之前处理过废话的话不要处理名言) 曾处理过废话 = false; }else if(分支 < 20) { if ((选项.之前处理过废话的话不要处理名言||false)?曾处理过废话:false) { continue maketmp; } tmp2 = 来点名人名言(); - 曾处理过废话 = false; + if(选项.之前处理过废话的话不要处理名言) 曾处理过废话 = false; } else if ((选项.分支大于24时加废话||false?分支>24:true) && (选项.有时不加废话||false?!((Math.floor((选项.LCG随机数机?LCG.来个小小数():Math.random())) * 80)&7==0):true)){ tmp2 = 下一句废话[下一句废话到哪儿了].replace(/x/g, 主题); @@ -68,7 +88,7 @@ function 生成狗屁(主题 = "学生会退会", 文章长度 = 6000 * 主题.l } else 下一句废话到哪儿了++; if ((选项.检测到底应该如何和又会如何产生||false?tmp2.indexOf("到底应该如何")>=0 || tmp2.indexOf("又会如何产生")>=0:false) && Math.floor((选项.LCG随机数机?LCG.来个小小数():Math.random()) * 3) == 2) tmp2 = tmp2.replace(/。/g,"?"); - 曾处理过废话 = true; + if(选项.之前处理过废话的话不要处理名言) 曾处理过废话 = true; } else { continue maketmp; }