摸鱼派 API Package
摸鱼派社区 (https://fishpi.cn/) 的 API Package,可以快速开发出一款应用支援社区功能。
支援
- 用户信息;
- 聊天室;
- 自定义表情包;
- 文件上传;
- 通知信息;
- 清风明月;
- 文章读写;
- 评论点赞;
- 私聊功能;
安装
npm install fishpi
用例
import FishPi from 'fishpi';
let apiKey = '';
let fish = new FishPi();
let rsp = await fish.login({
username: 'username',
passwd: 'password123456'
});
if (rsp.code == 0) apiKey = rsp.Key;
let fish = new FishPi(apiKey);
console.dir(await fish.account.info());
let emojis = await fish.emoji.get();
let defaultEmoji = fish.emoji.default;
fish.chatroom.addListener((ev:any) => console.dir(ev));
await fish.chatroom.send('Hello World!');
await fish.chatroom.redpacket.send({
type: 'random';
money: 32;
count: 2;
msg: '摸鱼者,事竟成!';
recivers: [];
})
let chatHistory = await fish.chat.get({ user: 'username', autoRead: false })
fishpi.chat.addListener(({ msg: any }) => {
switch (msg.command) {
case 'chatUnreadCountRefresh':
if(msg.count > 0) {
let unreadMsgs = await fishpi.chat.unread();
}
else this.users.forEach((u, i) => {
this.users[i].unread = 0;
});
break;
case 'newIdleChatMessage':
console.log(msg.senderUserName, '说:', notice.preview);
break;
case 'refreshNotification':
console.log('你有新消息【', await fishpi.notice.count(), '】')
break;
}
});
fishpi.chat.addListener(({ msg: ChatData }) => {
console.log(msg.senderUserName, '[', msg.time, ']:', msg.content);
}, 'username');
fishpi.chat.send('username', 'Hi~');
注意事项
API 库使用 fetch
做 API 请求,浏览器环境可以直接使用。在 Node 环境需要安装 node-fetch
2.x 版本的库。执行如下代码设置 fetch
函数:
import fetch from 'node-fetch'
globalThis.fetch = fetch as any;