File size: 1,707 Bytes
bb69f9b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const {
  bot,
  setWord,
  getWord,
  // genButtonMessage
} = require('../lib')

const actions = ['null', 'warn', 'kick']

bot(
  {
    pattern: 'antiword ?(.*)',
    desc: 'filter the group chat',
    onlyGroup: true,
    type: 'group',
  },
  async (message, match) => {
    if (!match || (match != 'on' && match != 'off' && !match.startsWith('action'))) {
      const { enabled, action } = await getWord(message.jid, message.id)
      return await message.send(
        `_Antiword is ${
          enabled ? 'on' : 'off'
        } (${action})_\n*Example :*\nantiword action/(kick|warn|null)\nantiword on | off\nsetvar ANTIWORDS:word1,word2`
      )
      // const buttons = actions
      // 	.filter((e) => e != action)
      // 	.map((button) => ({
      // 		text: button,
      // 		id: `antiword action/${button}`,
      // 	}))
      // buttons.push({
      // 	text: enabled ? 'OFF' : 'ON',
      // 	id: `antiword ${enabled ? 'off' : 'on'}`,
      // })
      // return await message.send(
      // 	await genButtonMessage(
      // 		buttons,
      // 		'AntiWord\nExample : antiword on/off\nantiword action/null or kick or warn\nsetvar ANTIWORDS:word1,word2,...'
      // 	),
      // 	{},
      // 	'button'
      // )
    }
    if (match.startsWith('action/')) {
      const action = match.replace('action/', '')
      if (!actions.includes(action)) return await message.send(`${action} _is a invalid action_`)
      await setWord(message.jid, action, message.id)
      return await message.send(`_antiword action updated as ${action}_`)
    }
    await setWord(message.jid, match == 'on', message.id)
    await message.send(`_AntiWord ${match == 'on' ? 'activated' : 'deactivated.'}_`)
  }
)