Advertisement
name

Robot of WeChat

Apr 13th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. from wxpy import *
  5. import requests
  6.  
  7. # 图灵机器人 - 中文语境下智能度最高的机器人大脑
  8. def tuling(info):
  9.     params = {
  10.         'key': 'db0b623ae0dd4e9ca28a89174abe156c',
  11.         'info': info,
  12.     }
  13.     try:
  14.         if '自动回复' not in info:
  15.             response = requests.get('http://www.tuling123.com/openapi/api', params=params, timeout=10)
  16.             return response.json()['text'] + '〖自动回复〗'
  17.     except Exception as e:
  18.         pass
  19.  
  20. # 手机微信扫码登陆
  21. bot = Bot(cache_path=True)
  22.  
  23. # 加自己为好友
  24. bot.self.add()
  25. bot.self.accept()
  26.  
  27. # 给自己发消息
  28. bot.self.send('能收到吗?')
  29.  
  30. # 我的群组
  31. my_groups = bot.groups().search('群组全名')[0]
  32.  
  33. # 我的妻子
  34. my_wife = bot.friends().search('妻子姓名')[0]
  35.  
  36. # 测试消息发送功能
  37. # my_wife.send('我们还是分手吧!')
  38. # my_wife.send('对不起,发错人了。')
  39.  
  40. # 自动打印剩余消息
  41. @bot.register()
  42. def print_others(msg):
  43.     print(msg)
  44.  
  45. # 自动回复群组消息
  46. @bot.register(my_groups)
  47. def reply_my_groups(msg):
  48.     if msg.type == 'Text':
  49.         content = msg.text
  50.         return tuling(content)
  51.  
  52. # 自动回复妻子消息
  53. @bot.register(my_wife)
  54. def reply_my_wife(msg):
  55.     if msg.type == 'Text':
  56.         content = msg.text
  57.         return tuling(content)
  58.  
  59. # 自动接受好友请求
  60. @bot.register(msg_types=FRIENDS)
  61. def auto_accept_friends(msg):
  62.     # 接受请求
  63.     new_friend = msg.card.accept()
  64.     # 发送消息
  65.     new_friend.send('哈哈,我自动接受了你的好友请求!')
  66.  
  67. # 进入 Python 命令行,程序在后台保持运行
  68. embed()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement