-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathincludes.js
60 lines (60 loc) · 1.63 KB
/
includes.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
const axios=require('axios');
const TelegramBot = require('node-telegram-bot-api');
const EventEmitter = require('events');
const includes={
isInt(value) {
return !isNaN(value) && (function(x) { return (x | 0) === x; })(parseFloat(value))
},
sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
},
parseTgUserNickname(user){
return ((user.first_name?user.first_name:'')
+' '
+(user.last_name?user.last_name:'')).toString().trim();
},
defTgMsgForm:{
parse_mode:'Markdown',
disable_web_page_preview:true,
reply_markup:{
remove_keyboard:true
}
},
axios:axios.create({
timeout:15000
}),
bot:new TelegramBot(),
template:{
networkError:'网络错误,请重试。'
},
formatWatchMessagePartial(arr){
let str='';
for(let vtb of arr){
str+=vtb.liveStatus?'🟢 ':'🔴 ';
str+='`'+vtb.username+'`';
//str+=' `'+vtb.mid+'`\n';
str+='\n';
str+=vtb.liveStatus?'👉▶️ ['+vtb.title+'](https://live.bilibili.com/'+vtb.roomid+')\n':'';
}
return str;
},
emitter:new EventEmitter(),
formatTgKeyboard(arr){
let keyboard=[];
let step=0;
for(let item of arr){
if(step==0){
keyboard.push([item]);
step=1;
}else{
keyboard[keyboard.length-1].push(item);
step=0;
}
}
return keyboard;
},
vtbList:[]
};
module.exports=includes;