Created
April 20, 2026 10:01
-
-
Save ayashiiiyo/d9d9bb7ebe41b44cebcac38355cbf08f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { load } from 'cheerio' | |
| function scoreMatch(q, title) { | |
| const query = q.toLowerCase().split(' ') | |
| const text = title.toLowerCase() | |
| let score = 0 | |
| for (let word of query) { | |
| if (text.includes(word)) score++ | |
| } | |
| return score | |
| } | |
| async function searchLirik(q) { | |
| const searchUrl = 'https://lirik.web.id/results/?q=' + encodeURIComponent(q) | |
| const res1 = await fetch(searchUrl, { | |
| headers: { | |
| 'user-agent': 'Mozilla/5.0' | |
| } | |
| }) | |
| const html1 = await res1.text() | |
| const $1 = load(html1) | |
| let best = { score: 0, link: null, title: null } | |
| $1('span[style*="font-size"] a').each((i, el) => { | |
| const title = $1(el).text().trim() | |
| const link = $1(el).attr('href') | |
| const score = scoreMatch(q, title) | |
| if (score > best.score) { | |
| best = { score, link, title } | |
| } | |
| }) | |
| if (!best.link) { | |
| return { | |
| status: 404, | |
| title: null, | |
| lyrics: null | |
| } | |
| } | |
| const res2 = await fetch(best.link, { | |
| headers: { | |
| 'user-agent': 'Mozilla/5.0' | |
| } | |
| }) | |
| const html2 = await res2.text() | |
| const $2 = load(html2) | |
| const container = $2('#konten').first() | |
| let lyrics = '' | |
| container.nextAll().each((i, el) => { | |
| if ($2(el).attr('id') === 'konten') return false | |
| const tag = el.tagName | |
| if (tag === 'p' || tag === 'div') { | |
| lyrics += '\n' + ($2(el).html() || '') | |
| } | |
| }) | |
| lyrics = lyrics | |
| .replace(/<br\s*\/?>/gi, '\n') | |
| .replace(/“|”/g, '"') | |
| .replace(/’/g, "'") | |
| .replace(/…/g, '...') | |
| .replace(/<[^>]+>/g, '') | |
| .replace(/^\s+|\s+$/g, '') | |
| .replace(/\n\s*\n/g, '\n') | |
| .trim() | |
| return { | |
| status: 200, | |
| title: best.title, | |
| lyrics | |
| } | |
| } | |
| let handler = async (m, { conn, text, command }) => { | |
| try { | |
| if (!text) return m.reply(`*Example :* .${command} Chiisana Koi no Uta`) | |
| m.reply(global.wait) | |
| const res = await searchLirik(text) | |
| m.reply(`*${res.title}* | |
| ${res.lyrics}`) | |
| } catch (e) { | |
| m.reply(e.message) | |
| } | |
| } | |
| handler.help = ['lirik', 'lyrics'] | |
| handler.command = ['lirik', 'lyrics'] | |
| handler.tags = ['search'] | |
| export default handler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment