-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
hisoka_chat.js
147 lines (121 loc) · 5.41 KB
/
hisoka_chat.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
require("./config")
const wawebjs = require("whatsapp-web.js")
const fs = require('fs')
const util = require('util')
const chalk = require('chalk')
const { exec, spawn, execSync } = require("child_process")
const axios = require('axios')
const os = require('os')
const moment = require("moment-timezone")
const { correct } = require("./lib/Correct")
module.exports = async (hisoka, m, commands) => {
try {
const { body, from, hasMedia: isMedia, type } = m
let sender = m.author || m.from
var prefix = /^[°•π÷׶∆£¢€¥®™+✓_=|~!?@#$%^&.©^]/gi.test(body) ? body.match(/^[°•π÷׶∆£¢€¥®™+✓_=|~!?@#$%^&.©^]/gi)[0] : '#'
let isCmd = body.startsWith(prefix)
const command = body.replace(prefix, '').trim().split(/ +/).shift().toLowerCase()
const args = body.trim().split(/ +/).slice(1)
const isOwner = [hisoka.info.wid._serialized, ...global.owner].map(v => v.replace(/[^0-9]/g, '') + '@c.us').includes(sender)
const text = args.join(" ")
const quoted = m.hasQuotedMsg ? await m.getQuotedMessage() : m
const mime = (quoted._data || quoted).mimetype || ""
const isGroup = from.endsWith("@g.us")
const metadata = await m.getChat()
const groupName = isGroup ? metadata.groupMetadata.name : ""
const participants = isGroup ? metadata.groupMetadata.participants : []
const groupAdmins = isGroup ? participants.filter(v => v.isAdmin && !v.isSuperAdmin).map(v => v.id._serialized) : []
const isBotAdmin = isGroup ? groupAdmins.includes(hisoka.info.wid._serialized) : false
const isAdmin = isGroup ? groupAdmins.includes(sender) : false
if (m) {
console.log(chalk.black(chalk.bgWhite('[ PESAN ]')), chalk.black(chalk.bgGreen(new Date(m._data.t * 1000))), chalk.black(chalk.bgGreen(body || type)) + "\n" + chalk.black(chalk.bgWhite("=> Dari")), chalk.black(chalk.bgGreen(m._data.notifyName)), chalk.black(chalk.yellow(sender)) + "\n" + chalk.black(chalk.bgWhite("=> Di")), chalk.bgGreen(isGroup ? groupName : m._data.notifyName, from))
}
//if (options.autoRead) (hisoka.type == "legacy") ? await hisoka.chatRead(m.key, 1) : await hisoka.sendReadReceipt(from, sender, [m.id])
if (options.mute && !isOwner) return
if (!options.public) {
if (!m.id.fromMe) return
}
const cmd = commands.get(command) || Array.from(commands.values()).find((v) => v.alias.find((x) => x.toLowerCase() == command)) || ""
if (isCmd && !cmd) {
var array = Array.from(commands.keys());
Array.from(commands.values()).map((v) => v.alias).join(" ").replace(/ +/gi, ",").split(",").map((v) => array.push(v))
var anu = await correct(command, array)
var alias = commands.get(anu.result) || Array.from(commands.values()).find((v) => v.alias.find((x) => x.toLowerCase() == anu.result)) || ""
console.log(anu)
teks = `
Command *Not Found!*, Maybe you mean is
*_Command :_* ${prefix + anu.result}
*_Alias :_* ${alias.alias.join(", ")}
*_Accurary :_* ${anu.rating}
_Send command again if needed_
`
m.reply(teks)
} else if (!cmd) return
if (cmd.isMedia && !isMedia) {
return global.mess("media", m)
}
if (cmd.isOwner && !isOwner) {
return
}
if (cmd.isGroup && !isGroup) {
return global.mess("group", m)
}
if (cmd.isPrivate && isGroup) {
return global.mess("private", m)
}
if (cmd.isBotAdmin && !isBotAdmin) {
return global.mess("botAdmin", m)
}
if (cmd.isAdmin && !isAdmin) {
return global.mess("admin", m)
}
if (cmd.isBot && m.id.fromMe) {
return global.mess("bot", m)
}
if (cmd.disable && cmd) {
return global.mess("dead", m)
}
if (cmd.desc && text.endsWith("--desc")) return m.reply(cmd.desc)
if (cmd.example && text.endsWith("--use")) {
return m.reply(`${cmd.example.replace(/%prefix/gi, prefix).replace(/%command/gi, cmd.name).replace(/%text/gi, text)}`)
}
if (cmd.isQuery && !text) {
return m.reply(`${cmd.example.replace(/%prefix/gi, prefix).replace(/%command/gi, cmd.name).replace(/%text/gi, text)}`)
}
try {
let cmdOptions = {
name: "Dika Ardnt.",
body,
from,
isMedia,
type,
sender,
prefix,
command,
commands,
args,
isOwner,
text,
quoted,
mime,
isGroup,
metadata,
groupName,
participants,
groupAdmins,
isBotAdmin,
isAdmin,
toUpper: function(query) {
return query.replace(/^\w/, c => c.toUpperCase())
},
Function: require("./lib"),
}
cmd.start(hisoka, m, cmdOptions)
} catch(e) {
console.error(e)
}
} catch (e) {
m.reply(util.format(e))
}
}
global.reloadFile(__filename)