Skip to content

Commit

Permalink
fix: fixed encoding issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mxvsh committed Jul 15, 2021
1 parent 29ed728 commit e858835
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"axios": "^0.21.1",
"cheerio": "^1.0.0-rc.10",
"dotenv": "^10.0.0",
"strip-ansi": "5.0.0",
"telegraf": "^4.4.0",
"urban-dictionary": "^3.0.1"
},
Expand Down
22 changes: 16 additions & 6 deletions src/modules/code/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import { Context } from "telegraf";
import { spawn } from "child_process";
import axios from "axios";
import stripAnsi from "strip-ansi";

import meta from "./meta";

const Response = async (ctx: Context, params?: any) => {
if (!params) return;
ctx.telegram.sendChatAction(ctx.chat.id, "typing");

const request = spawn("curl", [`cheat.sh/${params.replace(/ /, "+")}`]);
request.stdout.on("data", (data) => {
const response = data.toString();
ctx.reply(response || "Not found.");
});
let q = params.replace(/ /, "+");

axios
.get(`https://cheat.sh/${q}`, {
headers: {
"user-agent": "curl/7.64.1",
},
})
.then(({ data }) => {
ctx.telegram.sendDocument(ctx.chat.id, {
source: Buffer.from(stripAnsi(data)),
filename: `${q.replace("+", " ")}.txt`,
});
});
};

export default {
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ abort-controller@^3.0.0:
dependencies:
event-target-shim "^5.0.0"

ansi-regex@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997"
integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==

arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
Expand Down Expand Up @@ -265,6 +270,13 @@ source-map@^0.6.0:
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==

strip-ansi@5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.0.0.tgz#f78f68b5d0866c20b2c9b8c61b5298508dc8756f"
integrity sha512-Uu7gQyZI7J7gn5qLn1Np3G9vcYGTVqB+lFTytnDJv83dd8T22aGH451P3jueT2/QemInJDfxHB5Tde5OzgG1Ow==
dependencies:
ansi-regex "^4.0.0"

telegraf@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/telegraf/-/telegraf-4.4.0.tgz#a84228664a252062036b328fc364b5662ba3d22d"
Expand Down

0 comments on commit e858835

Please sign in to comment.