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 🙏

© 2024 – Pkg Stats / Ryan Hefner

cqhttp-ts

v1.3.0

Published

go-cqhttp的ts开发框架

Downloads

262

Readme

cqhttp-ts

OneBot11

基于go-cqhttp的ts开发框架。

快速开始

首先开启go-cqhttp的websocket,登录到一个qq。

npm i cqhttp-ts
import linkServer, { ModTypes, PostTypes, useMod } from 'cqhttp-ts';
linkServer(8080); //需要开启websocket

useMod.useMessageMod([friendMessageModTest([2389451262]),xxx(),xxx().....]);
//类似这样来加载更多的mod
import { CqApi,ModTypes,PostTypes} from 'cqhttp-ts';

export default (whiteList: number[] | false): ModTypes.GroupMessageModType => {
	const handler = async (msg: PostTypes.GroupMessageType) => {
		const res = await CqApi.setEssenceMsgApi({
			message_id: msg.message_id,
		});//注意 api始终需要传入一个参数对象,即使内容为空。
		console.log(res);//得到相应的结果。如果该条消息是精华等错误,则返回 调用api失败

		console.log(modMonitor.messageModStore)//得到当前所有正在运行的消息mod列表,可以在任何地方使用
	};

	return {
		type: 'groupMessageMod',
		name: '把消息设置为精华消息',
		whiteList,			//如果whiteList是false,则对所有消息都响应。有些mod没有设置白名单的字段。
		handler,
	};
};

如何监听事件

事件文档-> cqhttp帮助中心-事件

  1. 每一个事件都有一个对应的对象类型来与之对应。例如群消息mod的类型为ModTypes.GroupMessageModType.
  2. 原则上,每一种事件的监听都要在useMod.useMessageMod([])等函数中参数的数组中传入一个ModTypes中类型的对象。 注意即使没有mod也要传入一个空数组。
  3. modType中实现的handler函数会接收一个参数,参数名称和事件对应。比如群消息事件对应的消息类型为 PostTypes.GroupMessageType。
  4. 如果是message类型的mod,则msg上有reply函数可以快速回复。
  5. 消息类型mod中会有一个白名单whiteList的字段。如果传入false给whiteList,则表示取消白名单。否则接受一个number数组。

如何使用api

API列表-> cqhttp帮助中心-API

  1. 例如需要使用 获取群信息的API,则调用CqApi.getGroupInfoApi({})
  2. 在文档中有一个终结点,api的命名基本是以终结点转化为小驼峰式命名的。
  3. 这个函数规定必须传入一个参数对象,即使参数为空。 参数内容和文档的参数对应,或者查看ts类型。
  4. 这个api是返回的是一个promise。得到的结果是响应数据。

如何查看目前运行的所有mod

  1. 在每个mod对象中都有一个name属性,这里就是运用到name属性的地方。
  2. 在modMonitor对象中包含了所有的mod类型。modMonitor.messageModStore就可以获得message类型的mod。
  3. 通过name来区分mod。

综合上述-> 如何实现拓展

系统导出了类似于useMessageMod和useNoticeMod形式的函数。以群消息为例

  1. 在任何地方使用useMod.useMessageMod()函数
  2. 这个函数需要提供一个对应的mod类型的对象,你可以编写一个函数来实现对应的函数类型来返回这个对象。(FriendMessageModType)。
  3. FriendMessageModType要求强制传入一个number数组来实现白名单(具体是否实现了白名单,根据modType中的字段来查看)。还需要实现handler来作为处理的入口,实现name来进行统一管理,实现type来作为内部识别的标志
  4. 编写handler函数。通过调用框架导出的api来实现主动操作,或者调用msg上绑定的reply快速回复消息。

实现的mod接口

在ModTypes中调用以下所有函数 具体用处见 cqhttp帮助中心

messageMod

  • FriendMessageModType 朋友消息拓展模块
  • GroupMessageModType 群消息拓展模块

noticeMod

  • ClientStatusUpdateModType
  • FriendAddModType
  • FriendRecallModType
  • FriendPokeModType
  • GroupAdminUpdateModType
  • GroupBanModType
  • GroupCardUpdateModType
  • GroupEssenceModType
  • GroupHonorUpdateModType
  • GroupLuckyKingModType
  • GroupMemberDecreaseModType
  • GroupMemberIncreaseModType
  • GroupRecallModType
  • GroupPokeModType
  • GroupUploadFileModType
  • ReceiveOfflineFileModType

requestMod

  • friendAddRequestModType
  • groupAddRequestModType

实现api

CqApi是一个异步函数,可以获取到响应结果。 在CqApi中调用下列函数

  • canSendImageApi,
  • canSendRecordApi,
  • checkUrlSafelyApi,
  • cleanCacheApiExpect,
  • createGroupFileFolderApi,
  • deleteEssenceMsgApi,
  • deleteFriendApi,
  • deleteGroupFileApi,
  • deleteGroupFolderApi,
  • deleteMessageApi,
  • downloadFileApi,
  • getCookiesApiExpect,
  • getCredentialsApiExpect,
  • getCSRFTokenApiExpect,
  • getEssenceMsgListApi,
  • GetForwardMessageApi,
  • getFriendListApi,
  • getGroupAtAllRemainApi,
  • getGroupFileSystemInfoApi,
  • getGroupFilesByFolderApi,
  • getGroupFileUrlApi,
  • getGroupHonorInfoApi,
  • getGroupInfoApi,
  • getGroupListApi,
  • getGroupMemberListApi,
  • getGroupMessageHistoryApi,
  • getGroupNoticeApi,
  • getGroupRootFilesApi,
  • getGroupSystemMsgApi,
  • getImageApi,
  • getLoginInfoApi,
  • getMessageApi,
  • getModelShowApi,
  • getOnlineClientsApi,
  • getRecordApiExpect,
  • getStatusApi,
  • getStrangerInfoApi,
  • getUnidirectionalFriendListApi,
  • getVersionInfoApi,
  • markMessageAsReadApi,
  • ocrImageApi,
  • reloadEventFilterApi,
  • sendGroupForwardMessageApi,
  • sendGroupMessageApi,
  • sendGroupNoticeApi,
  • sendGroupSignApi,
  • sendMessageApi,
  • sendPrivateMessageApi,
  • setEssenceMsgApi,
  • setFriendAddRequestApi,
  • setGroupAddRequestApi,
  • setGroupAdminApi,
  • setGroupAnonymousApi,
  • setGroupAnonymousBanApi,
  • setGroupBanApi,
  • setGroupCardApi,
  • setGroupLeaveApi,
  • setGroupNameApi,
  • setGroupPortraitApi,
  • setGroupSpecialTitleApi,
  • setGroupWholeBanApi,
  • setModelShowApi,
  • setQQProfileApi,
  • setRestartApi,
  • uploadGroupFileApi,
  • uploadPrivateFileApi,