functions.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. import htmlparser from 'htmlparser2';
  2. import gotDefault from 'got';
  3. const got = gotDefault.extend( {
  4. throwHttpErrors: false,
  5. timeout: {
  6. request: 5_000
  7. },
  8. headers: {
  9. 'User-Agent': 'Wiki-Bot/' + ( isDebug ? 'testing' : process.env.npm_package_version ) + ' (Discord; ' + process.env.npm_package_name + ( process.env.invite ? '; ' + process.env.invite : '' ) + ')'
  10. },
  11. responseType: 'json'
  12. } );
  13. /**
  14. * @type {Map<String, {state: String, wiki: String, channel: import('discord.js').TextChannel, user: String}>}
  15. */
  16. const oauthVerify = new Map();
  17. /**
  18. * Parse infobox content
  19. * @param {Object} infobox - The content of the infobox.
  20. * @param {import('discord.js').MessageEmbed} embed - The message embed.
  21. * @param {String} [thumbnail] - The default thumbnail for the wiki.
  22. * @param {String} [pagelink] - The article path for relative links.
  23. * @returns {import('discord.js').MessageEmbed?}
  24. */
  25. function parse_infobox(infobox, embed, thumbnail, pagelink = '') {
  26. if ( !infobox || embed.fields.length >= 25 || embed.length > 5400 ) return;
  27. if ( infobox.parser_tag_version === 5 ) {
  28. infobox.data.forEach( group => {
  29. parse_infobox(group, embed, thumbnail, pagelink);
  30. } );
  31. embed.fields = embed.fields.filter( (field, i, fields) => {
  32. if ( field.name !== '\u200b' || !field.value.startsWith( '__**' ) ) return true;
  33. return ( fields[i + 1]?.name && ( fields[i + 1].name !== '\u200b' || !fields[i + 1].value.startsWith( '__**' ) ) );
  34. } );
  35. return embed;
  36. }
  37. switch ( infobox.type ) {
  38. case 'data':
  39. var {label = '', value = '', source = '', 'item-name': name = ''} = infobox.data;
  40. label = htmlToPlain(label, true).trim();
  41. value = htmlToDiscord(value, pagelink).trim();
  42. if ( label.includes( '*UNKNOWN LINK*' ) ) {
  43. if ( !( source || name ) ) break;
  44. label = '`' + ( source || name ) + '`';
  45. embed.brokenInfobox = true;
  46. }
  47. if ( value.includes( '*UNKNOWN LINK*' ) ) {
  48. if ( !( source || name ) ) break;
  49. value = '`' + ( source || name ) + '`';
  50. embed.brokenInfobox = true;
  51. }
  52. if ( label.length > 100 ) label = label.substring(0, 100) + '\u2026';
  53. if ( value.length > 500 ) value = limitLength(value, 500, 250);
  54. if ( label && value ) embed.addField( label, value, true );
  55. break;
  56. case 'panel':
  57. var embedLength = embed.fields.length;
  58. infobox.data.value.forEach( group => {
  59. parse_infobox(group, embed, thumbnail, pagelink);
  60. } );
  61. embed.fields = embed.fields.filter( (field, i, fields) => {
  62. if ( i < embedLength || field.name !== '\u200b' ) return true;
  63. if ( !field.value.startsWith( '__**' ) ) return true;
  64. return ( fields[i + 1]?.name && fields[i + 1].name !== '\u200b' );
  65. } ).filter( (field, i, fields) => {
  66. if ( i < embedLength || field.name !== '\u200b' ) return true;
  67. if ( field.value.startsWith( '__**' ) ) return true;
  68. return ( fields[i + 1]?.name && ( fields[i + 1].name !== '\u200b' || !fields[i + 1].value.startsWith( '__**' ) ) );
  69. } );
  70. break;
  71. case 'section':
  72. var {label = ''} = infobox.data;
  73. label = htmlToPlain(label).trim();
  74. if ( label.length > 100 ) label = label.substring(0, 100) + '\u2026';
  75. if ( label ) embed.addField( '\u200b', '**' + label + '**', false );
  76. case 'group':
  77. infobox.data.value.forEach( group => {
  78. parse_infobox(group, embed, thumbnail, pagelink);
  79. } );
  80. break;
  81. case 'header':
  82. var {value = ''} = infobox.data;
  83. value = htmlToPlain(value).trim();
  84. if ( value.length > 100 ) value = value.substring(0, 100) + '\u2026';
  85. if ( value ) embed.addField( '\u200b', '__**' + value + '**__', false );
  86. break;
  87. case 'image':
  88. if ( embed.thumbnail?.url !== thumbnail ) return;
  89. var image = infobox.data.find( img => {
  90. return ( /^(?:https?:)?\/\//.test(img.url) && /\.(?:png|jpg|jpeg|gif)$/.test(img.name) );
  91. } );
  92. if ( image ) embed.setThumbnail( image.url.replace( /^(?:https?:)?\/\//, 'https://' ) );
  93. break;
  94. }
  95. }
  96. /**
  97. * Make wikitext formatting usage.
  98. * @param {String} [text] - The text to modify.
  99. * @param {Boolean} [showEmbed] - If the text is used in an embed.
  100. * @param {import('./wiki.js').default} [wiki] - The wiki.
  101. * @param {String} [title] - The page title.
  102. * @param {Boolean} [fullWikitext] - If the text can contain full wikitext.
  103. * @returns {String}
  104. */
  105. function toFormatting(text = '', showEmbed = false, wiki, title = '', fullWikitext = false) {
  106. if ( showEmbed ) return toMarkdown(text, wiki, title, fullWikitext);
  107. else return toPlaintext(text, fullWikitext);
  108. };
  109. /**
  110. * Turns wikitext formatting into markdown.
  111. * @param {String} [text] - The text to modify.
  112. * @param {import('./wiki.js').default} wiki - The wiki.
  113. * @param {String} [title] - The page title.
  114. * @param {Boolean} [fullWikitext] - If the text can contain full wikitext.
  115. * @returns {String}
  116. */
  117. function toMarkdown(text = '', wiki, title = '', fullWikitext = false) {
  118. text = text.replace( /[()\\]/g, '\\$&' );
  119. var link = null;
  120. var regex = /\[\[(?:([^\|\]]+)\|)?([^\]]+)\]\]([a-z]*)/g;
  121. while ( ( link = regex.exec(text) ) !== null ) {
  122. var pagetitle = ( link[1] || link[2] );
  123. var page = wiki.toLink(( /^[#\/]/.test(pagetitle) ? title + ( pagetitle.startsWith( '/' ) ? pagetitle : '' ) : pagetitle ), '', ( pagetitle.startsWith( '#' ) ? pagetitle.substring(1) : '' ), true);
  124. text = text.replaceSave( link[0], '[' + link[2] + link[3] + '](' + page + ')' );
  125. }
  126. if ( title !== '' ) {
  127. regex = /\/\*\s*([^\*]+?)\s*\*\/\s*(.)?/g;
  128. while ( ( link = regex.exec(text) ) !== null ) {
  129. text = text.replaceSave( link[0], '[→' + link[1] + '](' + wiki.toLink(title, '', link[1], true) + ')' + ( link[2] ? ': ' + link[2] : '' ) );
  130. }
  131. }
  132. if ( fullWikitext ) {
  133. regex = /\[(?:https?:)?\/\/([^ ]+) ([^\]]+)\]/g;
  134. while ( ( link = regex.exec(text) ) !== null ) {
  135. text = text.replaceSave( link[0], '[' + link[2] + '](https://' + link[1] + ')' );
  136. }
  137. return htmlToDiscord(text, '', true, true).replaceSave( /'''/g, '**' ).replaceSave( /''/g, '*' );
  138. }
  139. return escapeFormatting(text, true);
  140. };
  141. /**
  142. * Removes wikitext formatting.
  143. * @param {String} [text] - The text to modify.
  144. * @param {Boolean} [fullWikitext] - If the text can contain full wikitext.
  145. * @returns {String}
  146. */
  147. function toPlaintext(text = '', fullWikitext = false) {
  148. text = text.replace( /\[\[(?:[^\|\]]+\|)?([^\]]+)\]\]/g, '$1' ).replace( /\/\*\s*([^\*]+?)\s*\*\//g, '→$1:' );
  149. if ( fullWikitext ) {
  150. return htmlToDiscord( text.replace( /\[(?:https?:)?\/\/(?:[^ ]+) ([^\]]+)\]/g, '$1' ) );
  151. }
  152. else return escapeFormatting(text);
  153. };
  154. /**
  155. * Change HTML text to plain text.
  156. * @param {String} html - The text in HTML.
  157. * @returns {String}
  158. */
  159. function htmlToPlain(html, includeComments = false) {
  160. var text = '';
  161. var ignoredTag = '';
  162. var parser = new htmlparser.Parser( {
  163. onopentag: (tagname, attribs) => {
  164. let classes = ( attribs.class?.split(' ') ?? [] );
  165. if ( classes.includes( 'noexcerpt' ) || ( classes.includes( 'mw-collapsible' ) && classes.includes( 'mw-collapsed' ) )
  166. || ( attribs.style?.includes( 'display' ) && /(^|;)\s*display\s*:\s*none\s*(;|$)/.test(attribs.style) ) ) {
  167. ignoredTag = tagname;
  168. return;
  169. }
  170. if ( tagname === 'sup' && classes.includes( 'reference' ) ) ignoredTag = 'sup';
  171. if ( tagname === 'span' && classes.includes( 'smwttcontent' ) ) ignoredTag = 'span';
  172. if ( tagname === 'br' ) text += ' ';
  173. },
  174. ontext: (htmltext) => {
  175. if ( !ignoredTag ) {
  176. htmltext = htmltext.replace( /[\r\n\t ]+/g, ' ' );
  177. if ( /[\n ]$/.test(text) && htmltext.startsWith( ' ' ) ) htmltext = htmltext.replace( /^ +/, '' );
  178. text += escapeFormatting(htmltext);
  179. }
  180. },
  181. onclosetag: (tagname) => {
  182. if ( tagname === ignoredTag ) ignoredTag = '';
  183. },
  184. oncomment: (commenttext) => {
  185. if ( includeComments && /^(?:IW)?LINK'" \d+(?::\d+)?$/.test(commenttext) ) {
  186. text += '*UNKNOWN LINK*';
  187. }
  188. }
  189. } );
  190. parser.write( String(html) );
  191. parser.end();
  192. return text;
  193. };
  194. /**
  195. * Change HTML text to markdown text.
  196. * @param {String} html - The text in HTML.
  197. * @param {String} [pagelink] - The article path for relative links.
  198. * @param {Boolean[]} [escapeArgs] - Arguments for the escaping of text formatting.
  199. * @returns {String}
  200. */
  201. function htmlToDiscord(html, pagelink = '', ...escapeArgs) {
  202. var text = '';
  203. var code = false;
  204. var href = '';
  205. var ignoredTag = '';
  206. var syntaxhighlight = '';
  207. var listlevel = -1;
  208. var parser = new htmlparser.Parser( {
  209. onopentag: (tagname, attribs) => {
  210. if ( ignoredTag || code ) return;
  211. let classes = ( attribs.class?.split(' ') ?? [] );
  212. if ( classes.includes( 'noexcerpt' ) || ( classes.includes( 'mw-collapsible' ) && classes.includes( 'mw-collapsed' ) )
  213. || ( attribs.style?.includes( 'display' ) && /(^|;)\s*display\s*:\s*none\s*(;|$)/.test(attribs.style) ) ) {
  214. ignoredTag = tagname;
  215. return;
  216. }
  217. if ( tagname === 'sup' && classes.includes( 'reference' ) ) ignoredTag = 'sup';
  218. if ( tagname === 'span' && classes.includes( 'smwttcontent' ) ) ignoredTag = 'span';
  219. if ( tagname === 'code' ) {
  220. code = true;
  221. text += '`';
  222. }
  223. if ( tagname === 'pre' ) {
  224. code = true;
  225. text += '```' + syntaxhighlight + '\n';
  226. }
  227. if ( tagname === 'div' && classes.length ) {
  228. if ( classes.includes( 'mw-highlight' ) ) {
  229. syntaxhighlight = ( classes.find( syntax => syntax.startsWith( 'mw-highlight-lang-' ) )?.replace( 'mw-highlight-lang-', '' ) || '' );
  230. }
  231. }
  232. if ( tagname === 'b' || tagname === 'strong' ) text += '**';
  233. if ( tagname === 'i' ) text += '*';
  234. if ( tagname === 's' ) text += '~~';
  235. if ( tagname === 'u' ) text += '__';
  236. if ( tagname === 'br' ) {
  237. text += '\n';
  238. if ( listlevel > -1 ) text += '\u200b '.repeat(4 * listlevel + 3);
  239. }
  240. if ( tagname === 'hr' ) {
  241. text = text.replace( / +$/, '' );
  242. if ( !text.endsWith( '\n' ) ) text += '\n';
  243. text += '─'.repeat(10) + '\n';
  244. }
  245. if ( tagname === 'p' && !text.endsWith( '\n' ) ) text += '\n';
  246. if ( tagname === 'ul' || tagname === 'ol' ) listlevel++;
  247. if ( tagname === 'li' ) {
  248. text = text.replace( / +$/, '' );
  249. if ( !text.endsWith( '\n' ) ) text += '\n';
  250. if ( !classes.includes( 'mw-empty-elt' ) ) {
  251. if ( listlevel > -1 ) text += '\u200b '.repeat(4 * listlevel);
  252. text += '• ';
  253. }
  254. }
  255. if ( tagname === 'dl' ) listlevel++;
  256. if ( tagname === 'dt' ) {
  257. text = text.replace( / +$/, '' );
  258. if ( !text.endsWith( '\n' ) ) text += '\n';
  259. if ( !classes.includes( 'mw-empty-elt' ) ) {
  260. if ( listlevel > -1 ) text += '\u200b '.repeat(4 * listlevel);
  261. text += '**';
  262. }
  263. }
  264. if ( tagname === 'dd' ) {
  265. text = text.replace( / +$/, '' );
  266. if ( !text.endsWith( '\n' ) ) text += '\n';
  267. if ( listlevel > -1 && !classes.includes( 'mw-empty-elt' ) ) text += '\u200b '.repeat(4 * (listlevel + 1));
  268. }
  269. if ( tagname === 'img' ) {
  270. if ( attribs.alt && attribs.src ) {
  271. let showAlt = true;
  272. if ( attribs['data-image-name'] === attribs.alt ) showAlt = false;
  273. else {
  274. let regex = new RegExp( '/([\\da-f])/\\1[\\da-f]/' + attribs.alt.replace( / /g, '_' ).replace( /\W/g, '\\$&' ) + '(?:/|\\?|$)' );
  275. if ( attribs.src.startsWith( 'data:' ) && attribs['data-src'] ) attribs.src = attribs['data-src'];
  276. if ( regex.test(attribs.src.replace( /(?:%[\dA-F]{2})+/g, partialURIdecode )) ) showAlt = false;
  277. }
  278. if ( showAlt ) {
  279. if ( href && !code ) attribs.alt = attribs.alt.replace( /[\[\]]/g, '\\$&' );
  280. if ( code ) text += attribs.alt.replace( /`/g, 'ˋ' );
  281. else text += escapeFormatting(attribs.alt, ...escapeArgs);
  282. }
  283. }
  284. }
  285. if ( tagname === 'h1' ) {
  286. text = text.replace( / +$/, '' );
  287. if ( !text.endsWith( '\n' ) ) text += '\n';
  288. text += '***__';
  289. }
  290. if ( tagname === 'h2' ) {
  291. text = text.replace( / +$/, '' );
  292. if ( !text.endsWith( '\n' ) ) text += '\n';
  293. text += '**__';
  294. }
  295. if ( tagname === 'h3' ) {
  296. text = text.replace( / +$/, '' );
  297. if ( !text.endsWith( '\n' ) ) text += '\n';
  298. text += '**';
  299. }
  300. if ( tagname === 'h4' ) {
  301. text = text.replace( / +$/, '' );
  302. if ( !text.endsWith( '\n' ) ) text += '\n';
  303. text += '__';
  304. }
  305. if ( tagname === 'h5' ) {
  306. text = text.replace( / +$/, '' );
  307. if ( !text.endsWith( '\n' ) ) text += '\n';
  308. text += '*';
  309. }
  310. if ( tagname === 'h6' ) {
  311. text = text.replace( / +$/, '' );
  312. if ( !text.endsWith( '\n' ) ) text += '\n';
  313. text += '';
  314. }
  315. if ( !pagelink ) return;
  316. if ( tagname === 'a' && attribs.href && !classes.includes( 'new' ) && /^(?:(?:https?:)?\/\/|\/|#)/.test(attribs.href) ) {
  317. href = new URL(attribs.href, pagelink).href.replace( /[()]/g, '\\$&' );
  318. if ( text.endsWith( '](<' + href + '>)' ) ) {
  319. text = text.substring(0, text.length - ( href.length + 5 ));
  320. }
  321. else text += '[';
  322. }
  323. },
  324. ontext: (htmltext) => {
  325. if ( !ignoredTag ) {
  326. if ( href && !code ) htmltext = htmltext.replace( /[\[\]]/g, '\\$&' );
  327. if ( code ) text += htmltext.replace( /`/g, 'ˋ' );
  328. else {
  329. htmltext = htmltext.replace( /[\r\n\t ]+/g, ' ' );
  330. if ( /[\n ]$/.test(text) && htmltext.startsWith( ' ' ) ) {
  331. htmltext = htmltext.replace( /^ +/, '' );
  332. }
  333. text += escapeFormatting(htmltext, ...escapeArgs);
  334. }
  335. }
  336. },
  337. onclosetag: (tagname) => {
  338. if ( tagname === ignoredTag ) {
  339. ignoredTag = '';
  340. return;
  341. }
  342. if ( code ) {
  343. if ( tagname === 'code' ) {
  344. code = false;
  345. text += '`';
  346. }
  347. if ( tagname === 'pre' ) {
  348. code = false;
  349. text += '\n```';
  350. }
  351. return;
  352. }
  353. if ( syntaxhighlight && tagname === 'div' ) syntaxhighlight = '';
  354. if ( tagname === 'b' ) text += '**';
  355. if ( tagname === 'i' ) text += '*';
  356. if ( tagname === 's' ) text += '~~';
  357. if ( tagname === 'u' ) text += '__';
  358. if ( tagname === 'ul' || tagname === 'ol' ) listlevel--;
  359. if ( tagname === 'dl' ) listlevel--;
  360. if ( tagname === 'dt' ) text += '**';
  361. if ( tagname === 'h1' ) text += '__***';
  362. if ( tagname === 'h2' ) text += '__**';
  363. if ( tagname === 'h3' ) text += '**';
  364. if ( tagname === 'h4' ) text += '__';
  365. if ( tagname === 'h5' ) text += '*';
  366. if ( tagname === 'h6' ) text += '';
  367. if ( !pagelink ) return;
  368. if ( tagname === 'a' && href ) {
  369. if ( text.endsWith( '[' ) ) text = text.substring(0, text.length - 1);
  370. else text += '](<' + href + '>)';
  371. href = '';
  372. }
  373. },
  374. oncomment: (commenttext) => {
  375. if ( pagelink && /^(?:IW)?LINK'" \d+(?::\d+)?$/.test(commenttext) ) {
  376. text += '*UNKNOWN LINK*';
  377. }
  378. }
  379. } );
  380. parser.write( String(html) );
  381. parser.end();
  382. return text;
  383. };
  384. /**
  385. * Escapes formatting.
  386. * @param {String} [text] - The text to modify.
  387. * @param {Boolean} [isMarkdown] - The text contains markdown links.
  388. * @param {Boolean} [keepLinks] - Don't escape non-markdown links.
  389. * @returns {String}
  390. */
  391. function escapeFormatting(text = '', isMarkdown = false, keepLinks = false) {
  392. if ( !isMarkdown ) text = text.replace( /\\/g, '\\\\' ).replace( /\]\(/g, ']\\(' );
  393. if ( !keepLinks ) text = text.replace( /\/\//g, '/\\/' );
  394. return text.replace( /[`_*~:<>{}@|]/g, '\\$&' );
  395. };
  396. /**
  397. * Limit text length without breaking link formatting.
  398. * @param {String} [text] - The text to modify.
  399. * @param {Number} [limit] - The character limit.
  400. * @param {Number} [maxExtra] - The maximal allowed character limit if needed.
  401. * @returns {String}
  402. */
  403. function limitLength(text = '', limit = 1000, maxExtra = 20) {
  404. var suffix = '\u2026';
  405. var link = null;
  406. var regex = /(?<!\\)\[((?:[^\[\]]|\\[\[\]])*?[^\\])\]\(<?(?:[^()]|\\[()])+?[^\\]>?\)/g;
  407. while ( ( link = regex.exec(text) ) !== null ) {
  408. if ( link.index < limit && link.index + link[0].length > limit ) {
  409. if ( link.index + link[0].length < limit + maxExtra ) suffix = link[0];
  410. else if ( link.index + link[1].length < limit + maxExtra ) suffix = link[1];
  411. if ( link.index + link[0].length < text.length ) suffix += '\u2026';
  412. limit = link.index;
  413. break;
  414. }
  415. else if ( link.index >= limit ) break;
  416. }
  417. return text.substring(0, limit) + suffix;
  418. };
  419. /**
  420. * Try to URI decode.
  421. * @param {String} m - The character to decode.
  422. * @returns {String}
  423. */
  424. function partialURIdecode(m) {
  425. var text = '';
  426. try {
  427. text = decodeURIComponent( m );
  428. }
  429. catch ( replaceError ) {
  430. if ( isDebug ) console.log( '- Failed to decode ' + m + ':' + replaceError );
  431. text = m;
  432. }
  433. return text;
  434. };
  435. /**
  436. * Check for timeout or pause.
  437. * @param {import('discord.js').Message|import('discord.js').Interaction} msg - The message.
  438. * @param {Boolean} [ignorePause] - Ignore pause for admins.
  439. * @returns {Boolean}
  440. */
  441. function breakOnTimeoutPause(msg, ignorePause = false) {
  442. if ( !msg.inGuild() ) return false;
  443. if ( msg.member?.communicationDisabledUntilTimestamp > Date.now() ) {
  444. console.log( '- Aborted, communication disabled for User.' );
  445. return true;
  446. }
  447. if ( msg.guild?.me.communicationDisabledUntilTimestamp > Date.now() ) {
  448. console.log( '- Aborted, communication disabled for Wiki-Bot.' );
  449. return true;
  450. }
  451. if ( pausedGuilds.has(msg.guildId) && !( ignorePause && ( msg.isAdmin() || msg.isOwner() ) ) ) {
  452. console.log( '- Aborted, guild paused.' );
  453. return true;
  454. };
  455. return false;
  456. };
  457. /**
  458. * Allow users to delete their command responses.
  459. * @param {import('discord.js').Message} msg - The response.
  460. * @param {String} author - The user id.
  461. */
  462. function allowDelete(msg, author) {
  463. msg?.awaitReactions?.( {
  464. filter: (reaction, user) => ( reaction.emoji.name === '🗑️' && user.id === author ),
  465. max: 1, time: 300_000
  466. } ).then( reaction => {
  467. if ( reaction.size ) msg.delete().catch(log_error);
  468. } );
  469. };
  470. /**
  471. * Sends an interaction response.
  472. * @param {import('discord.js').CommandInteraction|import('discord.js').ButtonInteraction} interaction - The interaction.
  473. * @param {import('discord.js').MessageOptions} message - The message.
  474. * @param {Boolean} [letDelete] - Let the interaction user delete the message.
  475. * @returns {Promise<import('discord.js').Message?>}
  476. */
  477. function sendMessage(interaction, message, letDelete = true) {
  478. if ( !interaction.ephemeral && letDelete && breakOnTimeoutPause(interaction) ) return Promise.resolve();
  479. if ( message?.embeds?.length && !message.embeds[0] ) message.embeds = [];
  480. return interaction.editReply( message ).then( msg => {
  481. if ( letDelete && (msg.flags & 64) !== 64 ) allowDelete(msg, interaction.user.id);
  482. return msg;
  483. }, log_error );
  484. };
  485. export {
  486. got,
  487. oauthVerify,
  488. parse_infobox,
  489. toFormatting,
  490. toMarkdown,
  491. toPlaintext,
  492. htmlToPlain,
  493. htmlToDiscord,
  494. escapeFormatting,
  495. limitLength,
  496. partialURIdecode,
  497. breakOnTimeoutPause,
  498. allowDelete,
  499. sendMessage
  500. };