Skip to content

Commit

Permalink
v 0.0.2 OHHHHH
Browse files Browse the repository at this point in the history
First Virsion able to use in Production!
  • Loading branch information
gfhdhytghd committed Jul 31, 2024
1 parent 1abf49f commit d6a27c2
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 135 deletions.
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# OQQWall
# 开放QQ校园墙自动运营系统
### 当前版本的架构很快就不会再维护了,我们正在尝试切换到nonebot架构
## 简介
本系统是一个校园墙自动运营系统,可以实现如下功能:
<br/>获取用户投稿消息,通过大语言模型实现自动分段,自动判断匿名与否
Expand All @@ -12,11 +11,8 @@
#### 目前系统处于非常早期的版本,完全不保证可用性。

已知问题如下:
<br/>群消息会导致发稿流程激活
<br/>错误的群审核指令会导致上一条指令被执行
<br/>qq空间两天就会退出登录
<br/>拉格朗日机器人偶尔会抽风
<br/>“否”指令有一些问题
<br/>使用qwen大语言模型的情况下,处理不了太长的帖子

# 使用方法
Expand All @@ -40,7 +36,7 @@

打开./SendQzone/qzonegettag
<br/>翻到60行
<br/>填写主账号到driendlist,辅助账号到my_qq
<br/>填写主账号到friendlist,辅助账号到my_qq
<br/>打开main.sh,填写管理群群号到group_id
<br/>打开getmsgserv/serv.py
<br/>找到第49行的if,填写管理群号到 == 和 and中间,群号两边记得留空格。
Expand All @@ -52,15 +48,16 @@

注:确保你的api余额够用。

注:目前使用的模型是qwen2-72b-instruct,效果还行,有能力的可以自己换更牛逼的模型。
注:目前使用的模型是qwen2-72b-instruct,效果还行,有能力的可以自己换更牛逼的模型,或者自己测试一下哪个模型好用

手动登陆主账号qq空间,发送一条说说,文案需要由#0开头,这是为了初始化编号系统
<br/>如果此帐号之前就是使用 #数字 方式进行编号,不需要进行这一步

启动主程序
<br/>打开QQ,登陆辅助账号
<br/>./main.sh
<br/>终端输入./main.sh
<br/>然后,理论上,应该就可以用了。
<br/>注意ctrl+c关闭程序时,Lagrange.Onebot和serv.py不会一并关闭,需要手动终止进程

### 审核群使用方法:
<br/>墙会在有新消息时将渲染好的消息图片带着编号一起发到群中来
Expand All @@ -75,13 +72,12 @@
<br/>指令有以下几种:
<br/>是:发送
<br/>否:机器跳过此条,人工去处理
<br/>当前版本不建议使用此指令,有bug,建议用“删”替代
<br/>当前版本等效于删
<br/>等:等待180秒,然后重新执行分段-渲染-审核流程,常用于稿件没发完的情况
<br/>删:从系统中删掉这个人的消息记录,常用于用户来找你聊天或者删帖等需要手动处理的情况
<br/>比如

<br/>@校园墙 348 是
@校园墙 348 是
<br/>将348号帖子发送出去
<br/>@校园墙 348 否
<br/>不删除任何东西,跳过此条
<br/>从系统中删掉这个人的消息记录,人工前往处理

21 changes: 0 additions & 21 deletions SendQzone/qzonegettag.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def login(my_qq):
browser.get('https://i.qq.com/')
time.sleep(2)
browser.switch_to.frame("login_frame")
time.sleep(2)

try:
find = browser.find_element(By.ID, f'img_out_{my_qq}')
Expand All @@ -36,7 +35,6 @@ def find_number(text):
# Get the text from the website and analyze it
def get(html):
print('Trying to get shuoshuos')
time.sleep(2)
soup = BeautifulSoup(html, "html.parser")
shuoshuos = soup.find_all(name="li", attrs={"class": "feed"})
print(f'There are {len(shuoshuos)} messages.')
Expand All @@ -62,35 +60,16 @@ def main():
# Get to the friend's QQ Zone
friendlist = ['']
print('Trying to get into the QQ Zone')
time.sleep(2)

driver.get(f'https://user.qzone.qq.com/{friendlist[0]}/311')
print('Get in!')

# Get the contents
while True:
# Move to the QQ Zone frame
iframe = driver.find_element(By.ID, 'app_canvas_frame')
time.sleep(2)
wait_element = WebDriverWait(driver, 20)
wait_element.until(EC.frame_to_be_available_and_switch_to_it(iframe))

# Find the unfold buttons and click them
while True:
try:
print('Trying to find unfold button')
buttons = driver.find_elements(By.XPATH, '//a[contains(@class, "has_more_con") and contains(text(), "展开查看全文")]')
for button in buttons:
print(button)
time.sleep(5)
driver.execute_script('arguments[0].scrollIntoView(false);', button)
time.sleep(2)
button.click()
break
except Exception as error:
print(f'\033[0;31mUnfold error! {error} \033[0m')
continue

# Get the HTML source code
time.sleep(2)
html = driver.page_source
Expand Down
26 changes: 24 additions & 2 deletions SendQzone/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,41 @@ async def publish_emotion(self, content: str, images: list[bytes] = []) -> str:


async def main():
if len(sys.argv) != 3:
if len(sys.argv) > 3:
print("Usage: python3 test.py <message> <image_directory>")
return

message = sys.argv[1]
image_directory = sys.argv[2]
try:
image_directory = sys.argv[2]
except:
image_directory='./getmsgserv/post-step5'

try:
with open('./cookies.json', 'r') as f:
cookies = json.load(f)
except:
cookies = None

if message == 'relogin':
login = QzoneLogin()

async def qrcode_callback(qrcode: bytes):
with open("qrcode.png", "wb") as f:
f.write(qrcode)

try:
cookies = await login.login_via_qrcode(qrcode_callback)
print("Cookies after login:", cookies)
with open('cookies.json', 'w') as f:
json.dump(cookies, f)
os.remove('./qrcode.png')
except Exception as e:
print("Failed to generate login QR code.")
traceback.print_exc()
return
sys.exit()

if not cookies:
login = QzoneLogin()

Expand Down
13 changes: 11 additions & 2 deletions getmsgserv/HTMLwork/gotojpg.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#!/bin/bash
input="$1"
mkdir ./getmsgserv/post-step5/${input}
rm ./getmsgserv/post-step5/${input}/*
folder=./getmsgserv/post-step5/${input}
jsonfile=./getmsgserv/post-step2/${input}.json
mkdir -p "$folder"
magick convert -density 320 -quality 95 ./getmsgserv/post-step4/${input}.pdf ./getmsgserv/post-step5/${input}/${input}.jpeg
existing_files=$(ls "$folder" | wc -l)
next_file_index=$existing_files
jq -r '.messages[].message[] | select(.type=="image") | .data.url' "$jsonfile" | while read -r url; do
# 下载文件并命名
curl -o "$folder/$input-$next_file_index" "$url"
# 增加文件索引
next_file_index=$((next_file_index + 1))
done
2 changes: 1 addition & 1 deletion getmsgserv/LM_work/sendtoLM.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
" # 判断他有没有说完,通常通过用语义来判断,检查记录中是否有“没发完”“发完了”一类的语句,判断已经发来的内容是否构成一个完整的稿件,也可以通过time判断,在最后一条消息的time距离timenow很久远的情况下可以判断为完整稿件,只有在非常肯定他发完了的情况下才为true\n"
" \"notregular\": \"true/false\",\n"
" # 判断这条信息是否需要非常规,规则如下"
" #任何一个\"message\" [\"type\"的值\"text\"/\"image\"/\"video\"的需要人工介入,比如含有record,poke等的即为非常规"
" #任何一个\"message\" [\"type\"的值,\"text\"/\"image\"的为常规,其他的,比如含有video,record,poke等的即为非常规"
" #内容中要求对之前发送的稿件进行修改或撤回等操作的为非常规"
" \"messages\": [\n"
" # 接下来输出分好组的message信息\n"
Expand Down
16 changes: 0 additions & 16 deletions getmsgserv/LM_work/test.py

This file was deleted.

17 changes: 14 additions & 3 deletions getmsgserv/serv.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ def do_POST(self):
sender = data.get('sender', {})
raw_message = data.get('raw_message', '')

if (group_id == and sender.get('role') == 'admin' and
raw_message.startswith('[CQ:at,qq=xxx]')):
if (group_id == 814783587 and sender.get('role') == 'admin' and
raw_message.startswith('[CQ:at,qq=1050373508]')):
# Extract and save the relevant part of raw_message
command_text = raw_message[len('[CQ:at,qq=xxx] '):]
command_text = raw_message[len('[CQ:at,qq=1050373508] '):]
command_file_path = os.path.join(COMMAND_DIR, 'commands.txt')

with open(command_file_path, 'a', encoding='utf-8') as f:
Expand Down Expand Up @@ -95,6 +95,17 @@ def do_POST(self):
with open(file_path, 'w', encoding='utf-8') as f:
json.dump(sorted_data, f, ensure_ascii=False, indent=4)

priv_post_path = os.path.join(ALLPOST_DIR, 'priv_post.json')
if os.path.exists(priv_post_path):
with open(priv_post_path, 'r', encoding='utf-8') as f:
priv_post_data = json.load(f)
else:
priv_post_data = []

priv_post_data.append(data)
with open(priv_post_path, 'w', encoding='utf-8') as f:
json.dump(priv_post_data, f, ensure_ascii=False, indent=4)

# 返回响应
self.send_response(200)
self.end_headers()
Expand Down
Loading

0 comments on commit d6a27c2

Please sign in to comment.