├── .idea ├── .gitignore ├── OPQBot_Plugins_Python.iml ├── deployment.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── sshConfigs.xml ├── vcs.xml └── webServers.xml ├── Arial.ttf ├── BotCore.py ├── README.md ├── Utils ├── .idea │ ├── Utils.iml │ ├── inspectionProfiles │ │ ├── Project_Default.xml │ │ └── profiles_settings.xml │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Arial.ttf ├── BaiduApi.py ├── SQLiteUtils.py ├── __init__.py ├── backgroud.jpg ├── ciyunUtil.py ├── forcast.jpg ├── simkai.ttf ├── utils.py └── weatherUtil.py ├── forcast.jpg ├── logs └── 2020-10-08_21-55-04_415979.log ├── morning ├── z01.jpg ├── z02.jpg ├── z03.jpg ├── z04.jpg ├── z05.jpg ├── z06.jpg ├── z07.jpg ├── z08.jpg ├── z09.jpg └── z10.jpg ├── sql ├── BotSQL.db └── setu.db ├── sucai ├── Arial.ttf └── forcast.jpg └── wyy ├── wyy01.jpeg ├── wyy02.jpeg ├── wyy03.jpeg ├── wyy04.gif ├── wyy05.gif ├── wyy06.jpg ├── wyy07.jpg ├── wyy08.jpg └── wyy09.jpg /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # 基于编辑器的 HTTP 客户端请求 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /.idea/OPQBot_Plugins_Python.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/deployment.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 35 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/sshConfigs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/webServers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | -------------------------------------------------------------------------------- /Arial.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/Arial.ttf -------------------------------------------------------------------------------- /BotCore.py: -------------------------------------------------------------------------------- 1 | import base64 2 | import datetime 3 | import json 4 | import os 5 | import random 6 | import re 7 | import threading 8 | import time 9 | from time import sleep 10 | 11 | import iotbot.decorators as deco 12 | import schedule 13 | from iotbot import IOTBOT, Action, GroupMsg, EventMsg 14 | 15 | from Utils import utils, SQLiteUtils, BaiduApi, ciyunUtil, weatherUtil 16 | 17 | bot = IOTBOT(1328382485, log_file=True) 18 | action = Action(bot, queue=True, queue_delay=2) 19 | 20 | 21 | def getGroupList(): 22 | GroupID = [] 23 | groupList = action.get_group_list() 24 | TroopList = groupList['TroopList'] 25 | for group in TroopList: 26 | GroupID.append(group['GroupId']) 27 | return GroupID 28 | 29 | 30 | def sent_wyy(): 31 | print("网抑云定时任务执行成功") 32 | file = os.listdir('wyy')[random.randint(0, 9)] 33 | groupList = getGroupList() 34 | text = SQLiteUtils.get_netease() 35 | with open('wyy//' + file, 'rb') as f: 36 | coding = base64.b64encode(f.read()).decode() 37 | for group in groupList: 38 | action.send_group_pic_msg(toUser=group, content=text, picBase64Buf=coding) 39 | sleep(1) 40 | return 41 | 42 | 43 | def sent_morning(): 44 | print("早安定时任务执行成功") 45 | file = os.listdir('morning')[random.randint(0, 10)] 46 | text = SQLiteUtils.get_morning() 47 | groupList = getGroupList() 48 | print(text) 49 | with open('morning//' + file, 'rb') as f: 50 | coding = base64.b64encode(f.read()).decode() 51 | for group in groupList: 52 | action.send_group_pic_msg(toUser=group, content=text, picBase64Buf=coding) 53 | sleep(1) 54 | return 55 | 56 | 57 | def sent_ciyun(): 58 | print("开始生成词云") 59 | today = datetime.date.today() 60 | oneday = datetime.timedelta(days=1) 61 | yesterday = (today - oneday).strftime("%Y%m%d") # 昨天的日期 62 | groupList = getGroupList() 63 | for group in groupList: 64 | filename = str(group) + '_' + yesterday + '.txt' 65 | pic_base64 = ciyunUtil.create_ciyun(filename) 66 | if pic_base64 is not None: 67 | action.send_group_pic_msg(toUser=group, content="昨日本群词云已生成,请查收~[PICFLAG]", picBase64Buf=pic_base64) 68 | # print(pic_base64) 69 | 70 | 71 | def schedule_test(): 72 | Content = time.asctime(time.localtime(time.time())) 73 | action.send_friend_text_msg(toUser=1127738407, content=Content) 74 | print("执行成功") 75 | 76 | 77 | def schedule_threading(): 78 | while True: 79 | schedule.run_pending() 80 | # print("refresh") 81 | sleep(1) 82 | 83 | 84 | @bot.on_group_msg 85 | def get_record(msg: GroupMsg): 86 | today = datetime.date.today().strftime("%Y%m%d") 87 | if msg.MsgType == 'TextMsg': 88 | filename = str(msg.FromGroupId) + '_' + today + '.txt' 89 | with open('record/' + filename, 'a+')as f: 90 | f.write(msg.Content + '\n') 91 | f.close() 92 | 93 | 94 | @bot.on_group_msg 95 | @deco.in_content("昨日词云") 96 | def send_ciyun(msg: GroupMsg): 97 | print("开始生成词云") 98 | today = datetime.date.today() 99 | oneday = datetime.timedelta(days=1) 100 | yesterday = (today - oneday).strftime("%Y%m%d") # 昨天的日期 101 | groupList = getGroupList() 102 | for group in groupList: 103 | filename = str(group) + '_' + yesterday + '.txt' 104 | pic_base64 = ciyunUtil.create_ciyun(filename) 105 | action.send_group_pic_msg(toUser=group, content="昨日本群词云已生成,请查收~[PICFLAG]", picBase64Buf=pic_base64) 106 | return 107 | 108 | 109 | @bot.on_group_msg 110 | @deco.in_content("色图") 111 | def send_setu(msg: GroupMsg): 112 | action.send_group_pic_msg(toUser=msg.FromGroupId, content='30S后销毁该消息,请快点冲,谢谢', 113 | picUrl='http://127.0.0.1:8080/getContent') 114 | 115 | 116 | @bot.on_group_msg 117 | @deco.in_content("(.*?)市天气") 118 | def send_waether(msg: GroupMsg): 119 | action.send_group_text_msg(toUser=msg.FromGroupId, content='正在查询中,请稍后······') 120 | pattern = re.compile(r'(.*?)市天气') 121 | m = pattern.match(msg.Content) 122 | city = m.group(1) 123 | weather = utils.GetWeather(city) 124 | File_name = weatherUtil.Draw(weather) 125 | with open('weather_pic/' + File_name, 'rb')as f: 126 | coding = base64.b64encode(f.read()).decode() 127 | action.send_group_pic_msg(toUser=msg.FromGroupId, picBase64Buf=coding) 128 | 129 | 130 | @bot.on_group_msg 131 | @deco.in_content("card(.*?)") 132 | def send_waether_card(msg: GroupMsg): 133 | pattern = re.compile(r'card(.*?)') 134 | m = pattern.match(msg.Content) 135 | city = m.group(1) 136 | weather = utils.GetWeather(city) 137 | File_name = weatherUtil.Draw(weather) 138 | with open('weather_pic/' + File_name, 'rb')as f: 139 | coding = base64.b64encode(f.read()).decode() 140 | action.send_group_pic_msg(toUser=msg.FromGroupId, picBase64Buf=coding) 141 | 142 | 143 | @bot.on_group_msg 144 | @deco.in_content("赞我") 145 | def send_like(msg: GroupMsg): 146 | UserUin = msg.FromUserId 147 | if UserUin != 1328382485: 148 | action.send_group_text_msg(toUser=msg.FromGroupId, content=msg.FromNickName + ',正在赞你,请稍后') 149 | for i in range(1, 50): 150 | action.like(userid=UserUin) 151 | action.send_group_text_msg(toUser=msg.FromGroupId, content=msg.FromNickName + ',赞完了') 152 | 153 | 154 | @bot.on_group_msg 155 | def revoke_msg(msg: GroupMsg): 156 | if msg.FromUserId == 1328382485 and msg.MsgType == 'PicMsg': 157 | Content = json.loads(msg.Content)['Content'] 158 | if Content == '30S后销毁该消息,请快点冲,谢谢': 159 | # print(Content) 160 | time.sleep(30) 161 | action.revoke_msg(msg.FromGroupId, msg.MsgSeq, msg.MsgRandom) 162 | 163 | 164 | @bot.on_group_msg 165 | @deco.in_content(".github") 166 | @deco.in_content("github") 167 | @deco.not_botself 168 | def send_proj(msg: GroupMsg): 169 | text = '本机器人源码:' + 'https://github.com/willyautoman/OPQBot_Plugins_Python' + '\n看后记得star一下哦' 170 | action.send_group_text_msg(toUser=msg.FromGroupId, content=text) 171 | 172 | 173 | @bot.on_group_msg 174 | @deco.in_content("彩虹屁") 175 | def send_chp(a: GroupMsg): 176 | text = utils.get_chp() 177 | print(text) 178 | action.send_group_text_msg(toUser=a.FromGroupId, content=text) 179 | 180 | 181 | @bot.on_group_msg 182 | def send_shanzhao(a: GroupMsg): 183 | if a.MsgType == 'PicMsg' and 'GroupPic' not in a.Content: 184 | Contents = json.loads(a.data.get('Content')) 185 | action.send_group_pic_msg(toUser=a.FromGroupId, content='震惊!居然有人敢在这个群里发闪照!', picUrl=Contents['Url'], 186 | fileMd5=Contents['FileMd5']) 187 | 188 | 189 | @bot.on_group_msg 190 | @deco.in_content("我想对你说") 191 | def send_voice(a: GroupMsg): 192 | file_name = BaiduApi.text2audio() 193 | with open(file_name, 'rb') as f: 194 | coding = base64.b64encode(f.read()) # 读取文件内容,转换为base64编码 195 | print('本地base64转码~') 196 | voice_base64 = coding.decode() 197 | action.send_group_voice_msg(toUser=a.FromGroupId, voiceBase64Buf=voice_base64) 198 | return 199 | 200 | 201 | @bot.on_group_msg 202 | @deco.in_content("QQ测运势") 203 | def send_qqcys(msg: GroupMsg): 204 | text = utils.get_cjx(msg) 205 | print(text) 206 | action.send_group_text_msg(toUser=msg.FromGroupId, content=text, atUser=msg.FromUserId) 207 | 208 | 209 | @bot.on_group_msg 210 | def send_xingzuo(a: GroupMsg): 211 | pattern = re.compile(r'(.*?座)(.*?)运势') 212 | m = pattern.match(a.Content) 213 | if m is not None: 214 | texts = utils.get_xzys(m.group(1), m.group(2)) 215 | print(texts) 216 | for text in texts: 217 | action.send_group_text_msg(toUser=a.FromGroupId, content=text) 218 | 219 | 220 | # 新成员入群欢迎 221 | @bot.on_event 222 | def on_people_in_group(event: EventMsg): 223 | if event.MsgType == 'ON_EVENT_GROUP_JOIN' and event.FromUin == '757360354': # 此处填入需要发送欢迎的群号 224 | 225 | UserName = event.EventData['UserName'] 226 | UserID = event.EventData['UserID'] 227 | with open('bqb//' + str(random.randint(1, 161)) + '.jpg', 'rb') as f: 228 | coding = base64.b64encode(f.read()).decode() 229 | text = "\n[表情109][表情109]欢迎萌新:%s入群[表情109][表情109]\n入群请先修改群名片(如:ubuntu-XXX)\n 有什么问题请尽管提问,老撕鸡们会很热♂情的帮你们解答的" % UserName 230 | action.send_group_pic_msg(toUser=event.FromUin, content=text, atUser=UserID, picBase64Buf=coding) 231 | 232 | 233 | @bot.on_group_msg 234 | @deco.in_content("获取个人信息") 235 | def get_detail(msg: GroupMsg): 236 | print(action.get_user_info(userID=msg.FromUserId)) 237 | print(type(action.get_user_info(userID=msg.FromUserId))) 238 | 239 | 240 | if __name__ == "__main__": 241 | schedule.every().day.at("00:00").do(sent_wyy) 242 | schedule.every().day.at("08:00").do(sent_ciyun) 243 | schedule.every().day.at("07:00").do(sent_morning) 244 | thread_schedule = threading.Thread(target=schedule_threading) 245 | thread_schedule.start() 246 | bot.run() 247 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OPQBot_plugins 2 | 3 | # 前言 4 | **历时断断续续的一个多月,总算把自己想象中的机器人差不多构建成功了,大概集成了有零零碎碎十多个功能,一会儿会逐个介绍,虽然多数都是调用的第三方的API,但是也总算是完成了一个比较完整的项目了** 5 | 6 | ---------- 7 | 8 | # 功能介绍 9 | 1. **关键词回复类** 10 | - 彩虹屁 11 | - 文案 12 | - 毒鸡汤 13 | (以上三个API均使用的 “shadiao.app”的接口,以上接口均需要向(shadiaoapp@gmail.com)发送邮件,以获取Token) 14 | 15 | 2. **闪照还原功能** 16 | 本功能主要用于将群里发的闪照还原为普通照片,但是直接还原照片有失败的风险,建议此处可以将闪照保存后再发送出去 17 | 18 | 3. **“我想对你说”文字转语音功能** 19 | 这个我是用上面的“彩虹屁”接口配合百度的文字转语音API进行的语音转换 20 | 21 | *注意:百度API的token有过期机制,需要每30天对token进行更新,我将我的'client_id'和'client_secret'已经删除,但是存在数据库的access_token还有效,大约会在2020年9月8日过期,可以先行适用后再去申请自己的API* 22 | 23 | 4. **星座测运势** 24 | 这个是使用的聚合数据的接口进行二次开发,主要可以实现12星座的(今日/明日/本周/本月/今年)运势,但由于OPQ系统限制,目前无法发送长文本,所以年运势可能无法发送,后期可能会升级为以图片的格式发送(咕咕咕)。 25 | 26 | 5. **智(zhi)能(zhang)聊天** 27 | 本项目使用的是github上的一个项目,经过部分修改后集成到机器人的功能内,目前触发概率为5%,如果需要提高或降低,请自行修改源代码 28 | 29 | 6. **定时任务模块** 30 | 目前本模块总共有三个定时任务 31 | - 早安问候(7:00)发送图片和文字,开启温暖的一天 32 | - 网抑云(0:00)每天准时陪你一起抑郁 33 | - 昨日词云(8:00) 每天上午8:00,会总结过去一天的群内聊天记录,并只作为词云后发送至群内。 34 | 35 | 7. **涩图** 36 | emmm,不必多说,涩图数据库在我另一个仓库内,放入项目内的sql文件夹即可,地址: 37 | 38 | ---------- 39 | 40 | # 食用方法 41 | 1. 因某些库为Linux专用库,所以本项目需在Linux环境下运行 42 | 2. 进入项目目录后,输入 pip install -r requirements.txt 安装依赖 43 | 3. 使用screen或Nohup等后台进程程序 运行BotCore.py即可 44 | 45 | ---------- 46 | 47 | # 鸣谢 48 | OPQBot们的开发者,让我有机会可以使用QQ机器人,项目地址:(https://github.com/OPQBOT/OPQ) 49 | python--iotbot 框架的开发者,让我可以不用花费心思在其他方面,而可以专心书写功能代码,项目地址:(https://github.com/xiyaowong/python--iotbot) 50 | Chinese-Chatbot-PyTorch-Implementation 聊天机器人的开发者,项目地址:(https://github.com/Doragd/Chinese-Chatbot-PyTorch-Implementation) 51 | 52 | ---------- 53 | # 结语 54 | ## 虽然还有一大部分功能没有完成,但是各位大佬,介不介意给个Star呢?😭 55 | 56 | ---------- 57 | 58 | # 更新日志: 59 | 2020-8-23 22:39 通过把星座的文字拆解为两条消息,实现了长消息发送 60 | 61 | 62 | 2020-9-6 13:47 新增查询七日天气功能,通过群内发送“****市天气”触发 63 | 64 | 2020-10-02 1:11 1️⃣更换了发送setu的图源,改为采用我自制的API获取图片发送2️⃣删除了聊天插件文件夹3️⃣更新了iotbot的版本,此版本与之前的版本有部分命令不兼容,必须进行更新(pip install --upgrade python-iotbot)5️⃣重新生成了requirements文件,减少对部分库的依赖6️⃣增加了消息队列设置,防止因发送消息过快而被TX屏蔽 65 | 66 | 2020-10-08 22:00 添加了QQ名片赞功能 -------------------------------------------------------------------------------- /Utils/.idea/Utils.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Utils/.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | -------------------------------------------------------------------------------- /Utils/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /Utils/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /Utils/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Utils/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 1598169371006 28 | 33 | 34 | 35 | 36 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Utils/Arial.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/Utils/Arial.ttf -------------------------------------------------------------------------------- /Utils/BaiduApi.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from Utils import utils, SQLiteUtils 3 | import time 4 | import os 5 | def get_token(): 6 | url = 'https://openapi.baidu.com/oauth/2.0/token' 7 | params = { 8 | 'grant_type': 'client_credentials', 9 | 'client_id': 'IpskvYso5W3E4kPV6dVMHH3N', 10 | 'client_secret': '1an3P3dSQC6Qxh5Mh2eU86Z4MsFP33Ak' 11 | } 12 | res = requests.get(url=url, params=params) 13 | return res.json() 14 | 15 | 16 | def is_token_expired(): 17 | data = SQLiteUtils.get_token() 18 | get_token_time = data[2] 19 | current_time = int(time.time()) 20 | interval = (current_time - get_token_time)/3600/24 21 | if interval <= 30: 22 | return data[1] 23 | else: 24 | new_data = get_token() 25 | new_data['get_token_time'] = current_time 26 | SQLiteUtils.refresh_token(new_data) 27 | return new_data['access_token'] 28 | 29 | 30 | 31 | def text2audio(): 32 | file_name = os.getcwd() +'/audioSave/'+ str(int(time.time())) + '.mp3' 33 | text = utils.get_chp() 34 | access_token = is_token_expired() 35 | url = 'https://tsn.baidu.com/text2audio' 36 | params = { 37 | 'tex' : text.encode('utf-8'), 38 | 'tok' : access_token, 39 | 'cuid': 'bfb934374a1c4625ada18fc366111c4d', 40 | 'ctp' : 1, 41 | 'lan' : 'zh', 42 | 'per' : 4 43 | } 44 | res = requests.get(url=url,params=params) 45 | with open(file_name,'wb') as f: 46 | f.write(res.content) 47 | return file_name 48 | 49 | 50 | if __name__ == '__main__': 51 | print(is_token_expired()) 52 | -------------------------------------------------------------------------------- /Utils/SQLiteUtils.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | import random 3 | import os 4 | def on_connect(): 5 | SQLPath = 'sql/BotSQL.db' 6 | # print(SQLPath) 7 | conn = sqlite3.connect(SQLPath) 8 | cursor = conn.cursor() 9 | 10 | return cursor 11 | 12 | 13 | def get_morning(): 14 | c = on_connect() 15 | c.execute("select text from morning where ID=?", (random.randint(1, 117),)) 16 | text = c.fetchone() 17 | return text[0] 18 | 19 | 20 | def get_netease(): 21 | c = on_connect() 22 | c.execute("select * from netease where ID=?", (random.randint(1, 25),)) 23 | text = c.fetchone() 24 | return text[1] 25 | 26 | 27 | def get_token(): 28 | c = on_connect() 29 | c.execute("select * from BaiduApi order by id desc limit 0,1") 30 | return c.fetchone() 31 | 32 | def refresh_token(data): 33 | c = on_connect() 34 | c.execute("INSERT INTO BaiduApi\(\"access_token\", \"get_time\"\) VALUES (?,?)",(data['access_token'], data['get_token_time'])) 35 | return 36 | 37 | 38 | if __name__ == '__main__': 39 | print(get_netease()) 40 | 41 | -------------------------------------------------------------------------------- /Utils/__init__.py: -------------------------------------------------------------------------------- 1 | from Utils import * 2 | -------------------------------------------------------------------------------- /Utils/backgroud.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/Utils/backgroud.jpg -------------------------------------------------------------------------------- /Utils/ciyunUtil.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import jieba # 分词 3 | import matplotlib.pyplot as plt # 数据可视化 4 | import numpy as np # 科学计算 5 | from PIL import Image # 处理图片 6 | from wordcloud import WordCloud, ImageColorGenerator, STOPWORDS # 词云 7 | from io import BytesIO 8 | import base64 9 | import os 10 | def create_ciyun(file_name): 11 | # 打开文本 12 | if os.path.exists('record/' + file_name): 13 | textfile = open('record/' + file_name, encoding='utf-8').read() # 读取文本内容 14 | wordlist = jieba.cut_for_search(textfile) 15 | space_list = " ".join(wordlist) # 链接词语 16 | backgroud = np.array(Image.open("Utils/backgroud.jpg")) # 背景图片 17 | mywordcloud = WordCloud(mask=backgroud, # 写字用的背景图,从背景图取颜色 18 | stopwords=STOPWORDS, # 停止的默认词语 19 | font_path="Utils/simkai.ttf", # 字体 20 | max_font_size=200, # 最大字体尺寸 21 | random_state=50, # 随机角度 22 | scale=2).generate(space_list) 23 | plt.imshow(mywordcloud) # 显示词云 24 | plt.axis("off") # 关闭保存 25 | save_file = BytesIO() 26 | plt.savefig(save_file, format='png') 27 | 28 | # 转换base64并以utf8格式输出 29 | file_base64 = base64.b64encode(save_file.getvalue()).decode() 30 | return file_base64 31 | 32 | -------------------------------------------------------------------------------- /Utils/forcast.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/Utils/forcast.jpg -------------------------------------------------------------------------------- /Utils/simkai.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/Utils/simkai.ttf -------------------------------------------------------------------------------- /Utils/utils.py: -------------------------------------------------------------------------------- 1 | import json 2 | import random 3 | import re 4 | import requests 5 | import os 6 | from urllib.parse import quote 7 | token = "willyautoman" 8 | 9 | def get_nmsl(): 10 | url = 'https://nmsl.shadiao.app/api.php?from=' + token 11 | res = requests.get(url=url).text 12 | return res 13 | 14 | 15 | def get_nmsl_max(): 16 | url = 'https://nmsl.shadiao.app/api.php?level=max&from=' + token 17 | res = requests.get(url=url).text 18 | return res 19 | 20 | 21 | def get_chp(): 22 | url = 'https://chp.shadiao.app/api.php?from=' + token 23 | res = requests.get(url=url).text 24 | return res 25 | 26 | 27 | def get_pyq(): 28 | url = 'https://pyq.shadiao.app/api.php?from=' + token 29 | res = requests.get(url=url).text 30 | return res 31 | 32 | def GetWeather(city): 33 | city_utf = quote(city) 34 | url = 'http://apis.juhe.cn/simpleWeather/query?city={}&key=7097f3d63ccb43ea8a17a4b2d788af90'.format(city_utf) 35 | reply = requests.post(url) 36 | text = reply.json() 37 | return text 38 | 39 | def get_djt(): 40 | url = 'https://du.shadiao.app/api.php?from=' + token 41 | res = requests.get(url=url).text 42 | return res 43 | 44 | 45 | def get_cjx(msg): 46 | QQ = msg.FromUserId 47 | url = 'http://japi.juhe.cn/qqevaluate/qq?key=c57c2f6ccb2bc93244c763bd399987df&qq='+str(QQ) 48 | res = requests.get(url=url) 49 | result = json.loads(res.text) 50 | conclusion = result['result']['data']['conclusion'] 51 | analysis = result['result']['data']['analysis'] 52 | text = '被测QQ号:'+str(QQ)+'\r\n' + '测试结论:' + conclusion + '\r\n' + '结果分析:' + analysis + "" 53 | return text 54 | 55 | 56 | def get_xzys(xing_zuo, dtype): 57 | if dtype == '今日': 58 | type = 'today' 59 | elif dtype == '明日': 60 | type = 'tomorrow' 61 | elif dtype == '周': 62 | type = 'week' 63 | elif dtype == '月': 64 | type = 'month' 65 | elif dtype == '年': 66 | type = 'year' 67 | else: 68 | return "使用说明:请输入**座今日/明日/周/月/年运势(例如:狮子座今日运势、狮子座周运势等)" 69 | url = 'http://web.juhe.cn:8080/constellation/getAll' 70 | params = { 71 | 'key': '894dba8749130fb4163ec298cecca934', 72 | 'consName': xing_zuo, 73 | 'type': type 74 | } 75 | res = requests.get(url=url,params=params) 76 | result = json.loads(res.text) 77 | text = list() 78 | if dtype == '今日' or dtype == '明日': 79 | text.append('星座名称: ' + result['name'] + '\r\n' + '日期: ' + result['datetime'] + '\r\n' + \ 80 | '综合指数: ' + result['all'] + '\r\n' + '健康指数: ' + result['health'] + '\r\n' + \ 81 | '爱情指数: ' + result['love'] + '\r\n' + '财运指数: ' + result['money'] + '\r\n' + \ 82 | '工作指数: ' + result['work'] + '\r\n' +'幸运色: ' + result['color'] + '\r\n' + \ 83 | '幸运数字: ' + str(result['number']) + '\r\n'+ '概述: ' + result['summary']) 84 | elif dtype == '周': 85 | text.append('星座名称: ' + result['name'] + '\r\n' + '日期: ' + result['date'] + '\r\n' + \ 86 | '学业/求职: ' + result['job'] + '\r\n' + '爱情: ' + result['love'] + '\r\n' + \ 87 | '财运: ' + result['money'] + '\r\n' + '工作: ' + result['work']) 88 | elif dtype == '月': 89 | text.append('星座名称: ' + result['name'] + '\r\n'+ '日期: ' + result['date'] + '\r\n' + result['all'] + '\r\n' + \ 90 | result['health']) 91 | text.append(result['love'] + '\r\n' + result['money'] + '\r\n' + \ 92 | result['work']) 93 | elif dtype == '年': 94 | text.append('星座名称: ' + result['name'] + '\r\n'+ '日期: ' + result['date'] + '\r\n' + \ 95 | '年度密码:①概述: ' + result['mima']['info'] + '\r\n' + '②说明: ' + result['mima']['text'][0]) 96 | text.append(result['career'][0] + '\r\n' + result['love'][0] + '\r\n' + result['health'][0] + '\r\n' + \ 97 | result['finance'][0]) 98 | print(res.text) 99 | return text 100 | 101 | 102 | def get_comment(): 103 | res = requests.get('https://www.mouse123.cn/api/163/api.php').json() 104 | text = res['comment_content'] 105 | return text 106 | 107 | 108 | if __name__ == '__main__': 109 | # sent_wyy() 110 | pattern = re.compile(r'#(.*?座)(.*?)运势') 111 | m = pattern.match("#白羊座今日运势") 112 | if m is not None: 113 | get_xzys(m.group(1), m.group(2)) 114 | else: 115 | print("参数错误") 116 | # get_comment() 117 | -------------------------------------------------------------------------------- /Utils/weatherUtil.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import time 3 | from PIL import Image,ImageFont,ImageDraw 4 | 5 | 6 | def Draw(det): 7 | font = ImageFont.truetype('sucai/Arial.ttf', 60) 8 | font_fu = ImageFont.truetype('sucai/Arial.ttf', 55) 9 | times = time.localtime() 10 | title = '{}年{}月{}日 {}'.format(times[0], times[1], times[2], det['result']['city']) 11 | # 打开底版图片 12 | imageFile = "sucai/forcast.jpg" 13 | im1 = Image.open(imageFile) 14 | # 在图片上添加日期、城市 15 | draw = ImageDraw.Draw(im1) 16 | draw.text((15, 50), title, (0, 0, 0), font=font) 17 | draw = ImageDraw.Draw(im1) 18 | 19 | # 在图片中添加实时天气 20 | draw = ImageDraw.Draw(im1) 21 | draw.text((200, 472), det['result']['realtime']['info'], (0, 0, 0), font=font) 22 | draw.text((200, 590), det['result']['realtime']['temperature'] + '°C', (0, 0, 0), font=font) 23 | draw.text((200, 703), det['result']['realtime']['humidity'] + '%', (0, 0, 0), font=font) 24 | draw.text((200, 816), det['result']['realtime']['direct'], (0, 0, 0), font=font) 25 | draw.text((200, 929), det['result']['realtime']['power'], (0, 0, 0), font=font) 26 | draw.text((200, 1042), det['result']['realtime']['aqi'], (0, 0, 0), font=font) 27 | draw = ImageDraw.Draw(im1) 28 | 29 | # 在图片中添加天气预报(每五行为一天) 30 | draw.text((710, 195), det['result']['future'][0]['date'], (0, 0, 0), font=font) 31 | draw.text((790, 285), det['result']['future'][0]['weather'], (0, 0, 0), font=font_fu) 32 | draw.text((790, 395), det['result']['future'][0]['temperature'].replace('℃', '°C'), (0, 0, 0), font=font_fu) 33 | draw.text((790, 505), det['result']['future'][0]['direct'], (0, 0, 0), font=font_fu) 34 | draw.text((790, 615), det['result']['future'][0]['wid']['day'] + '级', (0, 0, 0), font=font_fu) 35 | 36 | draw.text((1210, 195), det['result']['future'][1]['date'], (0, 0, 0), font=font) 37 | draw.text((1300, 285), det['result']['future'][1]['weather'], (0, 0, 0), font=font_fu) 38 | draw.text((1300, 395), det['result']['future'][1]['temperature'].replace('℃', '°C'), (0, 0, 0), font=font_fu) 39 | draw.text((1300, 505), det['result']['future'][1]['direct'], (0, 0, 0), font=font_fu) 40 | draw.text((1300, 615), det['result']['future'][1]['wid']['day'] + '级', (0, 0, 0), font=font_fu) 41 | 42 | draw.text((1710, 195), det['result']['future'][2]['date'], (0, 0, 0), font=font) 43 | draw.text((1810, 285), det['result']['future'][2]['weather'], (0, 0, 0), font=font_fu) 44 | draw.text((1810, 395), det['result']['future'][2]['temperature'].replace('℃', '°C'), (0, 0, 0), font=font_fu) 45 | draw.text((1810, 505), det['result']['future'][2]['direct'], (0, 0, 0), font=font_fu) 46 | draw.text((1810, 615), det['result']['future'][2]['wid']['day'] + '级', (0, 0, 0), font=font_fu) 47 | 48 | draw.text((710, 715), det['result']['future'][3]['date'], (0, 0, 0), font=font) 49 | draw.text((790, 805), det['result']['future'][3]['weather'], (0, 0, 0), font=font_fu) 50 | draw.text((790, 915), det['result']['future'][3]['temperature'].replace('℃', '°C'), (0, 0, 0), font=font_fu) 51 | draw.text((790, 1025), det['result']['future'][3]['direct'], (0, 0, 0), font=font_fu) 52 | draw.text((790, 1135), det['result']['future'][3]['wid']['day'] + '级', (0, 0, 0), font=font_fu) 53 | 54 | draw.text((1210, 715), det['result']['future'][4]['date'], (0, 0, 0), font=font) 55 | draw.text((1300, 805), det['result']['future'][4]['weather'], (0, 0, 0), font=font_fu) 56 | draw.text((1300, 915), det['result']['future'][4]['temperature'].replace('℃', '°C'), (0, 0, 0), font=font_fu) 57 | draw.text((1300, 1025), det['result']['future'][4]['direct'], (0, 0, 0), font=font_fu) 58 | draw.text((1300, 1135), det['result']['future'][4]['wid']['day'] + '级', (0, 0, 0), font=font_fu) 59 | today = datetime.date.today().strftime("%Y%m%d") 60 | name = today + '{}.jpg'.format(det['result']['city']) 61 | im1.save('weather_pic/'+name) 62 | return name 63 | -------------------------------------------------------------------------------- /forcast.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/forcast.jpg -------------------------------------------------------------------------------- /logs/2020-10-08_21-55-04_415979.log: -------------------------------------------------------------------------------- 1 | 2020-10-08 21:55 INFO Connecting to the server... 2 | 2020-10-08 21:55 ERROR 连接失败 3 | Traceback (most recent call last): 4 | 5 | File "D:\Program Files\JetBrains\PyCharm 2020.1.2\plugins\python\helpers\pydev\pydevd.py", line 2131, in 6 | main() 7 | └ 8 | 9 | File "D:\Program Files\JetBrains\PyCharm 2020.1.2\plugins\python\helpers\pydev\pydevd.py", line 2122, in main 10 | globals = debugger.run(setup['file'], None, None, is_module) 11 | │ │ │ └ False 12 | │ │ └ {'port': 5275, 'vm_type': None, 'client': '127.0.0.1', 'server': False, 'DEBUG_RECORD_SOCKET_READS': False, 'multiproc': True... 13 | │ └ 14 | └ <__main__.PyDB object at 0x000001B125165A48> 15 | 16 | File "D:\Program Files\JetBrains\PyCharm 2020.1.2\plugins\python\helpers\pydev\pydevd.py", line 1431, in run 17 | return self._exec(is_module, entry_point_fn, module_name, file, globals, locals) 18 | │ │ │ │ │ │ │ └ {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader obj... 19 | │ │ │ │ │ │ └ {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader obj... 20 | │ │ │ │ │ └ 'F:/PycharmProjects/OPQBot_Plugins_Python/BotCore.py' 21 | │ │ │ │ └ None 22 | │ │ │ └ '' 23 | │ │ └ False 24 | │ └ 25 | └ <__main__.PyDB object at 0x000001B125165A48> 26 | 27 | File "D:\Program Files\JetBrains\PyCharm 2020.1.2\plugins\python\helpers\pydev\pydevd.py", line 1438, in _exec 28 | pydev_imports.execfile(file, globals, locals) # execute the script 29 | │ │ │ │ └ {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader obj... 30 | │ │ │ └ {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader obj... 31 | │ │ └ 'F:/PycharmProjects/OPQBot_Plugins_Python/BotCore.py' 32 | │ └ 33 | └ 43 | bot.run() 44 | │ └ 45 | └ IOTBOT <1328382485> 46 | 47 | > File "D:\Program Files\Python37\lib\site-packages\iotbot\client.py", line 192, in run 48 | self.socketio.connect(f'{self.host}:{self.port}', transports=['websocket']) 49 | │ │ └ 50 | │ └ 51 | └ IOTBOT <1328382485> 52 | 53 | File "D:\Program Files\Python37\lib\site-packages\socketio\client.py", line 282, in connect 54 | six.raise_from(exceptions.ConnectionError(exc.args[0]), None) 55 | │ │ │ └ 56 | │ │ └ 57 | │ └ 58 | └ 59 | 60 | File "", line 3, in raise_from 61 | 62 | socketio.exceptions.ConnectionError: Connection error 63 | -------------------------------------------------------------------------------- /morning/z01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/morning/z01.jpg -------------------------------------------------------------------------------- /morning/z02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/morning/z02.jpg -------------------------------------------------------------------------------- /morning/z03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/morning/z03.jpg -------------------------------------------------------------------------------- /morning/z04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/morning/z04.jpg -------------------------------------------------------------------------------- /morning/z05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/morning/z05.jpg -------------------------------------------------------------------------------- /morning/z06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/morning/z06.jpg -------------------------------------------------------------------------------- /morning/z07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/morning/z07.jpg -------------------------------------------------------------------------------- /morning/z08.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/morning/z08.jpg -------------------------------------------------------------------------------- /morning/z09.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/morning/z09.jpg -------------------------------------------------------------------------------- /morning/z10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/morning/z10.jpg -------------------------------------------------------------------------------- /sql/BotSQL.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/sql/BotSQL.db -------------------------------------------------------------------------------- /sql/setu.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/sql/setu.db -------------------------------------------------------------------------------- /sucai/Arial.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/sucai/Arial.ttf -------------------------------------------------------------------------------- /sucai/forcast.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/sucai/forcast.jpg -------------------------------------------------------------------------------- /wyy/wyy01.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/wyy/wyy01.jpeg -------------------------------------------------------------------------------- /wyy/wyy02.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/wyy/wyy02.jpeg -------------------------------------------------------------------------------- /wyy/wyy03.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/wyy/wyy03.jpeg -------------------------------------------------------------------------------- /wyy/wyy04.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/wyy/wyy04.gif -------------------------------------------------------------------------------- /wyy/wyy05.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/wyy/wyy05.gif -------------------------------------------------------------------------------- /wyy/wyy06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/wyy/wyy06.jpg -------------------------------------------------------------------------------- /wyy/wyy07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/wyy/wyy07.jpg -------------------------------------------------------------------------------- /wyy/wyy08.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/wyy/wyy08.jpg -------------------------------------------------------------------------------- /wyy/wyy09.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willyautoman/OPQBot_Plugins_Python/53c8b83372568bef99203e27d08b3a655a412863/wyy/wyy09.jpg --------------------------------------------------------------------------------