-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
86 lines (73 loc) · 2.41 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
const TelegramBot = require('node-telegram-bot-api'); // https://github.com/yagop/node-telegram-bot-api
const Discord = require('discord.js'); // https://github.com/discordjs/discord.js
const config = require("./config.json");
const { WebhookClient, MessageEmbed,} = require('discord.js')
const token = config.token;
const token2 = config.token2;
const channelid = config.channelid;
const bot = new TelegramBot(token, {polling: true});
const bot2 = new Discord.Client();
bot.onText(/\/echo (.+)/, (msg, match) => {
const chatId = msg.chat.id;
const resp = match[1];
bot.sendMessage(chatId, resp);
});
const wc = new WebhookClient(config.webhookid, config.webhooktoken)
bot.on('photo', (msg) => {
const fileId = (msg.photo[msg.photo.length-1].file_id);
const downloadDir = './images'
let something = ''
var https = require('https')
bot.getFileLink(fileId).then( async (fileUri) => {
var base64Img = require('base64-img');
var fs = require('fs');
let time = process.hrtime();
let extension = fileUri.split('.').pop();
let newName = `${time[0]}${time[1]}.${extension}`;
let file = fs.createWriteStream(`${downloadDir}/${newName}`);
let request = await https.get(fileUri, (response) => {
response.pipe(file);
});
file.on('finish', () =>{
const embed = new MessageEmbed()
.setTitle('Image')
.attachFiles(`./images/${newName}`)
.setImage(`attachment://${newName}`)
.setColor(`#0088CC`)
try {
wc.send({
username : msg.from.first_name,
avatarURL : 'https://i.imgur.com/FvkH4GU.png',
embeds : [embed]
})
}
catch(error) {
console.log('error:', error);
}
})
});
});
bot.on('message', (msg) => {
const chatId = msg.chat.id;
if (!msg.photo) {
try {
wc.send({
username : msg.from.first_name,
avatarURL : 'https://i.imgur.com/FvkH4GU.png',
content : `${msg.text}`
})
}
catch(error) {
console.log('error:', error);
}
}
});
bot2.on('message', msg => {
if (msg.author.bot) return;
else if (msg.channel.id == '615514704135061509')
bot.sendMessage(-1001413954921, `${msg.author.username}: ${msg.content}`);
else return;
});
bot.on("polling_error", console.log);
bot2.login(token2);
// end of script