diff --git a/actions/warn.js b/actions/warn.js index bc05a1b..b489791 100644 --- a/actions/warn.js +++ b/actions/warn.js @@ -1,3 +1,4 @@ +// @ts-check 'use strict'; const dedent = require('dedent-js'); @@ -26,6 +27,7 @@ module.exports = async ({ admin, amend, reason, userToWarn }) => { { amend } ); + // @ts-ignore const recentWarns = warns.filter(isNewerThan(date - ms(expireWarnsAfter))); const count = { diff --git a/bot/options.js b/bot/options.js index 2807efb..bbe3e99 100644 --- a/bot/options.js +++ b/bot/options.js @@ -1,5 +1,7 @@ +// @ts-check 'use strict'; +/** @type {import('telegraf/typings/telegram-types').ExtraReplyMessage} */ const replyOptions = { disable_web_page_preview: true, parse_mode: 'HTML', diff --git a/handlers/commands/start.js b/handlers/commands/start.js index ab6391f..f275b74 100644 --- a/handlers/commands/start.js +++ b/handlers/commands/start.js @@ -1,4 +1,4 @@ +// @ts-check 'use strict'; -// "clone" the function (https://stackoverflow.com/a/6772648) -module.exports = require('./help').bind(); +module.exports = require('./help'); diff --git a/handlers/middlewares/index.js b/handlers/middlewares/index.js index cf45831..5502701 100644 --- a/handlers/middlewares/index.js +++ b/handlers/middlewares/index.js @@ -1,7 +1,12 @@ +// @ts-check 'use strict'; const { Composer } = require('telegraf'); +/** + * @typedef {import('../../typings/context').ExtendedContext} ExtendedContext + * @type {import('telegraf').Composer} + */ const composer = new Composer(); const { deleteAfter } = require('../../utils/tg'); diff --git a/utils/log.js b/utils/log.js index 1197591..aff94c4 100644 --- a/utils/log.js +++ b/utils/log.js @@ -1,21 +1,12 @@ +// @ts-check 'use strict'; /* eslint-disable no-console */ const { inspect } = require('util'); -/** - * @param {Error} err - * Logs errors to console - * @returns {undefined} - */ const logError = err => console.error(err); -/** - * @param {Object} value - * Echos the value of a value. - * @returns {undefined} - */ const print = value => console.log(inspect(value, { colors: true, depth: null })); diff --git a/utils/parse.js b/utils/parse.js index 21c0f6b..9a1862d 100644 --- a/utils/parse.js +++ b/utils/parse.js @@ -1,3 +1,4 @@ +// @ts-check 'use strict'; const XRegExp = require('xregexp'); @@ -21,6 +22,7 @@ const botReply = ({ from, entities = [] }) => { const flagsRegex = /\s+(?:--?|—)(\w+)(?:=(\S*))?/g; +/** @returns {Generator<[string, string | undefined]>} */ function *extractFlags(flagS) { for (const [ , name, value ] of flagS.matchAll(flagsRegex)) { yield [ name.toLowerCase(), value ]; diff --git a/utils/tg.js b/utils/tg.js index 453c814..0776efa 100644 --- a/utils/tg.js +++ b/utils/tg.js @@ -1,3 +1,4 @@ +// @ts-check 'use strict'; const millisecond = require('millisecond'); @@ -40,11 +41,7 @@ const displayUser = user => ? link(user) : html`an user with id ${user.id}`; -/** - * @param {number} ms - * Deletes messages after (ms) milliseconds - * @returns {undefined} - */ +/** @param {number | string | false} ms */ const deleteAfter = ms => (ctx, next) => { if (ms !== false) { setTimeout(ctx.deleteMessage, millisecond(ms)); @@ -52,6 +49,7 @@ const deleteAfter = ms => (ctx, next) => { next(); }; +/** @param {number | string | false} ms */ const scheduleDeletion = (ms = 5 * 60 * 1000) => message => { const { chat, message_id } = message;