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

Commit

Permalink
refa: migrate to node-gocqhttp
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Sep 8, 2022
1 parent 5a49c5b commit 689cbdc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 109 deletions.
21 changes: 0 additions & 21 deletions install.js

This file was deleted.

26 changes: 11 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-plugin-gocqhttp",
"description": "go-cqhttp launcher for Koishi",
"version": "3.0.7",
"version": "3.1.0",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand All @@ -13,8 +13,7 @@
"scripts": {
"build:server": "tsc -b",
"build:client": "koishi-console build",
"build": "yarn build:server && yarn build:client",
"postinstall": "node install"
"build": "yarn build:server && yarn build:client"
},
"author": "Shigma <[email protected]>",
"packageManager": "[email protected]",
Expand Down Expand Up @@ -46,23 +45,20 @@
}
},
"peerDependencies": {
"@koishijs/plugin-adapter-onebot": "^5.0.9",
"koishi": "^4.8.5"
"@koishijs/plugin-adapter-onebot": "^5.1.0",
"koishi": "^4.9.0"
},
"devDependencies": {
"@koishijs/client": "^4.3.10",
"@koishijs/plugin-adapter-onebot": "^5.0.9",
"@koishijs/plugin-console": "^4.3.10",
"@koishijs/plugin-market": "^1.2.4",
"@octokit/openapi-types": "^11.2.0",
"@koishijs/client": "^4.5.1",
"@koishijs/plugin-adapter-onebot": "^5.1.0",
"@koishijs/plugin-console": "^4.5.1",
"@koishijs/plugin-market": "^1.3.1",
"@types/node": "^18.6.4",
"@types/tar": "^6.1.1",
"koishi": "^4.8.5",
"koishi": "^4.9.0",
"typescript": "^4.7.4"
},
"dependencies": {
"axios": "^0.26.1",
"strip-ansi": "^6.0.1",
"tar": "^6.1.11"
"go-cqhttp": "^1.1.3",
"strip-ansi": "^6.0.1"
}
}
13 changes: 6 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { Context, Dict, interpolate, Logger, Schema } from 'koishi'
import OneBotBot from '@koishijs/plugin-adapter-onebot'
import { DataService } from '@koishijs/plugin-console'
import {} from '@koishijs/plugin-market'
import { ChildProcess, spawn } from 'child_process'
import { ChildProcess } from 'child_process'
import { resolve } from 'path'
import { createReadStream, promises as fsp } from 'fs'
import gocqhttp from 'go-cqhttp'
import strip from 'strip-ansi'

const { mkdir, copyFile, readFile, writeFile } = fsp
const { mkdir, readFile, writeFile } = fsp

declare module '@koishijs/plugin-console' {
namespace Console {
Expand Down Expand Up @@ -138,9 +139,7 @@ class Launcher extends DataService<Dict<Data>> {
async connect(bot: OneBotBot<Context>) {
// create working folder
const cwd = resolve(bot.ctx.baseDir, this.config.root, bot.selfId)
const file = '/go-cqhttp' + (process.platform === 'win32' ? '.exe' : '')
await mkdir(cwd, { recursive: true })
await copyFile(resolve(__dirname, '../bin/go-cqhttp'), cwd + file)

// create config.yml
await writeFile(cwd + '/config.yml', await this.getConfig(bot))
Expand All @@ -149,7 +148,7 @@ class Launcher extends DataService<Dict<Data>> {
this.setData(bot, { status: 'init' })

// spawn go-cqhttp process
bot.process = spawn('.' + file, ['-faststart'], { cwd })
bot.process = gocqhttp({ cwd, faststart: true })

bot.process.stdout.on('data', async (data: string) => {
data = strip(data.toString()).trim()
Expand Down Expand Up @@ -182,13 +181,13 @@ class Launcher extends DataService<Dict<Data>> {
this.payload[bot.sid].phone = phone
}
} else if (text.includes('captcha.jpg')) {
const buffer = await fsp.readFile(cwd + '/captcha.png')
const buffer = await readFile(cwd + '/captcha.png')
this.setData(bot, {
status: 'captcha',
image: 'data:image/png;base64,' + buffer.toString('base64'),
})
} else if (text.includes('qrcode.png')) {
const buffer = await fsp.readFile(cwd + '/qrcode.png')
const buffer = await readFile(cwd + '/qrcode.png')
this.setData(bot, {
status: 'qrcode',
image: 'data:image/png;base64,' + buffer.toString('base64'),
Expand Down
66 changes: 0 additions & 66 deletions src/install.ts

This file was deleted.

0 comments on commit 689cbdc

Please sign in to comment.