File size: 4,276 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const {
  bot,
  getMsg,
  jidToNum,
  resetMsgs,
  getFloor,
  sleep,
  secondsToHms,
  isAdmin,
  addSpace,
} = require('../lib')

bot(
  {
    pattern: 'msgs ?(.*)',
    desc: 'shows groups message count',
    type: 'group',
    onlyGroup: true,
  },
  async (message, match) => {
    const user = message.mention[0] || message.reply_message.jid
    const participants = await getMsg(message.jid, user)
    let msg = ''
    const now = new Date().getTime()
    if (user) {
      msg += `*Number :* ${jidToNum(user)}\n*Name :* ${participants.name || ''}\n*Total Msgs :* ${
        participants.total
      }\n`
      const { items } = participants
      for (const item in items) msg += `*${item} :* ${items[item]}\n`
      msg += `*lastSeen :* ${secondsToHms((now - participants.time) / 1000) || 0} ago\n\n`
    } else {
      for (const participant in participants) {
        msg += `*Number :* ${jidToNum(participant)}\n*Name :* ${
          participants[participant].name || ''
        }\n*Total Msgs :* ${participants[participant].total}\n`
        const { items } = participants[participant]
        for (const item in items) msg += `*${item} :* ${items[item]}\n`
        msg += `*lastSeen :* ${
          secondsToHms((now - participants[participant].time) / 1000) || 0
        } ago\n\n`
      }
    }
    await message.send(msg.trim())
  }
)

bot(
  {
    pattern: 'reset ?(.*)',
    desc: 'reset groups message count',
    type: 'group',
    onlyGroup: true,
  },
  async (message, match) => {
    const user = message.reply_message.jid || message.mention[0]
    if (!user && match != 'all')
      return await message.send('*Example :*\nreset all\nreset mention/reply a person')
    if (match == 'all') {
      await resetMsgs(message.jid)
      return await message.send('_Everyones message count deleted._')
    }
    await resetMsgs(message.jid, user)
    return await message.send(`_@${jidToNum(user)} message count deleted._`, {
      contextInfo: { mentionedJid: [user] },
    })
  }
)

bot(
  {
    pattern: 'inactive ?(.*)',
    desc: 'show/kick who message count not met',
    type: 'group',
    onlyGroup: true,
  },
  async (message, match) => {
    const members = await message.groupMetadata(message.jid)
    const membersJids = members.map(({ id }) => id)
    const [type, count, kickOrType, COUNT, KICK] = match.split(' ')
    if (
      !type ||
      !count ||
      (type.toLowerCase() != 'total' && type.toLowerCase() != 'day') ||
      isNaN(count) ||
      (kickOrType && kickOrType != 'total' && kickOrType != 'kick') ||
      (COUNT && isNaN(COUNT))
    )
      return await message.send(
        `*Example :*\ninactive day 10\ninactive day 10 kick\ninactive total 100\ninactive total 100 kick\ninactive day 7 total 150\ninactive day 7 total 150 kick\n\nif kick not mentioned, Just list`
      )
    const participants = await getMsg(message.jid)
    const now = new Date().getTime()
    const inactive = []
    for (const participant of membersJids) {
      if (!participants[participant]) inactive.push(participant)
      else if (kickOrType && kickOrType == 'total') {
        if (
          participants[participant].total <= COUNT &&
          getFloor((now - participants[participant].time) / 1000) / 86400 >= count
        )
          inactive.push(participant)
      } else if (type == 'total') {
        if (participants[participant].total <= count) inactive.push(participant)
      } else {
        if (getFloor((now - participants[participant].time) / 1000) / 86400 >= count)
          inactive.push(participant)
      }
    }
    let msg = `_Total inactives are : ${inactive.length}_`
    if (inactive.length < 1) return await message.send(msg)
    if (kickOrType == 'kick' || KICK == 'kick') {
      const isImAdmin = await isAdmin(members, message.client.user.jid)
      if (!isImAdmin) return await message.send(`_I'm not admin._`)
      await message.send(`_Removing ${inactive.length} inactive members in 7 seconds_`)
      await sleep(7000)
      return await message.Kick(inactive)
    }
    for (let i = 0; i < inactive.length; i++)
      msg += `\n*${i + 1}.*${addSpace(i + 1, inactive.length)} @${jidToNum(inactive[i])}`
    return await message.send(msg, {
      contextInfo: { mentionedJid: inactive },
    })
  }
)