SlieFamily / ErikaBot

A QQ(Tencent) robot created by go-cqhttp & nonebot2
12 stars 3 forks source link

以`CQ`码形式发送的image被风控,调`api`发无影响 #10

Closed SlieFamily closed 2 years ago

SlieFamily commented 2 years ago

经检验,结果是CQ码不再支持通过缓存的形式发送图片了。即[CQ:image,file=xxxx.image,url=xxxx]的形式不再受用。 问题已解决:只需整体将CQ码的file值设为图片地址url即可 代码:


import sqlite3
import re

db = sqlite3.connect('anas.db')
cur = db.cursor()

cur.execute(f'select * from AnaList')
AnaList = cur.fetchall()
for ana in AnaList:
    ana = ana[0]
    cur.execute(f'select * from "_{ana}"')
    print("正在处理:"+ana+"语录……")
    for msg in cur.fetchall():
        msg = msg[0]
        res = re.findall(",url=([a-zA-z]+://[^\s]*)[,]*\]",msg)
        if not res:
            print("----没有图片|跳过-----")
            continue
        new_msg =  re.sub("\[CQ:image,[\w\W]+,url=[a-zA-z]+://[^\s]*[,]*[\w\W]*\]","[CQ:image,file="+res[0]+"]",msg)
        try:
            cur.execute(f'update "_{ana}" set ana="{new_msg}" where ana="{msg}"')
            db.commit()
        except:
            print("-------修改失败-------")
            print("msg: "+msg)
            print("new_msg: "+new_msg)