Skip to content

Commit

Permalink
add qqBot
Browse files Browse the repository at this point in the history
  • Loading branch information
firmianay committed Apr 8, 2022
1 parent ad8c9cb commit 76a9cd6
Show file tree
Hide file tree
Showing 13 changed files with 2,405 additions and 33 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ jobs:
with:
python-version: '3.x'
- name: Install dependencies
run: pip install -r requirements.txt
run: ./install.sh

- name: Push articles
env:
FEISHU_KEY: ${{ secrets.FEISHU_KEY }}
WECOM_KEY: ${{ secrets.WECOM_KEY }}
DINGTALK_KEY: ${{ secrets.DINGTALK_KEY }}
run: python3 yarb.py --update
run: python3 yarb.py

- name: Commit
run: |
git diff
git config --global user.email [email protected]
git config --global user.name firmianay
git add archive today.md
git commit -m "Update: `date +'%Y-%m-%d'`"
git commit -m "每日安全资讯(`date +'%Y-%m-%d'`"
- name: Push changes
uses: ad-m/github-push-action@master
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rss/
cqhttp/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

另一个方便安全研究人员获取每日安全日报的爬虫和推送程序。支持导入 opml 文件从而批量订阅 RSS,因此可以订阅任何东西,而不局限于安全。

**懒人福音,每日自动更新,点击右上角 Watch 即可:[每日安全资讯](./today.md)**
**懒人福音,每日自动更新,点击右上角 Watch 即可:[每日安全资讯](./today.md)[历史存档](./archive)**

- [yarb (Yet Another Rss Bot)](#yarb-yet-another-rss-bot)
- [安装](#安装)
Expand All @@ -16,8 +16,8 @@
## 安装

```sh
$ git clone https://github.com/firmianay/yarb.git && cd yarb
$ python3 -m pip install -r requirements.txt
$ git clone https://github.com/firmianay/yarb.git
$ cd yarb && ./install.sh
```

## 运行
Expand Down Expand Up @@ -52,6 +52,7 @@ $ nohup ./yarb.py --update --cron 11:00 > run.log 2>&1 &
- [飞书群机器人](https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN)`FEISHU_KEY`
- [企业微信群机器人](https://developer.work.weixin.qq.com/document/path/91770)`WECOM_KEY`
- [钉钉群机器人](https://open.dingtalk.com/document/robots/custom-robot-access)`DINGTALK_KEY`
- [QQ群机器人](https://github.com/Mrs4s/go-cqhttp)`QQ_KEY`(需要关闭登录设备锁)

## 订阅源

Expand All @@ -68,27 +69,26 @@ $ nohup ./yarb.py --update --cron 11:00 > run.log 2>&1 &

```json
{
"rss": {
"CustomRSS": {
"enabled": true,
"filename": "CustomRSS.opml"
},
"CyberSecurityRSS": {
"enabled": true,
"url": "https://raw.githubusercontent.com/zer0yu/CyberSecurityRSS/master/CyberSecurityRSS.opml",
"filename": "CyberSecurityRSS.opml"
},
"rss": {
"CustomRSS": {
"enabled": true,
"filename": "CustomRSS.opml"
},
"CyberSecurityRSS": {
"enabled": true,
"url": "https://raw.githubusercontent.com/zer0yu/CyberSecurityRSS/master/CyberSecurityRSS.opml",
"filename": "CyberSecurityRSS.opml"
},
```

2. 在 `rss/CustomRSS.opml` 中添加链接:

```opml
<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0">
<head>
<title>CustomRSS</title>
</head>
<head><title>CustomRSS</title></head>
<body>
<outline xmlUrl="https://rsshub.app/hackerone/hacktivity" title="HackerOne Hacker Activity" text="HackerOne Hacker Activity" type="rss" htmlUrl="https://hackerone.com/hacktivity" />
</body>
</opml>
```
Expand Down
70 changes: 63 additions & 7 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import os
import time
import json
import yaml
import requests
from pathlib import Path

from utils import Color

__all__ = ["feishuBot", "wecomBot", "dingtalkBot"]
__all__ = ["feishuBot", "wecomBot", "dingtalkBot", "qqBot"]


class feishuBot:
Expand All @@ -19,9 +23,9 @@ def send(self, data):
r = requests.post(url=url, headers=headers, data=json.dumps(data))

if r.status_code == 200:
Color.print_success(f'[+] feishuBot 发送成功')
Color.print_success('[+] feishuBot 发送成功')
else:
Color.print_failed(f'[-] feishuBot 发送失败')
Color.print_failed('[-] feishuBot 发送失败')
print(r.text)

def send_text(self, text):
Expand All @@ -47,9 +51,9 @@ def send(self, data):
r = requests.post(url=url, headers=headers, data=json.dumps(data))

if r.status_code == 200:
Color.print_success(f'[+] wecomBot 发送成功')
Color.print_success('[+] wecomBot 发送成功')
else:
Color.print_failed(f'[-] wecomBot 发送失败')
Color.print_failed('[-] wecomBot 发送失败')
print(r.text)

def send_text(self, text):
Expand All @@ -74,9 +78,9 @@ def send(self, data):
r = requests.post(url=url, headers=headers, data=json.dumps(data))

if r.status_code == 200:
Color.print_success(f'[+] dingtalkBot 发送成功')
Color.print_success('[+] dingtalkBot 发送成功')
else:
Color.print_failed(f'[-] dingtalkBot 发送失败')
Color.print_failed('[-] dingtalkBot 发送失败')
print(r.text)

def send_text(self, text):
Expand All @@ -86,3 +90,55 @@ def send_text(self, text):
def send_markdown(self, title, text):
data = {"msgtype": "markdown", "markdown": {"title": title, "text": text}}
self.send(data)


class qqBot:
"""QQ群机器人
https://github.com/Mrs4s/go-cqhttp
"""
cqhttp_path = Path(__file__).absolute().parent.joinpath('cqhttp')

def __init__(self, group_id) -> None:
self.server = 'http://127.0.0.1:5700'
self.group_id = group_id

def send_text(self, text):
try:
r = requests.post(f'{self.server}/send_group_msg?group_id={self.group_id}&&message={text}')
if r.status_code == 200:
Color.print_success('[+] qqBot 发送成功')
else:
Color.print_failed('[-] qqBot 发送失败')
except Exception as e:
Color.print_failed('[-] qqBot 发送失败')
print(e)

def start_server(self, qq_id, qq_passwd, timeout=60):
config_path = self.cqhttp_path.joinpath('config.yml')
with open(config_path, 'r') as f:
data = yaml.load(f, Loader=yaml.FullLoader)
data['account']['uin'] = int(qq_id)
data['account']['password'] = qq_passwd
with open(config_path, 'w+') as f:
yaml.dump(data, f)

os.system('cd cqhttp && ./go-cqhttp -d')

timeout = time.time() + timeout
while True:
try:
requests.get(self.server)
Color.print_success('[+] qqBot 启动成功')
return True
except Exception as e:
time.sleep(1)

if time.time() > timeout:
qqBot.kill_server()
Color.print_failed('[-] qqBot 启动失败')
return False

@classmethod
def kill_server(cls):
pid_path = cls.cqhttp_path.joinpath('go-cqhttp.pid')
os.system(f'cat {pid_path} | xargs kill')
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@
"secrets": "DINGTALK_KEY",
"key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"msgtype": "markdown"
},
"qq": {
"enabled": true,
"secrets": "QQ_KEY",
"qq_id": "2419110059",
"group_id": ["808542982", "217863340"],
"key": "xxxxxxxxxx",
"msgtype": "text"
}
}
}
6 changes: 6 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

python3 -m pip install -r requirements.txt

wget -q https://github.com/Mrs4s/go-cqhttp/releases/download/v1.0.0-rc1/go-cqhttp_linux_amd64.tar.gz -O ./cqhttp/go-cqhttp.tar.gz
cd cqhttp && tar xzf go-cqhttp.tar.gz go-cqhttp && rm go-cqhttp.tar.gz
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ feedparser
pyfiglet
colorama
schedule
pyyaml
git+https://github.com/kurtmckee/listparser@develop
Loading

0 comments on commit 76a9cd6

Please sign in to comment.