Skip to content

Commit

Permalink
update mail
Browse files Browse the repository at this point in the history
  • Loading branch information
firmianay committed Oct 11, 2022
1 parent a84bf95 commit aeb2882
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
QQ_KEY: ${{ secrets.QQ_KEY }}
TELEGRAM_KEY: ${{ secrets.TELEGRAM_KEY }}
MAIL_KEY: ${{ secrets.MAIL_KEY }}
MAIL_RECEIVER: ${{ secrets.MAIL_RECEIVER }}
run: python3 yarb.py

- name: Commit
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ $ nohup ./yarb.py --cron 11:00 > run.log 2>&1 &

目前支持的推送机器人及对应的 secrets:

- [邮件机器人](https://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256)`MAIL_KEY`(需要申请授权码)(订阅较多时推荐)
- [邮件机器人](https://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256)
- `MAIL_KEY`(需要申请授权码,订阅较多时推荐)
- `MAIL_RECEIVER`(接收人,以“,”分隔)
- [飞书群机器人](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`
Expand Down
7 changes: 4 additions & 3 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,10 @@ def kill_server(cls):
class mailBot:
"""邮件机器人
"""
def __init__(self, sender, passwd, receiver: list, server='') -> None:
def __init__(self, sender, passwd, receiver: str, fromwho='', server='') -> None:
self.sender = sender
self.receiver = receiver
self.fromwho = fromwho or sender
server = server or self.get_server(sender)

self.smtp = smtplib.SMTP_SSL(server)
Expand Down Expand Up @@ -239,8 +240,8 @@ def send(self, text: str):

msg = MIMEText(text, 'html')
msg['Subject'] = Header(f'每日安全资讯({today})')
msg['From'] = f'security-bot <{self.sender}>'
msg['To'] = ','.join(self.receiver)
msg['From'] = self.fromwho
msg['To'] = self.receiver

try:
self.smtp.sendmail(self.sender, self.receiver, msg.as_string())
Expand Down
4 changes: 3 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@
"mail": {
"enabled": true,
"secrets": "MAIL_KEY",
"secrets_receiver": "MAIL_RECEIVER",
"address": "[email protected]",
"server": "smtp.163.com",
"receiver": ["[email protected]"],
"from": "security-bot <[email protected]>",
"receiver": "[email protected],[email protected]",
"key": "xxxxxxxxxx"
}
}
Expand Down
3 changes: 2 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

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
sudo apt-get install -y wget
wget -q https://github.com/Mrs4s/go-cqhttp/releases/download/v1.0.0-rc2/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 @@ -7,4 +7,5 @@ pyyaml
python-telegram-bot
PySocks
pyrate-limiter
poetry
git+https://github.com/kurtmckee/listparser
20 changes: 9 additions & 11 deletions yarb.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def parseThread(url: str, proxy_url=''):
if pubday == yesterday:
item = {entry.title: entry.link}
print(item)
result.update(item)
result |= item
Color.print_success(f'[+] {title}\t{url}\t{len(result.values())}/{len(r.entries)}')
except Exception as e:
Color.print_failed(f'[-] failed: {url}')
Expand All @@ -107,21 +107,20 @@ def init_bot(conf: dict, proxy_url=''):
bots = []
for name, v in conf.items():
if v['enabled']:
key = os.getenv(v['secrets'])
if not key:
key = v['key']
key = os.getenv(v['secrets']) or v['key']

if name == 'qq':
if name == 'mail':
receiver = os.getenv(v['secrets_receiver']) or v['receiver']
bot = globals()[f'{name}Bot'](v['address'], key, receiver, v['from'], v['server'])
bots.append(bot)
elif name == 'qq':
bot = globals()[f'{name}Bot'](v['group_id'])
if bot.start_server(v['qq_id'], key):
bots.append(bot)
elif name == 'telegram':
bot = globals()[f'{name}Bot'](key, v['chat_id'], proxy_url)
if bot.test_connect():
bots.append(bot)
elif name == 'mail':
bot = globals()[f'{name}Bot'](v['address'], key, v['receiver'], v['server'])
bots.append(bot)
else:
bot = globals()[f'{name}Bot'](key, proxy_url)
bots.append(bot)
Expand Down Expand Up @@ -178,9 +177,6 @@ def job(args):
with open(config_path) as f:
conf = json.load(f)

proxy_bot = conf['proxy']['url'] if conf['proxy']['bot'] else ''
bots = init_bot(conf['bot'], proxy_bot)

proxy_rss = conf['proxy']['url'] if conf['proxy']['rss'] else ''
feeds = init_rss(conf['rss'], args.update, proxy_rss)

Expand Down Expand Up @@ -210,6 +206,8 @@ def job(args):
update_today(results)

# 推送文章
proxy_bot = conf['proxy']['url'] if conf['proxy']['bot'] else ''
bots = init_bot(conf['bot'], proxy_bot)
for bot in bots:
bot.send(bot.parse_results(results))

Expand Down

0 comments on commit aeb2882

Please sign in to comment.