mirror of
https://github.com/zhigang1992/trending_github_telegram_bot.git
synced 2026-01-12 22:42:21 +08:00
chore: add deployment
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
node_modules
|
||||
.env
|
||||
dist/
|
||||
|
||||
64
index.ts
64
index.ts
@@ -1,14 +1,64 @@
|
||||
import dotenv from 'dotenv';
|
||||
import {Client} from 'memjs';
|
||||
import Telegraf from 'telegraf'
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
(async () => {
|
||||
const client = Client.create(process.env.MEMCACHIER_SERVER_STRING);
|
||||
const value = Buffer.from("sup", "utf-8");
|
||||
await client.set('hello', value, {expires: 0});
|
||||
const {value: getValue} = await client.get('hello');
|
||||
console.log(getValue.toString('utf-8'));
|
||||
})();
|
||||
interface Repo {
|
||||
author: string;
|
||||
name: string;
|
||||
avatar: string;
|
||||
url: string;
|
||||
description:string;
|
||||
stars: number;
|
||||
forks: number;
|
||||
currentPeriodStars: number;
|
||||
builtBy: Array<{
|
||||
href: string;
|
||||
avatar: string;
|
||||
username: string;
|
||||
}>
|
||||
}
|
||||
|
||||
const bot = new Telegraf(process.env.TELEGRAM_BOT_TOKEN!);
|
||||
|
||||
async function sendToTelegram(repo: Repo) {
|
||||
const description = `[${repo.author}/${repo.name}](${repo.url})
|
||||
`;
|
||||
await bot.telegram.sendMessage('@trending_github', description, {
|
||||
parse_mode: 'Markdown'
|
||||
})
|
||||
}
|
||||
|
||||
const client = Client.create(process.env.MEMCACHIER_SERVER_STRING);
|
||||
|
||||
async function getFromMemCache(url: string): Promise<Repo | null> {
|
||||
const {value} = await client.get(url);
|
||||
if (value == null) {
|
||||
return null
|
||||
}
|
||||
return JSON.parse(value.toString('utf-8'));
|
||||
}
|
||||
|
||||
async function saveToMemCache(repo: Repo) {
|
||||
await client.set(repo.url, JSON.stringify(repo), {expires: 0});
|
||||
}
|
||||
|
||||
async function getUpdates(): Promise<Repo[]> {
|
||||
const response = await fetch('https://github-trending-api.now.sh/repositories');
|
||||
return await response.json()
|
||||
}
|
||||
|
||||
export const handler = async () => {
|
||||
const repos = await getUpdates();
|
||||
for (const repo of repos) {
|
||||
const cached = await getFromMemCache(repo.url);
|
||||
if (cached == null || repo.stars - cached.stars > 500) {
|
||||
await sendToTelegram(repo);
|
||||
await saveToMemCache(repo);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
3
netlify.toml
Normal file
3
netlify.toml
Normal file
@@ -0,0 +1,3 @@
|
||||
[build]
|
||||
command = "yarn build"
|
||||
functions = "dist"
|
||||
@@ -13,6 +13,10 @@
|
||||
"dependencies": {
|
||||
"dotenv": "^8.1.0",
|
||||
"memjs": "^1.2.2",
|
||||
"node-fetch": "^2.6.0"
|
||||
"node-fetch": "^2.6.0",
|
||||
"telegraf": "^3.32.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
// "outDir": "./", /* Redirect output structure to the directory. */
|
||||
"outDir": "./dist", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
|
||||
37
yarn.lock
37
yarn.lock
@@ -23,7 +23,7 @@
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/node@*":
|
||||
"@types/node@*", "@types/node@^12.0.4":
|
||||
version "12.7.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.2.tgz#c4e63af5e8823ce9cc3f0b34f7b998c2171f0c44"
|
||||
integrity sha512-dyYO+f6ihZEtNPDcWNR1fkoTDf3zAK3lAABDze3mz6POyIercH0lEUawUFXlG8xaQZmm1yEBON/4TsYv/laDYg==
|
||||
@@ -38,6 +38,13 @@ buffer-from@^1.0.0:
|
||||
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
|
||||
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
|
||||
|
||||
debug@^4.0.1:
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
|
||||
integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==
|
||||
dependencies:
|
||||
ms "^2.1.1"
|
||||
|
||||
diff@^4.0.1:
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.1.tgz#0c667cb467ebbb5cea7f14f135cc2dba7780a8ff"
|
||||
@@ -58,11 +65,21 @@ memjs@^1.2.2:
|
||||
resolved "https://registry.yarnpkg.com/memjs/-/memjs-1.2.2.tgz#f7c7276c7016ba1b8ad800df09cecc32522a536c"
|
||||
integrity sha512-j6I5cQsjT8izm0FcBZrwga4VmlhTMsBTPKdyKolQenLulHNvKuNcDgDmBhQvScqNLy4tjpCCFwiqFK+5l6J20g==
|
||||
|
||||
node-fetch@^2.6.0:
|
||||
ms@^2.1.1:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
|
||||
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
|
||||
|
||||
node-fetch@^2.2.0, node-fetch@^2.6.0:
|
||||
version "2.6.0"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
|
||||
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
|
||||
|
||||
sandwich-stream@^2.0.1:
|
||||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/sandwich-stream/-/sandwich-stream-2.0.2.tgz#6d1feb6cf7e9fe9fadb41513459a72c2e84000fa"
|
||||
integrity sha512-jLYV0DORrzY3xaz/S9ydJL6Iz7essZeAfnAavsJ+zsJGZ1MOnsS52yRjU3uF3pJa/lla7+wisp//fxOwOH8SKQ==
|
||||
|
||||
source-map-support@^0.5.6:
|
||||
version "0.5.13"
|
||||
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.13.tgz#31b24a9c2e73c2de85066c0feb7d44767ed52932"
|
||||
@@ -76,6 +93,22 @@ source-map@^0.6.0:
|
||||
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
|
||||
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
|
||||
|
||||
telegraf@^3.32.0:
|
||||
version "3.32.0"
|
||||
resolved "https://registry.yarnpkg.com/telegraf/-/telegraf-3.32.0.tgz#70ec304b9c8645f8988924ebe90e5c00ee46ddbb"
|
||||
integrity sha512-5ZHiovyuG1rVLygJjaqf57wDt8e1nijAinKXCxN1tyUZ4BcrkZW/z5rVTEXA+KegpFbWxKKv3KnJwUJrKDqD0Q==
|
||||
dependencies:
|
||||
"@types/node" "^12.0.4"
|
||||
debug "^4.0.1"
|
||||
node-fetch "^2.2.0"
|
||||
sandwich-stream "^2.0.1"
|
||||
telegram-typings "^3.6.0"
|
||||
|
||||
telegram-typings@^3.6.0:
|
||||
version "3.6.1"
|
||||
resolved "https://registry.yarnpkg.com/telegram-typings/-/telegram-typings-3.6.1.tgz#1288d547f8694b61f1c01c2993e295f3114d9e25"
|
||||
integrity sha512-njVv1EAhIZnmQVLocZEADYUyqA1WIXuVcDYlsp+mXua/XB0pxx+PKtMSPeZ/EE4wPWTw9h/hA9ASTT6yQelkiw==
|
||||
|
||||
ts-node@^8.3.0:
|
||||
version "8.3.0"
|
||||
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.3.0.tgz#e4059618411371924a1fb5f3b125915f324efb57"
|
||||
|
||||
Reference in New Issue
Block a user