feat(onebot): list every emoji reaction on a message
Add get_msg_emoji_likes so a bot can see all reactions on one message and the users behind each emoji, instead of querying one emoji at a time. Closes #399
This commit is contained in:
2 files changed
+32
No files matched your search
@@ -91,6 +91,13 @@ export interface ApiActionContext {
|
|||||||
serverCount: number;
|
serverCount: number;
|
||||||
complete: boolean;
|
complete: boolean;
|
||||||
}>;
|
}>;
|
||||||
|
fetchEmojiLikeSummary: (messageId: number) => Promise<Array<{
|
||||||
|
emoji_id: string;
|
||||||
|
emoji_type: number;
|
||||||
|
count: number;
|
||||||
|
last_reaction_time: number;
|
||||||
|
users: Array<{ user_id: number }>;
|
||||||
|
}>>;
|
||||||
getImageInfo: (file: string) => Promise<JsonObject | null>;
|
getImageInfo: (file: string) => Promise<JsonObject | null>;
|
||||||
getRecordInfo: (file: string) => Promise<JsonObject | null>;
|
getRecordInfo: (file: string) => Promise<JsonObject | null>;
|
||||||
fetchPttText: (messageId: number) => Promise<{ text: string }>;
|
fetchPttText: (messageId: number) => Promise<{ text: string }>;
|
||||||
|
|||||||
@@ -129,6 +129,31 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
|||||||
if (!hasAuthoritativeSequence(meta)) throw new Error('message has no authoritative QQ sequence');
|
if (!hasAuthoritativeSequence(meta)) throw new Error('message has no authoritative QQ sequence');
|
||||||
await bridge.apis.interaction.setReaction(meta.targetId, meta.sequence, emojiId, set);
|
await bridge.apis.interaction.setReaction(meta.targetId, meta.sequence, emojiId, set);
|
||||||
},
|
},
|
||||||
|
fetchEmojiLikeSummary: async (messageId) => {
|
||||||
|
const meta = messageStore.findMeta(messageId);
|
||||||
|
if (!meta) throw new Error('message not found');
|
||||||
|
if (!meta.isGroup) throw new Error('emoji reactions are not supported on private messages');
|
||||||
|
if (!hasAuthoritativeSequence(meta)) throw new Error('message has no authoritative QQ sequence');
|
||||||
|
let summary: Array<{ emojiId: string; emojiType: number; count: number; lastReactionTime: number }>;
|
||||||
|
try {
|
||||||
|
summary = await bridge.apis.interaction.fetchReactionSummary(meta.targetId, meta.sequence);
|
||||||
|
} catch {
|
||||||
|
summary = reactionStore.summarizeMessage(meta.targetId, meta.sequence).map((entry) => ({
|
||||||
|
emojiId: entry.emojiId,
|
||||||
|
emojiType: entry.emojiType,
|
||||||
|
count: entry.count,
|
||||||
|
lastReactionTime: entry.lastSetAt,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return summary.map((entry) => ({
|
||||||
|
emoji_id: entry.emojiId,
|
||||||
|
emoji_type: entry.emojiType,
|
||||||
|
count: entry.count,
|
||||||
|
last_reaction_time: entry.lastReactionTime,
|
||||||
|
users: reactionStore.listUsers(meta.targetId, meta.sequence, entry.emojiId, 1000, 0)
|
||||||
|
.map((user) => ({ user_id: user.operatorUin })),
|
||||||
|
}));
|
||||||
|
},
|
||||||
fetchEmojiLikeUsers: async (messageId, emojiId, count, offset = 0) => {
|
fetchEmojiLikeUsers: async (messageId, emojiId, count, offset = 0) => {
|
||||||
const meta = messageStore.findMeta(messageId);
|
const meta = messageStore.findMeta(messageId);
|
||||||
if (!meta) throw new Error('message not found');
|
if (!meta) throw new Error('message not found');
|
||||||
|
|||||||
Reference in new issue
Block a user