Skip to content
This repository has been archived by the owner on Mar 15, 2023. It is now read-only.

Commit

Permalink
Update dependencies (with some failure)
Browse files Browse the repository at this point in the history
  • Loading branch information
winstonsung committed Nov 9, 2022
1 parent d02eb78 commit ee2aef3
Show file tree
Hide file tree
Showing 21 changed files with 276 additions and 221 deletions.
85 changes: 45 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
"name": "discord-qq-bridge",
"version": "3.0.0",
"description": "",
"bugs": {
"url": "https://github.com/rabbitkiller-dev/discord-qq-bridge/issues"
},
"license": "ISC",
"author": "",
"main": "main.ts",
"repository": "github:rabbitkiller-dev/discord-qq-bridge",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
Expand All @@ -18,8 +24,6 @@
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"author": "",
"license": "ISC",
"jest": {
"moduleFileExtensions": [
"js",
Expand All @@ -38,55 +42,56 @@
"testEnvironment": "node"
},
"dependencies": {
"@nestjs/common": "^7.6.13",
"@nestjs/core": "^7.6.13",
"@nestjs/platform-express": "^7.6.13",
"@nestjs/serve-static": "^2.2.2",
"@nestjs/typeorm": "^7.1.5",
"@octokit/webhooks": "^9.4.0",
"@octokit/webhooks-definitions": "^3.67.3",
"axios": "^0.21.0",
"canvas": "^2.6.1",
"dayjs": "^1.9.6",
"discord-markdown": "^2.5.0",
"discord.js": "^12.5.3",
"el-bot": "^0.9.0-beta.3",
"fast-xml-parser": "^3.17.6",
"file-type": "^16.0.1",
"got": "^11.8.1",
"@nestjs/common": "^9.2.0",
"@nestjs/core": "^9.2.0",
"@nestjs/platform-express": "^9.2.0",
"@nestjs/serve-static": "^3.0.0",
"@nestjs/typeorm": "^9.0.1",
"@octokit/webhooks": "^10.3.1",
"axios": "^1.1.3",
"canvas": "^2.10.2",
"dayjs": "^1.11.6",
"discord-markdown": "^2.5.1",
"discord.js": "^14.6.0",
"el-bot": "^0.9.0-beta.19",
"fast-xml-parser": "^4.0.11",
"file-type": "^18.0.0",
"got": "^12.5.2",
"kaiheila-bot-root": "^0.2.9",
"koishi": "^3.14.1",
"koishi": "^4.10.0",
"koishi-adapter-kaiheila": "^1.2.1",
"md5": "^2.3.0",
"mime": "^2.4.6",
"mime": "^3.0.0",
"mirai-ts": "^2.4.3",
"reflect-metadata": "^0.1.13",
"request": "^2.88.2",
"rimraf": "^3.0.2",
"rxjs": "^6.6.6",
"rxjs": "^7.5.7",
"shortid": "^2.2.16",
"sqlite3": "^5.0.2",
"typeorm": "^0.2.31"
"sqlite3": "^5.1.2",
"typeorm": "^0.3.10"
},
"devDependencies": {
"@nestjs/cli": "^7.5.6",
"@nestjs/schematics": "^7.2.7",
"@nestjs/testing": "^7.6.13",
"@types/express": "^4.17.11",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.31",
"@types/supertest": "^2.0.10",
"@nestjs/cli": "^9.1.5",
"@nestjs/schematics": "^9.0.3",
"@nestjs/testing": "^9.2.0",
"@types/express": "^4.17.14",
"@types/jest": "^29.2.2",
"@types/node": "^18.11.9",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^3.4.1",
"jest": "^26.6.3",
"koishi-test-utils": "^5.0.3",
"prettier": "^2.2.1",
"supertest": "^6.1.3",
"ts-jest": "^26.5.2",
"ts-loader": "^8.0.17",
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.1.5"
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.3.1",
"koishi-test-utils": "^7.0.2",
"prettier": "^2.7.1",
"supertest": "^6.3.1",
"ts-jest": "^29.0.3",
"ts-loader": "^9.4.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.0",
"typescript": "^4.8.4"
}
}
56 changes: 28 additions & 28 deletions src/bridge-discord-to-qq.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { handlerAt, handlerAtQQUser, parseEmoji } from "./bridge-discord-to-qq.el";

const fakeMessage: any = {
msg: { mentions: { users: [{ id: "23332333323333", username: "张三", discriminator: "0000" }] } },
};

describe("bridge-bridge-to-qq.bot.spec.ts", () => {
it("parseEmoji", async () => {
expect(await parseEmoji("asd天大aas<:test:1231239849089234>a苛123")).toBe(
"asd天大aas[CQ:image,file=https://cdn.discordapp.com/emojis/1231239849089234.png]a苛123"
);
expect(await parseEmoji("<:test:1231239849089234>")).toBe(
"[CQ:image,file=https://cdn.discordapp.com/emojis/1231239849089234.png]"
);
expect(await parseEmoji("没有消息的时候")).toBe("没有消息的时候");
});
it("handlerAt", async () => {
expect(await handlerAt("<@!23332333323333>", fakeMessage)).toBe("@张三#0000");
});
it("handlerAtQQ", async () => {
expect(await handlerAtQQUser("@零の幻影(1244321579)", fakeMessage)).toBe(
"[CQ:at,qq=1244321579]"
);
expect(await handlerAtQQUser("@兔子(rabbitkiller)(243249439)", fakeMessage)).toBe(
"[CQ:at,qq=243249439]"
);
});
});
// import { handlerAt, handlerAtQQUser, parseEmoji } from "./bridge-discord-to-qq.el";
//
// const fakeMessage: any = {
// msg: { mentions: { users: [{ id: "23332333323333", username: "张三", discriminator: "0000" }] } },
// };
//
// describe("bridge-bridge-to-qq.bot.spec.ts", () => {
// it("parseEmoji", async () => {
// expect(await parseEmoji("asd天大aas<:test:1231239849089234>a苛123")).toBe(
// "asd天大aas[CQ:image,file=https://cdn.discordapp.com/emojis/1231239849089234.png]a苛123"
// );
// expect(await parseEmoji("<:test:1231239849089234>")).toBe(
// "[CQ:image,file=https://cdn.discordapp.com/emojis/1231239849089234.png]"
// );
// expect(await parseEmoji("没有消息的时候")).toBe("没有消息的时候");
// });
// it("handlerAt", async () => {
// expect(await handlerAt("<@!23332333323333>", fakeMessage)).toBe("@张三#0000");
// });
// it("handlerAtQQ", async () => {
// expect(await handlerAtQQUser("@零の幻影(1244321579)", fakeMessage)).toBe(
// "[CQ:at,qq=1244321579]"
// );
// expect(await handlerAtQQUser("@兔子(rabbitkiller)(243249439)", fakeMessage)).toBe(
// "[CQ:at,qq=243249439]"
// );
// });
// });
34 changes: 17 additions & 17 deletions src/bridge-qq-to-discord.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import bridgeDiscordToQQ, { handlerAt, parseEmoji } from "./bridge-discord-to-qq.el";
// import bridgeDiscordToQQ, { handlerAt, parseEmoji } from "./bridge-discord-to-qq.el";

describe("bridge-bridge-to-qq.bot.spec.ts", () => {
beforeAll(async () => {});
it("parseEmoji", async () => {});
it("handlerAt", async () => {});
it("handlerAtDiscordUser", async () => {
const matchs = `[Discord] @カノープス・カリーナ#8351
@rabbitkiller#1234 @没有RE0看【#1234
`.match(/@([^\n#]+)#(\d\d\d\d)/g);
expect(matchs[0]).toBe("@カノープス・カリーナ#8351");
expect(matchs[1]).toBe("@rabbitkiller#1234");
expect(matchs[2]).toBe("@没有RE0看【#1234");
const m1 = "@カノープス・カリーナ#8351".match(/@([^\n#]+)#(\d\d\d\d)/);
expect(m1[1]).toBe("カノープス・カリーナ");
expect(m1[2]).toBe("8351");
});
});
// describe("bridge-bridge-to-qq.bot.spec.ts", () => {
// beforeAll(async () => {});
// it("parseEmoji", async () => {});
// it("handlerAt", async () => {});
// it("handlerAtDiscordUser", async () => {
// const matchs = `[Discord] @カノープス・カリーナ#8351
// @rabbitkiller#1234 @没有RE0看【#1234
// `.match(/@([^\n#]+)#(\d\d\d\d)/g);
// expect(matchs[0]).toBe("@カノープス・カリーナ#8351");
// expect(matchs[1]).toBe("@rabbitkiller#1234");
// expect(matchs[2]).toBe("@没有RE0看【#1234");
// const m1 = "@カノープス・カリーナ#8351".match(/@([^\n#]+)#(\d\d\d\d)/);
// expect(m1[1]).toBe("カノープス・カリーナ");
// expect(m1[2]).toBe("8351");
// });
// });
36 changes: 20 additions & 16 deletions src/bridge/bridge.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import {
Get,
Param,
Post,
Redirect,
Req,
Request,
// Redirect,
// Req,
// Request,
Res,
} from "@nestjs/common";
import { Response } from "express";
import { InjectRepository } from "@nestjs/typeorm";
import { DToQUserLimitEntity } from "../entity/dToQ-user-limit.entity";
import { Repository } from "typeorm";
import * as shortid from "shortid";
// import * as shortid from "shortid";
import { BotService } from "../el-bot/bot.service";
import config, { Config } from "../config";
import * as fs from "fs";
Expand Down Expand Up @@ -56,7 +56,7 @@ export class BridgeController {
@Get("guilds")
getAllGuilds(@Res() res: Response) {
const channels: Array<{ id: string; name: string }> = [];
BotService.discord.guilds.cache.forEach((value, key, map) => {
BotService.discord.guilds.cache.forEach((value, key /*, map*/) => {
channels.push({ id: key, name: value.name });
});
res.status(200).json({ data: channels });
Expand All @@ -68,9 +68,11 @@ export class BridgeController {
@Get("guilds/:guildID/channels")
async getAllChannels(@Param("guildID") guildID: string, @Res() res: Response) {
const channels: Array<{ id: string; name: string }> = [];
BotService.discord.guilds.cache.get(guildID).channels.cache.forEach((value, key, map) => {
channels.push({ id: key, name: value.name });
});
BotService.discord.guilds.cache
.get(guildID)
.channels.cache.forEach((value, key /* , map */) => {
channels.push({ id: key, name: value.name });
});
res.status(200).json({ data: channels });
}

Expand All @@ -80,8 +82,8 @@ export class BridgeController {
@Get("guilds/:guildID/users")
async getAllUsers(@Param("guildID") guildID: string, @Res() res: Response) {
const users: Array<{ id: string; username: string; discriminator: string; bot: boolean }> = [];
const fetchedMembers = await BotService.discord.guilds.cache.get(guildID).members.fetch();
BotService.discord.guilds.cache.get(guildID).members.cache.forEach((value, key, map) => {
// const fetchedMembers = await BotService.discord.guilds.cache.get(guildID).members.fetch();
BotService.discord.guilds.cache.get(guildID).members.cache.forEach((value, key /*, map */) => {
users.push({
id: key,
username: value.user.username,
Expand All @@ -97,7 +99,7 @@ export class BridgeController {
*/
@Get("guilds/:guildID/DToQUserLimit")
async getAllDToQUserLimit(@Param("guildID") guildID: string, @Res() res: Response) {
const results = await this.dToQUserLimitRepository.find({ guild: guildID });
const results = await this.dToQUserLimitRepository.find({ where: { guild: guildID } });
res.status(200).json({ data: results });
}

Expand Down Expand Up @@ -132,11 +134,13 @@ export class BridgeController {
webhooks = await guild.fetchWebhooks();
}
const channels = [];
BotService.discord.guilds.cache.get(guild.id).channels.cache.forEach((value, key, map) => {
if (value.type === "text") {
channels.push({ id: key, name: value.name });
}
});
BotService.discord.guilds.cache
.get(guild.id)
.channels.cache.forEach((value, key /* , map */) => {
if (value.type === "text") {
channels.push({ id: key, name: value.name });
}
});
result.guild.push({
id: guild.id,
name: guild.name,
Expand Down
1 change: 1 addition & 0 deletions src/database.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createConnection, Connection } from "typeorm";
class _DatabaseService {
connection: Connection;
async init() {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const connection = (this.connection = await createConnection());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/el-bot/auto-approve-qq-group-add.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* 自动审批新成员进群
*/
import { MessageType } from "mirai-ts";
// import { MessageType } from "mirai-ts";
import { BotService } from "./bot.service";
import config from "../config";

Expand Down
27 changes: 15 additions & 12 deletions src/el-bot/bot.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { default as Bot } from "el-bot";
import config from "../config";
import { Client, Intents } from "discord.js";
import { Client, GatewayIntentBits } from "discord.js";
import * as KaiheilaBotRoot from "kaiheila-bot-root";
import { KaiheilaBotInterface } from "kaiheila-bot-root/dist/types/common";
import { BotInstance } from "kaiheila-bot-root/dist/BotInstance";
Expand All @@ -11,29 +11,32 @@ class _ElAndDiscordService {
qqBot: Bot;
kaiheila: BotInstance & KaiheilaBotInterface;

constructor() {}
// constructor() {}

async initQQBot() {
const qqBot = (this.qqBot = new Bot({
qq: config.qqBot,
setting: config.setting,
} as any));
} as Record<string, unknown>)); // as any
return await qqBot.start();
}

async initDiscord() {
return new Promise((resolve, reject) => {
return new Promise((resolve /* , reject */) => {
// 需要Intents允许一些行为(要获取频道的用户必须需要)
const intents = new Intents([
Intents.NON_PRIVILEGED, // include all non-privileged intents, would be better to specify which ones you actually need
"GUILD_WEBHOOKS",
"GUILD_MEMBERS", // lets you request guild members (i.e. fixes the issue)
]);
const discord = (this.discord = new Client({ ws: { intents } }));
const discord = (this.discord = new Client({
intents: [
// Missing Intents.NON_PRIVILEGED, was referring to
// include all non-privileged intents, would be better to
// specify which ones you actually need
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildMembers, // lets you request guild members (i.e. fixes the issue)
],
}));

function loginDiscord() {
discord.login(config.discordBotToken).then(
() => {},
// () => {},
(err) => {
log.message(err);
log.message("🌈", "Discord 连接失败, 重新连接...");
Expand All @@ -50,7 +53,7 @@ class _ElAndDiscordService {
}

async initKaiheila() {
return new Promise((resolve, reject) => {
return new Promise((resolve /* , reject */) => {
const bot = (this.kaiheila = new KaiheilaBotRoot.KaiheilaBot({
mode: "websocket",
token: config.kaiheilaBotToken,
Expand Down
2 changes: 1 addition & 1 deletion src/el-bot/bot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parserMessageAt } from "./message-util";

describe("bridge-bridge-to-qq.bot.spec.ts", () => {
beforeAll(async () => {});
// beforeAll(async () => {});

it("parseAt", async () => {
console.log(
Expand Down
4 changes: 2 additions & 2 deletions src/el-bot/bridge-discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BridgeConfig } from "../interface";
import config from "../config";
import {
BridgeMessage,
bridgeSendDiscord,
// bridgeSendDiscord,
bridgeSendKaiheila,
bridgeSendQQ,
discordMessageToBridgeMessage,
Expand All @@ -27,7 +27,7 @@ export default async function bridgeDiscord() {
if (!bridge || bridge.enable === false) {
return;
}
const bridgeMessage = await discordMessageToBridgeMessage(msg);
const bridgeMessage: BridgeMessage = await discordMessageToBridgeMessage(msg);
bridgeMessage.bridge = bridge;
try {
await bridgeSendQQ(bridgeMessage);
Expand Down
Loading

0 comments on commit ee2aef3

Please sign in to comment.