npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

wechaty-decorator

v1.0.1

Published

> 装饰器版本的`wechaty`

Downloads

29

Readme

wechaty-decorator

装饰器版本的wechaty

可以使用装饰器方便的处理不同类型的事件

Install

npm install wechaty-decorator 
# or
yarn add wechaty-decorator
# or
pnpm add wechaty-decorator

TODO

  • [x] onRoomJoin
  • [x] OnRoomInvite
  • [x] OnRoomLeave
  • [x] OnRoomTopic
  • [x] OnScan
  • [x] OnLogin
  • [x] OnMessage
  • [x] OnFriendship
  • [x] OnError
  • [ ] OnRoomMessage
  • [ ] OnConcatMessage

Example

import { PuppetPadlocal } from 'wechaty-puppet-padlocal'
import {
  ScanStatus,
  Message,
  Room,
  Contact,
} from 'wechaty'
import { MessageType } from 'wechaty-puppet'
import {
  WechatyDecorator,
  onRoomJoin,
  OnRoomInvite,
  OnRoomLeave,
  OnRoomTopic,
  OnScan,
  OnLogin,
  OnMessage,
} from 'wechaty-decorator'

function log(...data) {
  console.log(...data)
}

class Example {
  constructor() {
    const puppet = new PuppetPadlocal({
      token: "YOU_TOKEN"
    })

    new WechatyDecorator({
      name: 'YOUR_BOT_NAME',
      puppet,
    })
  }

  @OnScan
  onScan(qrcode, status) {
    if (status === ScanStatus.Waiting || status === ScanStatus.Timeout) {
      const qrcodeImageUrl = [
        'https://wechaty.js.org/qrcode/',
        encodeURIComponent(qrcode),
      ].join('')
      log('StarterBot', 'onScan: %s(%s) - %s', ScanStatus[status], status, qrcodeImageUrl)
    } else {
      log('StarterBot', 'onScan: %s(%s)', ScanStatus[status], status)
    }
  }

  @OnLogin
  onLogin(user) {
    console.log('logged in', user.name())
  }

  // TODO: puppet限制 无法完成测试
  @onRoomJoin
  async onRoomJoin(room: Room, inviteeList, inviter: Contact, date) {
    console.log('topic', await room.topic())
    room.say(
      `今天${date}${inviter.name()},邀请了${inviteeList.map(ele => ele.name()).join(',')}`
    )
  }

  @OnRoomTopic
  async onRoomTopic(room: Room, newTopic, oldTopic, changer: Contact, date) {
    console.log('topic', await room.topic())
    log('newTopic: ', newTopic)
    log('oldTopic: ', oldTopic)
    room.say(`今天${date}${changer.name()},群名称被修改为: ${newTopic}, 之前的名称是: ${oldTopic}`)
  }

  // TODO: puppet限制 无法完成测试
  @OnRoomLeave
  async onRoomLeave(room: Room, leaverList, remover: Contact, date) {
    console.log('topic', await room.topic())
    log('leaverList: ', leaverList)
    log('remover: ', remover)
    log('date: ', date)
    room.say(
      `今天${date}${remover.name()}将${leaverList.map(ele => ele.name()).join(',')}移除了群聊`
    )
  }

  @OnRoomInvite
  async onRoomInvite(roomInvitation) {
    log(roomInvitation)
  }

  @OnMessage(MessageType.Text)
  async onMessage(message: Message) {
    log('message: ', message)
    const room = message.room()
    if (room) {
      const topic = await room.topic()
      if (/^机器人测试群/.test(topic)) {
        await room.say(`msg from ${topic}`)
      }
    }
  }

  @OnMessage(MessageType.Text, /^ding/)
  async onMessageRegexp(message: Message) {
    log('message: ', message)
    const room = message.room()
    if (room) {
      await room.say('dong')
    }
  }

  @OnMessage(MessageType.Text, (msg: Message) => /^ding/.test(msg.text()) )
  async onMessageFn(message: Message) {
    log('message: ', message)
    const room = message.room()
    if (room) {
      await room.say('dong')
    }
  }
}

new Example()

Tips

  • 项目中依赖的wechaty版本是^0.56.6 如果使用出现报错,请检查版本是否一致。