From fbec3d84fd59a8be2dc4a3f43c5ee241a22dad2f Mon Sep 17 00:00:00 2001 From: yeyang <746659424@qq.com> Date: Wed, 22 Mar 2023 13:13:20 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E9=80=82=E9=85=8D`segment`?= =?UTF-8?q?=E4=BD=9C=E4=B8=BA=E5=85=A8=E5=B1=80=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.cjs | 3 ++- apps/assistant.js | 1 - apps/fun.js | 1 - apps/groupAdmin.js | 1 - apps/groupVerify.js | 1 - apps/handle.js | 1 - apps/nga.js | 1 - apps/notice_friend.js | 1 - apps/notice_group.js | 1 - apps/notice_message.js | 1 - apps/notice_request.js | 1 - index.js | 8 ++++++++ lib/puppeteer/puppeteer.js | 1 - lib/request/request.js | 1 - model/GroupAdmin.js | 1 - model/PicSearch/ascii2d.js | 1 - model/PicSearch/whatanime.js | 1 - model/Pixiv.js | 1 - model/api/QQApi.js | 7 ++++++- model/api/funApi.js | 1 - tools/uploadRecord.js | 11 +++++++++-- 21 files changed, 25 insertions(+), 21 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index c8ecfd5..71c19cb 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -12,7 +12,8 @@ module.exports = { Bot: true, redis: true, logger: true, - plugin: true + plugin: true, + segment: true }, rules: { 'eqeqeq': ['off'], diff --git a/apps/assistant.js b/apps/assistant.js index 9c81527..dc889c5 100644 --- a/apps/assistant.js +++ b/apps/assistant.js @@ -1,5 +1,4 @@ import plugin from '../../../lib/plugins/plugin.js' -import { segment } from 'oicq' import { common, QQApi } from '../model/index.js' import _ from 'lodash' import moment from 'moment' diff --git a/apps/fun.js b/apps/fun.js index 5e02378..877c3f6 100644 --- a/apps/fun.js +++ b/apps/fun.js @@ -1,6 +1,5 @@ import plugin from '../../../lib/plugins/plugin.js' import fetch from 'node-fetch' -import { segment } from 'oicq' import _ from 'lodash' import { Config } from '../components/index.js' import { common, uploadRecord, QQApi, funApi } from '../model/index.js' diff --git a/apps/groupAdmin.js b/apps/groupAdmin.js index 81a0976..eec73ab 100644 --- a/apps/groupAdmin.js +++ b/apps/groupAdmin.js @@ -1,6 +1,5 @@ import _ from 'lodash' import moment from 'moment' -import { segment } from 'oicq' import plugin from '../../../lib/plugins/plugin.js' import { Config } from '../components/index.js' import { common, GroupAdmin as ga, puppeteer, QQApi } from '../model/index.js' diff --git a/apps/groupVerify.js b/apps/groupVerify.js index 9055338..f5a38d6 100644 --- a/apps/groupVerify.js +++ b/apps/groupVerify.js @@ -1,5 +1,4 @@ import plugin from '../../../lib/plugins/plugin.js' -import { segment } from 'oicq' import { Config } from '../components/index.js' import { common, GroupAdmin as ga } from '../model/index.js' import _ from 'lodash' diff --git a/apps/handle.js b/apps/handle.js index 945725a..3888d98 100644 --- a/apps/handle.js +++ b/apps/handle.js @@ -1,6 +1,5 @@ import plugin from '../../../lib/plugins/plugin.js' import _ from 'lodash' -import { segment } from 'oicq' import { common } from '../model/index.js' import moment from 'moment' const ROLE_MAP = { diff --git a/apps/nga.js b/apps/nga.js index e71283d..2c132c7 100644 --- a/apps/nga.js +++ b/apps/nga.js @@ -1,6 +1,5 @@ import plugin from '../../../lib/plugins/plugin.js' import gsCfg from '../../genshin/model/gsCfg.js' -import { segment } from 'oicq' import fs from 'node:fs' import common from '../../../lib/common/common.js' import { Data, Plugin_Path } from '../components/index.js' diff --git a/apps/notice_friend.js b/apps/notice_friend.js index 169f0d7..878a7e6 100644 --- a/apps/notice_friend.js +++ b/apps/notice_friend.js @@ -1,5 +1,4 @@ import plugin from '../../../lib/plugins/plugin.js' -import { segment } from 'oicq' import { common } from '../model/index.js' import { Config } from '../components/index.js' diff --git a/apps/notice_group.js b/apps/notice_group.js index 85bc9b1..3ccf78a 100644 --- a/apps/notice_group.js +++ b/apps/notice_group.js @@ -1,5 +1,4 @@ import plugin from '../../../lib/plugins/plugin.js' -import { segment } from 'oicq' import { common } from '../model/index.js' import { Config } from '../components/index.js' import moment from 'moment' diff --git a/apps/notice_message.js b/apps/notice_message.js index 97cbf6f..fdd71a4 100644 --- a/apps/notice_message.js +++ b/apps/notice_message.js @@ -1,5 +1,4 @@ import plugin from '../../../lib/plugins/plugin.js' -import { segment } from 'oicq' import { common } from '../model/index.js' import { Config } from '../components/index.js' diff --git a/apps/notice_request.js b/apps/notice_request.js index 3384bf2..5945a8d 100644 --- a/apps/notice_request.js +++ b/apps/notice_request.js @@ -1,5 +1,4 @@ import plugin from '../../../lib/plugins/plugin.js' -import { segment } from 'oicq' import cfg from '../../../lib/config/config.js' import { common } from '../model/index.js' import { Config } from '../components/index.js' diff --git a/index.js b/index.js index e378178..8e73162 100644 --- a/index.js +++ b/index.js @@ -13,6 +13,14 @@ files.forEach((file) => { ret.push(import(`./apps/${file}`)) }) +if (!global.segment) { + try { + global.segment = (await import('oicq')).segment + } catch (err) { + global.segment = (await import('icqq')).segment + } +} + ret = await Promise.allSettled(ret) let apps = {} diff --git a/lib/puppeteer/puppeteer.js b/lib/puppeteer/puppeteer.js index 3a0af83..c0ec457 100644 --- a/lib/puppeteer/puppeteer.js +++ b/lib/puppeteer/puppeteer.js @@ -1,4 +1,3 @@ -import { segment } from 'oicq' import fs from 'fs' import _ from 'lodash' import puppeteer from 'puppeteer' diff --git a/lib/request/request.js b/lib/request/request.js index 1e84239..661d1ee 100644 --- a/lib/request/request.js +++ b/lib/request/request.js @@ -1,5 +1,4 @@ import fetch from 'node-fetch' -import { segment } from 'oicq' import { Config } from '../../components/index.js' import { Agent } from 'https' import { HttpsProxyAgent } from './httpsProxyAgentMod.js' diff --git a/model/GroupAdmin.js b/model/GroupAdmin.js index d8d9c37..201c092 100644 --- a/model/GroupAdmin.js +++ b/model/GroupAdmin.js @@ -1,6 +1,5 @@ import _ from 'lodash' import moment from 'moment' -import { segment } from 'oicq' import loader from '../../../lib/plugins/loader.js' import { Config } from '../components/index.js' import { common, QQApi } from './index.js' diff --git a/model/PicSearch/ascii2d.js b/model/PicSearch/ascii2d.js index 3f28b15..e61ea84 100644 --- a/model/PicSearch/ascii2d.js +++ b/model/PicSearch/ascii2d.js @@ -1,6 +1,5 @@ /* eslint-disable no-unused-vars */ import _ from 'lodash' -import { segment } from 'oicq' import { puppeteer } from '../index.js' import request from '../../lib/request/request.js' import { Config } from '../../components/index.js' diff --git a/model/PicSearch/whatanime.js b/model/PicSearch/whatanime.js index 84a5e57..a12af41 100644 --- a/model/PicSearch/whatanime.js +++ b/model/PicSearch/whatanime.js @@ -1,6 +1,5 @@ import request from '../../lib/request/request.js' import { Config, Plugin_Path } from '../../components/index.js' -import { segment } from 'oicq' import common from '../../../../lib/common/common.js' import _ from 'lodash' export default async function doSearch (imgURL) { diff --git a/model/Pixiv.js b/model/Pixiv.js index 5e93586..6beb68d 100644 --- a/model/Pixiv.js +++ b/model/Pixiv.js @@ -1,7 +1,6 @@ import _ from 'lodash' import moment from 'moment' import fetch from 'node-fetch' -import { segment } from 'oicq' import { Config } from '../components/index.js' import request from '../lib/request/request.js' import { rankType } from '../tools/pixiv.js' diff --git a/model/api/QQApi.js b/model/api/QQApi.js index e8049d7..ffbb93b 100644 --- a/model/api/QQApi.js +++ b/model/api/QQApi.js @@ -2,7 +2,6 @@ import fetch from 'node-fetch' import { common } from '../index.js' import _ from 'lodash' import moment from 'moment' -import { core } from 'oicq' import request from '../../lib/request/request.js' /** 获取gtk */ const gtk = function (t) { @@ -426,6 +425,12 @@ export default new class { * @return {Object} */ async thumbUp (uid, times = 1) { + let core = null + try { + core = (await import('oicq')).core + } catch (err) { + core = (await import('icqq')).core + } if (times > 20) { times = 20 } let ReqFavorite if (Bot.fl.get(uid)) { diff --git a/model/api/funApi.js b/model/api/funApi.js index 2e193c8..0acd862 100644 --- a/model/api/funApi.js +++ b/model/api/funApi.js @@ -2,7 +2,6 @@ import fetch from 'node-fetch' import md5 from 'md5' import _ from 'lodash' import request from '../../lib/request/request.js' -import { segment } from 'oicq' const API_ERROR = '出了点小问题,待会再试试吧' export default new class { diff --git a/tools/uploadRecord.js b/tools/uploadRecord.js index b833b44..27666c9 100644 --- a/tools/uploadRecord.js +++ b/tools/uploadRecord.js @@ -1,5 +1,4 @@ /* eslint-disable no-void */ -import Contactable, { core } from 'oicq' import querystring from 'querystring' import fetch from 'node-fetch' import fs from 'fs' @@ -8,7 +7,15 @@ import os from 'os' import crypto from 'crypto' import child_process from 'child_process' let errors = {} - +let core = null +let Contactable = null +try { + Contactable = (await import('oicq')).default + core = (await import('oicq')).core +} catch (err) { + Contactable = (await import('icqq')).default + core = (await import('icqq')).core +} async function uploadRecord (record_url, seconds = 0, transcoding = true) { const result = await getPttBuffer(record_url, Bot.config.ffmpeg_path, transcoding) if (!result.buffer) {