(bot, chatId, array, parseMode, delimiter)
| 2136 | main(); |
| 2137 | |
| 2138 | function sendArray (bot, chatId, array, parseMode, delimiter) { |
| 2139 | if (!array || !array.length) { |
| 2140 | bot.sendMessage(chatId, '<b>Nothing found!</b>', {parse_mode: 'HTML'}).catch(globalErrorHandler()); |
| 2141 | return; |
| 2142 | } |
| 2143 | if (!delimiter) { |
| 2144 | delimiter = '\n'; |
| 2145 | } |
| 2146 | let remaining = array.length; |
| 2147 | let text = ''; |
| 2148 | while (remaining > 0) { |
| 2149 | const item = array[array.length - remaining]; |
| 2150 | if (text.length + item.length + (text.length ? delimiter.length : 0) > 4000) { |
| 2151 | bot.sendMessage(chatId, text, {parse_mode: parseMode}).catch(globalErrorHandler()); |
| 2152 | text = item; |
| 2153 | } else { |
| 2154 | if (text.length) { |
| 2155 | text += delimiter; |
| 2156 | } |
| 2157 | text += item; |
| 2158 | } |
| 2159 | remaining--; |
| 2160 | if (remaining == 0) { |
| 2161 | bot.sendMessage(chatId, text, {parse_mode: parseMode}).catch(globalErrorHandler()); |
| 2162 | } |
| 2163 | } |
| 2164 | } |
| 2165 | |
| 2166 | function sleep (milliseconds) { |
| 2167 | return new Promise(resolve => setTimeout(resolve, milliseconds)) |
no test coverage detected