0.0.34 • Published 3 years ago

@eine-nineteen/eine v0.0.34

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

🎩 Eine

API Document

(WIP) Another TypeScript framework to build a QQ bot.

npm install @eine-nineteen/eine --save-dev

Simple Usage

import Eine, { Components, Filters, Types } from "@eine-nineteen/eine";

const { Plain, ImageFrom } = Components;
const { SentBy, TextEquals } = Filters;
const { EventHandleResult } = Types;

// new Eine(config: Parital<EineOptions>)
const eine = new Eine({
  verifyKey: "YourVerifyKey",
  adapters: {
    http: {
      host: "127.0.0.1",
      port: 8080,
    },
    ws: {
      host: "127.0.0.1",
      port: 8080,
    },
  },
  qq: 12345678,

  // Eine depends on MongoDB to record something.
  // If you don't need, disable the follwing options:
  // enableDatabase: false,
  // enableServer: false,
  mongoConfig: {
    username: 'admin',
    password: 'admin',
    dbName: 'BOT',
  },

  // [experiment] concurrency mode
  // start many eine processes to handle events and messages
  // use with caution!
  enableConcurrent: true,
});

// start Eine
eine.init()
  .then(eine.verify)
  .then(eine.bind)
  .then(async () => {
    const profile = await eine.http!.botProfile();
    console.log("MyProfile: ", profile);
  });

// Register an event listener:
// eine.on(eventType: EineEventType)(handler: EventCallback)
eine.on('FriendMessage', 'GroupMessage')(async ({
  messageChain,
  quote,
  recall,
  reply,
  sender,
  str,
}: Partial<Types.EventCallbackParams>) => {
  // Do something with messageChain, sender, str(serialized messageChain)...
  // and use reply(messageChain), recall(messageChain), recall() to react...

  if (str.contains("hello!")) {
    reply!([
      Plain("Hi!"), 
      ImageFrom("./hello.jpg") 
    ]);
    return EventHandleResult.DONE;          // return DONE to block other events
  }

  return EventHandleResult.CONTINUE;        // ...or CONTINUE to react next event
})

// with Eine's wait mechanism, you can easily write an interactive procedure:
const MASTER = 10001;
eine.on('FriendMessage', SentBy(MASTER), TextEquals("/shutdown"))(function*() {
  const { iterator, sender, reply, wait }: Types.EventInterruptParams = yield null;
  reply!(["send /confirm to shutdown BOT."]);

  // wait(iterator: EventIterator, filters: EventFilter)
  const { messageChain } = yield wait(iterator, TextEquals("/confirm"));    
  reply!(["BOT is shutting down."]);
  eine.shutdown(0);
  
  return EventHandleResult.DONE;      // this should never reached
                                      // but you should return it 
                                      // when using wait() to do othewr things.
});

Advanced

  • Eine provided an simple GUI admin panel. You can visit http://[hostname]:9119 to use the panel.
  • Eine provided an asynchronized encapsulation of node-canvas called EinePainter. Check eine.painter for more detail.
  • Eine provided a logging system eine.logger. You can use logLevel option to control the level of logs.

License

Copyright(c) 2021 @kirainmoe

MIT License

0.0.34

3 years ago

0.0.30

3 years ago

0.0.31

3 years ago

0.0.32

3 years ago

0.0.33

3 years ago

0.0.27

3 years ago

0.0.28

3 years ago

0.0.29

3 years ago

0.0.26

3 years ago

0.0.25

3 years ago

0.0.23

3 years ago

0.0.24

3 years ago

0.0.20

3 years ago

0.0.21

3 years ago

0.0.22

3 years ago

0.0.18

3 years ago

0.0.19

3 years ago

0.0.13

3 years ago

0.0.16

3 years ago

0.0.17

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago