From 5f0029fe9a35cf0a1ce0b491eb0aa9fa49378414 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Sun, 23 Jun 2024 10:15:33 +0700 Subject: [PATCH] ci: move back to fly.io --- .github/workflows/ci.yml | 16 +++- fly.toml | 18 ++-- package-lock.json | 148 ------------------------------ package.json | 1 - src/app.js | 10 +- src/services/pesto/index.js | 178 ------------------------------------ src/uptime.js | 50 ---------- 7 files changed, 26 insertions(+), 395 deletions(-) delete mode 100644 src/services/pesto/index.js delete mode 100644 src/uptime.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad184ad..f52668b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,4 +75,18 @@ jobs: context: . push: true tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file + labels: ${{ steps.meta.outputs.labels }} + + deploy: + name: Deploy app + needs: + - ci + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: superfly/flyctl-actions/setup-flyctl@master + + - run: flyctl deploy --remote-only + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} \ No newline at end of file diff --git a/fly.toml b/fly.toml index 4889ee5..2d8cf76 100644 --- a/fly.toml +++ b/fly.toml @@ -1,12 +1,12 @@ -# fly.toml file generated for teknologi-umum-bot on 2021-08-08T13:56:06+07:00 +# fly.toml app configuration file generated for teknologi-umum-bot on 2024-06-23T10:04:06+07:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# -app = "teknologi-umum-bot-v2" -primary_region = "cdg" -kill_signal = "SIGINT" -kill_timeout = 5 +app = 'teknologi-umum-bot' +primary_region = 'ams' -[env] +[build] -[experimental] -allowed_public_ports = [] -auto_rollback = true +[[vm]] +size = 'shared-cpu-1x' diff --git a/package-lock.json b/package-lock.json index e7c83eb..5275f13 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,6 @@ "@logtail/node": "^0.4.21", "@sentry/node": "^7.112.2", "@teknologi-umum/nedb-promises": "^5.0.3", - "@teknologi-umum/pesto": "^1.0.0", "carret": "^1.0.4", "cheerio": "^1.0.0-rc.12", "dotenv": "^16.3.1", @@ -404,34 +403,6 @@ "@seald-io/nedb": "^2.2.1" } }, - "node_modules/@teknologi-umum/pesto": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@teknologi-umum/pesto/-/pesto-1.0.0.tgz", - "integrity": "sha512-jE/pZGsDidrO6MrlDjuTXkg7caq4m385Y6Vmy2EBpWV4Up3lK3vKzAqX1kvhGqJ5Pt1lCtScl+sq3AArWcgRwA==", - "dependencies": { - "node-fetch": "^3.3.0" - }, - "funding": { - "url": "https://github.com/sponsors/teknologi-umum" - } - }, - "node_modules/@teknologi-umum/pesto/node_modules/node-fetch": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.1.tgz", - "integrity": "sha512-cRVc/kyto/7E5shrWca1Wsea4y6tL9iYJE5FBCius3JQfb/4P4I295PfhgbJQBLTx6lATE4z+wK0rPM4VS2uow==", - "dependencies": { - "data-uri-to-buffer": "^4.0.0", - "fetch-blob": "^3.1.4", - "formdata-polyfill": "^4.0.10" - }, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/node-fetch" - } - }, "node_modules/@telegraf/types": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/@telegraf/types/-/types-7.1.0.tgz", @@ -904,14 +875,6 @@ "url": "https://github.com/sponsors/fb55" } }, - "node_modules/data-uri-to-buffer": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", - "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", - "engines": { - "node": ">= 12" - } - }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -1421,28 +1384,6 @@ "reusify": "^1.0.4" } }, - "node_modules/fetch-blob": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", - "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/jimmywarting" - }, - { - "type": "paypal", - "url": "https://paypal.me/jimmywarting" - } - ], - "dependencies": { - "node-domexception": "^1.0.0", - "web-streams-polyfill": "^3.0.3" - }, - "engines": { - "node": "^12.20 || >= 14.13" - } - }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -1524,17 +1465,6 @@ "node": ">= 14.17" } }, - "node_modules/formdata-polyfill": { - "version": "4.0.10", - "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", - "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", - "dependencies": { - "fetch-blob": "^3.1.2" - }, - "engines": { - "node": ">=12.20.0" - } - }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -2210,24 +2140,6 @@ "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, - "node_modules/node-domexception": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", - "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/jimmywarting" - }, - { - "type": "github", - "url": "https://paypal.me/jimmywarting" - } - ], - "engines": { - "node": ">=10.5.0" - } - }, "node_modules/node-fetch": { "version": "2.6.7", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", @@ -3290,14 +3202,6 @@ "integrity": "sha512-EcswR2S8bpR7fD0YPeS7r2xXExrScVMxg4MedACaWHEtx9ftCF/qHG1xGkolzTPcEmjTavCQgbVzHUIdTMzFGA==", "dev": true }, - "node_modules/web-streams-polyfill": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", - "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", - "engines": { - "node": ">= 8" - } - }, "node_modules/webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", @@ -3730,26 +3634,6 @@ "@seald-io/nedb": "^2.2.1" } }, - "@teknologi-umum/pesto": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@teknologi-umum/pesto/-/pesto-1.0.0.tgz", - "integrity": "sha512-jE/pZGsDidrO6MrlDjuTXkg7caq4m385Y6Vmy2EBpWV4Up3lK3vKzAqX1kvhGqJ5Pt1lCtScl+sq3AArWcgRwA==", - "requires": { - "node-fetch": "^3.3.0" - }, - "dependencies": { - "node-fetch": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.1.tgz", - "integrity": "sha512-cRVc/kyto/7E5shrWca1Wsea4y6tL9iYJE5FBCius3JQfb/4P4I295PfhgbJQBLTx6lATE4z+wK0rPM4VS2uow==", - "requires": { - "data-uri-to-buffer": "^4.0.0", - "fetch-blob": "^3.1.4", - "formdata-polyfill": "^4.0.10" - } - } - } - }, "@telegraf/types": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/@telegraf/types/-/types-7.1.0.tgz", @@ -4120,11 +4004,6 @@ "resolved": "https://registry.npmjs.org/css-what/-/css-what-6.1.0.tgz", "integrity": "sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==" }, - "data-uri-to-buffer": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", - "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==" - }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -4475,15 +4354,6 @@ "reusify": "^1.0.4" } }, - "fetch-blob": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", - "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", - "requires": { - "node-domexception": "^1.0.0", - "web-streams-polyfill": "^3.0.3" - } - }, "file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -4544,14 +4414,6 @@ "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-2.1.4.tgz", "integrity": "sha512-yDYSgNMraqvnxiEXO4hi88+YZxaHC6QKzb5N84iRCTDeRO7ZALpir/lVmf/uXUhnwUr2O4HU8s/n6x+yNjQkHw==" }, - "formdata-polyfill": { - "version": "4.0.10", - "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", - "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", - "requires": { - "fetch-blob": "^3.1.2" - } - }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -5020,11 +4882,6 @@ "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, - "node-domexception": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", - "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" - }, "node-fetch": { "version": "2.6.7", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", @@ -5783,11 +5640,6 @@ "integrity": "sha512-EcswR2S8bpR7fD0YPeS7r2xXExrScVMxg4MedACaWHEtx9ftCF/qHG1xGkolzTPcEmjTavCQgbVzHUIdTMzFGA==", "dev": true }, - "web-streams-polyfill": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", - "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==" - }, "webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", diff --git a/package.json b/package.json index 44aff7b..56b7242 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "@logtail/node": "^0.4.21", "@sentry/node": "^7.112.2", "@teknologi-umum/nedb-promises": "^5.0.3", - "@teknologi-umum/pesto": "^1.0.0", "carret": "^1.0.4", "cheerio": "^1.0.0-rc.12", "dotenv": "^16.3.1", diff --git a/src/app.js b/src/app.js index 92c6029..c9e6e58 100644 --- a/src/app.js +++ b/src/app.js @@ -14,7 +14,6 @@ import * as meme from "#services/meme/index.js"; import * as help from "#services/help/index.js"; import * as quote from "#services/quote/index.js"; import * as covid from "#services/covid/index.js"; -import * as snap from "#services/snap/index.js"; import * as blidingej from "#services/bliding-ej/index.js"; import * as evalBot from "#services/eval/index.js"; import * as blog from "#services/devread/index.js"; @@ -25,7 +24,6 @@ import * as laodeai from "#services/laodeai/index.js"; import * as analytics from "#services/analytics/index.js"; import * as news from "#services/news/index.js"; import * as qr from "#services/qr/index.js"; -import * as pesto from "#services/pesto/index.js"; import { getCommandName } from "#utils/command.js"; dotenv.config({ path: pathTo(import.meta.url, "../.env") }); @@ -52,13 +50,11 @@ const mongo = mongoose.createConnection(String(process.env.MONGO_URL), { // Fork processes const hackernewsFork = fork(pathTo(import.meta.url, "./hackernews.js"), { detached: true }); -const uptimeFork = fork(pathTo(import.meta.url, "./uptime.js", { detached: true })); async function terminate(caller) { const t = Date.now(); bot.stop(caller); hackernewsFork.kill(); - uptimeFork.kill(); await mongo.close(); await Sentry.flush(); terminal.info(`${caller}: ${Date.now() - t}ms`); @@ -77,7 +73,7 @@ async function main() { } // TODO: Move this somewhere else - const validCommands = ["blidingej", "covid", "devread", "dukun", "eval", "laodeai", "news", "hilih", "joke", "kktbsys", "yntks", "homework", "illuminati", "c", "cpp", "clisp", "dotnet", "go", "java", "js", "julia", "lua", "php", "python", "ruby", "sqlite3", "tengo", "ts", "v", "brainfuck", "qr", "quote", "search", "snap"]; + const validCommands = ["blidingej", "covid", "devread", "dukun", "eval", "laodeai", "news", "hilih", "joke", "kktbsys", "yntks", "homework", "illuminati", "qr", "quote", "search"]; if (ctx.updateType === "message") { const command = getCommandName(ctx); if (command === "" || !validCommands.includes(command)) { @@ -108,7 +104,6 @@ async function main() { quote.register(bot), covid.register(bot, cache), poll.register(bot, mongo, cache), - snap.register(bot), blidingej.register(bot), evalBot.register(bot), blog.register(bot, cache), @@ -118,8 +113,7 @@ async function main() { laodeai.register(bot), analytics.register(bot, mongo), news.register(bot), - qr.register(bot), - pesto.register(bot) + qr.register(bot) ] .filter((v) => Array.isArray(v)) .flat(); diff --git a/src/services/pesto/index.js b/src/services/pesto/index.js deleted file mode 100644 index fd2fd4f..0000000 --- a/src/services/pesto/index.js +++ /dev/null @@ -1,178 +0,0 @@ -import { getCommandArgs } from "#utils/command.js"; -import { PestoClient } from "@teknologi-umum/pesto"; - -const pestoClient = new PestoClient({ token: process.env.PESTO_TOKEN }); - -/** - * - * @param {import('telegraf').Context} context - * @param {String} command - * @param {String} language - */ -async function executeCode(context, command, language) { - const code = getCommandArgs(command, context); - if (!code) { - return; - } - - const codeResponse = await pestoClient.execute({ - language: language, - version: "latest", - code: code - }); - - if (codeResponse.compile.exitCode !== 0) { - await context.telegram.sendMessage( - context.chat.id, - `${codeResponse.compile.output.replace( - /[\u00A0-\u9999<>&]/gim, - (i) => "&#" + i.charCodeAt(0) + ";")}`, - { - parse_mode: "HTML", - reply_to_message_id: context.message.message_id, - allow_sending_without_reply: true - } - ); - } else if (codeResponse.runtime.exitCode !== 0) { - await context.telegram.sendMessage( - context.chat.id, - `${codeResponse.runtime.output.replace( - /[\u00A0-\u9999<>&]/gim, - (i) => "&#" + i.charCodeAt(0) + ";")}`, - { - parse_mode: "HTML", - reply_to_message_id: context.message.message_id, - allow_sending_without_reply: true - } - ); - } else if (codeResponse.runtime.output.length > 1000) { - await context.telegram.sendMessage( - context.chat.id, - "Output is too long", - { - parse_mode: "HTML", - reply_to_message_id: context.message.message_id, - allow_sending_without_reply: true - } - ); - } else { - await context.telegram.sendMessage( - context.chat.id, - `Code:\n${code.replace( - /[\u00A0-\u9999<>&]/gim, - (i) => "&#" + i.charCodeAt(0) + ";") - }\n\nOutput:\n${ - // Stolen from https://stackoverflow.com/a/23834738/3153224 - codeResponse.runtime.output.replace( - /[\u00A0-\u9999<>&]/gim, - (i) => "&#" + i.charCodeAt(0) + ";") - }`, - { - parse_mode: "HTML", - reply_to_message_id: context.message.message_id, - allow_sending_without_reply: true - } - ); - } -} - -/** - * - * @param {import('telegraf').Telegraf} bot - * @returns {{command: String, description: String}[]} - */ -export function register(bot) { - bot.command("c", (context) => executeCode(context, "c", "C")); - bot.command("cpp", (context) => executeCode(context, "cpp", "C++")); - bot.command("clisp", (context) => executeCode(context, "clisp", "Common Lisp")); - bot.command("dotnet", (context) => executeCode(context, "dotnet", ".NET")); - bot.command("go", (context) => executeCode(context, "go", "Go")); - bot.command("janet", (context) => executeCode(context, "janet", "Janet")); - bot.command("java", (context) => executeCode(context, "java", "Java")); - bot.command("js", (context) => executeCode(context, "js", "Javascript")); - bot.command("julia", (context) => executeCode(context, "julia", "Julia")); - bot.command("lua", (context) => executeCode(context, "lua", "Lua")); - bot.command("php", (context) => executeCode(context, "php", "PHP")); - bot.command("python", (context) => executeCode(context, "python", "Python")); - bot.command("ruby", (context) => executeCode(context, "ruby", "Ruby")); - bot.command("sqlite3", (context) => executeCode(context, "sqlite3", "SQLite3")); - bot.command("tengo", (context) => executeCode(context, "tengo", "Tengo")); - bot.command("ts", (context) => executeCode(context, "ts", "Typescript")); - bot.command("v", (context) => executeCode(context, "v", "V")); - bot.command("brainfuck", (context) => executeCode(context, "brainfuck", "Brainfuck")); - - return [ - { - command: "c", - description: "Execute C code" - }, - { - command: "cpp", - description: "Execute C++ code" - }, - { - command: "clisp", - description: "Execute Common Lisp code" - }, - { - command: "dotnet", - description: "Execute .NET code" - }, - { - command: "go", - description: "Execute Go code" - }, - { - command: "janet", - description: "Execute Janet code" - }, - { - command: "java", - description: "Execute Java code" - }, - { - command: "js", - description: "Execute Javascript code" - }, - { - command: "julia", - description: "Execute Julia code" - }, - { - command: "lua", - description: "Execute Lua code" - }, - { - command: "php", - description: "Execute PHP code" - }, - { - command: "python", - description: "Execute Python code" - }, - { - command: "ruby", - description: "Execute Ruby code" - }, - { - command: "sqlite3", - description: "Execute SQLite3 code" - }, - { - command: "tengo", - description: "Execute TenGo code" - }, - { - command: "ts", - description: "Execute Typescript code" - }, - { - command: "v", - description: "Execute V code" - }, - { - command: "brainfuck", - description: "Execute Brainfuck code" - } - ]; -} \ No newline at end of file diff --git a/src/uptime.js b/src/uptime.js deleted file mode 100644 index 29f32ea..0000000 --- a/src/uptime.js +++ /dev/null @@ -1,50 +0,0 @@ -import dotenv from "dotenv"; -import * as Sentry from "@sentry/node"; -import { pathTo } from "#utils/path.js"; - -dotenv.config({ path: pathTo(import.meta.url, "../.env") }); - -const UPTIME_MONITOR_URL = process.env.UPTIME_MONITOR_URL; - -function sleep(ms) { - return new Promise((resolve) => setTimeout(resolve, ms)); -} - -async function run(url) { - const searchParams = new URLSearchParams(); - searchParams.set("msg", "OK"); - searchParams.set("ping", "0"); - searchParams.set("status", "up"); - - await fetch(url + "?" + searchParams.toString()); -} - -for (;;) { - // Don't start the uptime service if the monitor url is empty. - if (!UPTIME_MONITOR_URL) { - break; - } - - let done = false; - - // eslint-disable-next-line no-await-in-loop - await run(UPTIME_MONITOR_URL) - .catch((error) => { - Sentry.captureException(error); - }) - .finally(() => { - done = true; - }); - - while (!done) { - // wait - await sleep(1000); - } - - // How long do we need to sleep - const now = new Date(); - const nextTime = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes() + 1, 0, 0); - - // eslint-disable-next-line no-await-in-loop - await sleep(nextTime.getTime() - now.getTime()); -}