Giter Site home page Giter Site logo

etbot's Introduction

ETBot

一个明确,简洁,实用的QQ机器人框架。

使用「ETBot」非常简单,不到30行代码就可以构建一个酷炫的QQ机器人。

import * as ETBot from "etbot"

var config = new ETBot.etbot_config("http://127.0.0.1:2333",3000)

var bot = new ETBot.Bot(config)

bot.get_user_info(function(result) {
    console.log(result)
})

bot.on(ETBot.Event.receive_message,function(message) {
    console.log(message.info)
    message.reply("你好")
})

是不是非常酷炫??

Api文档

单击进入

快速开始

使用这个框架需要具备的知识

  • Node.js相关
  • TypeScript

这里使用一个回复好友说的话的小事例来大概介绍一下ETBot的工作原理。

ETBot配合使用Perl语言编写的项目sjdy521/Mojo-Webqq使用,通过请求该项目的Api与收取该项目的上报信息工作。

首先,先确认您的电脑安装了Perl,并安装Perl模块Mojo::Webqqsjdy521/Mojo-Webqq中配置运行环境的详细说明

接着,编写一个main.pl脚本

#!/usr/bin/env perl
 use Mojo::Webqq;
 my ($host,$port,$post_api);
 
 $host = "0.0.0.0"; #发送消息接口监听地址,没有特殊需要请不要修改
 $port = 5000;      #发送消息接口监听端口,修改为自己希望监听的端口
 $post_api = 'http://127.0.0.1:3000';  #接收到的消息上报接口,如果不需要接收消息上报,可以删除或注释此行
 
 my $client = Mojo::Webqq->new();
 $client->load("ShowMsg");
 $client->load("Openqq",data=>{listen=>[{host=>$host,port=>$port}], post_api=>$post_api, post_event_list => ['login','stop','state_change','input_qrcode','new_group','new_friend','new_group_member','lose_group','lose_friend','lose_group_member']});
 $client->run();

接着,运行这个脚本

perl main.pl

并根据提示登录QQ。

接着,建立一个typescript项目并安装ETBot

npm init

配置好tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "sourceMap": true
    },
    "exclude": [
        "node_modules"
    ]
}

然后创建一个index.ts,并引入ETBot

import * as ETBot from "etbot"

接着,构造出一个Bot类

let config = new ETBot.config("http://127.0.0.1:5000",3000)

let bot = new ETBot.Bot(config)

很好,机器人已经创建完毕,接下来,我们需要写一个监听事件,用于监听QQ好友信息

bot.on(ETBot.Event.receive_message, (message) => {
  message.reply("你说了"+message.info.content)
})

接着,使用tsc命令将文件编译为.js

tsc

最后,运行这个项目:

node index.js

是不是非常的酷??

更多

作者是初中党。。时间不多,Api文档正在编写过程中,完成之后第一时间发布上来

还有...

某些命名规则可能没有遵循TypeScript。。。会在后期作出改进。

etbot's People

Stargazers

Eric Wei avatar  avatar Eric Wong avatar hexsum avatar

Watchers

James Cloos avatar Eric Wei avatar

Forkers

jijicanyu m310n

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.