mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-26 14:19:11 +02:00
Proper await
This commit is contained in:
@@ -16,6 +16,6 @@ module.exports = class CanYouNot extends commando.Command {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
|
||||
}
|
||||
console.log(`[Command] ${message.content}`);
|
||||
return message.channel.send('Can YOU not?');
|
||||
message.channel.send('Can YOU not?');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -20,6 +20,6 @@ module.exports = class GiveFlowerCommand extends commando.Command {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
|
||||
}
|
||||
console.log(`[Command] ${message.content}`);
|
||||
return message.channel.send('Ooh, what a pretty flower. What, I may have it? Thanks! I like flowers, yes? ♪');
|
||||
message.channel.send('Ooh, what a pretty flower. What, I may have it? Thanks! I like flowers, yes? ♪');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -16,6 +16,6 @@ module.exports = class LennyCommand extends commando.Command {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
|
||||
}
|
||||
console.log(`[Command] ${message.content}`);
|
||||
return message.channel.send('( ͡° ͜ʖ ͡°)');
|
||||
message.channel.send('( ͡° ͜ʖ ͡°)');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,10 +18,10 @@ module.exports = class LotteryCommand extends commando.Command {
|
||||
console.log(`[Command] ${message.content}`);
|
||||
let lotteryNumber = ['Winner'][Math.floor(Math.random() * 100)];
|
||||
if (lotteryNumber === "Winner") {
|
||||
return message.channel.send(`Wow ${message.author.username}! You actually won! Great job!`);
|
||||
message.channel.send(`Wow ${message.author.username}! You actually won! Great job!`);
|
||||
}
|
||||
else {
|
||||
return message.channel.send(`Nope, sorry ${message.author.username}, you lost.`);
|
||||
message.channel.send(`Nope, sorry ${message.author.username}, you lost.`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -41,23 +41,24 @@ module.exports = class MathGameCommand extends commando.Command {
|
||||
let randomExpression = randomValue1 + randomType + randomValue2;
|
||||
let solved = math.eval(randomExpression);
|
||||
if (!randomValue) {
|
||||
return message.channel.send(':x: Error! No difficulty set! (Choose Easy, Medium, Hard, or Extreme)');
|
||||
message.channel.send(':x: Error! No difficulty set! (Choose Easy, Medium, Hard, or Extreme)');
|
||||
}
|
||||
else {
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setTitle('You have **ten** seconds to answer:')
|
||||
.setDescription(randomExpression);
|
||||
await message.channel.sendEmbed(embed).then(() => {
|
||||
message.channel.awaitMessages(response => response.content === solved.toString() && response.author.id === message.author.id, {
|
||||
let embedMsg = await message.channel.sendEmbed(embed);
|
||||
try {
|
||||
let collected = await message.channel.awaitMessages(response => response.content === solved.toString() && response.author.id === message.author.id, {
|
||||
max: 1,
|
||||
time: 10000,
|
||||
errors: ['time'],
|
||||
}).then((collected) => {
|
||||
return message.channel.send(`Good Job! You won!`);
|
||||
}).catch(() => {
|
||||
return message.channel.send(`Aw... Too bad, try again next time!\nThe Correct Answer was: ${solved}`);
|
||||
});
|
||||
});
|
||||
message.channel.send(`Good Job! You won! ${collected} is the correct answer!`);
|
||||
}
|
||||
catch (err) {
|
||||
message.channel.send(`Aw... Too bad, try again next time!\nThe correct answer is: ${solved}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -23,6 +23,6 @@ module.exports = class NitroCommand extends commando.Command {
|
||||
.setColor(0x748BD9)
|
||||
.setURL("https://discordapp.com/nitro")
|
||||
.setDescription("This Message can only be viewed by members with Discord Nitro.\n\n\n[More Information](https://discordapp.com/nitro)");
|
||||
return message.channel.sendEmbed(embed).catch(console.error);
|
||||
message.channel.sendEmbed(embed);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -30,21 +30,21 @@ module.exports = class QuizCommand extends commando.Command {
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setTitle('You have **fifteen** seconds to answer this question:')
|
||||
.setDescription(`**Category: ${response.body[0].category.title}**\n${response.body[0].question}`);
|
||||
let embededMessage = await message.channel.sendEmbed(embed);
|
||||
let embedMsg = await message.channel.sendEmbed(embed);
|
||||
try {
|
||||
let collected = await message.channel.awaitMessages(res => res.content.toLowerCase() === response.body[0].answer.toLowerCase() && res.author.id === message.author.id, {
|
||||
max: 1,
|
||||
time: 15000,
|
||||
errors: ['time']
|
||||
});
|
||||
let winnerMes = await message.channel.send(`Good Job! You won!`);
|
||||
message.channel.send(`Good Job! You won! ${collected} is the correct answer!`);
|
||||
}
|
||||
catch (err) {
|
||||
let loserMes = await message.channel.send(`Aw... Too bad, try again next time!\nThe Correct Answer was: ${response.body[0].answer}`);
|
||||
message.channel.send(`Aw... Too bad, try again next time!\nThe Correct Answer was: ${response.body[0].answer}`);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
let errorMessage = await message.channel.send(":x: Error! Something went wrong!");
|
||||
message.channel.send(":x: Error! Something went wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -16,6 +16,6 @@ module.exports = class SlowClapCommand extends commando.Command {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
|
||||
}
|
||||
console.log(`[Command] ${message.content}`);
|
||||
return message.channel.send('*slow clap*');
|
||||
message.channel.send('*slow clap*');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -23,51 +23,50 @@ module.exports = class SoundBoardCommand extends commando.Command {
|
||||
console.log(`[Command] ${message.content}`);
|
||||
if (message.channel.type !== 'dm') {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['CONNECT', 'SPEAK', 'ADD_REACTIONS'])) {
|
||||
return message.channel.send(':x: Error! In order to do this command, you must give me the permissions to "Connect" and "Speak", as well as the permission to Add Reactions!');
|
||||
message.channel.send(':x: Error! In order to do this command, you must give me the permissions to "Connect" and "Speak", as well as the permission to Add Reactions!');
|
||||
}
|
||||
else {
|
||||
let voiceChannel = message.member.voiceChannel;
|
||||
if (!voiceChannel) {
|
||||
return message.channel.send(`:x: Error! Please be in a voice channel first!`);
|
||||
message.channel.send(`:x: Error! Please be in a voice channel first!`);
|
||||
}
|
||||
else {
|
||||
let soundToPlay = message.content.toLowerCase().split(" ").slice(1).join(" ");
|
||||
if (!soundToPlay) {
|
||||
return message.channel.send(':x: Error! No sound set. Please use ;soundboard list to see a list of sounds you can play.');
|
||||
message.channel.send(':x: Error! No sound set. Please use ;soundboard list to see a list of sounds you can play.');
|
||||
}
|
||||
else if (soundToPlay === 'list') {
|
||||
return message.channel.send("**Available Sounds:** Cat, Pikachu, Vader, Doh, It's a Trap, Mario Death, Pokemon Center, Dun Dun Dun, Spongebob, Ugly Barnacle, Woo Hoo, Space, GLaDOS Bird, Airhorn, Zelda Chest, Eat my Shorts, No This is Patrick, Wumbo");
|
||||
message.channel.send("**Available Sounds:** Cat, Pikachu, Vader, Doh, It's a Trap, Mario Death, Pokemon Center, Dun Dun Dun, Spongebob, Ugly Barnacle, Woo Hoo, Space, GLaDOS Bird, Airhorn, Zelda Chest, Eat my Shorts, No This is Patrick, Wumbo");
|
||||
}
|
||||
else if (soundToPlay === sounds.avaliable[soundToPlay]) {
|
||||
let alreadyConnected = await this.client.voiceConnections.get(voiceChannel.guild.id);
|
||||
if (alreadyConnected) {
|
||||
if (alreadyConnected.channel.id === voiceChannel.id) {
|
||||
return message.channel.send(':x: Error! I am already playing a sound!');
|
||||
message.channel.send(':x: Error! I am already playing a sound!');
|
||||
}
|
||||
else {
|
||||
return message.channel.send(':x: Error! I am already playing a sound!');
|
||||
message.channel.send(':x: Error! I am already playing a sound!');
|
||||
}
|
||||
}
|
||||
else {
|
||||
await voiceChannel.join().then(connection => {
|
||||
let stream = sounds.paths[soundToPlay];
|
||||
let dispatcher = connection.playStream(stream);
|
||||
message.react('🔊');
|
||||
dispatcher.on('end', () => {
|
||||
message.react('✅');
|
||||
return voiceChannel.leave();
|
||||
});
|
||||
let connection = await voiceChannel.join();
|
||||
let stream = sounds.paths[soundToPlay];
|
||||
let dispatcher = connection.playStream(stream);
|
||||
message.react('🔊');
|
||||
dispatcher.on('end', () => {
|
||||
message.react('✅');
|
||||
return voiceChannel.leave();
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
return message.channel.send(':x: Error! Sound not found! Use `;soundboard list` to see a list of sounds you can play.');
|
||||
message.channel.send(':x: Error! Sound not found! Use `;soundboard list` to see a list of sounds you can play.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return message.channel.send(':x: This is a DM!');
|
||||
message.channel.send(':x: This is a DM!');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -16,6 +16,6 @@ module.exports = class SpamCommand extends commando.Command {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'ATTACH_FILES'])) return;
|
||||
}
|
||||
console.log(`[Command] ${message.content}`);
|
||||
return message.channel.sendFile("./images/Spam.jpg");
|
||||
message.channel.sendFile("./images/Spam.jpg");
|
||||
}
|
||||
};
|
||||
|
||||
+22
-21
@@ -21,26 +21,27 @@ module.exports = class TodayCommand extends commando.Command {
|
||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'EMBED_LINKS'])) return;
|
||||
}
|
||||
console.log("[Command] " + message.content);
|
||||
return request
|
||||
.get('http://history.muffinlabs.com/date')
|
||||
.set({
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
})
|
||||
.buffer(true)
|
||||
.then(function(response) {
|
||||
let responseData = JSON.parse(response.text);
|
||||
let randomNumber = Math.floor(Math.random() * responseData.data.Events.length);
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setColor(0x9797FF)
|
||||
.setURL(responseData.url)
|
||||
.setTitle('On this day (' + responseData.date + ')...')
|
||||
.setTimestamp()
|
||||
.setDescription(responseData.data.Events[randomNumber].text + ' (' + responseData.data.Events[randomNumber].year + ')');
|
||||
return message.channel.sendEmbed(embed).catch(console.error);
|
||||
}).catch(function(err) {
|
||||
console.log(err);
|
||||
return message.channel.send(":x: Error! Something went wrong!");
|
||||
});
|
||||
try {
|
||||
let response = await request
|
||||
.get('http://history.muffinlabs.com/date')
|
||||
.set({
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
})
|
||||
.buffer(true);
|
||||
let responseData = JSON.parse(response.text);
|
||||
let randomNumber = Math.floor(Math.random() * responseData.data.Events.length);
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setColor(0x9797FF)
|
||||
.setURL(responseData.url)
|
||||
.setTitle('On this day (' + responseData.date + ')...')
|
||||
.setTimestamp()
|
||||
.setDescription(responseData.data.Events[randomNumber].text + ' (' + responseData.data.Events[randomNumber].year + ')');
|
||||
message.channel.sendEmbed(embed);
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
message.channel.send(":x: Error! Something went wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -51,23 +51,24 @@ module.exports = class TypingGameCommand extends commando.Command {
|
||||
break;
|
||||
}
|
||||
if (!time) {
|
||||
return message.channel.send(':x: Error! No difficulty set! (Choose Easy, Medium, Hard, or Extreme)');
|
||||
message.channel.send(':x: Error! No difficulty set! (Choose Easy, Medium, Hard, or Extreme)');
|
||||
}
|
||||
else {
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setTitle(`You have **${levelWord}** seconds to type:`)
|
||||
.setDescription(randomSentence);
|
||||
await message.channel.sendEmbed(embed).then(() => {
|
||||
message.channel.awaitMessages(response => response.content === randomSentence && response.author.id === message.author.id, {
|
||||
let embedMsg = await message.channel.sendEmbed(embed);
|
||||
try {
|
||||
let collected = await message.channel.awaitMessages(response => response.content === randomSentence && response.author.id === message.author.id, {
|
||||
max: 1,
|
||||
time: time,
|
||||
errors: ['time'],
|
||||
}).then((collected) => {
|
||||
return message.channel.send(`Good Job! You won!`);
|
||||
}).catch(() => {
|
||||
return message.channel.send('Aw... Too bad, try again next time!');
|
||||
errors: ['time']
|
||||
});
|
||||
});
|
||||
message.channel.send(`Good Job! You won!\n${collected} was typed fast enough!`);
|
||||
}
|
||||
catch (err) {
|
||||
message.channel.send('Aw... Too bad, try again next time!');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user