zoukankan      html  css  js  c++  java
  • QQ机器人教程

    机器人框架:Graia Framework

    1.安装Java运行时(版本必须 >= 11)

    2.下载MCL

    3.双击运行mcl.cmd

    4.配置自动登录信息config/Console/AutoLogin.yml:

     5.安装辅助登录插件

    mcl --update-package net.mamoe:mirai-login-solver-selenium --channel nightly --type plugin

    运行mcl.cmd,拖动滑块验证登录

    6.安装mirai-api-http

    mcl --update-package net.mamoe:mirai-api-http --channel stable --type plugin

    运行mcl.cmd,记录config/net.mamoe.mirai-api-http/setting.yml的authKey

     7.编写机器人业务代码

    from graia.broadcast import Broadcast
    from graia.application import GraiaMiraiApplication, Session
    from graia.application.message.chain import MessageChain
    import asyncio
    
    from graia.application.message.elements.internal import Plain
    from graia.application.friend import Friend
    
    loop = asyncio.get_event_loop()
    
    bcc = Broadcast(loop=loop)
    app = GraiaMiraiApplication(
        broadcast=bcc,
        connect_info=Session(
            host="http://localhost:8080", # 填入 httpapi 服务运行的地址
            authKey="graia-mirai-api-http-authkey", # 填入 authKey
            account=5234120587, # 你的机器人的 qq 号
            websocket=True # Graia 已经可以根据所配置的消息接收的方式来保证消息接收部分的正常运作.
        )
    )
    
    @bcc.receiver("FriendMessage")
    async def friend_message_listener(app: GraiaMiraiApplication, friend: Friend):
        await app.sendFriendMessage(friend, MessageChain.create([
            Plain("Hello, World!")
        ]))
    
    app.launch_blocking()
  • 相关阅读:
    [LeetCode] Contains Duplicate II
    [LeetCode] House Robber II
    [LeetCode] Permutations II
    [LeetCode] Permutations
    [LeetCode] Next Permutation
    谈谈套接字
    基于Linux系统的Nagios网络管理模块的实现
    Windows/Linux下磁盘使用的图形化工具简介
    利用日志使管理Linux更轻松
    实际感受美丽的Linux(多组视频)
  • 原文地址:https://www.cnblogs.com/viewts/p/14505745.html
Copyright © 2011-2022 走看看