-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (42 loc) · 1.56 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
require('dotenv').config();
const {Client, Intents} = require('discord.js');
const axios = require('axios');
const client = new Client({intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]});
client.on('ready', () => {
console.log(`logged in as ${client.user.tag}`);
});
client.login(process.env.CLIENT_TOKEN);
const API_KEY = process.env.TENOR_API_KEY;
const API_URL = process.env.API_URL;
const getMeme = async (search, limit = 50) => {
const res = await axios.get(`${API_URL}/search?key=${API_KEY}&q=${search}&limit=${limit}&media_filter=gif&contentfilter=medium`);
const memeId = Math.floor((Math.random() * res.data.results.length) + 1);
return res.data.results[memeId].url;
};
const isGouterTime = () => {
const now = new Date();
const hours = now.getHours();
return hours >= 16 && hours < 18;
};
const isApertoTime = () => {
const now = new Date();
const hours = now.getHours();
return hours >= 18 && hours < 20;
};
client.on('message', async msg => {
let img;
switch (msg.content) {
case '!apero':
const isApero = isApertoTime();
img = await getMeme(isApero ? 'yes' : 'no', 50);
msg.channel.send(img);
msg.reply(isApero ? `Oui c'est carrément l'heure de l'apéro !!` : `Non c'est pas encore l'heure de l'apéro !!`);
break;
case '!gouter':
const isGouter = isGouterTime();
img = await getMeme(isGouter ? 'yes' : 'no', 50);
msg.channel.send(img);
msg.reply(isGouter ? `Oui c'est carrément l'heure du goûter !!` : `Non c'est pas encore l'heure du goûter !!`);
break;
}
});