-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
158 lines (141 loc) · 6.53 KB
/
index.ts
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
/**
* @license
BSD 3-Clause License
Copyright (c) 2024, the respective contributors, as shown by Persian Caesar and Sobhan.SRZA (mr.sinre) file.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Add color to console messages.
import "colors";
// Support .env args
import * as dotenv from "dotenv";
dotenv.config();
// Load discord client
import { readdirSync } from "fs";
import TelegramClient from "./src/classes/Client";
import packageJSON from "./src/types/package.json";
import logger from "./src/functions/logger";
import error from "./src/utils/error";
import post from "./src/functions/post";
import os from "os";
const
client = new TelegramClient(),
handle = readdirSync(__dirname + "/src/handlers").filter(file => file.endsWith(".js"));
// Login
const main = async () => {
try {
// Load Handlers
let amount = 0;
const packageJSON: packageJSON = await import(`${process.cwd()}/package.json`);
post(
"Welcome to ".cyan + (packageJSON.name).blue + "! | Version: ".cyan + (packageJSON.version).blue + "\n" +
"Coded By ".cyan + ("Sobhan-SRZA").yellow + " & ".cyan + ("Persian Caesar").yellow + " With ".cyan + ("❤️").red + "\n" +
`Discord: ${("Mr.Sinre").blue}` + " | ".cyan + `${("mr.sinre").blue}` + " | ".cyan + `${("https://dsc.gg/persian-caesar").blue}` + "\n" +
`GitHub: ${("https://github.com/Sobhan-SRZA").blue}` + " | ".cyan + `${("https://github.com/Persian-Caesar").blue}`,
"W",
"magenta",
"cyan"
);
post("Logging into the BOT...", "S");
for (const file of handle) {
const handlerFile = await import(`./src/handlers/${file}`);
const handler = handlerFile.default || handlerFile;
await handler(client);
amount++;
}
post((String(amount)).cyan + " Handler Is Loaded!!".green, "S");
if (client.config.bot.token)
await client
.launch(async () => {
post(
"Telegram bot is online!".blue + `\n` +
"@" + client.botInfo!.username.cyan + " is now online :)".green,
"S"
);
logger(
"Commands: ".blue +
`${client.commands.size}`.cyan + `\n` +
"Telegraf.js: ".blue +
`v${packageJSON.dependencies.telegraf.replace("^", "")}`.cyan + `\n` +
"Node.js: ".blue +
`${process.version}`.cyan + `\n` +
"Plattform: ".blue +
`${process.platform} ${process.arch} | ${os.cpus().map((i) => `${i.model}`)[0]} | ${String(os.loadavg()[0])}%`.cyan + `\n` +
"Memory: ".blue +
`${Math.round(
+((os.totalmem() - os.freemem()) / 1024 / 1024).toFixed(2)
)
.toLocaleString()
}/${Math.round(
+((os.totalmem()) / 1024 / 1024).toFixed(2)
)
.toLocaleString()
} MB | ${(
(
(os.totalmem() - os.freemem()) / os.totalmem()
) * 100)
.toFixed(2)
}%`.cyan
);
// Upload commands to the button menu.
const commands = client.commands.map(
a => {
return {
command: a.data.name.slice(0, 31),
description: a.data.description.slice(0, 255)
}
}
);
await client.telegram.setMyCommands(
commands
)
})
.catch(e => {
post("Something when bot is loading went wrong!", "E", "red", "red");
error(e);
});
else
post("Please write your bot token opposite the token in the config.js file (or .env file) in your project!!", "E", "red", "red");
} catch (e: any) {
error(e);
client.stop();
process.exit(1);
}
};
void main();
// Load Anti Crash
if (client.config.source.anti_crash) {
process.on("unhandledRejection", (e: any) => error(e));
process.on("rejectionHandled", (e: any) => error(e));
process.on("uncaughtException", (e: any) => error(e));
process.on("uncaughtExceptionMonitor", (e: any) => error(e));
}
// Export client
export default client;
/**
* @copyright
* Code by Sobhan-SRZA (mr.sinre) | https://github.com/Sobhan-SRZA
* Developed for Persian Caesar | https://github.com/Persian-Caesar | https://dsc.gg/persian-caesar
*
* If you encounter any issues or need assistance with this code,
* please make sure to credit "Persian Caesar" in your documentation or communications.
*/