Skip to content

Commit

Permalink
可以不使用 bot
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Nov 18, 2021
1 parent b7b7475 commit 63bb4dd
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion config.example.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
username: '学习通登录名'
password: 学习通密码
bot:
uin: qq机器人用户名
uin: qq机器人用户名,或者`disabled`
password: 机器人密码
notifyGroups:
- 签到时通知的群组
Expand All @@ -11,3 +11,8 @@ bot:
- 忽略某个群成员发送的消息,一般指定同一群的其他机器人
ignoreCourses:
- course id
geoLocations:
- courseId: 233333
lat:
lon:
address: 地图显示的地址
2 changes: 1 addition & 1 deletion handlers/handleEasemobMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
5 changes: 1 addition & 4 deletions index.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -27,8 +26,6 @@ import {imConnect} from './providers/easemob'
const schoolname = await db.getMeta<string>('schoolname')
const name = await db.getMeta<string>('name')
success(`欢迎来自 ${schoolname}${name}`)
//机器人接收二维码和解码签到事件
attachGroupMessageHandler(bot)
//连接 IM
info('准备连接 IM')
await imConnect()
Expand Down
24 changes: 18 additions & 6 deletions providers/bot.ts
Original file line number Diff line number Diff line change
@@ -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<any>(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)
}
}
2 changes: 1 addition & 1 deletion providers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface Config {
username: string;
password: string;
bot: {
uin: number;
uin: number | 'disabled';
password: string;
notifyGroups: number[];
qrcodeGroups: number[];
Expand Down
9 changes: 0 additions & 9 deletions utils/pushQMsg.ts

This file was deleted.

0 comments on commit 63bb4dd

Please sign in to comment.