-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
282 lines (254 loc) · 8.33 KB
/
Copy pathindex.js
File metadata and controls
282 lines (254 loc) · 8.33 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
const { TelegramClient, Api } = require("telegram");
const { StringSession } = require("telegram/sessions");
const input = require("input");
const axios = require("axios");
const chalk = require("chalk");
require("dotenv").config();
const { Logger } = require("telegram/extensions");
Logger.setLevel("none");
const apiId = parseInt(process.env.API_ID);
const apiHash = process.env.API_HASH;
const stringSession = new StringSession(process.env.STRING_SESSION);
const geminiApiKey = process.env.GEMINI_API_KEY;
const GEMINI_API_URL = `https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=${geminiApiKey}`;
let groupsCreated = 0;
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function getRandomDelay(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
function generateFallbackGroupName() {
const adjectives = [
"Awesome",
"Happy",
"Creative",
"Fun",
"Amazing",
"Positive",
"Super",
"Cool",
"Vibrant",
"Dynamic",
];
const nouns = [
"Crew",
"Team",
"Squad",
"Group",
"Friends",
"Community",
"Zone",
"Hub",
"Circle",
"Alliance",
];
const adjective = adjectives[Math.floor(Math.random() * adjectives.length)];
const noun = nouns[Math.floor(Math.random() * nouns.length)];
return `🚀 ${adjective} ${noun} ${Math.floor(Math.random() * 1000)}`;
}
async function generateRandomGroupInfo() {
console.log(
chalk.blue("│ ") +
chalk.yellow("🤖 Asking AI for a group name and description...")
);
try {
const response = await axios.post(GEMINI_API_URL, {
contents: [
{
parts: [
{
text: 'Generate a unique, creative, and friendly Telegram group name and a short, welcoming description for it. The group is for making new friends and sharing positive vibes. Return the result as a single, clean JSON object with two keys: "groupName" and "groupDescription". Example: {"groupName": "Cosmic Connections 🚀", "groupDescription": "A place to share good vibes and connect with new people."}',
},
],
},
],
generationConfig: {
responseMimeType: "application/json",
},
});
const data = response.data.candidates[0].content.parts[0].text;
const parsedData = JSON.parse(data);
console.log(
chalk.blue("│ ") + chalk.green("🤖 AI provided creative assets!")
);
return parsedData;
} catch (error) {
console.log(
chalk.red("│ ") +
chalk.yellow("⚠️ Gemini API error for group info, using fallback.")
);
return {
groupName: generateFallbackGroupName(),
groupDescription:
"A friendly and motivational group created with good vibes.",
};
}
}
async function generateRandomMessage(groupName) {
try {
const response = await axios.post(GEMINI_API_URL, {
contents: [
{
parts: [
{
text: `Generate a unique, welcoming, and friendly message for a new Telegram group called "${groupName}". The message should be short, positive, and include a relevant emoji. Make it sound natural and not repetitive.`,
},
],
},
],
generationConfig: {
temperature: 0.8,
},
});
return response.data.candidates[0].content.parts[0].text.trim();
} catch (error) {
console.log(
chalk.red("│ ") +
chalk.yellow("⚠️ Gemini API error, using fallback message")
);
return "Welcome everyone! Let's make this group awesome! ✨";
}
}
async function createGroupAndSendMessages(client) {
try {
console.log(chalk.blue("╭─ ") + chalk.bold("Creating New Group"));
const { groupName, groupDescription } = await generateRandomGroupInfo();
console.log(
chalk.blue("│ ") +
chalk.cyan("🏗️ Group Name: ") +
chalk.bold.white(`"${groupName}"`)
);
console.log(
chalk.blue("│ ") +
chalk.cyan("📝 Description: ") +
chalk.dim.white(`"${groupDescription}"`)
);
console.log(chalk.blue("│ ") + chalk.gray("⏳ Setting up channel..."));
const group = await client.invoke(
new Api.channels.CreateChannel({
title: groupName,
about: groupDescription,
megagroup: true,
})
);
const chatId = group.chats[0].id;
groupsCreated++;
console.log(
chalk.blue("│ ") + chalk.green("✅ Group created successfully!")
);
console.log(
chalk.blue("│ ") +
chalk.yellow("📊 Total Groups: ") +
chalk.bold.cyan(groupsCreated)
);
console.log(chalk.blue("╰─ ") + chalk.dim(`Chat ID: ${chatId}`));
console.log();
const mainDelay = getRandomDelay(30, 90);
console.log(chalk.magenta("╭─ ") + chalk.bold("Preparation Phase"));
console.log(
chalk.magenta("│ ") +
chalk.yellow("⏱️ Applying anti-spam delay: ") +
chalk.bold.white(`${mainDelay} seconds`)
);
await sleep(mainDelay * 1000);
console.log(chalk.magenta("╰─ ") + chalk.green("Ready to send messages!"));
console.log();
const messageCount = getRandomDelay(5, 10);
console.log(chalk.green("╭─ ") + chalk.bold("Message Broadcast"));
console.log(
chalk.green("│ ") +
chalk.cyan("📨 Messages to send: ") +
chalk.bold.white(messageCount)
);
for (let i = 0; i < messageCount; i++) {
const message = await generateRandomMessage(groupName);
console.log(
chalk.green("│ ") +
chalk.blue(`[${i + 1}/${messageCount}] `) +
chalk.white("📝 ") +
chalk.dim(message)
);
await client.invoke(
new Api.messages.SetTyping({
peer: chatId,
action: new Api.SendMessageTypingAction(),
})
);
const messageDelay = getRandomDelay(15, 45);
console.log(
chalk.green("│ ") + chalk.gray(` ...waiting ${messageDelay}s`)
);
await sleep(messageDelay * 1000);
await client.sendMessage(chatId, { message: message });
}
console.log(
chalk.green("╰─ ") +
chalk.bold.green("🎉 All messages sent successfully!")
);
console.log();
} catch (error) {
console.log(chalk.red("╭─ ") + chalk.bold("Error Occurred"));
console.log(chalk.red("│ ") + chalk.yellow("⚠️ ") + error.message);
console.log(
chalk.red("╰─ ") + chalk.dim("Continuing to next operation...")
);
console.log();
}
}
(async () => {
console.clear();
console.log(chalk.magenta.bold("========================================="));
console.log(
chalk.magenta.bold("🤖 Welcome to the AI Telegram Group Creator 🤖")
);
console.log(
chalk.magenta.bold("=========================================\n")
);
const client = new TelegramClient(stringSession, apiId, apiHash, {
connectionRetries: 5,
});
await client.start({
phoneNumber: async () =>
await input.text(chalk.blue("📞 Please enter your number: ")),
password: async () =>
await input.text(chalk.blue("🔒 Please enter your password: ")),
phoneCode: async () =>
await input.text(chalk.blue("🔢 Please enter the code you received: ")),
onError: (err) => console.log(chalk.red(err)),
});
const me = await client.getMe();
console.log(
chalk.green(`\n✅ Logged in successfully as ${chalk.bold(me.firstName)}`)
);
if (process.env.STRING_SESSION.length === 0) {
console.log(
chalk.yellow("\n🔑 Your session string is:", client.session.save())
);
console.log(
chalk.yellow.bold(
"💾 Please save this to your .env file as STRING_SESSION to avoid logging in again."
)
);
await client.disconnect();
return;
}
while (true) {
await createGroupAndSendMessages(client);
const continueChoice = await input.text(
chalk.blue.bold("\n❓ Create another group? (y/n): ")
);
if (continueChoice.toLowerCase() !== "y") {
break;
}
}
console.log(chalk.cyan("\n👋 All done! Disconnecting..."));
await client.disconnect();
console.log(
chalk.magenta.bold("\n=========================================")
);
console.log(
chalk.magenta.bold(`📊 Final Statistics: ${groupsCreated} groups created.`)
);
console.log(chalk.magenta.bold("========================================="));
})();