-
Notifications
You must be signed in to change notification settings - Fork 19
/
muxia_hot_search.js
102 lines (87 loc) · 2.95 KB
/
muxia_hot_search.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* @Author: MuXia
* @Date: 2022/10/08
*/
import fetch from "node-fetch";
import common from "../../lib/common/common.js";
import plugin from "../../lib/plugins/plugin.js";
export class hotSearch extends plugin {
constructor() {
super({
name: "热搜榜",
dsc: "微博热搜和知乎热搜",
/** https://oicqjs.github.io/oicq/#events */
event: "message.group",
priority: 1500,
rule: [
{
/** 命令正则匹配 */
reg: "^#?微博热搜$",
/** 执行方法 */
fnc: "weibo"
},
{
/** 命令正则匹配 */
reg: "^#?知乎热搜$",
/** 执行方法 */
fnc: "zhihu"
}
]
});
}
async weibo(e) {
console.log("用户命令:", e.msg);
//执行的逻辑功能
let url = `http://api.weibo.cn/2/guest/search/hot/word`;
let res = await fetch(url).catch((err) => logger.error(err));
if (res.status != 200) {
logger.error("[热搜榜] 微博热搜获取失败");
await e.reply("[热搜榜] 微博热搜获取失败");
return true;
}
res = await res.json();
let data = res.data;
let text = ["微博热搜榜"];
let addText = "";
for (let i = 1; i < data.length; i++) {
addText = addText + i + "、" + data[i - 1].word;
if (i % 5 == 0) {
addText = addText.replace(/#/g, "");
text.push(addText);
addText = "";
} else {
addText = addText + "\n\n";
}
}
e.reply(await common.makeForwardMsg(this.e, text, text[0]));
//返回true 阻挡消息不再往下
return true;
}
async zhihu(e) {
console.log("用户命令:", e.msg);
//执行的逻辑功能
let url = `https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total?limit=50&desktop=true`;
let res = await fetch(url).catch((err) => logger.error(err));
if (res.status != 200) {
logger.error("[热搜榜] 知乎热搜获取失败");
await e.reply("[热搜榜] 知乎热搜获取失败");
return true;
}
res = await res.json();
let data = res.data;
let text = ["知乎热搜榜:"];
let addText = "";
for (let i = 1; i < data.length; i++) {
addText = addText + i + "、" + data[i - 1].target.title;
if (i % 5 == 0) {
text.push(addText);
addText = "";
} else {
addText = addText + "\n\n";
}
}
e.reply(await common.makeForwardMsg(this.e, text, text[0]));
//返回true 阻挡消息不再往下
return true;
}
}