forked from Ilhamskhyi/botv1-Md
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-search.js
43 lines (40 loc) · 1.33 KB
/
github-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
let fetch = require('node-fetch')
let handler = async (m, { text, command, usedPrefix }) => {
if (!text) throw `contoh:\n${usedPrefix + command} ShiraoriBOT-Md`
let res = await fetch(global.API('https://api.github.com', '/search/repositories', {
q: text
}))
if (!res.ok) throw await `${res.status} ${res.statusText}`
let json = await res.json()
if (res.status !== 200) throw json
let str = json.items.map((repo, index) => {
return `
${1 + index}. *${repo.full_name}*${repo.fork ? ' (fork)' : ''}
_${repo.html_url}_
_Dibuat pada *${formatDate(repo.created_at)}*_
_Terakhir update pada *${formatDate(repo.updated_at)}*_
👁
${repo.watchers} ${repo.forks} ${repo.stargazers_count}
${repo.open_issues} Issue${repo.description ? `
*Deskripsi:*\n${repo.description}` : ''}
*Clone:* \`\`\`$ git clone ${repo.clone_url}\`\`\`
`.trim()
}).join('\n\n')
m.reply(str)
}
handler.help = ['githubsearch'].map(v => v + ' <pencarian>')
handler.tags = ['github']
handler.command = /^g(ithub|h)search$/i
module.exports = handler
function formatDate(n, locale = 'id') {
let d = new Date(n)
return d.toLocaleDateString(locale, {
weekday: 'long',
day: 'numeric',
month: 'long',
year: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric'
})
}