t-comm
Version:
专业、稳定、纯粹的工具库
81 lines (74 loc) • 2.87 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var _regeneratorRuntime = require('@babel/runtime/regenerator');
var tslib_es6 = require('../tslib.es6-0d92ef81.js');
var wecomRobot_batchSend = require('../wecom-robot/batch-send.js');
var weather_weather = require('./weather.js');
require('../wecom-robot/base.js');
require('../wecom-robot/helper.js');
require('axios');
require('../wecom-robot/send-img.js');
require('../nodejs/path.js');
require('../node-img/img.js');
require('../nodejs/crypto.js');
require('../nodejs/fs.js');
require('../nodejs/request.js');
require('./api.js');
require('./parse.js');
require('../fs/fs-util.js');
require('@babel/runtime/helpers/toConsumableArray');
require('../fs/fs.js');
require('../nodejs/os.js');
require('../time/time.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
/**
* 获取天气信息并发送
* @param {object} options 配置
* @param {string} options.webhookUrl 机器人hook地址
* @param {string} [options.chatId] 会话Id
* @param {string} [options.force] 是否在和之前获取数据相同时,也发送
* @returns {Promise<Object>} 请求Promise
* @example
* ```ts
* await sendWeatherRobotMsg({
* webhookUrl: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx',
* chatId: ['chat-id-1', 'chat-id-2'],
* force: false, // 默认 false:和上次数据一致时不发送
* });
* ```
*/
function sendWeatherRobotMsg(_ref) {
var webhookUrl = _ref.webhookUrl,
chatId = _ref.chatId,
_ref$force = _ref.force,
force = _ref$force === void 0 ? false : _ref$force;
return tslib_es6.__awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
var _yield$getWeatherRobo, content, isSame;
return _regeneratorRuntime__default["default"].wrap(function (_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 1;
return weather_weather.getWeatherRobotContent();
case 1:
_yield$getWeatherRobo = _context.sent;
content = _yield$getWeatherRobo.content;
isSame = _yield$getWeatherRobo.isSame;
console.log('[sendWeatherRobotMsg] 天气是否有变化: ', !isSame);
if (!(!isSame || force)) {
_context.next = 2;
break;
}
return _context.abrupt("return", wecomRobot_batchSend.batchSendWxRobotMarkdown({
webhookUrl: webhookUrl,
chatId: chatId,
content: content
}));
case 2:
case "end":
return _context.stop();
}
}, _callee);
}));
}
exports.sendWeatherRobotMsg = sendWeatherRobotMsg;