This repository has been archived by the owner on Jan 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
137 lines (106 loc) · 3.65 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
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
const Discord = require('discord.js');
const client = new Discord.Client({
partials: [
'MESSAGE', 'CHANNEL', 'REACTION'
],
intents: [Discord.Intents.FLAGS.DIRECT_MESSAGES, Discord.Intents.FLAGS.DIRECT_MESSAGE_TYPING]
})
const extractUrls = require("extract-urls");
const {SauceNao} = require('saucenao.js');
const config = require('./config.json');
const {saucenao, allowed_channels} = config;
const sauce = new SauceNao({api_key: saucenao})
client.on("message", async message => {
if (message.guild === null) {
return;
}
if (message.attachments.size > 0) {
let aaa = message
.attachments
.first();
if (String(aaa.url).match(/\.(jpeg|jpg|png)$/) != null) {
await message.react('😳');
await message.react("🖕");
}
}
if (!(message.attachments.size > 0)) {
// var urlRegex = /(https?:\/\/[^ ]*)/; var find_url
// =message.content.match(urlRegex)[1]; console.log(message.url)
// console.log(message.content)
let said = await extractUrls(message.content);
// console.log(said) var find_url = said[0].match(/\bhttps?:\/\/\S+/gi);
// console.log(find_url[0])
if (String(said).match(/\.(jpeg|jpg|png)$/) != null) {
await message.react('😳');
await message.react("🖕");
}
}
})
client.on('messageReactionAdd', async(reaction, user) => {
if (!allowed_channels.includes(reaction.message.channel.id)) {
return;
}
if (user.bot) {
return;
}
if (reaction.message.channel.type == 'dm') {
// console.log("private dm");
return;
}
var input;
const aaa = await reaction
.message
.channel
.messages
.fetch(reaction.message.id);
aaa.attachments.size > 0
? input = aaa
.attachments
.first()
.url
: input = await extractUrls(aaa.content);;
if (String(input).match(/\.(jpeg|jpg|gif|png)$/) == null) {
return;
}
if (['🖕'].includes(reaction.emoji.name) && !user.bot) {
user.send(`${input}`);
}
if (['😳'].includes(reaction.emoji.name) && !user.bot) {
client
.users
.fetch(user.id, false)
.then((user) => {
sauce
.find({url: input})
.then((data) => {
const results = data.results[0].data.ext_urls;
const source = data.results[0].data.source;
if (results && source) {
user
.send(`Results:<${results}>\nSource:${source}\nFor: ${input}`)
.catch((e) => {})
};
if (results && typeof source === 'undefined') {
user
.send(`Results:<${results}>\nFor: ${input}`)
.catch((e) => {})
}
if (source && typeof results === 'undefined') {
user
.send(`Source:${source}\nFor: ${input}`)
.catch((e) => {})
}
})
})
.catch((e) => {
console.log(e)
})
}
});
client.on('ready', async() => {
console.log(`Logged in as ${client.user.tag}!
:flushed: - To get the source of the image.
:middle_finger: - To store the image in your dms(without source)
`);
});
client.login(config.token)