-
Notifications
You must be signed in to change notification settings - Fork 1
/
点赞续火.js
134 lines (125 loc) · 3.69 KB
/
点赞续火.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import plugin from "../../lib/plugins/plugin.js"
import common from "../../lib/common/common.js"
import schedule from 'node-schedule'
/** 自动点赞续火列表
* @push 是否开启点赞消息推送
* @hitokoto 是否开启推送一言
*/
const thumbsUpMelist = {
/** 作者 */
1719549416: {
push: false,
hitokoto: false
},
/** 作者的机器人 */
2859278670: {
push: false,
hitokoto: false
}
}
/** 点赞次数,非会员10次,会员20次 */
const thumbsUpMe_sum = 10
/** 点赞消息推送文本 */
const thumbsUpMe_msg = '派蒙给你点赞啦,记得给我回赞哦'
/** 一言接口,请使用纯文本的接口 */
const hitokoto_api = 'https://v1.hitokoto.cn/?encode=text&charset=utf-8&c=d&c=i&c=h&c=e'
/** 一言默认文案,网络请求失败时发送这个 */
const hitokoto_Default_text = '种自己的花,爱自己的宇宙🌍'
/** 被消息触发 */
export class dzxh extends plugin {
constructor() {
super({
name: "点赞续火",
dsc: "给群友点赞及续火",
event: "message",
priority: 5000,
rule: [
{
reg: "^#*赞我$",
fnc: "thumbsUpMe",
},
{
reg: "^#*(续火|一言|壹言)$",
fnc: "hitokoto",
}
],
})
/** 创建定时任务 这个是云崽提供的内置方法,暂无使用的考虑
this.task = {
cron: '30 5 12 * * *',
name: '定时点赞',
fnc: () => this.thumbsUpMe(), // 指触发的函数
log: false // 是否输出日志
}
*/
}
/** 赞我 */
async thumbsUpMe() {
Bot.pickFriend(this.e.user_id).thumbUp(thumbsUpMe_sum)
this.e.reply(thumbsUpMe_msg)
return true
}
/** 续火 */
async hitokoto(e) {
fetch(hitokoto_api)
.then(response => {
return response.text()
})
.then(data => {
e.reply(data)
})
.catch(() => {
e.reply(hitokoto_Default_text) // 请求失败的默认文案
logger.warn(`[点赞续火][续火] 接口请求失败,使用默认文案`)
})
}
}
/** 休眠函数
* @time 毫秒
*/
function sleep(time){
return new Promise((resolve) => setTimeout(resolve, time));
}
/** 主动触发-点赞
* 点赞开始时间
* cron表达式定义推送时间 (秒 分 时 日 月 星期)
* 可使用此网站辅助生成:https://www.matools.com/cron/
* 注意,每天都需要触发,因此日及以上选通配符或不指定
* 只选小时就可以了
*/
schedule.scheduleJob('30 5 12 * * *', async () => {
for (let qq of Object.keys(thumbsUpMelist)) {
Bot.pickFriend(qq).thumbUp(thumbsUpMe_sum)
logger.mark(`[点赞续火][自动点赞] 已给QQ${qq}点赞${thumbsUpMe_sum}次`)
if (thumbsUpMelist[qq].push){
common.relpyPrivate(qq, thumbsUpMe_msg)
}
await sleep(10000) // 等10秒在下一个
}
})
// 主动触发-续火
schedule.scheduleJob('30 15 12 * * *', async (e) => {
logger.mark(`[点赞续火][自动续火] 触发一言定时`)
fetch(hitokoto_api)
.then(response => {
return response.text()
})
.then(async data => {
for (let qq of Object.keys(thumbsUpMelist)) {
if (thumbsUpMelist[qq].hitokoto){
common.relpyPrivate(qq, data)
}
await sleep(2000) // 等2秒在下一个
}}
)
.catch(async () => {
for (let qq of Object.keys(thumbsUpMelist)) {
if (thumbsUpMelist[qq].hitokoto){
common.relpyPrivate(qq, hitokoto_Default_text) // 请求失败的默认文案
logger.warn(`[点赞续火][自动续火] 接口请求失败,使用默认文案`)
}
await sleep(2000) // 等2秒在下一个
}
})
}
)