From 63bb4ddb2004e2caae2dcad6a9ffb78f9ea5c077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=8C=E8=8E=9E?= Date: Thu, 18 Nov 2021 13:16:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E4=B8=8D=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20bot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/discord.xml | 2 +- config.example.yaml | 7 ++++++- handlers/handleEasemobMessage.ts | 2 +- index.ts | 5 +---- providers/bot.ts | 24 ++++++++++++++++++------ providers/config.ts | 2 +- utils/pushQMsg.ts | 9 --------- 7 files changed, 28 insertions(+), 23 deletions(-) delete mode 100644 utils/pushQMsg.ts diff --git a/.idea/discord.xml b/.idea/discord.xml index 30bab2a..d8e9561 100644 --- a/.idea/discord.xml +++ b/.idea/discord.xml @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/config.example.yaml b/config.example.yaml index 8baf15f..f2fc160 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -1,7 +1,7 @@ username: '学习通登录名' password: 学习通密码 bot: - uin: qq机器人用户名 + uin: qq机器人用户名,或者`disabled` password: 机器人密码 notifyGroups: - 签到时通知的群组 @@ -11,3 +11,8 @@ bot: - 忽略某个群成员发送的消息,一般指定同一群的其他机器人 ignoreCourses: - course id +geoLocations: + - courseId: 233333 + lat: + lon: + address: 地图显示的地址 diff --git a/handlers/handleEasemobMessage.ts b/handlers/handleEasemobMessage.ts index c48a93b..1fe86c3 100644 --- a/handlers/handleEasemobMessage.ts +++ b/handlers/handleEasemobMessage.ts @@ -3,7 +3,7 @@ import { error, info, success, warn } from '../utils/log' import getCheckinDetail from '../requests/getCheckinDetail' import * as db from '../providers/db' import handlerSimpleCheckin from './handlerSimpleCheckin' -import pushQMsg from '../utils/pushQMsg' +import {pushQMsg} from '../providers/bot' import config from '../providers/config' import handleGeoCheckin from './handleGeoCheckin' diff --git a/index.ts b/index.ts index 21fa604..fce3525 100644 --- a/index.ts +++ b/index.ts @@ -1,10 +1,9 @@ import validateCookie from './requests/validateCookie' import {info, success, warn} from './utils/log' import * as db from './providers/db' -import {bot, loginBot} from './providers/bot' +import {loginBot} from './providers/bot' import loginAndSaveInfo from './utils/loginAndSaveInfo' import axios from 'axios' -import attachGroupMessageHandler from './handlers/attachGroupMessageHandler' import {imConnect} from './providers/easemob' (async () => { @@ -27,8 +26,6 @@ import {imConnect} from './providers/easemob' const schoolname = await db.getMeta('schoolname') const name = await db.getMeta('name') success(`欢迎来自 ${schoolname} 的 ${name}`) - //机器人接收二维码和解码签到事件 - attachGroupMessageHandler(bot) //连接 IM info('准备连接 IM') await imConnect() diff --git a/providers/bot.ts b/providers/bot.ts index 106d26b..6eb4571 100644 --- a/providers/bot.ts +++ b/providers/bot.ts @@ -1,12 +1,24 @@ -import {createClient} from 'oicq' +import {Client, createClient, Sendable} from 'oicq' import config from './config' +import attachGroupMessageHandler from '../handlers/attachGroupMessageHandler' -export const bot = createClient(config.bot.uin, { +let bot: Client + +export const loginBot = () => new Promise(resolve => { + if (config.bot.uin === 'disabled') return resolve(0) + bot = createClient(config.bot.uin, { brief: true, log_level: 'warn', + }) + bot.once('system.online', resolve) + bot.login(config.bot.password) + //机器人接收二维码和解码签到事件 + attachGroupMessageHandler(bot) }) -export const loginBot = () => new Promise(resolve => { - bot.once('system.online', resolve) - bot.login(config.bot.password) -}) +export const pushQMsg = async (message: Sendable) => { + if (config.bot.uin === 'disabled') return + for (const group of config.bot.notifyGroups) { + await bot.sendGroupMsg(group, message) + } +} diff --git a/providers/config.ts b/providers/config.ts index bbc223e..b5ad051 100644 --- a/providers/config.ts +++ b/providers/config.ts @@ -5,7 +5,7 @@ interface Config { username: string; password: string; bot: { - uin: number; + uin: number | 'disabled'; password: string; notifyGroups: number[]; qrcodeGroups: number[]; diff --git a/utils/pushQMsg.ts b/utils/pushQMsg.ts deleted file mode 100644 index eb8ed0e..0000000 --- a/utils/pushQMsg.ts +++ /dev/null @@ -1,9 +0,0 @@ -import {Sendable} from 'oicq' -import {bot} from '../providers/bot' -import config from '../providers/config' - -export default async (message: Sendable) => { - for (const group of config.bot.notifyGroups) { - await bot.sendGroupMsg(group, message) - } -}