call sqlite-plugin in run-core

This commit is contained in:
geekgeekrun
2024-03-17 16:15:31 +08:00
parent 6649691025
commit ed822d7cc4
6 changed files with 49 additions and 12 deletions
@@ -113,8 +113,6 @@ export async function mainLoop (hooks) {
hooks.pageLoaded?.call()
let userInfoResponse = await userInfoPromise
hooks.userInfoResponse?.call(userInfoResponse)
if (userInfoResponse.code !== 0) {
autoStartChatEventBus.emit('LOGIN_STATUS_INVALID', {
userInfoResponse
@@ -123,6 +121,7 @@ export async function mainLoop (hooks) {
throw new Error("LOGIN_STATUS_INVALID")
} else {
await storeStorage(page).catch(() => void 0)
await hooks.userInfoResponse?.promise(userInfoResponse)
}
// check set security question tip modal
@@ -14,6 +14,11 @@ import {
AUTO_CHAT_ERROR_EXIT_CODE
} from './enums.mjs'
import SqlitePluginModule from '@geekgeekrun/sqlite-plugin'
const {
default: SqlitePlugin
} = SqlitePluginModule
const rerunInterval = (() => {
let v = Number(process.env.MAIN_BOSSGEEKGO_RERUN_INTERVAL)
if (isNaN(v)) {
@@ -32,6 +37,7 @@ const { groupRobotAccessToken: dingTalkAccessToken } = readConfigFile('dingtalk.
const initPlugins = (hooks) => {
new DingtalkPlugin(dingTalkAccessToken).apply(hooks)
new SqlitePlugin().apply(hooks)
}
const main = async () => {
@@ -43,6 +49,7 @@ const main = async () => {
puppeteerLaunched: new SyncHook(),
pageLoaded: new SyncHook(),
cookieWillSet: new SyncHook(['cookies']),
userInfoResponse: new AsyncSeriesHook(['userInfo']),
newChatWillStartup: new AsyncSeriesHook(['positionInfoDetail']),
newChatStartup: new SyncHook(['positionInfoDetail']),
noPositionFoundForCurrentJob: new SyncHook(),
@@ -79,5 +86,7 @@ const main = async () => {
(async () => {
try {
await main()
} catch {}
} catch(err) {
console.error(err)
}
})()
@@ -14,6 +14,7 @@
"dependencies": {
"@geekgeekrun/dingtalk-plugin": "workspace:*",
"@geekgeekrun/geek-auto-start-chat-with-boss": "workspace:*",
"@geekgeekrun/utils": "workspace:*"
"@geekgeekrun/utils": "workspace:*",
"@geekgeekrun/sqlite-plugin": "workspace:*"
}
}
+1
View File
@@ -2,6 +2,7 @@
"name": "@geekgeekrun/sqlite-plugin",
"version": "0.0.1",
"description": "",
"main": "dist/index.js",
"dependencies": {
"reflect-metadata": "^0.2.1",
"sqlite3": "^5.1.7",
+15 -4
View File
@@ -33,7 +33,18 @@ async function initDb() {
return appDataSource.initialize();
}
(async () => {
const a = await initDb();
console.log(a);
})();
export default class SqlitePlugin {
initPromise: Promise<DataSource>
constructor () {
this.initPromise = initDb()
}
apply (hooks) {
hooks.userInfoResponse.tapPromise(
'SqlitePlugin',
(userInfo) => new Promise((resolve, reject) => {
console.log(userInfo)
})
)
}
}