aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndrajith K L2021-03-11 19:01:19 +0530
committerIndrajith K L2021-03-11 19:01:19 +0530
commit3c1d3e9f924ec66c8b643e43fc2d1461977b147d (patch)
tree83a1dbd2f4be5d4857c7ce4d3acdb6d643037c39
parent80f8f8d90194dd846b95b2aa34f3e37ceb232d22 (diff)
downloadlul-bot-3c1d3e9f924ec66c8b643e43fc2d1461977b147d.tar.gz
lul-bot-3c1d3e9f924ec66c8b643e43fc2d1461977b147d.tar.bz2
lul-bot-3c1d3e9f924ec66c8b643e43fc2d1461977b147d.zip
Update Command
* Jokes
-rw-r--r--src/main.js32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/main.js b/src/main.js
index a80a172..1f0ec70 100644
--- a/src/main.js
+++ b/src/main.js
@@ -8,9 +8,9 @@ client.on('message', (message) => {
if (message.author.bot) return;
if (message.content.startsWith(CMD_PREFIX)) {
const commandReply = parseCMD(message);
- if (commandReply) {
- parseCMD(message);
- } else {
+ if (commandReply && (typeof commandReply != "object")) {
+ message.reply(commandReply);
+ } else if(typeof commandReply != "object"){
generateConfusionGif(message);
}
@@ -26,7 +26,7 @@ client.on('message', (message) => {
function parseCasualMessage(message) {
const { content } = message;
- switch (content.trim()) {
+ switch (content.trim().toLowerCase()) {
case 'hello':
case 'hi':
return `Hey ${message.author} 🙋‍♂️. How Are You?`;
@@ -45,6 +45,7 @@ function parseCasualMessage(message) {
}
function generateConfusionGif(message) {
+ message.channel.startTyping();
const embed = new MessageEmbed()
.setDescription(`I dont understand what you are saying <@${process.env.KLIAS_TAG}> do you know what this guy is asking?`)
.setColor("RANDOM");
@@ -52,7 +53,8 @@ function generateConfusionGif(message) {
fetch(`https://api.tenor.com/v1/random?key=${process.env.TENOR_TOKEN}&q=I%20dont%20understand&limit=10`)
.then(res => res.json())
.then(response => {
- embed.setImage(response.results[0].media[0].gif.url);
+ embed.setImage(response.results[randomIndex].media[0].gif.url);
+ message.channel.stopTyping();
message.channel.send(embed);
});
}
@@ -63,10 +65,30 @@ function parseCMD(message) {
.substring(CMD_PREFIX.length)
.split(/\s+/);
switch (CMD_NAME) {
+ case 'jokes': randomJokes(message); return {};
default: return null;
}
}
+function randomJokes(message) {
+ message.channel.startTyping();
+ fetch(`https://official-joke-api.appspot.com/jokes/random`)
+ .then(res => res.json())
+ .then(response => {
+ message.channel.stopTyping();
+ if(response) {
+ message.channel.startTyping();
+ message.reply(response.setup);
+ setTimeout(() => {
+ message.channel.stopTyping();
+ message.reply(response.punchline);
+ }, 5000)
+ }
+
+ console.log(response);
+ })
+}
+
client.login(process.env.LUL_BOT_TKN)
.then(() => {
console.log("BOT Logged in");