mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-03-10 04:39:57 +00:00
Removed unused import + disabled wiki.js for mantainance
This commit is contained in:
parent
6528c9e015
commit
8a7c9d89f0
@ -1,4 +1,3 @@
|
||||
const { spawn } = require('child_process');
|
||||
const { getStrings } = require('../plugins/checklang.js');
|
||||
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
|
||||
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
|
||||
|
@ -1,36 +1,36 @@
|
||||
const axios = require("axios");
|
||||
// const axios = require("axios");
|
||||
|
||||
function capitalizeFirstLetter(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
// function capitalizeFirstLetter(string) {
|
||||
// return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
// }
|
||||
|
||||
function mediaWikiToMarkdown(input) {
|
||||
input = input.replace(/===(.*?)===/g, '*$1*');
|
||||
input = input.replace(/==(.*?)==/g, '*$1*');
|
||||
input = input.replace(/=(.*?)=/g, '*$1*');
|
||||
input = input.replace(/'''(.*?)'''/g, '**$1**');
|
||||
input = input.replace(/''(.*?)''/g, '_$1_');
|
||||
input = input.replace(/^\*\s/gm, '- ');
|
||||
input = input.replace(/^\#\s/gm, '1. ');
|
||||
input = input.replace(/{{Quote(.*?)}}/g, "```\n$1```\n");
|
||||
input = input.replace(/\[\[(.*?)\|?(.*?)\]\]/g, (_, link, text) => {
|
||||
const sanitizedLink = link.replace(/ /g, '_');
|
||||
return text ? `[${text}](${sanitizedLink})` : `[${sanitizedLink}](${sanitizedLink})`;
|
||||
});
|
||||
input = input.replace(/\[\[File:(.*?)\|.*?\]\]/g, '');
|
||||
// function mediaWikiToMarkdown(input) {
|
||||
// input = input.replace(/===(.*?)===/g, '*$1*');
|
||||
// input = input.replace(/==(.*?)==/g, '*$1*');
|
||||
// input = input.replace(/=(.*?)=/g, '*$1*');
|
||||
// input = input.replace(/'''(.*?)'''/g, '**$1**');
|
||||
// input = input.replace(/''(.*?)''/g, '_$1_');
|
||||
// input = input.replace(/^\*\s/gm, '- ');
|
||||
// input = input.replace(/^\#\s/gm, '1. ');
|
||||
// input = input.replace(/{{Quote(.*?)}}/g, "```\n$1```\n");
|
||||
// input = input.replace(/\[\[(.*?)\|?(.*?)\]\]/g, (_, link, text) => {
|
||||
// const sanitizedLink = link.replace(/ /g, '_');
|
||||
// return text ? `[${text}](${sanitizedLink})` : `[${sanitizedLink}](${sanitizedLink})`;
|
||||
// });
|
||||
// input = input.replace(/\[\[File:(.*?)\|.*?\]\]/g, '');
|
||||
|
||||
return input;
|
||||
}
|
||||
// return input;
|
||||
// }
|
||||
|
||||
module.exports = (bot) => {
|
||||
bot.command("wiki", async (ctx) => {
|
||||
const userInput = capitalizeFirstLetter(ctx.message.text.split(' ')[1]);
|
||||
const apiUrl = `https://en.wikipedia.org/w/index.php?title=${userInput}&action=raw`;
|
||||
const response = await axios(apiUrl, { headers: { 'Accept': "text/plain" } });
|
||||
const convertedResponse = response.data.replace(/<\/?div>/g, "").replace(/{{Infobox.*?}}/s, "");
|
||||
// module.exports = (bot) => {
|
||||
// bot.command("wiki", async (ctx) => {
|
||||
// const userInput = capitalizeFirstLetter(ctx.message.text.split(' ')[1]);
|
||||
// const apiUrl = `https://en.wikipedia.org/w/index.php?title=${userInput}&action=raw`;
|
||||
// const response = await axios(apiUrl, { headers: { 'Accept': "text/plain" } });
|
||||
// const convertedResponse = response.data.replace(/<\/?div>/g, "").replace(/{{Infobox.*?}}/s, "");
|
||||
|
||||
const result = mediaWikiToMarkdown(convertedResponse).slice(0, 2048);
|
||||
// const result = mediaWikiToMarkdown(convertedResponse).slice(0, 2048);
|
||||
|
||||
ctx.reply(result, { parse_mode: 'Markdown', disable_web_page_preview: true, reply_to_message_id: ctx.message.message_id });
|
||||
});
|
||||
};
|
||||
// ctx.reply(result, { parse_mode: 'Markdown', disable_web_page_preview: true, reply_to_message_id: ctx.message.message_id });
|
||||
// });
|
||||
// };
|
||||
|
Loading…
x
Reference in New Issue
Block a user