-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhentAI.js
176 lines (146 loc) · 4.99 KB
/
hentAI.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
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
const Discord = require('discord.js');
const fs = require("fs");
var options = require("./options.json");
const sagiri = require('sagiri');
const { randomInt } = require('crypto');
const sagiriclient = sagiri(options.SauceToken);
const { playMusic, stopMusic, getQueue } = require('./music.js');
const Twitch = require('./twitch');
const client = new Discord.Client();
//var permdat = require("./permdat.json");
client.once('ready', () => {
console.log(`Logged in with ${client.user.tag}`);
});
client.once('reconnecting', () => {
console.log('Reconnecting!');
});
client.once('disconnect', () => {
console.log('Disconnect!');
});
//let links = "https://media.discordapp.net/attachments/741730351025619034/758044171675369574/EcpoBzmUMAAlhO_.png?width=960&height=614";
async function getSauce(link)
{
let results = await sagiriclient(link);
let endres = [];
let sites = [];
for (result of results)
if(result.similarity >= 40.0 && !sites.includes(result.site))
{
sites.push(result.site);
endres.push(result);
}
//console.log(endres);
if(endres.length === 0)
{
return "Could not find reliable sauce";
}
console.log('creating embed')
const embed = new Discord.MessageEmbed()
.setTitle('Some spicy sauce comming right up')
.setColor('f089dd')
.setDescription('you requested the sauce, you got the sauce')
.setThumbnail(endres[0].thumbnail)
.addField(`The best sauce from ${endres[0].site}, with confidence of ${endres[0].similarity}%:`, endres[0].url);
endres.shift();
console.log('starting for loop');
for(res of endres)
{
embed.addField(`Sauce from ${res.site}, with confidence of ${res.similarity}%:`, res.url);
}
//console.log(embed);
return embed;
}
//getSauce(links);
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('pong');
}
else if(msg.content === 'random number'){
let num = randomInt(100000, 350000);
msg.channel.send(num);
}
else if(msg.content.toLowerCase() === 'good bot'.toLocaleLowerCase()){
msg.channel.send('bad human');
fs.readFile('./permdat.json', (err,data) => {
if (err) {
msg.channel.send(err);
throw err;
}
let permdat = JSON.parse(data);
permdat.goodbotcnt+=1;
fs.writeFileSync('./permdat.json', JSON.stringify(permdat));
});
}
else if(msg.content === 'bad bot'){
msg.channel.send('fuck you too');
}
else if(msg.content.toLowerCase() === '!goodbotcount'.toLowerCase())
{
console.log("goodbotcount")
fs.readFile('./permdat.json', (err,data) => {
if (err) {
console.log("error");
msg.channel.send(err);
throw err;
}
let permdat = JSON.parse(data);
//console.log(permdat);
msg.channel.send(`Good boy points: ${permdat.goodbotcnt}`);
});
}
});
client.on('message', async msg => {
const args = msg.content.trim().split(' ');
let atts = msg.attachments.array();
const args2 = msg.content.slice(('nyaa').length).trim().split(' ');
const command = args2.shift().toLowerCase();
if(args.shift().toLowerCase() === 'sauce?' && args.length === 1 && atts.length === 0)
{
console.log("shouldn't be here");
let tmpsc = await getSauce(args[0]);
console.log('got message');
msg.channel.send(tmpsc);
}
else if(atts.length > 0 && msg.content === 'sauce?')
{
console.log("got in");
console.log(msg.attachments.array().url);
let tmpsc = await getSauce(atts[atts.length -1].url);
//console.log('got message');
msg.channel.send(tmpsc);
}
else if(msg.content.toLocaleLowerCase() === 'sauce?' && args.length === 0 && atts.length === 0)
{
msg.channel.messages.fetch({ limit: 30 }).then(async messages => {
const botMessages = messages.filter(msga => msga.attachments.array().length >0);
if(botMessages.array().length > 0)
{
temp = await getSauce(botMessages.array()[0].attachments.array()[botMessages.array()[0].attachments.array().length-1].url);
msg.channel.send(temp);
}
else
msg.channel.send("could not find image in last 30 messages, sorry");
});
}
switch (command) {
case 'play':
await playMusic(msg, args2[0])
break
case 'stop':
case 'die':
await stopMusic(msg)
break
case 'queue':
getQueue(msg)
break
case 'settwitchchannel':
twitch.setNotificationChannel(msg);
break;
case 'settwitchrole':
twitch.setNotificationRole(msg);
break;
}
});
//getSauce(links);
client.login(options.Token);
const twitch = new Twitch(client);