Created
June 22, 2017 19:42
-
-
Save tjreigh/3fcf117d43327370da7cc6aab4e0eaf1 to your computer and use it in GitHub Desktop.
Food bot broken code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const Discord = require('discord.js'), | |
bot = new Discord.Client(), | |
config = require('./config.json'), | |
prefix = config.prefix; | |
let cooldownUsers = [], | |
data = {}, | |
usedIDs = [], | |
help = [ | |
`Prefix is: \`${prefix}\``, | |
"**help** - Sends this list.", | |
"**ping** - Pong!", | |
"**order [food]** - Sends your order to Discord Breakfast so it can be cooked for you.", | |
"**myorder** - Sends the details on your order.", | |
"**invite** - Sends the OAuth so you can invite me to your server!" | |
]; | |
console.log('Requires and vars initialized.'); | |
function makeID() { | |
let id = ""; | |
let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
for (let i = 0; i < 5; i++) id += possible.charAt(Math.floor(Math.random() * possible.length)); | |
if (usedIDs.includes(id)) { | |
let id = ""; | |
let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
for (let i = 0; i < 5; i++) id += possible.charAt(Math.floor(Math.random() * possible.length)); | |
return id; | |
} else { | |
return id; | |
} | |
} | |
const commands = { | |
'ping': (msg) => { | |
msg.channel.sendMessage("Pong!"); | |
}, | |
'help': (msg) => { | |
msg.reply("Check your DM's!"); | |
msg.author.sendMessage(help.join('\n')); | |
}, | |
'invite': (msg) => { | |
msg.channel.sendMessage(`You can invite me with this: ${config.oauth}`); | |
}, | |
'order': (msg) => { | |
if (!data[msg.author.id]) data[msg.author.id] = { | |
orders: [] | |
}; | |
if (cooldownUsers.includes(msg.author.id)) { | |
msg.channel.sendMessage(`:no_entry_sign: **${msg.author.username}**, you've already sent an order!\nType, \`${prefix}myorder\` to view the details of it.`); | |
} else { | |
let args = msg.content.replace(prefix + 'order ', ''); | |
if (args == '' || args === undefined) return msg.channel.sendMessage(`You must put a food to order after \`${prefix}order\``); | |
let orderID = makeID(); | |
usedIDs.push(orderID); | |
cooldownUsers.push(msg.author.id); | |
data[msg.author.id].orders.push({ | |
order: args, | |
id: orderID, | |
user: `${msg.author.username}#${msg.author.discriminator}`, | |
status: 'Awaiting a chef.', | |
ready: false | |
}); | |
let channel = msg.channel; | |
let user = msg.author.id; | |
let tosend = []; | |
data[msg.author.id].orders.forEach((order) => { | |
tosend.push(`Food: **${order.order}**\nOrder ID: \`${order.id}\`\nUser: **${order.user}**\nStatus: **${order.status}**`); | |
}); | |
msg.channel.sendMessage(`**${msg.author.username}**, I've sent your order to Discord Breakfast!\nOrder ID: \`${orderID}\``); | |
bot.channels.get('299989992284094464').sendMessage(`**Order:**\n${tosend}`) | |
.then((message) => { | |
bot.on('message', msg => { | |
if (msg.content.startsWith(prefix + "cook")) { | |
if (config.chefs.includes(msg.author.id)) { | |
let args = msg.content.replace(prefix + 'cook ', ''); | |
if (args == '' || args === undefined) return msg.reply(`You must specify an order ID to cook.`); | |
if (usedIDs.includes(args)) { | |
let filteredOrders = data[user].orders.filter(function(order) { | |
return order.id === args; | |
}); | |
filteredOrders.forEach((order) => { | |
order.status = 'Cooking. Done in 5 minutes.'; | |
}); | |
msg.reply('Cooking will take 5 minutes.'); | |
setTimeout(() => { | |
let tosend2 = []; | |
filteredOrders.forEach((order) => { | |
tosend2.push(`Food: **${order.order}**\nOrder ID: \`${order.id}\`\nUser: **${order.user}**\nStatus: **${order.status}**`); | |
}); | |
message.edit(`**Order:**\n${tosend2}`); | |
}, 2000); | |
setTimeout(() => { | |
let tosend3min = []; | |
filteredOrders.forEach((order) => { | |
order.status = 'Cooking. Done in 3 minutes.'; | |
tosend3min.push(`Food: **${order.order}**\nOrder ID: \`${order.id}\`\nUser: **${order.user}**\nStatus: **${order.status}**`); | |
}); | |
message.edit(`**Order:**\n${tosend3min}`); | |
}, 120000); | |
setTimeout(() => { | |
let tosend1min = []; | |
filteredOrders.forEach((order) => { | |
order.status = 'Cooking. Done in 1 minute.'; | |
tosend1min.push(`Food: **${order.order}**\nOrder ID: \`${order.id}\`\nUser: **${order.user}**\nStatus: **${order.status}**`); | |
}); | |
message.edit(`**Order:**\n${tosend1min}`); | |
}, 240000); | |
setTimeout(() => { | |
let tosend4 = []; | |
filteredOrders.forEach((order) => { | |
order.status = 'Cooked. Ready for delivery.'; | |
order.ready = true; | |
tosend4.push(`Food: **${order.order}**\nOrder ID: \`${order.id}\`\nUser: **${order.user}**\nStatus: **${order.status}**`); | |
bot.channels.get('299992229651415040').sendMessage("Order `" + `${order.id}` + "` is ready to deliver"); | |
}); | |
message.edit(`**Order:**\n${tosend4}`); | |
}, 300000) | |
} else { | |
msg.reply("That isn't an active order ID."); | |
} | |
} else { | |
return; | |
} | |
} | |
if (msg.content.startsWith(prefix + 'deliver')) { | |
if (config.deliverers.includes(msg.author.id)) { | |
let args = msg.content.replace(prefix + 'deliver ', ''); | |
if (args == '' || args === undefined) return msg.reply(`You must specify an order ID to deliver.`); | |
if (usedIDs.includes(args)) { | |
setTimeout(() => { | |
message.delete(); | |
}, 2000); | |
msg.reply("I've DMed you info on this order."); | |
channel.createInvite().then(x => msg.author.sendMessage(`Go to ${x.url} to deliver!`)); | |
let userIndex = cooldownUsers.indexOf(user); | |
let idIndex = usedIDs.indexOf(orderID); | |
cooldownUsers.splice(userIndex, 1); | |
usedIDs.splice(idIndex, 1); | |
data[user] = ''; | |
} else { | |
msg.reply("That isn't an active order ID."); | |
} | |
} else { | |
return; | |
} | |
} | |
}); | |
}); | |
} | |
}, | |
'myorder': (msg) => { | |
if (!data[msg.author.id]) data[msg.author.id] = { | |
orders: [] | |
}; | |
if (!data[msg.author.id] === undefined) return msg.channel.sendMessage(`**${msg.author.username}**, you haven't ordered anything yet.`); | |
let tosend = []; | |
data[msg.author.id].orders.forEach((order) => { | |
tosend.push(`**${order.order}**\nOrder ID: \`${order.id}\`\nStatus: **${order.status}**`); | |
}); | |
msg.channel.sendMessage(`**${msg.author.username}**, you've ordered:\n${tosend}`); | |
} | |
}; | |
bot.on('message', msg => { | |
if (!msg.content.startsWith(prefix)) return; | |
if (msg.author.bot) return; | |
if (commands.hasOwnProperty(msg.content.toLowerCase().slice(prefix.length).split(' ')[0])) commands[msg.content.toLowerCase().slice(prefix.length).split(' ')[0]](msg); | |
}); | |
bot.on('ready', () => { | |
console.log(`Discord Breakfast online!\nOn ${bot.guilds.size} guilds with ${bot.users.size} users.`); | |
bot.user.setGame(`db.order | ${bot.guilds.size} servers!`); | |
let oChan = bot.channels.get('299989992284094464'); | |
oChan.bulkDelete(99); | |
oChan.send('This is the orders channel.'); | |
console.log('Orders purged.') | |
}); | |
bot.login(config.token); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment