-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
187 lines (163 loc) · 6.68 KB
/
Copy pathindex.js
File metadata and controls
187 lines (163 loc) · 6.68 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
const { Telegraf } = require('telegraf');
const fs = require('fs');
const bot = new Telegraf('Your_Token_Bot');
let anonymousUsers = [];
function saveAnonymousUsers() {
fs.writeFileSync('anonymous.json', JSON.stringify(anonymousUsers), 'utf8');
}
try {
const data = fs.readFileSync('anonymous.json', 'utf8');
if (data) {
anonymousUsers = JSON.parse(data);
}
} catch (err) {
console.error('Error reading anonymous users data:', err);
}
bot.start((ctx) => {
return ctx.reply('Hello! Let\'s play anonymously. Choose an action below:', {
reply_markup: {
inline_keyboard: [
[{ text: '🎭 Search', callback_data: 'search' },
{ text: '🛑 Stop', callback_data: 'stop' }],
[{ text: '➡️ Next', callback_data: 'next' },
{ text: '👤 Send Profile', callback_data: 'sendprofile' }]
]
}
});
});
bot.action('search', (ctx) => {
const userId = ctx.from.id;
if (!anonymousUsers.includes(userId)) {
anonymousUsers.push(userId);
saveAnonymousUsers();
const availableUsers = anonymousUsers.filter(user => user !== userId);
if (availableUsers.length > 0) {
const randomUser = availableUsers[Math.floor(Math.random() * availableUsers.length)];
ctx.editMessageText(`🎭 You have been connected with another anonymous user.`, {
reply_markup: {
inline_keyboard: [
[{ text: '🛑 Stop', callback_data: 'stop' },
{ text: '➡️ Next', callback_data: 'next' }]
]
}
});
ctx.telegram.sendMessage(randomUser, `🎭 You have been connected with another anonymous user.`, {
reply_markup: {
inline_keyboard: [
[{ text: '🛑 Stop', callback_data: 'stop' },
{ text: '➡️ Next', callback_data: 'next' }]
]
}
});
const chatId = `anonim_${userId}_${randomUser}`;
ctx.telegram.sendMessage(userId, `📞 You are communicating anonymously. Type /stop to end it.`);
ctx.telegram.sendMessage(randomUser, `📞 You are communicating anonymously. Type /stop to end it.`);
} else {
ctx.reply('🛑 No other anonymous users are available at the moment. Please wait.');
}
} else {
ctx.reply('🔒 You are already playing anonymously.');
}
});
bot.action('next', (ctx) => {
const currentUserIndex = anonymousUsers.indexOf(ctx.from.id);
if (currentUserIndex === -1) {
ctx.reply('🚫 You must start playing anonymously first with /search.');
return;
}
const nextUserIndex = (currentUserIndex + 1) % anonymousUsers.length;
const nextUserId = anonymousUsers[nextUserIndex];
ctx.telegram.sendMessage(nextUserId, '🔄 You are connected with another anonymous user.', {
reply_markup: {
inline_keyboard: [
[{ text: '🛑 Stop', callback_data: 'stop' }]
]
}
});
ctx.editMessageText('🔄 You have been moved to the next anonymous user.', {
reply_markup: {
inline_keyboard: [
[{ text: '🛑 Stop', callback_data: 'stop' }]
]
}
});
});
bot.action('stop', (ctx) => {
const userId = ctx.from.id;
const index = anonymousUsers.indexOf(userId);
if (index !== -1) {
anonymousUsers.splice(index, 1);
saveAnonymousUsers();
ctx.editMessageText('Are You Satisfied Playing Anonymous?', {
reply_markup: {
inline_keyboard: [
[{ text: '👍', callback_data: 'like' }],
[{ text: '👎', callback_data: 'dislike' }]
]
}
});
} else {
ctx.reply('🔒 You are not playing anonymously.');
}
});
bot.action('like', (ctx) => {
ctx.editMessageText('Thank You for Playing Anonymous. Don\'t Forget to Play Again!');
});
bot.action('dislike', (ctx) => {
ctx.editMessageText('Thank You for Your Rating. We will continuously update our bot\'s quality.');
});
bot.action('sendprofile', async (ctx) => {
const user = ctx.from;
try {
let userProfilePhotoUrl = '';
const userProfilePhotos = await ctx.telegram.getUserProfilePhotos(ctx.from.id);
if (userProfilePhotos && userProfilePhotos.photos.length > 0) {
const fileId = userProfilePhotos.photos[0][0].file_id;
userProfilePhotoUrl = await ctx.telegram.getFileLink(fileId);
}
const defaultPhotoUrl = 'https://cdn.miftah.biz.id/file/65d8155726ba1.jpeg';
await ctx.telegram.sendPhoto(ctx.from.id, { url: userProfilePhotoUrl || defaultPhotoUrl });
await ctx.editMessageText(`👤 Username: ${user.username}\nID: ${ctx.from.id}`);
} catch (error) {
console.error('Error sending user profile:', error);
await ctx.reply('Sorry, an error occurred while sending the user profile.');
}
});
bot.on('message', (ctx) => {
const userId = ctx.from.id;
const message = ctx.message;
const availableUsers = anonymousUsers.filter(user => user !== userId);
if (availableUsers.length > 0) {
const randomUser = availableUsers[Math.floor(Math.random() * availableUsers.length)];
if (message.text) {
ctx.telegram.sendMessage(randomUser, message.text);
} else if (message.photo) {
const photo = message.photo[0];
ctx.telegram.sendPhoto(randomUser, photo.file_id);
} else if (message.document) {
const document = message.document;
ctx.telegram.sendDocument(randomUser, document.file_id);
} else if (message.voice) {
const voice = message.voice;
ctx.telegram.sendVoice(randomUser, voice.file_id);
} else if (message.video) {
const video = message.video;
ctx.telegram.sendVideo(randomUser, video.file_id);
} else if (message.sticker) {
const sticker = message.sticker;
ctx.telegram.sendSticker(randomUser, sticker.file_id);
} else if (message.animation) {
const animation = message.animation;
ctx.telegram.sendAnimation(randomUser, animation.file_id);
} else {
ctx.reply('🛑 Unsupported file type. Please send another type of file.');
}
} else {
ctx.reply('🛑 No other anonymous users are available at the moment. Please wait.');
}
});
bot.launch().then(() => {
console.log("</> Bot is now running");
}).catch((err) => {
console.error('Error starting the bot:', err);
});