├── .gitignore ├── lib ├── bugfree.txt ├── auto_update.js ├── define.json └── calendar.js ├── package.json ├── LICENSE ├── README.md └── bin └── calendar.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | -------------------------------------------------------------------------------- /lib/bugfree.txt: -------------------------------------------------------------------------------- 1 | 2 | _oo8oo_ 3 | o8888888o 4 | 88" . "88 5 | (| -_- |) 6 | 0\ = /0 7 | ___/'==='\___ 8 | .' \\| |// '. 9 | / \\||| : |||// \ 10 | / _||||| -:- |||||_ \ 11 | | | \\\ - /// | | 12 | | \_| ''\---/'' |_/ | 13 | \ .-\__ '-' __/-. / 14 | ___'. .' /--.--\ '. .'___ 15 | ."" '< '.___\_<|>_/___.' >' "". 16 | | | : `- \`.:`\ _ /`:.`/ -` : | | 17 | \ \ `-. \_ __\ /__ _/ .-` / / 18 | =====`-.____`.___ \_____/ ___.`____.-`===== 19 | `=---=` 20 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "programmer-calendar", 3 | "version": "0.0.5", 4 | "description": "程序员老黄历命令行版", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/leizongmin/programmer-calendar.git" 12 | }, 13 | "author": "Zongmin Lei ", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/leizongmin/programmer-calendar/issues" 17 | }, 18 | "homepage": "https://github.com/leizongmin/programmer-calendar#readme", 19 | "dependencies": { 20 | "cli-color": "^1.1.0", 21 | "lei-download": "^0.3.1" 22 | }, 23 | "engines": { 24 | "node": ">= 4.0.0" 25 | }, 26 | "bin": { 27 | "programmer-calendar": "./bin/calendar.js" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Zongmin Lei 4 | http://ucdok.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | -------------------------------------------------------------------------------- /lib/auto_update.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 程序员老黄历命令行版 3 | * 4 | * 本程序灵感来源于 http://sandbox.runjs.cn/show/ydp3it7b 5 | * 部分代码也来自该项目 6 | * 7 | * 佛祖图案来源于 https://github.com/ottomao/bugfreejs 8 | * 9 | * @author Zongmin Lei 10 | */ 11 | 12 | module.exports = function (file) { 13 | 14 | const path = require('path'); 15 | const fs = require('fs'); 16 | const util = require('util'); 17 | const clc = require('cli-color'); 18 | const updateUrl = 'https://raw.githubusercontent.com/leizongmin/programmer-calendar/master/lib/define.json'; 19 | 20 | fs.stat(file, (err, stats) => { 21 | if (err) { 22 | if (err.code !== 'ENOENT') { 23 | console.error(err); 24 | } 25 | var update = true; 26 | } else { 27 | if (stats.atime.getTime() - (new Date().getTime()) > 3600000 * 24 * 7) { 28 | var update = true; 29 | } else { 30 | var update = false; 31 | } 32 | } 33 | 34 | if (!update) return; 35 | 36 | startUpdate(); 37 | }); 38 | 39 | function startUpdate() { 40 | 41 | console.log(''); 42 | console.log('正在自动更新...'); 43 | const download = require('lei-download'); 44 | 45 | download(updateUrl, file, (size, total) => { 46 | 47 | process.stdout.write(clc.move.to(0, clc.windowSize.height)); 48 | process.stdout.write(clc.erase.line); 49 | process.stdout.write(util.format('进度:%s%% [%s/%s]', (size / total * 100).toFixed(1), size, total)); 50 | 51 | }, err => { 52 | 53 | console.log('更新完成。'); 54 | process.exit(); 55 | 56 | }); 57 | 58 | } 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # programmer-calendar 2 | 命令行版程序员老黄历 3 | 4 | ![image](https://cloud.githubusercontent.com/assets/841625/11815171/8687b8f6-a385-11e5-988f-82d540091eed.png) 5 | 6 | ## 安装 7 | 8 | ```bash 9 | $ npm install -g programmer-calendar 10 | ``` 11 | 12 | ## 使用 13 | 14 | 执行以下命令启动: 15 | 16 | ```bash 17 | $ programmer-calendar 18 | ``` 19 | 20 | **可将其设置为启动Shell时自动执行,建议终端窗口尺寸不小于 100x40** 21 | 22 | ## 更新数据 23 | 24 | 文件`lib/define.json`,`activities`中的`good`和`bad`每项文字长度不超过**16**,`name`不超过**17** 25 | 26 | ## License 27 | 28 | ``` 29 | The MIT License (MIT) 30 | 31 | Copyright (c) 2015 Zongmin Lei 32 | http://ucdok.com 33 | 34 | Permission is hereby granted, free of charge, to any person obtaining a copy 35 | of this software and associated documentation files (the "Software"), to deal 36 | in the Software without restriction, including without limitation the rights 37 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 38 | copies of the Software, and to permit persons to whom the Software is 39 | furnished to do so, subject to the following conditions: 40 | 41 | The above copyright notice and this permission notice shall be included in all 42 | copies or substantial portions of the Software. 43 | 44 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 45 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 46 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 47 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 48 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 49 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 50 | SOFTWARE. 51 | ``` 52 | -------------------------------------------------------------------------------- /bin/calendar.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | 4 | /** 5 | * 程序员老黄历命令行版 6 | * 7 | * 本程序灵感来源于 http://sandbox.runjs.cn/show/ydp3it7b 8 | * 部分代码也来自该项目 9 | * 10 | * 佛祖图案来源于 https://github.com/ottomao/bugfreejs 11 | * 12 | * @author Zongmin Sei 13 | */ 14 | 15 | const path = require('path'); 16 | const fs = require('fs'); 17 | const clc = require('cli-color'); 18 | const calendar = require('../lib/calendar'); 19 | const bugfree = fs.readFileSync(path.resolve(__dirname, '../lib/bugfree.txt')).toString().split(/\r?\n/); 20 | 21 | 22 | const screenWidth = process.stdout.columns; 23 | const screenHeight = process.stdout.rows; 24 | const printWidth = 80; 25 | const printWidthHalf = printWidth / 2; 26 | const printOffsetLeft = parseInt((screenWidth - printWidth) / 2); 27 | 28 | function print(str) { 29 | console.log(take(printOffsetLeft, ' ') + str); 30 | } 31 | 32 | function take(n, s) { 33 | let r = ''; 34 | for (let i = 0; i < n; i++) { 35 | r += s; 36 | } 37 | return r; 38 | } 39 | 40 | function printLength(c) { 41 | var n = 0; 42 | for (let i = 0; i < c.length; i++) { 43 | let p = c.charCodeAt(i); 44 | if (p < 128 || p == 9733 || p == 9734) { 45 | n++; 46 | } else { 47 | n +=2 ; 48 | } 49 | } 50 | return n; 51 | } 52 | 53 | function fix(str, len, S) { 54 | let l = printLength(clc.strip(str)); 55 | return str + S(take(len - l, ' ')); 56 | } 57 | 58 | function L(str, S) { 59 | print(fix(str, printWidth, S)); 60 | } 61 | 62 | function S0(str) { 63 | return clc.xterm(227).bgXterm(0)(str); 64 | } 65 | 66 | function S1(str) { 67 | return clc.xterm(0).bgXterm(250)(str); 68 | } 69 | 70 | function S2(str) { 71 | return clc.xterm(0).bgXterm(229)(str); 72 | } 73 | 74 | function S3(str) { 75 | return clc.xterm(0).bgXterm(220)(str); 76 | } 77 | 78 | function S4(str) { 79 | return clc.xterm(0).bgXterm(210)(str); 80 | } 81 | 82 | function S5(str) { 83 | return clc.xterm(0).bgXterm(196)(str); 84 | } 85 | 86 | //////////////////////////////////////////////////////////////////////////////// 87 | 88 | let offsetLeft = ' '; 89 | for (let str of bugfree) { 90 | print(fix(S0(offsetLeft + str), printWidth, S0)); 91 | } 92 | 93 | L(S1(''), S1); 94 | L(S1(offsetLeft + ' ' + calendar.getTodayString()), S1); 95 | L(S1(''), S1); 96 | L(S1(offsetLeft + ' 座位朝向:面向' + clc.xterm(28)(calendar.getDirectionString()) + '写程序,BUG 最少。'), S1); 97 | L(S1(offsetLeft + ' 今日宜饮:' + calendar.getDrinkString()), S1); 98 | L(S1(offsetLeft + ' 女神亲近指数:' + clc.xterm(196)(calendar.getStarString())), S1); 99 | L(S1(''), S1); 100 | 101 | let lucks = calendar.pickTodaysLuck(); 102 | let luckLength = Math.max(lucks.good.length, lucks.bad.length); 103 | let middleIndex = parseInt(luckLength / 2 + 0.5); 104 | 105 | print(fix(S3(' '), printWidthHalf, S2) + fix(S5(' '), printWidthHalf, S4)); 106 | 107 | for (let i = 0; i < luckLength; i++) { 108 | let good = lucks.good[i] || {name: '', good: ''}; 109 | let bad = lucks.bad[i] || {name: '', bad: ''}; 110 | 111 | let left = ''; 112 | let right = ''; 113 | 114 | if (i === middleIndex) { 115 | left = S3(' 宜 '); 116 | right = S5(' 忌 '); 117 | } else { 118 | left = S3(' '); 119 | right = S5(' '); 120 | } 121 | 122 | left = fix(left + S2(' ' + clc.xterm(0)(good.name)), printWidthHalf, S2); 123 | right = fix(right + S4(' ' + clc.xterm(0)(bad.name)), printWidthHalf, S4); 124 | print(left + right); 125 | 126 | left = fix(S3(' ') + S2(' ' + clc.xterm(240)(good.good)), printWidthHalf, S2); 127 | right = fix(S5(' ') + S4(' ' + clc.xterm(240)(bad.bad)), printWidthHalf, S4); 128 | print(left + right); 129 | } 130 | 131 | print(fix(S3(' '), printWidthHalf, S2) + fix(S5(' '), printWidthHalf, S4)); 132 | -------------------------------------------------------------------------------- /lib/define.json: -------------------------------------------------------------------------------- 1 | { 2 | "weeks": ["日", "一", "二", "三", "四", "五", "六"], 3 | "directions": ["北方", "东北方", "东方", "东南方", "南方", "西南方", "西方", "西北方"], 4 | "activities": [{ 5 | "name": "写单元测试", 6 | "good": "写单元测试将减少出错", 7 | "bad": "写单元测试会降低你的开发效率" 8 | }, { 9 | "name": "洗澡", 10 | "good": "你几天没洗澡了?", 11 | "bad": "会把设计方面的灵感洗掉", 12 | "weekend": true 13 | }, { 14 | "name": "锻炼一下身体", 15 | "good": "", 16 | "bad": "能量没消耗多少,吃得却更多", 17 | "weekend": true 18 | }, { 19 | "name": "抽烟", 20 | "good": "抽烟有利于提神,增加思维敏捷", 21 | "bad": "除非你活够了,死得早点没关系", 22 | "weekend": true 23 | }, { 24 | "name": "白天上线", 25 | "good": "今天白天上线是安全的", 26 | "bad": "可能导致灾难性后果" 27 | }, { 28 | "name": "重构", 29 | "good": "代码质量得到提高", 30 | "bad": "你很有可能会陷入泥潭" 31 | }, { 32 | "name": "使用%t", 33 | "good": "你看起来更有品位", 34 | "bad": "别人会觉得你在装逼" 35 | }, { 36 | "name": "跳槽", 37 | "good": "该放手时就放手", 38 | "bad": "鉴于当前的经济形势,你的下一份工作未必比现在强" 39 | }, { 40 | "name": "招人", 41 | "good": "你面前这位有成为牛人的潜质", 42 | "bad": "这人会写程序吗?" 43 | }, { 44 | "name": "面试", 45 | "good": "面试官今天心情很好", 46 | "bad": "面试官不爽,会拿你出气" 47 | }, { 48 | "name": "提交辞职申请", 49 | "good": "公司找到了一个比你更能干更便宜的家伙,巴不得你赶快滚蛋", 50 | "bad": "鉴于当前的经济形势,你的下一份工作未必比现在强" 51 | }, { 52 | "name": "申请加薪", 53 | "good": "老板今天心情很好", 54 | "bad": "公司正在考虑裁员" 55 | }, { 56 | "name": "晚上加班", 57 | "good": "晚上是程序员精神最好的时候", 58 | "bad": "", 59 | "weekend": true 60 | }, { 61 | "name": "在妹子面前吹牛", 62 | "good": "改善你矮穷挫的形象", 63 | "bad": "会被识破", 64 | "weekend": true 65 | }, { 66 | "name": "撸管", 67 | "good": "避免缓冲区溢出", 68 | "bad": "强撸灰飞烟灭", 69 | "weekend": true 70 | }, { 71 | "name": "浏览成人网站", 72 | "good": "重拾对生活的信心", 73 | "bad": "你会心神不宁", 74 | "weekend": true 75 | }, { 76 | "name": "命名变量\"%v\"", 77 | "good": "", 78 | "bad": "" 79 | }, { 80 | "name": "写超过%l行的方法", 81 | "good": "你的代码组织的很好,长一点没关系", 82 | "bad": "你的代码将混乱不堪,你自己都看不懂" 83 | }, { 84 | "name": "提交代码", 85 | "good": "遇到冲突的几率是最低的", 86 | "bad": "你遇到的一大堆冲突会让你觉得自己是不是时间穿越了" 87 | }, { 88 | "name": "代码复审", 89 | "good": "发现重要问题的几率大大增加", 90 | "bad": "你什么问题都发现不了,白白浪费时间" 91 | }, { 92 | "name": "开会", 93 | "good": "写代码之余放松一下打个盹,有益健康", 94 | "bad": "小心被扣屎盆子背黑锅" 95 | }, { 96 | "name": "打DOTA", 97 | "good": "你将有如神助", 98 | "bad": "你会被虐的很惨", 99 | "weekend": true 100 | }, { 101 | "name": "晚上上线", 102 | "good": "晚上是程序员精神最好的时候", 103 | "bad": "你白天已经筋疲力尽了" 104 | }, { 105 | "name": "修复BUG", 106 | "good": "你今天对BUG的嗅觉大大提高", 107 | "bad": "新产生的BUG将比修复的更多" 108 | }, { 109 | "name": "设计评审", 110 | "good": "设计评审会议将变成头脑风暴", 111 | "bad": "人人筋疲力尽,评审就这么过了" 112 | }, { 113 | "name": "需求评审", 114 | "good": "", 115 | "bad": "" 116 | }, { 117 | "name": "上微博", 118 | "good": "今天发生的事不能错过", 119 | "bad": "今天的微博充满负能量", 120 | "weekend": true 121 | }, { 122 | "name": "上AB站", 123 | "good": "还需要理由吗?", 124 | "bad": "满屏兄贵亮瞎你的眼", 125 | "weekend": true 126 | }, { 127 | "name": "玩FlappyBird", 128 | "good": "今天破纪录的几率很高", 129 | "bad": "除非你想玩到把手机砸了", 130 | "weekend": true 131 | }], 132 | "specials": [{ 133 | "date": 20151224, 134 | "type": "good", 135 | "name": "待在男(女)友身边", 136 | "description": "今天晚上不要加班了吧?" 137 | }, { 138 | "date": 20160214, 139 | "type": "bad", 140 | "name": "待在男(女)友身边", 141 | "description": "脱团火葬场,入团保平安。" 142 | }], 143 | "tools": ["Eclipse写程序", "MSOffice写文档", "记事本写程序", "Windows8", "Linux", "MacOS", "IE", "Android设备", "iOS设备"], 144 | "varNames": ["jieguo", "huodong", "pay", "expire", "zhangdan", "every", "free", "i1", "a", "virtual", "ad", "spider", "mima", "pass", "ui"], 145 | "drinks": ["水", "茶", "红茶", "绿茶", "咖啡", "奶茶", "可乐", "鲜奶", "豆奶", "果汁", "果味汽水", "苏打水", "运动饮料", "酸奶", "酒"] 146 | } 147 | -------------------------------------------------------------------------------- /lib/calendar.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * 程序员老黄历命令行版 5 | * 6 | * 本程序灵感来源于 http://sandbox.runjs.cn/show/ydp3it7b 7 | * 部分代码也来自该项目 8 | * 9 | * 佛祖图案来源于 https://github.com/ottomao/bugfreejs 10 | * 11 | * @author Zongmin Lei 12 | */ 13 | 14 | const path = require('path'); 15 | 16 | // 尝试载入最新的数据 17 | const defineNewestFile = path.resolve(process.env.HOME, '.programmer-calendar.define.json'); 18 | try { 19 | var defineNewest = require(defineNewestFile); 20 | } catch (err) { 21 | if (err.code !== 'MODULE_NOT_FOUND') { 22 | console.error(err); 23 | } 24 | var defineNewest = require('./define'); 25 | } 26 | 27 | // 自动更新 28 | require('./auto_update')(defineNewestFile); 29 | 30 | const define = defineNewest; 31 | const today = new Date(); 32 | const iday = today.getFullYear() * 10000 + (today.getMonth() + 1) * 100 + today.getDate(); 33 | 34 | 35 | /* 36 | * 注意:本程序中的“随机”都是伪随机概念,以当前的天为种子。 37 | */ 38 | function random(dayseed, indexseed) { 39 | var n = dayseed % 11117; 40 | for (var i = 0; i < 100 + indexseed; i++) { 41 | n = n * n; 42 | n = n % 11117; // 11117 是个质数 43 | } 44 | return n; 45 | } 46 | 47 | function is_someday() { 48 | return today.getMonth() == 5 && today.getDate() == 4; 49 | } 50 | 51 | function getTodayString() { 52 | return "今天是" + today.getFullYear() + "年" + (today.getMonth() + 1) + "月" + today.getDate() + "日 星期" + define.weeks[today.getDay()]; 53 | } 54 | 55 | function star(num) { 56 | var result = []; 57 | var i = 0; 58 | while (i < num) { 59 | result.push('★'); 60 | i++; 61 | } 62 | while (i < 5) { 63 | result.push('☆'); 64 | i++; 65 | } 66 | return result.join(' '); 67 | } 68 | 69 | // 生成今日运势 70 | function pickTodaysLuck() { 71 | let _activities = filter(define.activities); 72 | 73 | let numGood = random(iday, 98) % 3 + 2; 74 | let numBad = random(iday, 87) % 3 + 2; 75 | let eventArr = pickRandomActivity(_activities, numGood + numBad); 76 | 77 | let special = pickSpecials(); 78 | 79 | let goodList = special.good; 80 | let badList = special.bad; 81 | 82 | for (let i = 0; i < numGood; i++) { 83 | goodList.push(eventArr[i]); 84 | } 85 | 86 | for (let i = 0; i < numBad; i++) { 87 | badList.push(eventArr[numGood + i]); 88 | } 89 | 90 | return {good: goodList.slice(0, 4), bad: badList.slice(0, 4)}; 91 | } 92 | 93 | // 去掉一些不合今日的事件 94 | function filter(activities) { 95 | let result = []; 96 | 97 | // 周末的话,只留下 weekend = true 的事件 98 | if (isWeekend()) { 99 | 100 | for (let i = 0; i < activities.length; i++) { 101 | if (activities[i].weekend) { 102 | result.push(activities[i]); 103 | } 104 | } 105 | 106 | return result; 107 | } 108 | 109 | return activities; 110 | } 111 | 112 | function isWeekend() { 113 | return today.getDay() == 0 || today.getDay() == 6; 114 | } 115 | 116 | // 添加预定义事件 117 | function pickSpecials() { 118 | 119 | let goodList = []; 120 | let badList = []; 121 | 122 | for (let i = 0; i < define.specials.length; i++) { 123 | let special = define.specials[i]; 124 | 125 | if (iday == special.date) { 126 | if (special.type == 'good') { 127 | goodList.push({ 128 | name: special.name, 129 | good: special.description 130 | }); 131 | } else { 132 | badList.push({ 133 | name: special.name, 134 | bad: special.description 135 | }); 136 | } 137 | } 138 | } 139 | 140 | return {good: goodList, bad: badList}; 141 | } 142 | 143 | // 从 activities 中随机挑选 size 个 144 | function pickRandomActivity(activities, size) { 145 | let picked_events = pickRandom(activities, size); 146 | 147 | for (let i = 0; i < picked_events.length; i++) { 148 | picked_events[i] = parse(picked_events[i]); 149 | } 150 | 151 | return picked_events; 152 | } 153 | 154 | // 从数组中随机挑选 size 个 155 | function pickRandom(array, size) { 156 | let result = []; 157 | 158 | for (let i = 0; i < array.length; i++) { 159 | result.push(array[i]); 160 | } 161 | 162 | for (let j = 0; j < array.length - size; j++) { 163 | let index = random(iday, j) % result.length; 164 | result.splice(index, 1); 165 | } 166 | 167 | return result; 168 | } 169 | 170 | // 解析占位符并替换成随机内容 171 | function parse(event) { 172 | let result = { 173 | name: event.name, 174 | good: event.good, 175 | bad: event.bad 176 | }; // clone 177 | 178 | if (result.name.indexOf('%v') != -1) { 179 | result.name = result.name.replace('%v', define.varNames[random(iday, 12) % define.varNames.length]); 180 | } 181 | 182 | if (result.name.indexOf('%t') != -1) { 183 | result.name = result.name.replace('%t', define.tools[random(iday, 11) % define.tools.length]); 184 | } 185 | 186 | if (result.name.indexOf('%l') != -1) { 187 | result.name = result.name.replace('%l', (random(iday, 12) % 247 + 30).toString()); 188 | } 189 | 190 | return result; 191 | } 192 | 193 | // 获得座位朝向 194 | function getDirectionString() { 195 | return define.directions[random(iday, 2) % define.directions.length]; 196 | } 197 | 198 | // 获得今日宜饮 199 | function getDrinkString() { 200 | return pickRandom(define.drinks, 2).join(','); 201 | } 202 | 203 | // 获得女神亲近指数 204 | function getStarString() { 205 | return star(random(iday, 6) % 5 + 1); 206 | } 207 | 208 | 209 | exports.getTodayString = getTodayString; 210 | exports.getDirectionString = getDirectionString; 211 | exports.getDrinkString = getDrinkString; 212 | exports.getStarString = getStarString; 213 | exports.pickTodaysLuck = pickTodaysLuck; 214 | --------------------------------------------------------------------------------