import { definePlugin } from 'kivibot' import type { KiviPluginContext, AllMessageEvent, oicq } from 'kivibot' // 推送的群号 const pushGroups = [] export default definePlugin({ name: '看世界', version: '1.2.0', setup(ctx) { ctx.handle('message', async (e) => { ctx.runWithErrorHandler.call( ctx.bot, async () => { const txt = ctx.getText(e) if (!txt) return if (['60s', '60秒', '看世界'].includes(txt)) { const news = await fetch60s.call(ctx, e) if (!news) return await e.reply('获取 60s 新闻失败') await e.reply(news) } if (['抖音热搜'].includes(txt)) { const { message_id } = await e.reply('图片上传中,请等待...', true) const msgs = await fetchDouyin.call(ctx, e) if (!msgs) return await e.reply('获取抖音热搜失败') await e.reply(msgs) ctx.isGroupMsg(e) && (await e.group.recallMsg(message_id)) } if (['知乎热搜'].includes(txt)) { const msgs = await fetchZhihu.call(ctx, e) if (!msgs) return await e.reply('获取知乎热搜失败') await e.reply(msgs) } if (['知乎热榜', '知乎热门问题'].includes(txt)) { const { message_id } = await e.reply('图片上传中,请等待...', true) const msgs = await fetchZhihuHot.call(ctx, e) if (!msgs) return await e.reply('获取知乎热榜失败') await e.reply(msgs) ctx.isGroupMsg(e) && (await e.group.recallMsg(message_id)) } if (['b站热搜'].includes(txt.toLowerCase())) { const msgs = await fetchBili.call(ctx, e) if (!msgs) return await e.reply('获取 B 站热搜失败') await e.reply(msgs) } if (['微博热搜'].includes(txt.toLowerCase())) { const msgs = await fetchWeibo.call(ctx, e) if (!msgs) return await e.reply('获取微博热搜失败') await e.reply(msgs) } if (['热搜', '新闻'].includes(txt)) { const { message_id } = await e.reply('正在获取,请稍等...') const news = [ await fetchDouyin.call(ctx, e), await fetchZhihuHot.call(ctx, e), await fetch60s.call(ctx, e), await fetchWeibo.call(ctx, e), await fetchBili.call(ctx, e), await fetchZhihu.call(ctx, e), ].filter(Boolean) as oicq.Sendable[] if (!news.length) return await e.reply('获取热搜失败') const messages = await ctx.bot.makeForwardMsg( news.map((item) => ({ user_id: e?.sender?.user_id, nickname: e?.sender?.nickname, message: item, })), ) await e.reply(messages) ctx.isGroupMsg(e) && (await e.group.recallMsg(message_id)) } }, e, ) }) }, cron: [ [ '0 8 * * *', // 每天早上八点推送 async (ctx) => { const news = await fetch60s.call(ctx) if (!news) return await ctx.noticeGroups.call(ctx.bot, pushGroups, news) }, ], ], }) async function fetch60s(this: KiviPluginContext, e?: AllMessageEvent): Promise { const { data } = await this.http.get('https://60s.viki.moe?v2=1') const { news } = data?.data ?? {} if (!news || !news.length) return null const { nickname = 'QQ 用户', user_id = this.bot.uid } = e?.sender || {} const messages = await this.bot.makeForwardMsg([ { nickname, user_id, message: '〓 每天 60 秒看世界 〓' }, ...news.slice(0, 20).map((item: any, idx: number) => ({ nickname, user_id, message: `【${idx + 1}】${item}\n\n详情: https://www.baidu.com/s?wd=${encodeURIComponent(item)}`, })), ]) return messages } async function fetchDouyin(this: KiviPluginContext, e: AllMessageEvent): Promise { const { data } = await this.http.get('https://60s.viki.moe/douyin') const list = (data?.data ?? []) as any[] if (!list.length) return null const messages = await this.bot.makeForwardMsg([ { nickname: e.sender.nickname, user_id: e.sender.user_id, message: '〓 抖音热搜榜 〓' }, ...list.slice(0, 10).map((item, idx) => ({ nickname: e.sender.nickname, user_id: e.sender.user_id, message: [ this.oicq.segment.image(item.cover), `【${idx + 1}】${item.word}\n时间:${this.dayjs(item.active_time).format('YYYY/MM/DD HH:mm:ss')}\n\n详情: https://www.douyin.com/root/search/${encodeURIComponent(item.word)}`, ], })), ]) return messages } async function fetchZhihu(this: KiviPluginContext, e: AllMessageEvent): Promise { const { data } = await this.http.get('https://60s.viki.moe/zhihu') const list = (data?.data ?? []) as any[] if (!list.length) return null const messages = await this.bot.makeForwardMsg([ { nickname: e.sender.nickname, user_id: e.sender.user_id, message: '〓 知乎热搜榜 〓' }, ...list.map((item, idx) => ({ nickname: e.sender.nickname, user_id: e.sender.user_id, message: `【${idx + 1}】${item.query}\n\n详情: https://www.zhihu.com/search?q=${encodeURIComponent(item.query)}`, })), ]) return messages } async function fetchZhihuHot(this: KiviPluginContext, e: AllMessageEvent): Promise { const { data } = await this.http.get('https://60s.viki.moe/zhihu-hot') const list = (data?.data ?? []) as any[] if (!list.length) return null const messages = await this.bot.makeForwardMsg([ { nickname: e.sender.nickname, user_id: e.sender.user_id, message: '〓 知乎热门问题 〓' }, ...list.slice(0, 10).map((item, idx) => ({ nickname: e.sender.nickname, user_id: e.sender.user_id, message: [ this.oicq.segment.image(item.cover), `【${idx + 1}】【${item.metrics}】${item.title}\n\n${item.detail}\n\n详情: ${item.link}`, ], })), ]) return messages } async function fetchBili(this: KiviPluginContext, e: AllMessageEvent): Promise { const { data } = await this.http.get('https://60s.viki.moe/bili') const list = (data?.data ?? []) as any[] if (!list.length) return null const messages = await this.bot.makeForwardMsg([ { nickname: e.sender.nickname, user_id: e.sender.user_id, message: '〓 B 站热搜榜 〓' }, ...list.map((item, idx) => { const word = item.show_name || item.keyword return { nickname: e.sender.nickname, user_id: e.sender.user_id, message: `【${idx + 1}】${word}\n\n详情: https://search.bilibili.com/all?keyword=${encodeURIComponent(word)}`, } }), ]) return messages } async function fetchWeibo(this: KiviPluginContext, e: AllMessageEvent): Promise { const { data } = await this.http.get('https://60s.viki.moe/weibo') const list = (data?.data ?? []) as any[] if (!list.length) return null const messages = await this.bot.makeForwardMsg([ { nickname: e.sender.nickname, user_id: e.sender.user_id, message: '〓 微博热搜榜 〓' }, ...list.map((item, idx) => { const icon = item.icon_desc ? `[${item.icon_desc}] ` : '' return { nickname: e.sender.nickname, user_id: e.sender.user_id, message: `【${idx + 1}】${icon}${item.word || item.note}\n\n详情: https://s.weibo.com/weibo?q=${encodeURIComponent(item.word_scheme)}`, } }), ]) return messages }