|
@ -1,9 +1,15 @@ |
|
|
const { EOL } = require('os'); |
|
|
const { EOL } = require('os'); |
|
|
const { path } = require('../util/index.js'); |
|
|
const { path } = require('../util/index.js'); |
|
|
|
|
|
|
|
|
const success = (response, mode) => ctx => { |
|
|
const parseOptions = ({ mode, asReply }, ctx) => { |
|
|
const respondAs = (mode && mode.toLowerCase() === 'html') ? 'replyWithHTML' : 'reply'; |
|
|
const respondMode = (mode && mode.toLowerCase() === 'html') ? 'replyWithHTML' : 'reply'; |
|
|
return response ? ctx[respondAs](response) : null; |
|
|
const options = asReply ? { reply_to_message_id: ctx.message.message_id } : {}; |
|
|
|
|
|
return [ respondMode, options ]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const success = (response, options) => ctx => { |
|
|
|
|
|
const [ respondMode, replyOptions ] = parseOptions(options, ctx); |
|
|
|
|
|
return response ? ctx[respondMode](response, replyOptions) : null; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const convertCtx = ctx => { |
|
|
const convertCtx = ctx => { |
|
@ -19,7 +25,8 @@ const convertCtx = ctx => { |
|
|
}, null, 2); |
|
|
}, null, 2); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const fail = response => ctx => { |
|
|
const fail = (response, options) => ctx => { |
|
|
|
|
|
const [ respondMode, replyOptions ] = parseOptions(options, ctx); |
|
|
if(!response |
|
|
if(!response |
|
|
|| !path(['update', 'message'], ctx) |
|
|
|| !path(['update', 'message'], ctx) |
|
|
) return; |
|
|
) return; |
|
@ -30,7 +37,7 @@ const fail = response => ctx => { |
|
|
`With context: `, |
|
|
`With context: `, |
|
|
convertCtx(ctx), |
|
|
convertCtx(ctx), |
|
|
); |
|
|
); |
|
|
return ctx.reply(response); |
|
|
return ctx[respondMode](response, replyOptions); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
module.exports = { |
|
|
module.exports = { |
|
|