-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.sh.bak
executable file
·394 lines (370 loc) · 12.6 KB
/
main.sh.bak
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#!/bin/bash
groupid=$(grep 'management-group-id' oqqwall.config | cut -d'=' -f2 | tr -d '"')
commgroup_id=$(grep 'communicate-group' oqqwall.config | cut -d'=' -f2 | tr -d '"')
file_to_watch="./getmsgserv/all/priv_post.json"
command_file="./qqBot/command/commands.txt"
litegettag=$(grep 'use_lite_tag_generator' oqqwall.config | cut -d'=' -f2 | tr -d '"')
mkdir ./getmsgserv/rawpost
mkdir ./getmsgserv/post-step2
mkdir ./getmsgserv/post-step3
mkdir ./getmsgserv/post-step4
mkdir ./getmsgserv/post-step5
mkdir ./qqBot/command
touch ./qqBot/command/commands.txt
pkill startd.sh
# Activate virtual environment
source ./venv/bin/activate
# start startd
./qqBot/startd.sh &
echo 等待启动十秒
sleep 10
waitforfilechange(){
last_mod_time_cmd=$(stat -c %Y "$1")
while true; do
sleep 5
# 获取文件的当前修改时间
current_mod_time_cmd=$(stat -c %Y "$1")
# 检查文件是否已被修改
if [ "$current_mod_time_cmd" -ne "$last_mod_time_cmd" ]; then
echo 检测到指令
break
fi
done
}
sendimagetoqqgroup() {
# 设置文件夹路径
folder_path="$(pwd)/getmsgserv/post-step5/$numnext"
# 检查文件夹是否存在
if [ ! -d "$folder_path" ]; then
echo "文件夹 $folder_path 不存在"
exit 1
fi
find "$folder_path" -maxdepth 1 -type f | sort | while IFS= read -r file_path; do
echo "发送文件: $file_path"
msg=[CQ:image,file=file://$file_path]
encoded_msg=$(python3 -c "import urllib.parse; print(urllib.parse.quote('''$msg'''))")
# 构建 curl 命令,并发送编码后的消息
cmd="curl \"http://127.0.0.1:8083/send_group_msg?group_id=$groupid&message=$encoded_msg\""
echo $cmd
eval $cmd
sleep 1 # 添加延时以避免过于频繁的请求
done
echo "所有文件已发送"
}
askforintro(){
msg=请发送指令
encoded_msg=$(python3 -c "import urllib.parse; print(urllib.parse.quote('''$msg'''))")
# 构建 curl 命令,并发送编码后的消息
cmd="curl \"http://127.0.0.1:8083/send_group_msg?group_id=$groupid&message=$encoded_msg\""
echo $cmd
eval $cmd
# 初始化文件的上次修改时间
waitforfilechange "./qqBot/command/commands.txt"
sendmsggroup 已收到指令
mapfile -t lines < "$command_file"
line=${lines[-1]}
# 获取行的第一个和第二个字段
number=$(echo $line | awk '{print $1}')
status=$(echo $line | awk '{print $2}')
# 检查行的第一个字段是否等于 numnext
if [[ $number -eq $numnext ]]; then
case $status in
是)
postcmd="true"
postqzone
;;
否)
postcmd="false"
rm ./getmsgserv/rawpost/$id.json
rm -rf ./getmsgserv/post-step5/$numnext
;;
等)
postcmd="wait"
sleep 180
processsend
;;
删)
postcmd="del"
rm ./getmsgserv/rawpost/$id.json
rm -rf ./getmsgserv/post-step5/$numnext
;;
拒)
postcmd="ref"
rm ./getmsgserv/rawpost/$id.json
rm -rf ./getmsgserv/post-step5/$numnext
sendmsgpriv $id '你的稿件被拒绝,请尝试修改后重新投稿'
;;
匿)
sendmsggroup 尝试切换匿名状态...
file="./getmsgserv/post-step2/$numnext.json"
json_content=$(cat "$file")
modified_json=$(echo "$json_content" | jq '.needpriv = (.needpriv == "true" | not | tostring)')
echo "$modified_json" > "$file"
python3 ./getmsgserv/HTMLwork/gotohtml.py "$numnext"
./getmsgserv/HTMLwork/gotopdf.sh "$numnext"
./getmsgserv/HTMLwork/gotojpg.sh "$numnext"
sendimagetoqqgroup
sendmsggroup $numnext
echo askforgroup...
askforintro
;;
*)
sendmsggroup 没有此指令,请查看说明
askforintro
;;
esac
elif [[ $number -eq relogin ]]; then
case $status in
是)
postcmd="true"
renewqzonelogin
;;
否)
postcmd="false"
echo retry...
sendmsggroup 重新尝试发送中...
postqzone
;;
*)
sendmsggroup 没有此指令,请查看说明
askforintro
;;
esac
else
sendmsggroup 指令语法错误,请查看说明
askforintro
fi
}
getnumnext(){
if [[ "$litegettag" == false ]]; then
echo 使用主算法...
getnumcmd='python3 ./SendQzone/qzonegettag-headless.py'
output=$(eval $getnumcmd)
else
output="Log Error!"
fi
if echo "$output" | grep -q "Log Error!"; then
echo 使用备用算法...
mapfile -t lines < "$command_file"
line=${lines[-1]}
# 获取行的第一个和第二个字段
number=$(echo $line | awk '{print $1}')
status=$(echo $line | awk '{print $2}')
echo '$number $status'
if [[ $number -ne relogin ]]; then
echo 检查到num,检查指令
case $status in
是)
numnext=$[ number + 1 ]
;;
否)
numnext=$[ number + 1 ]
;;
等)
numnext=$[ number + 1 ]
;;
删)
numnext=$number
;;
拒)
numnext=$number
;;
*)
numnext=$[ numnext + 1 ]
;;
esac
elif [[ $number -eq relogin ]]; then
echo 检查到relogin,检查下一行
line=${lines[-2]}
# 获取行的第一个和第二个字段
number=$(echo $line | awk '{print $1}')
status=$(echo $line | awk '{print $2}')
echo $number $status
if [[ $number -eq relogin ]]; then
numnext=$[ numnext + 1]
else
case $status in
是)
numnext=$[ number + 1 ]
;;
否)
numnext=$[ number + 1 ]
;;
等)
numnext=$[ number + 1 ]
;;
删)
numnext=$number
;;
拒)
numnext=$number
;;
*)
numnext=$[ numnext + 1 ]
;;
esac
fi
fi
else
numnow=$( cat ./numb.txt )
numnext=$[ numnow + 1 ]
fi
echo numnext=$numnext
}
postqzone(){
if [ ! -f "./cookies.json" ]; then
echo "Cookies file does not exist. Executing relogin script."
python3 SendQzone/send.py relogin &
sleep 2
sendmsggroup 请立即扫描二维码
sendmsggroup "[CQ:image,file=$(pwd)/qrcode.png]"
eval $command
sleep 60
else
echo "Cookies file exists. No action needed."
fi
json_path="./getmsgserv/post-step2/$numnext.json"
need_priv=$(jq -r '.needpriv' "$json_path")
# 检查 need_priv 的值并执行相应的命令
if [ "$need_priv" == "true" ]; then
postcommand="python3 ./SendQzone/send.py '#$numnext' ./getmsgserv/post-step5/$numnext/"
else
postcommand="python3 ./SendQzone/send.py '#$numnext @{uin:$id,nick:,who:1}' ./getmsgserv/post-step5/$numnext/"
fi
output=$(eval $postcommand)
if echo "$output" | grep -q "Failed to publish."; then
getnumnext
output=$(eval $postcommand)
if echo "$output" | grep -q "Failed to publish."; then
sendmsggroup "空间发送错误,可能需要重新登陆"
sendmsggroup "发送\"@本账号 relogin 是\"以手动重新登陆"
askforintro
else
echo 发送完毕
sendmsgpriv $id $numnext
sendmsgpriv $id '已发送(系统自动发送,请勿回复)'
sendmsggroup 已发送
fi
else
echo 发送完毕
sendmsgpriv $id $numnext
sendmsgpriv $id '已发送(系统自动发送,请勿回复)'
sendmsggroup 已发送
fi
current_mod_time_id=$(stat -c %Y "$id_file")
current_mod_time_privmsg=$(stat -c %Y "./getmsgserv/all/priv_post.json")
echo "'current-mod-time-id:'$current_mod_time_id"
echo "'last-mod-time-id:'$last_mod_time_id"
echo "'current_mod_time_privmsg'$current_mod_time_privmsg"
echo "'last_mod_time_privmsg':$last_mod_time_privmsg"
if [ "$current_mod_time_id" -eq "$last_mod_time_id" ]; then
echo "过程中此人无新消息,删除此人记录"
rm ./getmsgserv/rawpost/$id.json
fi
if [ "$current_mod_time_privmsg" -ne "$last_mod_time_privmsg " ]; then
echo "过程中有新消息,重跑发件流程"
processsend
fi
}
renewqzonelogin(){
rm ./cookies.json
rm ./qrcode.png
postqzone &
sleep 2
sleep 60
}
sendmsggroup(){
msg=$1
encoded_msg=$(python3 -c "import urllib.parse; print(urllib.parse.quote('''$msg'''))")
# 构建 curl 命令,并发送编码后的消息
cmd="curl \"http://127.0.0.1:8083/send_group_msg?group_id=$groupid&message=$encoded_msg\""
echo $cmd
eval $cmd
}
sendmsgpriv(){
msg=$2
encoded_msg=$(python3 -c "import urllib.parse; print(urllib.parse.quote('''$msg'''))")
# 构建 curl 命令,并发送编码后的消息
cmd="curl \"http://127.0.0.1:8083/send_private_msg?user_id=$1&message=$encoded_msg\""
echo $cmd
eval $cmd
}
#主逻辑代码
processsend(){
echo getnum...
getnumnext
echo waitingforsender...
sleep 120
id=$(find ./getmsgserv/rawpost -type f -printf '%T+ %p\n' | sort | head -n 1 | awk '{print $2}')
id=$(basename "$id" .json)
id=$(echo "$id" | sed 's/.*\///')
id_file=./getmsgserv/rawpost/$id.json
last_mod_time_id=$(stat -c %Y "$id_file")
last_mod_time_privmsg=$(stat -c %Y "./getmsgserv/all/priv_post.json")
echo $id
echo 'wait-for-LM...'
python3 ./getmsgserv/LM_work/sendtoLM.py ${id} ${numnext}
for i in {1..3}
do
if [ -f "./getmsgserv/post-step2/${numnext}.json" ]; then
echo "File exists, continuing..."
break
else
echo "File not found, running Python script..."
python3 ./getmsgserv/LM_work/sendtoLM.py "${id}" "${numnext}"
fi
if [ "$i" -eq 3 ] && [ ! -f "./getmsgserv/post-step2/${numnext}.json" ]; then
sendmsggroup LLM处理错误,请检查相关信息
fi
done
echo LM-workdone
json_file=./getmsgserv/post-step2/${numnext}.json
isover=$(jq -r '.isover' "$json_file")
notregular=$(jq -r '.notregular' "$json_file")
safemsg=$(jq -r '.safemsg' "$json_file")
python3 ./getmsgserv/HTMLwork/gotohtml.py "$numnext"
./getmsgserv/HTMLwork/gotopdf.sh "$numnext"
./getmsgserv/HTMLwork/gotojpg.sh "$numnext"
if [ "$isover" = "true" ] && [ "$notregular" = "false" ]; then
sendmsggroup 有常规消息
elif [ "$isover" = "true" ] && [ "$notregular" = "true" ]; then
sendmsggroup 有非常规消息
elif [ "$isover" = "false" ] && [ "$notregular" = "true" ]; then
sendmsggroup 有常规但疑似未写完帖子
elif [ "$isover" = "false" ] && [ "$notregular" = "false" ]; then
sendmsggroup 有非常规且疑似未写完帖子
else
sendmsggroup 有需要审核的消息
fi
if [ "$safemsg" = "true" ]; then
sendmsggroup AI审核判定安全
elif [ "$safemsg" = "false" ]; then
sendmsggroup AI审核判定不安全
fi
content=$(<"$id_file")
sendmsggroup "原始信息: $content"
sendimagetoqqgroup
sendmsggroup $numnext
echo askforgroup...
askforintro
}
sendmsggroup 机器人已启动
echo 获取priv_post文件更改时间
last_mod_time=$(stat -c %Y "$file_to_watch")
echo $last_mod_time
echo 启动主循环
while true; do
echo 启动等待循环
while true; do
sleep 5
# 获取文件的当前修改时间
current_mod_time=$(stat -c %Y "$file_to_watch")
# 检查文件是否已被修改
if [ "$current_mod_time" -ne "$last_mod_time" ]; then
echo "有新私聊消息"
break
fi
done
processsend
last_mod_time=$(stat -c %Y "$file_to_watch")
done