-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
监听模式支持多位置尝试签到(暂不支持从Web启用监听的情况);手动签到添加位置列表;
- Loading branch information
Showing
4 changed files
with
274 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { red } from 'kolorist'; | ||
import prompts from 'prompts'; | ||
|
||
export const PromptsOptions = { | ||
onCancel: () => { | ||
console.log(red('✖') + ' 操作取消'); | ||
process.exit(0); | ||
}, | ||
}; | ||
|
||
// 最多保存10个位置,签到失败则轮流尝试 | ||
export const addressPrompts = async () => { | ||
const presetAddress = []; | ||
for (let i = 0; i < 10; i++) { | ||
let { lon_lat_address } = await prompts({ | ||
type: 'text', | ||
name: 'lon_lat_address', | ||
message: `位置参数预设#${i + 1}(经纬度/地址)`, | ||
initial: '113.516288,34.817038/河南省郑州市万科城大学软件楼', | ||
}, PromptsOptions); | ||
lon_lat_address = lon_lat_address.match(/([\d.]*),([\d.]*)\/(\S*)/); | ||
console.log(`#${i + 1} 经度: ${lon_lat_address?.[1]} 纬度: ${lon_lat_address?.[2]} 地址: ${lon_lat_address?.[3]}`); | ||
presetAddress.push({ | ||
lon: lon_lat_address?.[1], | ||
lat: lon_lat_address?.[2], | ||
address: lon_lat_address?.[3] | ||
}); | ||
// 到10个就不再询问继续 | ||
if (i < 9) { | ||
const { next } = await prompts({ | ||
type: () => i === 9 ? null : 'confirm', | ||
name: 'next', | ||
message: '是否继续添加', | ||
initial: true, | ||
}, PromptsOptions); | ||
if (!next) break; | ||
} | ||
} | ||
return presetAddress; | ||
}; | ||
|
||
/** | ||
* 监听模式问题数组 | ||
*/ | ||
export const monitorPromptsQuestions: Array<prompts.PromptObject> = [ | ||
{ | ||
type: 'number', | ||
name: 'delay', | ||
message: '签到延时(单位:秒)', | ||
initial: 0, | ||
}, | ||
{ | ||
type: 'confirm', | ||
name: 'mail', | ||
message: '是否启用邮件通知?', | ||
initial: false, | ||
}, | ||
{ | ||
type: (prev) => (prev ? 'text' : null), | ||
name: 'host', | ||
message: 'SMTP服务器', | ||
initial: 'smtp.qq.com', | ||
}, | ||
{ | ||
type: (prev) => (prev ? 'confirm' : null), | ||
name: 'ssl', | ||
message: '是否启用SSL', | ||
initial: true, | ||
}, | ||
{ | ||
type: (prev) => (prev ? 'number' : null), | ||
name: 'port', | ||
message: '端口号', | ||
initial: 465, | ||
}, | ||
{ | ||
type: (prev) => (prev ? 'text' : null), | ||
name: 'user', | ||
message: '邮件账号', | ||
initial: '[email protected]', | ||
}, | ||
{ | ||
type: (prev) => (prev ? 'text' : null), | ||
name: 'pass', | ||
message: '授权码(密码)', | ||
}, | ||
{ | ||
type: (prev) => (prev ? 'text' : null), | ||
name: 'to', | ||
message: '接收邮箱', | ||
}, | ||
{ | ||
type: 'confirm', | ||
name: 'cq_enabled', | ||
message: '是否连接到go-cqhttp服务?', | ||
initial: false, | ||
}, | ||
{ | ||
type: (prev) => (prev ? 'text' : null), | ||
name: 'ws_url', | ||
message: 'Websocket 地址', | ||
initial: 'ws://127.0.0.1:8080', | ||
}, | ||
{ | ||
type: (prev) => (prev ? 'select' : null), | ||
name: 'target_type', | ||
message: '选择消息的推送目标', | ||
choices: [ | ||
{ title: '群组', value: 'group' }, | ||
{ title: '私聊', value: 'private' } | ||
], | ||
}, | ||
{ | ||
type: (prev) => (prev ? 'number' : null), | ||
name: 'target_id', | ||
message: '接收号码', | ||
initial: 10001, | ||
}, | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,118 @@ | ||
import { CHAT_GROUP, PPTSIGN } from '../configs/api'; | ||
import { delay } from '../utils/helper'; | ||
import { cookieSerialize, request } from '../utils/request'; | ||
|
||
export const LocationSign = async ( | ||
args: BasicCookie & { name: string; address: string; activeId: string; lat: string; lon: string; fid: string; } | ||
): Promise<string> => { | ||
const { name, address, activeId, lat, lon, fid, ...cookies } = args; | ||
const url = `${PPTSIGN.URL}?name=${name}&address=${address}&activeId=${activeId}&uid=${cookies._uid}&clientip=&latitude=${lat}&longitude=${lon}&fid=${fid}&appType=15&ifTiJiao=1`; | ||
const result = await request(url, { | ||
secure: true, | ||
headers: { | ||
Cookie: cookieSerialize(cookies), | ||
}, | ||
}); | ||
const msg = result.data === 'success' ? '[位置]签到成功' : `[位置]${result.data}`; | ||
interface AddressItem { | ||
lon: string; | ||
lat: string; | ||
address: string; | ||
} | ||
type PresetAddress = AddressItem[]; | ||
type CookieWithAddressItemArgs = BasicCookie & AddressItem & { name: string; activeId: string; fid: string; }; | ||
type CookieWithPresetAddressArgs = BasicCookie & { presetAddress: PresetAddress; name: string; activeId: string; fid: string; }; | ||
|
||
type LocationSignType = { | ||
(arg1: CookieWithAddressItemArgs): Promise<string>; | ||
(arg1: CookieWithPresetAddressArgs): Promise<string>; | ||
}; | ||
|
||
export const LocationSign: LocationSignType = async (args): Promise<string> => { | ||
let msg = ''; | ||
if ('address' in args) { | ||
// 单个位置直接签 | ||
const { name, address, activeId, lat, lon, fid, ...cookies } = args; | ||
const url = `${PPTSIGN.URL}?name=${name}&address=${address}&activeId=${activeId}&uid=${cookies._uid}&clientip=&latitude=${lat}&longitude=${lon}&fid=${fid}&appType=15&ifTiJiao=1`; | ||
const result = await request(url, { | ||
secure: true, | ||
headers: { | ||
Cookie: cookieSerialize(cookies), | ||
}, | ||
}); | ||
msg = result.data === 'success' ? '[位置]签到成功' : `[位置]${result.data}`; | ||
} else { | ||
// 多个位置尝试 | ||
const { name, activeId, presetAddress, fid, ...cookies } = args; | ||
for (let i = 0; i < presetAddress.length; i++) { | ||
const url = `${PPTSIGN.URL}?name=${name}&address=${presetAddress[i].address}&activeId=${activeId}&uid=${cookies._uid}&clientip=&latitude=${presetAddress[i].lat}&longitude=${presetAddress[i].lon}&fid=${fid}&appType=15&ifTiJiao=1`; | ||
const result = await request(url, { | ||
secure: true, | ||
headers: { | ||
Cookie: cookieSerialize(cookies), | ||
}, | ||
}); | ||
if (result.data === 'success') { | ||
msg = '[位置]签到成功'; | ||
break; | ||
} else { | ||
msg = `[位置]${result.data}`; | ||
await delay(1); | ||
} | ||
} | ||
} | ||
console.log(msg); | ||
return msg; | ||
}; | ||
|
||
/** | ||
* 位置签到,无课程群聊版本 | ||
*/ | ||
export const LocationSign_2 = async ( | ||
args: BasicCookie & { name: string; address: string; activeId: string; lat: string; lon: string; fid: string; } | ||
): Promise<string> => { | ||
const { address, activeId, lat, lon, ...cookies } = args; | ||
const formdata = `address=${encodeURIComponent(address)}&activeId=${activeId}&uid=${cookies._uid | ||
}&clientip=&useragent=&latitude=${lat}&longitude=${lon}&fid=&ifTiJiao=1`; | ||
const result = await request( | ||
CHAT_GROUP.SIGN.URL, | ||
{ | ||
secure: true, | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
Cookie: cookieSerialize(cookies), | ||
export const LocationSign_2: LocationSignType = async (args): Promise<string> => { | ||
let msg = ''; | ||
if ('address' in args) { | ||
// 单个位置直接签 | ||
const { address, activeId, lat, lon, ...cookies } = args; | ||
const formdata = `address=${encodeURIComponent(address)}&activeId=${activeId}&uid=${cookies._uid}&clientip=&useragent=&latitude=${lat}&longitude=${lon}&fid=&ifTiJiao=1`; | ||
const result = await request( | ||
CHAT_GROUP.SIGN.URL, | ||
{ | ||
secure: true, | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
Cookie: cookieSerialize(cookies), | ||
}, | ||
}, | ||
}, | ||
formdata | ||
); | ||
const msg = result.data === 'success' ? '[位置]签到成功' : `[位置]${result.data}`; | ||
formdata | ||
); | ||
msg = result.data === 'success' ? '[位置]签到成功' : `[位置]${result.data}`; | ||
} else { | ||
// 多个位置尝试 | ||
const { activeId, presetAddress, ...cookies } = args; | ||
for (let i = 0; i < presetAddress.length; i++) { | ||
const formdata = `address=${encodeURIComponent(presetAddress[i].address)}&activeId=${activeId}&uid=${cookies._uid}&clientip=&useragent=&latitude=${presetAddress[i].lat}&longitude=${presetAddress[i].lon}&fid=&ifTiJiao=1`; | ||
const result = await request( | ||
CHAT_GROUP.SIGN.URL, | ||
{ | ||
secure: true, | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
Cookie: cookieSerialize(cookies), | ||
}, | ||
}, | ||
formdata | ||
); | ||
if (result.data === 'success') { | ||
msg = '[位置]签到成功'; | ||
break; | ||
} else { | ||
msg = `[位置]${result.data}`; | ||
await delay(1); | ||
} | ||
} | ||
} | ||
console.log(msg); | ||
return msg; | ||
}; | ||
|
||
export const presetAddressChoices = (presetAddress: any[] = []) => { | ||
const arr = []; | ||
for (let i = 0; i < presetAddress.length; i++) { | ||
arr.push({ | ||
title: `${presetAddress[i].lon},${presetAddress[i].lat}/${presetAddress[i].address}`, | ||
value: i, | ||
}); | ||
} | ||
arr.push({ title: '手动添加', value: -1 }); | ||
return [...arr]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.