-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
182 lines (160 loc) · 9.26 KB
/
index.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
const { fetchJson, range, parseMarkdown } = require('./lib/function')
const { Telegraf } = require('telegraf')
const help = require('./lib/help')
const tele = require('./lib/tele')
const chalk = require('chalk')
const os = require('os')
const fs = require('fs')
const {
apikey,
bot_token,
owner,
ownerLink,
version,
prefix
} = JSON.parse(fs.readFileSync(`./config.json`))
if (bot_token == "") {
return console.log("=== BOT TOKEN CANNOT BE EMPTY ===")
}
const bot = new Telegraf(bot_token)
bot.on("new_chat_members", async(lol) => {
var message = lol.message
var pp_group = await tele.getPhotoProfile(message.chat.id)
var groupname = message.chat.title
var groupmembers = await bot.telegram.getChatMembersCount(message.chat.id)
for (x of message.new_chat_members) {
var pp_user = await tele.getPhotoProfile(x.id)
var full_name = tele.getUser(x).full_name
console.log(chalk.whiteBright("├"), chalk.cyanBright("[ JOINS ]"), chalk.whiteBright(full_name), chalk.greenBright("join in"), chalk.whiteBright(groupname))
await lol.replyWithPhoto({ url: `https://api.lolhuman.xyz/api/base/welcome?apikey=${apikey}&img1=${pp_user}&img2=${pp_group}&background=https://i.ibb.co/8B6Q84n/LTqHsfYS.jpg&username=${full_name}&member=${groupmembers}&groupname=${groupname}` })
}
})
bot.on("left_chat_member", async(lol) => {
var message = lol.message
var pp_group = await tele.getPhotoProfile(message.chat.id)
var pp_user = await tele.getPhotoProfile(message.left_chat_member.id)
var pp_group = await tele.getPhotoProfile(message.chat.id)
var groupname = message.chat.title
var groupmembers = await bot.telegram.getChatMembersCount(message.chat.id)
var pp_user = await tele.getPhotoProfile(message.left_chat_member.id)
var full_name = tele.getUser(message.left_chat_member).full_name
console.log(chalk.whiteBright("├"), chalk.cyanBright("[ LEAVE ]"), chalk.whiteBright(full_name), chalk.greenBright("leave from"), chalk.whiteBright(groupname))
await lol.replyWithPhoto({ url: `https://api.lolhuman.xyz/api/base/leave?apikey=${apikey}&img1=${pp_user}&img2=${pp_group}&background=https://i.ibb.co/8B6Q84n/LTqHsfYS.jpg&username=${full_name}&member=${groupmembers}&groupname=${groupname}` })
})
bot.command('start', async(lol) => {
user = tele.getUser(lol.message.from)
await help.start(lol, user.full_name)
await lol.deleteMessage()
})
bot.command('help', async(lol) => {
user = tele.getUser(lol.message.from)
await help.help(lol, user.full_name, lol.message.from.id.toString())
})
bot.on("callback_query", async(lol) => {
cb_data = lol.callbackQuery.data.split("-")
user_id = Number(cb_data[1])
if (lol.callbackQuery.from.id != user_id) return lol.answerCbQuery("Sorry, You do not have the right to access this button.", { show_alert: true })
callback_data = cb_data[0]
user = tele.getUser(lol.callbackQuery.from)
const isGroup = lol.chat.type.includes("group")
const groupName = isGroup ? lol.chat.title : ""
if (!isGroup) console.log(chalk.whiteBright("├"), chalk.cyanBright("[ ACTIONS ]"), chalk.whiteBright(callback_data), chalk.greenBright("from"), chalk.whiteBright(user.full_name))
if (isGroup) console.log(chalk.whiteBright("├"), chalk.cyanBright("[ ACTIONS ]"), chalk.whiteBright(callback_data), chalk.greenBright("from"), chalk.whiteBright(user.full_name), chalk.greenBright("in"), chalk.whiteBright(groupName))
if (callback_data == "help") return await help[callback_data](lol, user.full_name, user_id)
await help[callback_data](lol, user_id.toString())
})
bot.on("message", async(lol) => {
try {
const body = lol.message.text || lol.message.caption || ""
comm = body.trim().split(" ").shift().toLowerCase()
cmd = false
if (prefix != '' && body.startsWith(prefix)) {
cmd = true
comm = body.slice(1).trim().split(" ").shift().toLowerCase()
}
const command = comm
const args = await tele.getArgs(lol)
const user = tele.getUser(lol.message.from)
const reply = async(text) => {
for (var x of range(0, text.length, 4096)) {
return await lol.replyWithMarkdown(text.substr(x, 4096), { disable_web_page_preview: true })
}
}
const isCmd = cmd
const isGroup = lol.chat.type.includes("group")
const groupName = isGroup ? lol.chat.title : ""
const isImage = lol.message.hasOwnProperty("photo")
const isVideo = lol.message.hasOwnProperty("video")
const isAudio = lol.message.hasOwnProperty("audio")
const isSticker = lol.message.hasOwnProperty("sticker")
const isContact = lol.message.hasOwnProperty("contact")
const isLocation = lol.message.hasOwnProperty("location")
const isDocument = lol.message.hasOwnProperty("document")
const isAnimation = lol.message.hasOwnProperty("animation")
const isMedia = isImage || isVideo || isAudio || isSticker || isContact || isLocation || isDocument || isAnimation
const quotedMessage = lol.message.reply_to_message || {}
const isQuotedImage = quotedMessage.hasOwnProperty("photo")
const isQuotedVideo = quotedMessage.hasOwnProperty("video")
const isQuotedAudio = quotedMessage.hasOwnProperty("audio")
const isQuotedSticker = quotedMessage.hasOwnProperty("sticker")
const isQuotedContact = quotedMessage.hasOwnProperty("contact")
const isQuotedLocation = quotedMessage.hasOwnProperty("location")
const isQuotedDocument = quotedMessage.hasOwnProperty("document")
const isQuotedAnimation = quotedMessage.hasOwnProperty("animation")
const isQuoted = lol.message.hasOwnProperty("reply_to_message")
var typeMessage = body.substr(0, 50).replace(/\n/g, '')
if (isImage) typeMessage = "Image"
else if (isVideo) typeMessage = "Video"
else if (isAudio) typeMessage = "Audio"
else if (isSticker) typeMessage = "Sticker"
else if (isContact) typeMessage = "Contact"
else if (isLocation) typeMessage = "Location"
else if (isDocument) typeMessage = "Document"
else if (isAnimation) typeMessage = "Animation"
if (!isGroup && !isCmd) console.log(chalk.whiteBright("├"), chalk.cyanBright("[ PRIVATE ]"), chalk.whiteBright(typeMessage), chalk.greenBright("from"), chalk.whiteBright(user.full_name))
if (isGroup && !isCmd) console.log(chalk.whiteBright("├"), chalk.cyanBright("[ GROUP ]"), chalk.whiteBright(typeMessage), chalk.greenBright("from"), chalk.whiteBright(user.full_name), chalk.greenBright("in"), chalk.whiteBright(groupName))
if (!isGroup && isCmd) console.log(chalk.whiteBright("├"), chalk.cyanBright("[ COMMAND ]"), chalk.whiteBright(typeMessage), chalk.greenBright("from"), chalk.whiteBright(user.full_name))
if (isGroup && isCmd) console.log(chalk.whiteBright("├"), chalk.cyanBright("[ COMMAND ]"), chalk.whiteBright(typeMessage), chalk.greenBright("from"), chalk.whiteBright(user.full_name), chalk.greenBright("in"), chalk.whiteBright(groupName))
var file_id = ""
if (isQuoted) {
file_id = isQuotedImage ? lol.message.reply_to_message.photo[lol.message.reply_to_message.photo.length - 1].file_id :
isQuotedVideo ? lol.message.reply_to_message.video.file_id :
isQuotedAudio ? lol.message.reply_to_message.audio.file_id :
isQuotedDocument ? lol.message.reply_to_message.document.file_id :
isQuotedAnimation ? lol.message.reply_to_message.animation.file_id : ""
}
var mediaLink = file_id != "" ? await tele.getLink(file_id) : ""
switch (command) {
default:
/* if (!isGroup && !isCmd && !isMedia) {
await lol.replyWithChatAction("typing")
simi = await fetchJson(`https://api.lolhuman.xyz/api/simi?apikey=${apikey}&text=${body}`)
await reply(simi.result)
}
*/
if (!isGroup && !isCmd && !isMedia) {
await lol.replyWithChatAction("typing")
tai = await fetchJson(`https://api.srart24.xyz/srart24/simi?apikey=MlwlKq3V&pesan=${body}`)
ilhan = tai.result
await reply(ilhan)
}
}
} catch (e) {
console.log(chalk.whiteBright("├"), chalk.cyanBright("[ ERROR ]"), chalk.redBright(e))
}
})
bot.launch()
bot.telegram.getMe().then((getme) => {
itsPrefix = (prefix != "") ? prefix : "No Prefix"
console.log(chalk.greenBright(' ===================================================='))
console.log(chalk.greenBright(" │ + Owner : " + owner || ""))
console.log(chalk.greenBright(" │ + Bot Name : " + getme.first_name || ""))
console.log(chalk.greenBright(" │ + Version : " + version || ""))
console.log(chalk.greenBright(" │ + Host : " + os.hostname() || ""))
console.log(chalk.greenBright(" │ + Platfrom : " + os.platform() || ""))
console.log(chalk.greenBright(" │ + Prefix : " + itsPrefix))
console.log(chalk.greenBright(' ===================================================='))
console.log(chalk.whiteBright('╭─── [ LOG ]'))
})
process.once('SIGINT', () => bot.stop('SIGINT'))
process.once('SIGTERM', () => bot.stop('SIGTERM'))