• 微信机器人终端1.0未来的设想就是做成telegram一样强大的机器人群体集控终端


    Bot console 是本人最近研发的一款项目,目前存放在github中
    Bot console未来的设想就是做成telegram一样强大的机器人群体集控终端
    在自定义机器人和脚本这块可以说是自由度非常高,当然对编程技术也有一定要求,有兴趣的可以一起开发和讨论,也感谢收听的观众支持


    script下的脚本代码主要就是集成了指令,例如 /help /天气-北京 等,指令也在代码中详细的介绍
    wx下的则是自定义的群机器人,目前有debug版本和后台版,可以自定义监控的群组
    打包好的下载地址:zip下载
    https://github.com/CJ-from-LosSantos/bot-console/releases/tag/%E5%8F%91%E5%B8%83

    [Python] 纯文本查看 复制代码

    ?

    001

    002

    003

    004

    005

    006

    007

    008

    009

    010

    011

    012

    013

    014

    015

    016

    017

    018

    019

    020

    021

    022

    023

    024

    025

    026

    027

    028

    029

    030

    031

    032

    033

    034

    035

    036

    037

    038

    039

    040

    041

    042

    043

    044

    045

    046

    047

    048

    049

    050

    051

    052

    053

    054

    055

    056

    057

    058

    059

    060

    061

    062

    063

    064

    065

    066

    067

    068

    069

    070

    071

    072

    073

    074

    075

    076

    077

    078

    079

    080

    081

    082

    083

    084

    085

    086

    087

    088

    089

    090

    091

    092

    093

    094

    095

    096

    097

    098

    099

    100

    101

    102

    103

    104

    105

    106

    107

    108

    109

    110

    111

    112

    113

    114

    115

    116

    117

    118

    119

    120

    121

    122

    123

    124

    125

    126

    127

    128

    129

    130

    131

    132

    133

    134

    135

    136

    137

    138

    139

    140

    141

    142

    143

    144

    145

    146

    147

    148

    149

    150

    151

    152

    153

    154

    155

    156

    157

    158

    159

    160

    161

    162

    163

    164

    165

    166

    167

    168

    169

    170

    171

    172

    173

    174

    175

    176

    177

    178

    179

    180

    181

    182

    183

    184

    185

    186

    187

    188

    189

    190

    191

    192

    193

    from requests import request

    class Spider:

        token = "EOk6j38PELxUwJy8"

        def __init__(self):

            self.headers = {'Content-Type'"application/x-www-form-urlencoded"}

        @staticmethod

        def other(key):

            url = f'https://cn.bing.com/search?q="{key}"&FORM=BESBTB'

            return f'😢没有该指令,已自动根据你的指令搜索到如下内容,请点击查看\n{url}'

        @staticmethod

        def what_to_eat_today(*args):

            """

            今天吃什么

            :docs: https://www.apispace.com/eolink/api/eat222/apiDocument

            """

            url = "https://eolink.o.apispace.com/eat222/api/v1/forward/chishenme"

            payload = {"size""3"}

            headers = {

                "X-APISpace-Token""zbxmug9fyd25pvq7b37urfl2yqm46f0g",

                "Authorization-Type""apikey"

            }

            result = request('GET', url, params=payload, headers=headers).json()

            if result['code'== 200:

                return f'亲~,今日推荐的食谱,三选一吧🥙:\n【{result["data"]}】'

            return 'api 错误或者失效了'

        def help_(self*args):

            return f'🚩 命令格式:/命令名称\n🚩 注意:命令带有下划线请忽略填写\n🚩 命令列表:{list(self.By.keys())}'

        def query_virus_cities(self, province, city=None, county=None):

            """

            疫情风险地区查询

            :docs: https://alapi.cn/api/view/106

            """

            url = "https://v2.alapi.cn/api/springTravel/risk"

            payload = {

                'token'self.token,

                'province': province,

                'city': city,

                "country": county

            }

            result = request('POST', url, params=payload, headers=self.headers).json()

            if result['code'== 200:

                if 10 len(result['config']['high_list']) > 0:

                    high_list = result['config']['high_list']

                    msg = ''.join(f"{row['area_name']} - ⛔ 高风险社区:{len(row['communitys'])}个\n" for row in high_list)

                elif city is None:

                    msg = f"{province} ⛔ 存在高风险地区:{result['config']['high_count']}个\n"

                else:

                    msg = f"{city} ⛔ 存在高风险地区:{result['config']['high_count']}个\n"

                msg = f"{msg}⚠ 存在中风险地区:{result['config']['middle_count']}个\n最新发布时间:{result['config']['end_update_time']}"

                return msg

            return 'api 错误或者失效了'

        def get_healthy_travel(self, from_, to):

            """

            出行防疫政策指南

            :docs: https://alapi.cn/api/view/87

            """

            return '该接口已取消'

            # table = City()

            # from_id = table.get_city_id(from_)

            # to_id = table.get_city_id(to)

            #

            # url = "https://v2.alapi.cn/api/springTravel/query"

            # payload = {

            #     'token': self.token,

            #     'from': from_id,

            #     'to': to_id

            # }

            #

            # result = request('POST', url, params=payload, headers=self.headers).json()

            # if result['code'] == 200:

            #     out_desc = result['config']['from_info']['out_desc']

            #     out_code_name = result['config']['from_info']['health_code_name']

            #     in_desc = result['config']['to_info']['low_in_desc']

            #     in_code_name = result['config']['to_info']['health_code_name']

            #

            #     return f"🌏 {from_}出站:\n📕 健康码:{out_code_name}\n🚆 {out_desc}\n🌏 {to}进站:\n📕 健康码:{in_code_name}\n🚆 {in_desc}\n"

        def get_weather(self, city=None):

            """

            国内天气查询

            :docs: https://alapi.cn/api/view/65

            """

            url = 'https://v2.alapi.cn/api/tianqi'

            payload = {

                'token'self.token,

                'city': city

            }

            result = request('POST', url, params=payload, headers=self.headers).json()

            if result['code'== 200:

                hour_list = result['config']['hour']

                msg = ''.join(f"⏰ {row['time'].split()[-1]} - {row['wea']} - {row['temp']}°\n" for row in hour_list)

                msg = f'今日早晨-明日早晨\n{msg}'

                return msg

            return 'api 错误或者失效了'

        def query_logistics(self, number):

            """

            快递查询

            :docs: https://alapi.cn/api/view/63

            """

            url = 'https://v2.alapi.cn/api/kd'

            payload = {

                'token'self.token,

                'number': number,

                'order''asc'

            }

            result = request('POST', url, params=payload, headers=self.headers).json()

            if result['code'== 200:

                new_state = result['config']['info'][-1]

                return f"⏰ 最新更新时间:{new_state['time']}\n📦 {new_state['content']}"

            return 'api 错误或者失效了'

        def get_news_to_day(self):

            """

            每日60秒早报

            :docs: https://alapi.cn/api/view/93

            """

            url = 'https://v2.alapi.cn/api/zaobao'

            payload = {

                'token'self.token,

                'format''json'

            }

            result = request('POST', url, params=payload, headers=self.headers).json()

            if result['code'== 200:

                image_url = result['config']['image']

                = request('GET', image_url).content

                filename = r'D:\GI\network-tools\images\zaobao.png'

                with open(filename, 'wb') as f:

                    f.write(c)

                return filename

            return 'api 错误或者失效了'

        def oneiromancy(self, key):

            """

            周公解梦

            :docs: https://www.apispace.com/eolink/api/zgjm/guidence/

            """

            url = "https://eolink.o.apispace.com/zgjm/common/dream/searchDreamDetail"

            payload = {"keyword": key}

            headers = {

                "X-APISpace-Token""zbxmug9fyd25pvq7b37urfl2yqm46f0g",

                "Authorization-Type""apikey",

                "Content-Type""application/x-www-form-urlencoded"

            }

            result = request('POST', url, data=payload, headers=headers).json()

            if result['statusCode'== '000000':

                contents = result["result"]

                msg = ''.join(f'关键字:{key}\n内容:{c["content"]}' for in contents)

                return msg

            return 'api 错误或者失效了'

    class BySpiderCommand(Spider):

        By = None

        def __init__(self):

            super().__init__()

            self.By = {

                'help'self.help_,

                'other'self.other,

                '疫情查询'self.query_virus_cities,

                '出行防疫'self.get_healthy_travel,

                '天气'self.get_weather,

                '快递'self.query_logistics,

                '早报'self.get_news_to_day,

                '吃东西'self.what_to_eat_today,

                '解梦'self.oneiromancy,

            }

     

    使用方法

    支持的微信版本下载 pc微信客户端

    初始化

    1. 下载代码后解压

    2. 在有bot.exe的目录下进入终端,执行bot init test_robot

    3. 正常情况下初始化命令执行成功会生成了一些机器人启动的文件

    启动

    1. 在有bot.exe的目录下进入终端,执行bot start test_robot

    2. 如果您没有登录pc端微信,他将会弹出登录窗口,扫描即可,随后机器人将管控您的微信

      1. 如果您已在pc端登陆,极有可能也会弹出扫码窗口,忽略即可
    3. 验证机器人是否成功,在包含被机器人管控的群组中输入/help发送,将会收到机器人回复

      1. 如果未收到回复,请尝试退出微信以启动机器人后弹出的扫码界面扫码进入

    结束

    1. 在有bot.exe的目录下进入终端,执行bot close

    其他自定义

    • 可以自定义脚本命令,参考script/spider.py文件格式,同时记得同步修改配置文件(yaml)

    • 可以机器人脚本,暂无参考

    成品软件:https://download.csdn.net/download/china365love/86729328回复

    举报

  • 相关阅读:
    JWT 使用入门(三)请求流程
    Perl 中的循环结构
    QImage函数setAlphaChannel
    提升“架构思维”?这本书值得一读!
    1.什么是Angular?
    C++ Primer学习笔记-----第二章:变量和基本类型
    Power BI 傻瓜入门 13. 进入仪表板
    iOS 之homebrew ruby cocoapods 安装
    Idea - 快速生成一个测试方法
    npm install webpack 下载失败
  • 原文地址:https://blog.csdn.net/china365love/article/details/127124532