摸鱼派 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(({ msg }) => console.dir(msg));
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(async ({ msg }: { msg: NoticeMsg }) => {
switch (msg.command) {
case 'chatUnreadCountRefresh':
if(msg.count! > 0) {
let unreadMsgs = await fishpi.chat.unread();
}
break;
case 'newIdleChatMessage':
console.log(msg.senderUserName, '说:', msg.preview);
break;
case 'refreshNotification':
console.log('你有新消息【', await fishpi.notice.count(), '】')
break;
}
});
fishpi.chat.addListener(({ msg }: { msg: ChatData }) => {
console.log(msg.senderUserName, '[', msg.time, ']:', msg.content);
}, 'username');
fishpi.chat.send('username', 'Hi~');
import { Finger, FingerTo } from 'fishpi';
await FingerTo('GoldenFingerKey').queryLatestLoginIP('username')
const finger = new Finger(apiKey);
await finger.queryLatestLoginIP('username');
注意事项
API 库使用 fetch
做 API 请求,浏览器环境可以直接使用。在 Node 环境需要安装 node-fetch
2.x 版本的库。执行如下代码设置 fetch
函数:
import fetch from 'node-fetch'
globalThis.fetch = fetch as any;