├── simsimi ├── README.md ├── __init__.py └── simsimi.py ├── README.md ├── tuling └── __init__.py ├── help └── __init__.py ├── chatter └── __init__.py ├── .gitignore └── LICENSE /simsimi/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /simsimi/__init__.py: -------------------------------------------------------------------------------- 1 | from .simsimi import * 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wechat-plugins 2 | Collection of plugins for https://github.com/dongweiming/wechat-admin 3 | 4 | ### plugin list 5 | 6 | | 插件名 | 描述 | 7 | | ------| ------ | 8 | | Simsimi | 小黄鸡哟哟 | 9 | | Help | 帮助插件,根据所有插件的description属性的内容生成 | 10 | | Tuling | 图灵机器人,@群主即可开聊 | 11 | | Chatter | 基于机器学习的ChatterBot 和群主私聊 | 12 | -------------------------------------------------------------------------------- /tuling/__init__.py: -------------------------------------------------------------------------------- 1 | from flask import current_app 2 | from wxpy import Tuling 3 | from wxpy.api.consts import TEXT 4 | 5 | 6 | description = """ 7 | 图灵机器人,触发条件: @群主 即可 8 | """ 9 | 10 | try: 11 | from config import TULING_KEY 12 | except: 13 | TULING_KEY = '5194eb3277ec4a86b404695f8f991706' 14 | 15 | tuling = Tuling(api_key=TULING_KEY) 16 | 17 | 18 | class TulingPlugin: 19 | name = 'TulingPlugin' 20 | version = '0.1' 21 | msg_types = TEXT 22 | description = description 23 | 24 | @classmethod 25 | def main(cls, msg): 26 | nick_name = current_app.nick_name if current_app else None 27 | if nick_name is not None: 28 | at = '@{}'.format(nick_name) 29 | text = msg.text 30 | if at in text: 31 | msg.text = text.replace(at, '').replace('\u2005', '').strip() 32 | tuling.do_reply(msg) 33 | return '' # do_reply已经是回应了,所以不会返回再回应一次 34 | 35 | 36 | def export(): 37 | return TulingPlugin 38 | -------------------------------------------------------------------------------- /help/__init__.py: -------------------------------------------------------------------------------- 1 | from flask import current_app 2 | from wxpy import Friend 3 | from wxpy.api.consts import TEXT 4 | 5 | description = """ 6 | 帮助信息,触发条件: "help" 7 | """ 8 | 9 | help_text = """ 10 | 目前支持如下插件: 11 | {} 12 | """ 13 | 14 | def format_desc(plugin, prefix=' '): 15 | name = plugin.name.replace('Plugin', '') 16 | desc = getattr(plugin, 'description', '').strip() 17 | desc = ('\n' + prefix).join(desc.split('\n')) 18 | return '{name}:\n{prefix}{desc}'.format( 19 | name=name, prefix=prefix, desc=desc 20 | ) 21 | 22 | 23 | class HelpPlugin: 24 | name = 'HelpPlugin' 25 | version = '0.1' 26 | chats = Friend 27 | msg_types = TEXT 28 | patterns = ['help'] 29 | exclusive = True 30 | description = description 31 | 32 | @classmethod 33 | def main(cls, msg): 34 | plugin_modules = current_app.plugin_modules if current_app else [] 35 | docs = [] 36 | for plugin in plugin_modules.values(): 37 | docs.append(format_desc(plugin)) 38 | return help_text.format('\n'.join(docs)) 39 | 40 | 41 | def export(): 42 | return HelpPlugin 43 | -------------------------------------------------------------------------------- /chatter/__init__.py: -------------------------------------------------------------------------------- 1 | from wxpy import Friend 2 | from wxpy.api.consts import TEXT 3 | 4 | description = """ 5 | ChatterBot,触发条件: 和群主私聊 6 | """ 7 | 8 | try: 9 | from chatterbot import ChatBot 10 | except ImportError: 11 | raise 12 | print('Chatterbot is not available') 13 | class ChatBot: 14 | def __init__(self, *args, **kwargs): 15 | pass 16 | 17 | def train(self, corpus): 18 | return '' 19 | 20 | def get_response(self, input_item, session_id=None): 21 | return '' 22 | 23 | 24 | wechat = ChatBot('wechat', 25 | database_uri='sqlite:///wechat.db', 26 | trainer='chatterbot.trainers.ChatterBotCorpusTrainer') 27 | wechat.train('chatterbot.corpus.chinese') 28 | 29 | 30 | class ChatterBotPlugin: 31 | name = 'ChatterBotPlugin' 32 | version = '0.1' 33 | chats = Friend 34 | msg_types = TEXT 35 | description = description 36 | exclude_patterns = ['help'] 37 | 38 | @classmethod 39 | def main(cls, msg): 40 | return wechat.get_response(msg.text) 41 | 42 | 43 | def export(): 44 | return ChatterBotPlugin 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | -------------------------------------------------------------------------------- /simsimi/simsimi.py: -------------------------------------------------------------------------------- 1 | # -*-coding:utf-8-*- 2 | """ 3 | Copy from https://github.com/python-cn/slack_bot 4 | """ 5 | 6 | import requests 7 | import random 8 | from wxpy import Friend 9 | from wxpy.api.consts import TEXT 10 | 11 | try: 12 | from config import SIMSIMI_KEY 13 | except: 14 | SIMSIMI_KEY = '6afe892c-596b-4743-a9a1-123ea951b88f' 15 | 16 | description = """ 17 | 色色的小黄鸡。触发条件:所有未触发其他插件的内容。 18 | """ 19 | 20 | COOKIE = "lang=zh_CN; normalProb=0; lc=ch; dotcom_session_key=s%3Al72WKytkaM46llEhIhE4-gRTK1esLSAX.k2HkRSHiK4UDOfM2WHTDVArOVZsmJ7%2Bfpo%2FF01qtOqg; currentChatCnt=1; _ga=GA1.2.1248391853.1500434158; _gid=GA1.2.950691851.1500434158" 21 | 22 | 23 | class SimSimi: 24 | 25 | def __init__(self): 26 | 27 | self.session = requests.Session() 28 | 29 | self.chat_url = ( 30 | 'http://simsimi.com/getRealtimeReq?lc=ch&ft=1&normalProb=0&' 31 | 'reqText={}&status=W&talkCnt=0' 32 | ) 33 | self.api_url = ('http://sandbox.api.simsimi.com/request.p?' 34 | 'key=%s&lc=ch&ft=1.0&text=%s') 35 | 36 | def initSimSimiCookie(self): 37 | self.session.headers.update( 38 | { 39 | 'User-Agent': ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5)' 40 | ' AppleWebKit/537.36 (KHTML, like Gecko)' 41 | ' Chrome/43.0.2357.81 Safari/537.36'), 42 | 'Referer': 'http://simsimi.com/', 43 | 'Host': 'simsimi.com', 44 | 'Accept-Language' : 'en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4,zh-TW;q=0.2', # noqa 45 | 'Accept': 'application/json, text/javascript, */*; q=0.01', 46 | 'Cookie': COOKIE 47 | }) 48 | 49 | def getSimSimiResult(self, message, method='normal'): 50 | if method == 'normal': 51 | self.initSimSimiCookie() 52 | r = self.session.get(self.chat_url.format(message)) 53 | else: 54 | url = self.api_url % (SIMSIMI_KEY, message) 55 | r = requests.get(url) 56 | return r 57 | 58 | def chat(self, message=''): 59 | if message: 60 | r = self.getSimSimiResult(message, 'api') 61 | try: 62 | answer = r.json()['response'].encode('utf-8') 63 | return answer 64 | except: 65 | try: 66 | r = self.getSimSimiResult(message, 'normal') 67 | answer = r.json()['respSentence'].encode('utf-8') 68 | return answer 69 | except: 70 | return random.choice(['呵呵', '。。。', '= =', '=。=']) 71 | else: 72 | return '叫我干嘛' 73 | 74 | simsimi = SimSimi() 75 | 76 | 77 | class SimSimiPlugin: 78 | name = 'SimSimiPlugin' 79 | version = '0.1' 80 | chats = Friend 81 | msg_types = TEXT 82 | except_self = True 83 | run_async = True 84 | patterns = None 85 | exclusive = False 86 | description = description 87 | exclude_patterns = ['help'] 88 | 89 | @classmethod 90 | def main(cls, msg): 91 | rs = simsimi.chat(msg.text.lower()).strip() 92 | if not isinstance(rs, str): 93 | rs = rs.decode('utf-8') 94 | return rs 95 | 96 | 97 | def export(): 98 | return SimSimiPlugin 99 | 100 | 101 | if __name__ == '__main__': 102 | print(simsimi.chat({'message': '最后一个问题'})) 103 | print(simsimi.chat({'message': '还有一个问题'})) 104 | print(simsimi.chat({'message': '其实我有三个问题'})) 105 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | --------------------------------------------------------------------------------