forked from juzheng/sdu-course-bot
		
	Compare commits
	
		
			2 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 9567fbb889 | |||
| eb39fb1c04 | 
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -4,3 +4,4 @@ node_modules/* | |||||||
| /pnpm-lock.yaml | /pnpm-lock.yaml | ||||||
| /arr.json | /arr.json | ||||||
| backup | backup | ||||||
|  | resetCookieRequest.txt | ||||||
|   | |||||||
| @@ -5,7 +5,9 @@ | |||||||
|   "main": "index.js", |   "main": "index.js", | ||||||
|   "scripts": { |   "scripts": { | ||||||
|     "test": "ts-node src/test.ts", |     "test": "ts-node src/test.ts", | ||||||
|     "start": "ts-node src/index.ts" |     "start": "ts-node src/index.ts", | ||||||
|  |     "draw": "ts-node src/draw.ts", | ||||||
|  |     "resetCookie": "ts-node src/resetCookieRequest.ts" | ||||||
|   }, |   }, | ||||||
|   "author": "", |   "author": "", | ||||||
|   "license": "ISC", |   "license": "ISC", | ||||||
|   | |||||||
							
								
								
									
										46
									
								
								src/draw.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/draw.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | |||||||
|  | import {countStr, getTimeNow, logAndNotifyUser, resetCookie, sduAxios, sleep} from "./includes" | ||||||
|  | import * as fs from "fs" | ||||||
|  |  | ||||||
|  | export async function draw() { | ||||||
|  |     while (true) { | ||||||
|  |         let html = '' | ||||||
|  |         try { | ||||||
|  |             let resp = await sduAxios.get("jsxsd/xsxkjg/comeXkjglb?isktx=true") | ||||||
|  |             html = JSON.stringify(resp.data) | ||||||
|  |         } catch (e) { | ||||||
|  |             console.log(e) | ||||||
|  |         } | ||||||
|  |         if (countStr(html, 'cqOper') < 2) { | ||||||
|  |             logAndNotifyUser('登录失败,重设cookie ' + getTimeNow()) | ||||||
|  |             try { | ||||||
|  |                 await resetCookie() | ||||||
|  |             } catch (e) { | ||||||
|  |                 console.log(e) | ||||||
|  |             } | ||||||
|  |             continue | ||||||
|  |         } | ||||||
|  |         if (countStr(html, 'cqOper') > 2) { | ||||||
|  |             logAndNotifyUser('可以抽签,正在进行抽签') | ||||||
|  |             fs.writeFileSync('draw-' + Date.now() + '.html', html) | ||||||
|  |             let arr = [ | ||||||
|  |                 '2021202222605',// 英语 | ||||||
|  |                 '2021202225984',// 周易 | ||||||
|  |                 '2021202225817',// 刻瓷 | ||||||
|  |                 '2021202222614',// 众智 | ||||||
|  |                 '2021202222613',// 移动互联网 | ||||||
|  |             ] | ||||||
|  |             for (let id of arr) { | ||||||
|  |                 try { | ||||||
|  |                     let resp = await sduAxios.get('/jsxsd/xsxkjg/xscqOper?jx0404id=' + id + '&cqqk=3')// 3抽的中,2抽不中 | ||||||
|  |                     logAndNotifyUser(JSON.stringify(resp.data)) | ||||||
|  |                 } catch (e) { | ||||||
|  |                     console.log(e) | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         console.log('轮询中:' + getTimeNow()) | ||||||
|  |         await sleep(1000) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | draw() | ||||||
| @@ -43,10 +43,14 @@ export async function logAndNotifyUser(text: string) { | |||||||
|     //         'Content-Type': 'application/x-www-form-urlencoded' |     //         'Content-Type': 'application/x-www-form-urlencoded' | ||||||
|     //     } |     //     } | ||||||
|     // }) |     // }) | ||||||
|     await axios.post('https://' + appConfig.tgApiDomain + '/bot' + appConfig.tgApiKey + '/sendMessage', qs.stringify({ |     try { | ||||||
|         chat_id: appConfig.tgChatId, |         await axios.post('https://' + appConfig.tgApiDomain + '/bot' + appConfig.tgApiKey + '/sendMessage', qs.stringify({ | ||||||
|         text: text |             chat_id: appConfig.tgChatId, | ||||||
|     })) |             text: text | ||||||
|  |         })) | ||||||
|  |     } catch (e) { | ||||||
|  |         console.log(e) | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| export function sleep(ms: number) { | export function sleep(ms: number) { | ||||||
|   | |||||||
| @@ -3,8 +3,10 @@ import {appConfig} from "./config" | |||||||
| import {acquireProcess, monitProcess, replaceProcess} from "./actions" | import {acquireProcess, monitProcess, replaceProcess} from "./actions" | ||||||
| import {resetCookie, sleep} from "./includes" | import {resetCookie, sleep} from "./includes" | ||||||
| import {health} from "./health" | import {health} from "./health" | ||||||
|  | import * as fs from "fs" | ||||||
|  |  | ||||||
| async function start() { | async function start() { | ||||||
|  |     fs.writeFileSync('resetCookieRequest.txt','0') | ||||||
|     console.log('开始获取Cookie') |     console.log('开始获取Cookie') | ||||||
|     await resetCookie() |     await resetCookie() | ||||||
|     console.log('开始启动轮询进程') |     console.log('开始启动轮询进程') | ||||||
|   | |||||||
							
								
								
									
										15
									
								
								src/poll.ts
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/poll.ts
									
									
									
									
									
								
							| @@ -2,6 +2,7 @@ import {IJsonCourse} from "./types" | |||||||
| import {getTimeNow, logAndNotifyUser, resetCookie, sduAxios, sleep} from "./includes" | import {getTimeNow, logAndNotifyUser, resetCookie, sduAxios, sleep} from "./includes" | ||||||
| import {appConfig} from "./config" | import {appConfig} from "./config" | ||||||
| import * as qs from "qs" | import * as qs from "qs" | ||||||
|  | import * as fs from "fs" | ||||||
|  |  | ||||||
| export let reqBody = 'sEcho=1&iColumns=15&sColumns=&iDisplayStart=0&iDisplayLength=2000&mDataProp_0=kch&mDataProp_1=kcmc&mDataProp_2=kxhnew&mDataProp_3=jkfs&mDataProp_4=xmmc&mDataProp_5=fzmc&mDataProp_6=ktmc&mDataProp_7=xf&mDataProp_8=skls&mDataProp_9=sksj&mDataProp_10=skdd&mDataProp_11=xqmc&mDataProp_12=syrs&mDataProp_13=ctsm&mDataProp_14=czOper' | export let reqBody = 'sEcho=1&iColumns=15&sColumns=&iDisplayStart=0&iDisplayLength=2000&mDataProp_0=kch&mDataProp_1=kcmc&mDataProp_2=kxhnew&mDataProp_3=jkfs&mDataProp_4=xmmc&mDataProp_5=fzmc&mDataProp_6=ktmc&mDataProp_7=xf&mDataProp_8=skls&mDataProp_9=sksj&mDataProp_10=skdd&mDataProp_11=xqmc&mDataProp_12=syrs&mDataProp_13=ctsm&mDataProp_14=czOper' | ||||||
| let currentErrorCount = 0 | let currentErrorCount = 0 | ||||||
| @@ -59,6 +60,7 @@ async function updateRx() { | |||||||
| } | } | ||||||
|  |  | ||||||
| export async function poll() { | export async function poll() { | ||||||
|  |     await checkResetCookieRequest() | ||||||
|     if (appConfig.channels.includes('bx')) { |     if (appConfig.channels.includes('bx')) { | ||||||
|         await updateBx() |         await updateBx() | ||||||
|         await sleep(appConfig.interval) |         await sleep(appConfig.interval) | ||||||
| @@ -74,6 +76,19 @@ export async function poll() { | |||||||
|     setImmediate(poll) |     setImmediate(poll) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | async function checkResetCookieRequest() { | ||||||
|  |     let req = parseInt(fs.readFileSync('resetCookieRequest.txt').toString()) | ||||||
|  |     if (req) { | ||||||
|  |         try { | ||||||
|  |             await resetCookie() | ||||||
|  |             logAndNotifyUser('[resetCookie]成功') | ||||||
|  |             fs.writeFileSync('resetCookieRequest.txt', '0') | ||||||
|  |         } catch (e) { | ||||||
|  |             logAndNotifyUser('[resetCookie]失败') | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| async function processError(e: Error) { | async function processError(e: Error) { | ||||||
|     currentErrorCount++ |     currentErrorCount++ | ||||||
|     if (currentErrorCount >= 30) { |     if (currentErrorCount >= 30) { | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								src/resetCookieRequest.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/resetCookieRequest.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | import * as fs from "fs" | ||||||
|  |  | ||||||
|  | fs.writeFileSync('resetCookieRequest.txt','1') | ||||||
|  | console.log('已请求resetCookie') | ||||||
							
								
								
									
										24
									
								
								src/test.ts
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								src/test.ts
									
									
									
									
									
								
							| @@ -1,5 +1,5 @@ | |||||||
| import {appConfig} from "./config" | import {appConfig} from "./config" | ||||||
| import {logAndNotifyUser, sduAxios} from "./includes" | import {countStr, logAndNotifyUser, sduAxios, sleep} from "./includes" | ||||||
| import {reqBody} from "./poll" | import {reqBody} from "./poll" | ||||||
| import * as fs from "fs" | import * as fs from "fs" | ||||||
| import {IJsonCourse} from "./types" | import {IJsonCourse} from "./types" | ||||||
| @@ -29,7 +29,27 @@ async function test() { | |||||||
|     // for (let course of courseList) { |     // for (let course of courseList) { | ||||||
|     //     console.log(course.kcmc + ' ' + course.kch + ' ' + course.kxh + ' ' + course.syrs + ' ' + course.xf) |     //     console.log(course.kcmc + ' ' + course.kch + ' ' + course.kxh + ' ' + course.syrs + ' ' + course.xf) | ||||||
|     // } |     // } | ||||||
|     logAndNotifyUser('log test') |     // let lastData = '' | ||||||
|  |     // let first=true | ||||||
|  |     // let count=0 | ||||||
|  |     // while (true) { | ||||||
|  |     //     let resp = await sduAxios.get("jsxsd/xsxkjg/comeXkjglb?isktx=true", { | ||||||
|  |     //         headers: { | ||||||
|  |     //             'Cookie': 'bzb_jsxsd=329BCA4E7D8E2421309B14C02587784F; bzb_njw=55FFC1D9D9B2EF5A10D3F28BEC294AE1; SERVERID=123' | ||||||
|  |     //         } | ||||||
|  |     //     }) | ||||||
|  |     //     if (resp.data !== lastData && !first) { | ||||||
|  |     //         logAndNotifyUser('可以抽签了') | ||||||
|  |     //         first=false | ||||||
|  |     //         break | ||||||
|  |     //     } | ||||||
|  |     //     lastData = resp.data | ||||||
|  |     //     console.log('rotate '+count) | ||||||
|  |     //     count++ | ||||||
|  |     //     await sleep(1000) | ||||||
|  |     // } | ||||||
|  |     let str=fs.readFileSync('backup/2.html') | ||||||
|  |     console.log(countStr(JSON.stringify(str.toString()),'cqOper')) | ||||||
| } | } | ||||||
|  |  | ||||||
| test() | test() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user