Code Monkey home page Code Monkey logo

amiablenext's Introduction

Amiable Next

是什么?

Amiable Next是使用了HTTPAPI的一个C# Bot开发框架

适配那些平台?

目前支持:

  • MYQQ

即将支持:

  • QQ频道

快速上手

1️⃣配置HTTPAPI

使用 MYQQ

使用MYQQ作为框架,你需要安装MYQQ的官方 HTTP API

myqqx官网-插件下载文档

  1. 下载HTTPAPI
  2. 配置HTTPAPI插件的信息:手册

AmiableNext的针对Myqq的回调地址为/MyqqMsg (你也可以自己修改)

也就是说,你需要在appsettings.json里面配置好本机URL后

在MYQQ内的HTTP API插件配置填入{url}/MyqqMsg

同时 配置请求头。

Content-Type:application/json
  1. 配置AmiableNext的配置文件。位于同一目录appsettings.json
{
  "Mode": "MyQQ_HTTP_API",
  "MyQQ_HTTP_API": {
    "ApiUrl": "url",
    "AuthToken": "auth"
  }
}

使用 Mirai-Console-Loader (Mirai)

  1. 使用 mirai-api-http

AmiableNext仅支持使用2.x的mirai-http-api

  1. 配置mirai-http-api

请进入mirai-http-api的配置文件,为其添加http与webhook的adpater

adapters: 
  - webhook
  - http

紧接着

enableVerify: true
verifyKey: xxxxxx
singleMode: true
adapterSettings:
  webhook:
    destinations:
      - '{{url}}/MiraiEvent' #url应为appsettings.json下配置的地址
  http:
    host: localhost
    port: 8091 # 可更改,但也要同步更改AmiableNext使用的Mirai配置
    cors: [ * ]
  1. 配置AmiableNext的Mirai兼容

位于 appsettings.json

{
  "Mode": "Mirai_HTTP_HOOK",
  "Mirai_HTTP_HOOK": {
    "ApiUrl": "这里是刚刚配置的adapterSettings.host:port",
    "AuthToken": "这里是刚刚自己配置的verifyKey"
  }
}

支持的API_Mode

  • MyQQ_HTTP_API
  • Mirai_HTTP_HOOK

位于 appsettings.json

{
  "Mode": "Mirai_HTTP_HOOK"
}
{
  "Mode": "MyQQ_HTTP_API"
}

2️⃣启动AmiableNext

3️⃣编写事件代码

  1. 创建继承IBotEvent的类
  2. 实现类。
  3. 注册事件。

例子

实现类DemoPrivateMsg2

EventType 是 CommonEventType.MessageFriend (好友消息)

public class DemoPrivateMsg2 : IBotEvent
{
    public CommonEventType EventType { get; set; } = CommonEventType.MessageFriend;

    public async void Process(AmiableEventContext ctx)
    {
        if (Regex.IsMatch(ctx.Content, @"我是谁[?.]?"))
        {
            ctx.PrivateReply($"你是:{await ctx.Api.GetNickAsync(ctx.BotId, ctx.AuthorId)}");
        }
    }
}

注册类

AmiableService.cs

app.RegEvent<DemoPrivateMsg2>("样例私聊事件2");

重启应用

重启后成功载入事件。

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.