fix: remove airportsub

This commit is contained in:
lyz05
2024-03-09 16:50:09 +08:00
parent 59f8575c0d
commit c31df4db7a
8 changed files with 1 additions and 552 deletions

2
app.js
View File

@@ -10,7 +10,6 @@ require("dotenv")
// 引入一个个路由模块
const danmakuRouter = require("./routes/danmaku");
const airportsubRouter = require("./routes/airportsub");
const DEBUG = !(process.env.DEBUG === "false");
const app = express();
// 启用gzip压缩
@@ -37,7 +36,6 @@ app.use("/assets", [
// 加载路由
app.use("/", danmakuRouter);
app.use("/sub", airportsubRouter);
// catch 404 and forward to error handler
app.use(function (req, res, next) {

View File

@@ -27,4 +27,4 @@ kill_timeout = "5s"
[[vm]]
cpu_kind = "shared"
cpus = 1
memory_mb = 256
memory_mb = 512

View File

@@ -1,24 +0,0 @@
const express = require("express");
const router = express.Router();
const leancloud = require("../utils/leancloud");
/* GET users listing. */
router.get("/", async function (req, res) {
// leancloud.add("SubAccess", {
// remoteIP: req.ip,
// UA: req.headers["user-agent"],
// user: req.query.user,
// ctype: req.query.ctype
// });
if (req.query.user) {
if (req.query.ctype) {
res.redirect("https://sub.home999.cc/sub/"+req.query.user+"/"+req.query.ctype);
} else {
res.redirect("https://sub.home999.cc/sub/"+req.query.user);
}
} else {
res.status(400).send("Bad Request 缺少参数");
}
});
module.exports = router;

View File

@@ -1,85 +0,0 @@
const axios = require("axios");
const BASE_URL = "https://gd.lyz05.workers.dev";
function group(array, subGroupLength) {
let index = 0;
const newArray = [];
while (index < array.length) {
newArray.push(array.slice(index, index += subGroupLength));
}
return newArray;
}
async function id2path(id) {
const url = `${BASE_URL}/0:id2path`;
const ret = await axios.post(url, { id });
return `${BASE_URL}/0:${ret.data}`;
}
async function query(q) {
const url = `${BASE_URL}/0:search`;
let files = [];
let page_token = null;
// eslint-disable-next-line no-constant-condition
while (true) {
const data = {
q,
page_index: 1,
page_token,
};
const ret = await axios.post(url, data);
files = files.concat(ret.data.data.files);
// console.log(ret.data.data.files)
page_token = ret.data.nextPageToken;
if (page_token === null) {
break;
}
}
// console.log('files:',files);
return files;
}
// async function queryData(path = "") {
// const url = `${BASE_URL}/0:/Inbox/seer/%E5%86%99%E7%9C%9F/Miho%20Kaneko%20Complete%20Photo%20Collection/${path}`;
// const data = {
// q: "",
// page_index: 0,
// page_token: null,
// password: null,
// };
// const response = await axios.post(url, data);
// return response.data;
// }
// async function dfs(path) {
// let l = [];
// const res = await queryData(path);
// for (const item of res.data.files) {
// if (item.mimeType === "application/vnd.google-apps.folder") {
// l = l.concat(await dfs(`${path + item.name}/`));
// } else {
// l.push(item.name);
// }
// }
// return l;
// }
// async function main(num) {
// // const res = await dfs('');
// // console.log(res);
// const files = await query();
// const link = files[num].thumbnailLink;
// console.log(link);
// }
module.exports = {
query,
id2path,
group,
};
// main(12);
// console.log(response.data.data.files)

View File

@@ -1,49 +0,0 @@
const { Configuration, OpenAIApi } = require("openai");
require("dotenv").config({ path: "../.env" });
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
let prompt = { "role": "system", "content": "You are a helpful assistant." }
async function setprompt(content) {
prompt = { "role": "system", "content": content || "You are a helpful assistant." }
return prompt.content
}
async function completions(prompt) {
const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt: prompt,
});
console.log(completion.data.choices[0].text);
}
async function chat(content, messages) {
if (!messages || messages.length == 0) {
messages = [prompt]
}
messages.push({ "role": "user", "content": content });
const completion = await openai.createChatCompletion({
"model": "gpt-3.5-turbo",
"messages": messages,
});
messages.push(completion.data.choices[0].message);
console.log(messages)
return [completion.data.choices[0].message.content, messages];
}
async function main() {
const messages = [];
// completions("护眼")
await chat("我们来玩个猜数游戏", messages);
await chat("规则是你心中默想一个数,然后我猜你想的数,数的范围是一到一百", messages);
await chat("我猜50", messages);
console.log(messages)
}
module.exports = {
completions,
chat,
setprompt,
}

View File

@@ -1,322 +0,0 @@
// Import modules
const whacko = require("whacko");
const yaml = require("js-yaml");
const TelegramBot = require("node-telegram-bot-api");
const axios = require("axios");
const oss = require("../../utils/oss");
const goindex = require("../api/goindex");
const openai = require("../api/openai");
const https = require('https');
async function finduserbychatid(chatid) {
const database = await oss.get("SUB/database.yaml");
const data = yaml.load(database);
const users = data.user;
// eslint-disable-next-line no-restricted-syntax
for (const user in users) {
if (users[user].chatID == chatid) {
return user;
}
}
return null;
}
async function setchatidbyuser(user, chatid) {
const database = await oss.get("SUB/database.yaml");
const data = yaml.load(database);
data.user[user].chatID = chatid;
oss.put("SUB/database.yaml", yaml.dump(data));
}
// function sleep(ms) {
// return new Promise((resolve) => setTimeout(resolve, ms));
// }
module.exports = (TOKEN) => {
const game = {};
let openai_messages = {};
let setu = {};
const bot = new TelegramBot(TOKEN, { polling: true });
function sendSetu(chatId, i) {
const href = setu[i];
const prev = {
text: "上一张",
callback_data: i - 1
};
const next = {
text: "下一张",
callback_data: i + 1
};
let replyMarkup = { inline_keyboard: [[prev, next]] };
if (i === 0) {
replyMarkup = { inline_keyboard: [[next]] };
} else if (i + 1 === setu.length) {
replyMarkup = { inline_keyboard: [[prev]] };
}
bot.sendMessage(chatId, href, { reply_markup: replyMarkup });
}
// Just to ping!
bot.on("message", (msg) => {
if (!msg.text) {
bot.sendMessage(msg.chat.id, "I can only understand text messages!");
}
});
// 智能聊天机器人
bot.on("text",async (msg) => {
if (msg.text.indexOf("/") === -1) {
bot.sendMessage(msg.chat.id, `you said: ${msg.text}`);
const agent = new https.Agent({
rejectUnauthorized: false
});
const res = await axios.get(`https://api.qingyunke.com/api.php?key=free&appid=0&msg=${encodeURI(msg.text)}`, { httpsAgent: agent })
console.log(res.data);
bot.sendMessage(msg.chat.id, res.data.content);
}
});
// ChatGPT版智能聊天机器人
// bot.on("text", async (msg) => {
// if (msg.text.indexOf("/") === -1) {
// bot.sendMessage(msg.chat.id, `you said: ${msg.text}`);
// let messages = openai_messages[msg.chat.id] || [], res;
// [res, messages] = await openai.chat(msg.text, messages);
// const length = (messages.length - 1) / 2;
// bot.sendMessage(msg.chat.id, `${res}\n\nPowered by OpenAI 连续对话了${length}次`);
// openai_messages[msg.chat.id] = messages;
// }
// });
bot.onText(/\/clear/, (msg) => {
openai_messages[msg.chat.id] = [];
bot.sendMessage(msg.chat.id, "已清空对话记录");
});
bot.onText(/\/prompt/, async (msg) => {
const prompt = msg.text.replace("/prompt ", "").replace("/prompt", "");
openai_messages[msg.chat.id] = [];
const res = await openai.setprompt(prompt);
bot.sendMessage(msg.chat.id, `已设置对话提示为:${res}`);
});
// 欢迎页面
bot.onText(/\/start/, (msg) => {
let name = [msg.from.first_name];
if (msg.from.last_name) {
name.push(msg.from.last_name);
}
name = name.join(" ");
bot.sendMessage(msg.chat.id, `Welcome, ${name}!`);
bot.sendMessage(msg.chat.id, "你可以给我发送消息,我会回复你.");
bot.sendMessage(msg.chat.id, "你可以发送类似这样的指令 /start, /help.");
});
// 发送用户头像
bot.onText(/\/sendpic/, (msg) => {
bot.getUserProfilePhotos(msg.chat.id)
.then((photos) => {
const photo = photos.photos[0][0];
bot.sendPhoto(msg.chat.id, photo.file_id, {
caption: "This is a picture of You!",
});
});
// bot.sendPhoto(msg.chat.id, "https://blog.home999.cc/images/avatar.jpg");
});
bot.onText(/\/register/, async (msg) => {
const user = await finduserbychatid(msg.chat.id);
if (user == null) {
const user = msg.text.replace("/register ", "");
if (msg.text === "/register") {
bot.sendMessage(msg.chat.id, `您的ChatId为: ${msg.chat.id}\n若要进行注册请跟上您的user信息 /register example`);
} else {
setchatidbyuser(user, msg.chat.id);
bot.sendMessage(msg.chat.id, "注册完成!");
}
} else {
bot.sendMessage(msg.chat.id, "您已经注册过了,请勿重复注册。");
}
});
bot.onText(/\/sub/, async (msg) => {
const user = await finduserbychatid(msg.chat.id);
const url = `https://fc.home999.cc/sub?user=${user}`;
if (user == null) {
bot.sendMessage(msg.chat.id, "您未注册!请输入 /register 进行注册");
} else {
bot.sendMessage(msg.chat.id, `你好,${user}`);
bot.sendMessage(msg.chat.id, `您的订阅链接为:${url}`);
}
});
// 猜数游戏
bot.onText(/\/game/, async (msg) => {
const chatID = msg.chat.id;
const guess = parseInt(msg.text.replace("/game", ""), 10);
if (game[chatID] === undefined) {
game[chatID] = {
num: Math.floor(Math.random() * 100),
limit: 10,
};
await bot.sendMessage(chatID, "我们来玩猜数游戏吧!");
await bot.sendMessage(chatID, "猜一个数字你有10次机会。范围:[0, 100)");
await bot.sendMessage(chatID, "请输入你的猜测:(例:/game 50)");
return;
}
const {
num,
limit
} = game[chatID];
if (limit <= 0) {
bot.sendMessage(chatID, `游戏结束!未猜出正确答案,正确答案为:${num}`);
game[chatID] = undefined;
return;
}
game[chatID].limit -= 1;
if (guess === num) {
bot.sendMessage(chatID, "恭喜你猜对了!");
game[chatID] = undefined;
} else if (guess > num) {
bot.sendMessage(chatID, "你猜的数字太大了!");
} else {
bot.sendMessage(chatID, "你猜的数字太小了!");
}
});
bot.onText(/\/help/, (msg) => {
const helpMsg = [
{
command: "start",
description: "欢迎界面"
},
{
command: "game",
description: "猜数游戏"
},
{
command: "sub",
description: "订阅链接"
},
{
command: "register",
description: "注册"
},
{
command: "sendpic",
description: "发送你的头像"
},
{
command: "setu",
description: "随机色图,可加编号"
},
{
command: "goindex",
description: "查询GoIndex上的文件"
},
{
command: "help",
description: "帮助"
},
{
command: "clear",
description: "清空OpenAI聊天记录"
},
{
command: "prompt",
description: "设置OpenAI聊天提示句"
}
];
const helpMsgText = helpMsg.map((item) => `/${item.command} - ${item.description}`)
.join("\n");
bot.sendMessage(msg.chat.id, helpMsgText, { parse_mode: "HTML" });
bot.setMyCommands(helpMsg);
});
bot.onText(/\/setu/, async (msg) => {
const index = parseInt(msg.text.replace("/setu", ""), 10);
bot.sendMessage(msg.chat.id, "色图模式");
const res = await axios.get("https://asiantolick.com/ajax/buscar_posts.php", { params: { index } });
const $ = whacko.load(res.data);
setu = Object.values($(".miniatura"))
.map((item) => $(item)
.attr("href"));
sendSetu(msg.chat.id, 0);
});
bot.on("callback_query", async (query) => {
const i = parseInt(query.data, 10);
const queryId = query.id;
sendSetu(query.message.chat.id, i);
bot.answerCallbackQuery(queryId);
});
bot.onText(/\/goindex/, (msg) => {
const q = msg.text.replace("/goindex ", "");
bot.sendMessage(msg.chat.id, `正在搜寻“${q}”...`);
goindex.query(q)
.then((res) => {
// 筛选符合条件的文件
const videos = res.filter((e) => e.mimeType === "video/mp4")
.filter((e) => e.size < 50 * 1024 * 1024);
let images = res.filter((e) => e.mimeType === "image/jpeg");
const audios = res.filter((e) => e.mimeType === "audio/mp3")
.filter((e) => e.size < 50 * 1024 * 1024);
const folders = res.filter((e) => e.mimeType === "application/vnd.google-apps.folder");
bot.sendMessage(msg.chat.id, `共有${images.length}个图片结果,${videos.length}个视频,${audios.length}个音乐,${folders.length}个目录,搜索结果:`);
bot.sendChatAction(msg.chat.id, "upload_photo");
images = goindex.group(images, 10);
images.forEach((e, i) => {
setTimeout(() => {
bot.sendMediaGroup(msg.chat.id, e.map((el) => ({
type: "photo",
media: el.thumbnailLink.replace("=s220", "=s0"),
caption: el.name,
})));
}, i * 2000);
});
bot.sendChatAction(msg.chat.id, "upload_video");
videos.forEach((e, i) => {
setTimeout(() => {
goindex.id2path(e.id)
.then((path) => {
console.log(path);
bot.sendVideo(msg.chat.id, encodeURI(path), {
caption: `${e.name}`,
reply_markup: {
inline_keyboard: [
[{
text: "带我去看片",
url: encodeURI(path)
}],
],
},
});
});
}, i * 2000);
});
bot.sendChatAction(msg.chat.id, "upload_voice");
audios.forEach((e, i) => {
setTimeout(() => {
goindex.id2path(e.id)
.then((path) => {
console.log(path);
bot.sendAudio(msg.chat.id, path, { caption: `${e.name}` });
});
}, i * 2000);
});
});
});
bot.onText(/\/senddice/, (msg) => {
bot.sendDice(msg.chat.id, { emoji: "🎲" });
});
bot.on("polling_error", (error) => {
console.log(error.message); // => 'EFATAL'
});
return bot;
};

View File

@@ -1,46 +0,0 @@
const TelegramBot = require("node-telegram-bot-api");
module.exports = (TOKEN) => {
const bot = new TelegramBot(TOKEN, {polling: true});
// Just to ping!
bot.on("message", msg => {
if (msg.text) {
bot.sendMessage(msg.chat.id, msg.text);
} else {
bot.sendMessage(msg.chat.id, "I can only understand text messages!");
}
});
bot.on("video", msg => {
bot.sendMessage(msg.chat.id, "I reveive video message!");
bot.sendMessage(msg.chat.id, JSON.stringify(msg.video));
});
bot.on("photo", msg => {
bot.sendMessage(msg.chat.id, "I reveive photo message!");
bot.sendMessage(msg.chat.id, JSON.stringify(msg.photo));
});
bot.on("audio", msg => {
bot.sendMessage(msg.chat.id, "I reveive audio message!");
bot.sendMessage(msg.chat.id, JSON.stringify(msg.audio));
});
bot.on("document", msg => {
bot.sendMessage(msg.chat.id, "I reveive document message!");
bot.sendMessage(msg.chat.id, JSON.stringify(msg.document));
});
bot.on("sticker", msg => {
bot.sendMessage(msg.chat.id, "I reveive sticker message!");
bot.sendMessage(msg.chat.id, JSON.stringify(msg.sticker));
});
bot.on("location", msg => {
bot.sendMessage(msg.chat.id, "I reveive location message!");
bot.sendMessage(msg.chat.id, JSON.stringify(msg.location));
});
bot.on("contact", msg => {
bot.sendMessage(msg.chat.id, "I reveive contact message!");
bot.sendMessage(msg.chat.id, JSON.stringify(msg.contact));
});
bot.on("polling_error", (error) => {
console.log(error.code); // => 'EFATAL'
});
return bot;
};

View File

@@ -1,23 +0,0 @@
require("dotenv").config({path: "../.env"});
const hkaliyun = require("./bot/hkaliyun.js");
const airportsub = require("./bot/airportsub.js");
const bots = {
hkaliyun: hkaliyun(process.env.TELEGRAM_TOKEN_HKALIYUN),
airportsub: airportsub(process.env.TELEGRAM_TOKEN_AIRPORTSUB),
};
console.log("bot.js loaded");
for (const bot in bots) {
bots[bot].getMe().then((botInfo) => {
console.log("Bot info:", botInfo);
});
bots[bot].deleteWebHook();
// bot.getWebHookInfo().then((webhookInfo) => {
// console.log('Webhook info:', webhookInfo);
// });
}
module.exports = bots;