storage.get('skipTypes', ['rockPaperScissors']);
storage.get('delaySec', 1.0);
fishpi.toolbar.register({
id: 'quick-actions',
title: '快捷助手',
actions: [
{ id: 'bingbing', label: '去打劫', subtitle: '发送去打劫' },
{ id: 'ge', label: '行行好', subtitle: '发送鸽行行好' }
]
});
on('toolbarAction', function(action) {
if (!action || action.entryId !== 'quick-actions') return;
if (action.actionId === 'bingbing') {
fishpi.call('sendChatRoomMessage', {content: '冰冰 去打劫'});
}
if (action.actionId === 'ge') {
fishpi.call('sendChatRoomMessage', {content: '鸽 行行好吧'});
}
});
on('message', function(msg) {
if (msg.type !== 'redPacket') return;
var rp = msg.redPacket;
if (!rp.openable) return;
var skip = storage.get('skipTypes', ['rockPaperScissors']);
var delaySec = Number(storage.get('delaySec', 3.0));
if (!isFinite(delaySec) || delaySec < 0) delaySec = 3.0;
if (skip.indexOf(rp.type) >= 0) return;
if (rp.type === 'specify') {
var recv = rp.receivers || [];
if (userName && recv.indexOf(userName) < 0) return;
}
setTimeout(function() {
fishpi.call('openRedPacket', {messageId: msg.oId, gesture: -1}).then(function(r) {
if (r.ok === false) { log('openRedPacket error: ' + r.error); return; }
var me = r.who.length > 0 ? r.who[r.who.length - 1] : null;
var got = me ? me.userMoney : 0;
ui.toast('[红包助手] 🧧 抢到' + got + '积分');
});
}, Math.round(delaySec * 1000));
});