Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const TelegramBot = require('node-telegram-bot-api');
- const mongoose = require('mongoose');
- const User = require('./models/User')
- const utils = require("./modules/utils");
- mongoose.connect('mongodb://localhost/test' , {
- useNewUrlParser: true,
- useUnifiedTopology: true
- })
- .then(() => {
- console.log('mongo db connected');
- })
- .catch(error => console.log(error));
- const token = 'токен';
- const bot = new TelegramBot(token, {polling: true});
- bot.onText(/\/echo (.+)/, (msg, match) => {
- const chatId = msg.chat.id;
- const resp = match[1];
- bot.sendMessage(chatId, resp);
- });
- bot.on('message', async (msg) => {
- const chatId = msg.chat.id;
- const count = await User.countDocuments();
- var fromId = msg.from.id
- console.log('[+] Runned /start command')
- User.find({id: fromId}, (err, user) => {
- if (err) throw err
- if (user.length === 0) {
- const newUser = new User({
- id: msg.from.id,
- uid: count + 1,
- balance: 0,
- username: msg.from.username,
- firstname: msg.from.first_name,
- lastname: msg.from.last_name,
- createdAt: getUnix(),
- gender: 0,
- chats: 0,
- active: 'Не задано',
- active1: 0,
- vip: false,
- admin: false,
- premium: false,
- notifications: true,
- ban: false,
- free: 0,
- free2: 0,
- free3: 0,
- free4: 0,
- free5: 0,
- free6: 0,
- free7: 0,
- free8: 0,
- free9: 0,
- boolean: false,
- boolean1: false,
- boolean2: false,
- boolean3: false,
- boolean4: false,
- boolean5: false,
- boolean6: false,
- boolean7: false,
- boolean8: false,
- boolean9: false,
- string: 'string',
- string1: 'string',
- string2: 'string',
- string3: 'string',
- string4: 'string',
- string5: 'string',
- string6: 'string',
- string7: 'string',
- string8: 'string',
- string9: 'string'
- })
- newUser.save((err) => {
- if (err) throw err
- bot.sendMessage(msg.chat.id, `Привет ${msg.from.first_name}, спасибо что зарегистрировались в нашем боте! \n Наш бот находится в разработке, поэтому Вы пока что не сможете найти тут собеседников. Прошу Вас пока что присоединиться к нашему телеграм каналу, чтобы следить за новостями - t.me/RuAnon \n Как только бот будет готов, мы обо всём там напишем и Вы сможете общаться 😏 \n По всем вопросам - @superman_da`);
- })
- }
- })
- })
- bot.on('sticker', function(msg) {
- sendX('sticker', msg);
- });
- bot.on('audio', function(msg) {
- sendX('audio', msg);
- });
- bot.on('document', function(msg) {
- sendX('document', msg);
- });
- bot.on('photo', function(msg) {
- sendX('photo', msg);
- });
- bot.on('video', function(msg) {
- sendX('video', msg);
- });
- bot.on('voice', function(msg) {
- sendX('voice', msg);
- });
- bot.on('contact', function(msg) {
- sendX('contact', msg);
- });
- bot.on('location', function(msg) {
- sendX('location', msg);
- });
- bot.onText(/\профиль/, async msg => {
- var fromId = msg.from.id
- let muser = await User.findOne({id: fromId})
- bot.sendMessage(msg.chat.id,`
- 🔎 ID: ${muser.uid}
- Дата регистрации: ${unixStamp(muser.createdAt)}`)
- })
- bot.onText(/\/start/, async msg => {
- var fromId = msg.from.id
- let muser = await User.findOne({id: fromId})
- bot.sendMessage(msg.chat.id,` ${muser.firstname}, Вы уже зарегестрированы!`)
- })
- bot.onText(/\/sharelink/, async msg => {
- var fromId = msg.from.id
- let muser = await User.findOne({
- id: fromId
- })
- console.log(`${muser.id}`)
- let id = msg.chat.id;
- let message = `[Вот ссылка на Ваш аккаунт](tg://user?id=${muser.id})`
- console.log(message)
- return bot.sendMessage(id, message, {parse_mode: 'Markdown'})
- })
- bot.onText(/\стат/, async msg => {
- var fromId = msg.from.id
- let muser = await User.findOne({
- id: fromId
- })
- await muser.set("free", msg.from.id)
- let _users = await User.countDocuments();
- bot.sendMessage(msg.chat.id, `🙎♂️ Пользователей: ${_users}`)
- bot.sendMessage(msg.chat.id, `🙎♂️ ${muser.free}`)
- })
- bot.onText(/\/send/, async msg => {
- var fromId = msg.from.id
- let muser = await User.findOne({
- id: fromId
- })
- await muser.set("free", msg.from.id)
- bot.sendMessage(msg.chat.id, `айди ${muser.free}
- айди в боте ${muser.uid} `)
- })
- bot.onText(/\/search/, async msg => {
- var fromId = msg.from.id
- let muser = await User.findOne({
- id: fromId
- })
- let users = await User.find({
- free: {
- $gte
- }
- });
- let user2 = users[utils.random(0, users.length - 1)]
- let user1 = await User.findOne({
- id: msg.chat.id
- });
- sendX('Собеседник найден!')
- await muser.set("free", msg.from.id)
- });
- console.log('[START]')
- User.prototype.inc = function(field, value) {
- this[field] += value;
- return this.save();
- }
- User.prototype.dec = function(field, value) {
- this[field] -= value;
- return this.save();
- }
- User.prototype.set = function(field, value) {
- this[field] = value;
- return this.save();
- }
- function flipString(string) {
- let result = "";
- string = string.toLowerCase().split("").reverse();
- string.map((symbol) => {
- result += flipTable[symbol] || symbol;
- });
- return result;
- }
- function time() {
- let date = new Date();
- let days = date.getDate();
- let hours = date.getHours();
- let minutes = date.getMinutes();
- let seconds = date.getSeconds();
- if (hours < 10) hours = "0" + hours;
- if (minutes < 10) minutes = "0" + minutes;
- if (seconds < 10) seconds = "0" + seconds;
- var times = hours + ':' + minutes + ':' + seconds
- return times;
- }
- //------------------------------------------------------------------------------------\\
- function date() {
- var date = new Date();
- let days = date.getDate();
- let month = date.getMonth() + 1;
- let year = date.getFullYear()
- if (month < 10) month = "0" + month;
- if (days < 10) days = "0" + days;
- var datas = days + '.' + month + '.' + year;
- return datas;
- }
- function timeConverter(UNIX_timestamp) {
- let a = new Date(UNIX_timestamp * 1000);
- let months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
- let year = a.getFullYear();
- let month = months[a.getMonth()];
- let date = a.getDate();
- let hour = a.getHours();
- let min = a.getMinutes();
- let sec = a.getSeconds();
- if (hour < 10) hour = `0${hour}`;
- if (min < 10) min = `0${min}`;
- if (sec < 10) sec = `0${sec}`;
- if (date < 10) date = `0${date}`;
- let read_time = `${hour}:${min}:${sec}`;
- let read_date = date + '.' + month + '.' + year;
- let time_date = date + '.' + month + '.' + year + ' | ' + hour + ':' + min + ':' + sec;
- let time = {
- moment: time_date,
- date: read_date,
- time: read_time,
- years: year,
- months: month,
- number: date,
- hours: hour,
- minutes: min,
- secunds: sec
- }
- return time;
- }
- function getUnix() {
- return Date.now();
- }
- function unixStamp(stamp) {
- let a = new Date(stamp);
- let months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
- let year = a.getFullYear();
- let month = months[a.getMonth()];
- let date = a.getDate();
- let hour = a.getHours();
- let min = a.getMinutes();
- let sec = a.getSeconds();
- if (hour < 10) hour = `0${hour}`;
- if (min < 10) min = `0${min}`;
- if (sec < 10) sec = `0${sec}`;
- if (date < 10) date = `0${date}`;
- let read_time = `${hour}:${min}:${sec}`;
- let read_date = date + '.' + month + '.' + year;
- let time_date = date + '.' + month + '.' + year + ' , ' + hour + ':' + min + ':' + sec;
- return time_date;
- }
- function unixStampLeft(stamp) {
- stamp = stamp / 1000;
- let s = stamp % 60;
- stamp = (stamp - s) / 60;
- let m = stamp % 60;
- stamp = (stamp - m) / 60;
- let h = (stamp) % 24;
- let d = (stamp - h) / 24;
- let text = ``;
- if (d > 0) text += Math.floor(d) + " д. ";
- if (h > 0) text += Math.floor(h) + " ч. ";
- if (m > 0) text += Math.floor(m) + " мин. ";
- if (s > 0) text += Math.floor(s) + " с.";
- return text;
- }
- async function sendX(string, msg){
- let users = await User.find({
- free
- });
- var currentChatId = msg.chat.id;
- var partnerChatId = users.free;
- if(partnerChatId == undefined)
- if(includes.inAnObject(msg.chat.id)){
- bot.sendMessage(currentChatId, "нет пользователей");
- return;
- } else {
- bot.sendMessage(currentChatId,"ура dialog начат" );
- return;
- }
- switch(string){
- case 'text':
- bot.sendMessage(partnerChatId, msg.text);
- break;
- case 'sticker':
- bot.sendSticker(partnerChatId, msg.sticker.file_id);
- break;
- case 'audio':
- bot.sendAudio(partnerChatId, msg.audio.file_id);
- break;
- case 'document':
- bot.sendDocument(partnerChatId, msg.document.file_id);
- break;
- case 'photo':
- bot.sendPhoto(partnerChatId, msg.photo[msg.photo.length - 1].file_id, {caption: msg.caption});
- break;
- case 'video':
- bot.sendVideo(partnerChatId, msg.video.file_id, {caption: msg.caption});
- break;
- case 'voice':
- bot.sendVoice(partnerChatId, msg.voice.file_id);
- break;
- case 'contact':
- bot.sendContact(partnerChatId, msg.contact.phone_number, msg.contact.first_name);
- break;
- case 'location':
- bot.sendLocation(partnerChatId, msg.location.latitude, msg.location.longitude);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement