Skip to content

Commit 84ff76f

Browse files
committed
feat(examples): trigger airich-bot on ".za oii" (owner-only, private/group)
1 parent df52cd5 commit 84ff76f

1 file changed

Lines changed: 29 additions & 15 deletions

File tree

examples/airich-bot.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
import { Client } from '../src/index.js'
22

3-
const TO = process.env['AIRICH_TO'] ?? ''
4-
if (!TO) {
5-
console.error('Set AIRICH_TO, e.g. AIRICH_TO=628xxxx@s.whatsapp.net bun run examples/airich-bot.ts')
3+
const OWNER = (process.env['OWNER'] ?? process.env['AIRICH_TO'] ?? '').replace(/\D/g, '')
4+
if (!OWNER) {
5+
console.error('Set OWNER (nomor kamu), e.g. OWNER=6285xxxx bun run examples/airich-bot.ts')
66
process.exit(1)
77
}
88

9+
const TRIGGER = '.za oii'
910
const POSTER = 'https://placehold.co/600x800/png'
1011
const SHOT = 'https://placehold.co/512x512/png'
1112
const CLIP = 'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4'
1213

1314
const sleep = (ms: number): Promise<void> => new Promise((r) => setTimeout(r, ms))
15+
const digitsOf = (jid: string): string => (jid.split(/[:@]/)[0] ?? '').replace(/\D/g, '')
1416

15-
const client = new Client()
16-
17-
client.on('qr', ({ qrString }) => console.log('Scan QR:', qrString))
18-
19-
client.on('connect', async ({ me }) => {
20-
const bar = '═'.repeat(34)
21-
console.log(`\n${bar}\n zaileys · AIRich showcase\n ${me.id}${TO}\n${bar}\n`)
17+
const client = new Client({ ignoreMe: false })
2218

19+
const showcase = async (target: string): Promise<void> => {
2320
let n = 0
2421
let ok = 0
2522
const send = async (label: string, fn: () => unknown): Promise<void> => {
@@ -68,7 +65,7 @@ client.on('connect', async ({ me }) => {
6865
]
6966

7067
await send('briefing', () =>
71-
client.send(TO).aiRich(
68+
client.send(target).aiRich(
7269
[
7370
{ type: 'text', text: brief },
7471
{ type: 'code', language: 'typescript', content: code },
@@ -83,7 +80,7 @@ client.on('connect', async ({ me }) => {
8380
)
8481

8582
await send('galeri', () =>
86-
client.send(TO).aiRich(
83+
client.send(target).aiRich(
8784
[
8885
{ type: 'text', text: '*Galeri rilis v4* — geser untuk lihat tangkapan layar & klip.' },
8986
{ type: 'image', url: [POSTER, SHOT] },
@@ -96,7 +93,7 @@ client.on('connect', async ({ me }) => {
9693
)
9794

9895
await send('sosial', () =>
99-
client.send(TO).aiRich(
96+
client.send(target).aiRich(
10097
[
10198
{ type: 'text', text: 'Lagi ramai dibahas komunitas 👇' },
10299
{
@@ -119,7 +116,7 @@ client.on('connect', async ({ me }) => {
119116
)
120117

121118
await send('toko', () =>
122-
client.send(TO).aiRich(
119+
client.send(target).aiRich(
123120
[
124121
{ type: 'text', text: 'Merch komunitas zaileys 🛍️' },
125122
{
@@ -136,5 +133,22 @@ client.on('connect', async ({ me }) => {
136133
),
137134
)
138135

139-
console.log(`\n${bar}\n selesai · ${ok}/${n} terkirim — cek WhatsApp kamu\n${bar}\n`)
136+
console.log(` └─ ${ok}/${n} terkirim`)
137+
}
138+
139+
client.on('qr', ({ qrString }) => console.log('Scan QR:', qrString))
140+
141+
client.on('connect', ({ me }) => {
142+
const bar = '═'.repeat(40)
143+
console.log(`\n${bar}\n zaileys · AIRich trigger bot\n online as ${me.id}\n kirim "${TRIGGER}" (private/grup) dari ${OWNER}\n${bar}\n`)
144+
})
145+
146+
client.on('text', async (msg) => {
147+
if (digitsOf(msg.senderId) !== OWNER) return
148+
if (msg.text.trim().toLowerCase() !== TRIGGER) return
149+
150+
const target = msg.roomId ?? msg.senderId
151+
console.log(`\n[trigger] "${TRIGGER}" dari ${msg.senderId}${target}`)
152+
await showcase(target)
153+
console.log('[trigger] selesai\n')
140154
})

0 commit comments

Comments
 (0)