From 8a3d6d50006b071171f9db56f83064d06b78dcc2 Mon Sep 17 00:00:00 2001 From: juakotorres Date: Tue, 22 Sep 2020 21:43:08 -0300 Subject: [PATCH] bot --- .gitignore | 3 +++ .idea/.gitignore | 8 ++++++++ .idea/GoJapanBanBot.iml | 12 ++++++++++++ .idea/jsLibraryMappings.xml | 6 ++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ goJapanBanBot.js | 28 ++++++++++++++++++++++++++++ package.json | 10 ++++++++++ 9 files changed, 87 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/GoJapanBanBot.iml create mode 100644 .idea/jsLibraryMappings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 goJapanBanBot.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index d333b23..009b40d 100644 --- a/.gitignore +++ b/.gitignore @@ -107,3 +107,6 @@ dist # Stores VSCode versions used for testing VSCode extensions .vscode-test +package-lock.json +pass.js + diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/GoJapanBanBot.iml b/.idea/GoJapanBanBot.iml new file mode 100644 index 0000000..24643cc --- /dev/null +++ b/.idea/GoJapanBanBot.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..d23208f --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0389f87 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/goJapanBanBot.js b/goJapanBanBot.js new file mode 100644 index 0000000..0fa59bd --- /dev/null +++ b/goJapanBanBot.js @@ -0,0 +1,28 @@ +const TelegramBot = require('node-telegram-bot-api'); +const axios = require('axios'); +const cheerio = require('cheerio'); + +// replace the value below with the Telegram token you receive from @BotFather +let token = require("./pass.js").token; + +// Create a bot that uses 'polling' to fetch new updates +const bot = new TelegramBot(token, {polling: true}); + +bot.onText(/\/saleGoJapon/, async (msg, match) => { + + let ban = false; + const chatId = msg.chat.id; + let response = await axios.get('https://www.mofa.go.jp/ca/fna/page4e_001053.html'); + + const $ = await cheerio.load(response.data); + + ban = $('#section1').text().toUpperCase().includes("CHILE"); + + if(ban) { + bot.sendMessage(chatId, "TodavĂ­a baneados prro"); + } else { + bot.sendMessage(chatId, "/goJapon"); + } +}); + +bot.on("polling_error", (err) => console.log(err)); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..bfd1dc2 --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "version": "5.4.0", + "private": true, + "dependencies": { + "axios": "^0.20.0", + "cheerio": "^1.0.0-rc.3", + "node-telegram-bot-api": "^0.30.0" + }, + "devDependencies": {} +}