Skip to content

Instantly share code, notes, and snippets.

@funnbot
Last active February 19, 2017 05:24
Show Gist options
  • Save funnbot/c406fe35b459d8148e0dd5c53e7ce849 to your computer and use it in GitHub Desktop.
Save funnbot/c406fe35b459d8148e0dd5c53e7ce849 to your computer and use it in GitHub Desktop.
Cards Against Humanity for MopBot
let cah = {}
exports.exec = (message, bot, suffix, param) => {
if (param[1] === "end") {
let staffRole = config.getStaffRole(message.guild.id);
if (!message.guild.roles.exists('name', staffRole) || !message.author.id === message.guild.ownerID) return sendWarn(message, `Your server does not have the designated Staff Role \`${staffRole}\`.\nIt is required for some of my commands`);
if (!message.member.roles.exists('name', staffRole) || !message.author.id === message.guild.ownerID) return sendWarn(message, `To end a cards against humanity game you need the role \`${staffRole}\`.`);
delete cah[message.guild.id];
sendSucc(message, "Cards Against Humanity Game Ended.")
}
if (param[1] === "start") {
let gid = message.guild.id;
let staffRole = config.getStaffRole(message.guild.id);
if (!!cah[gid]) return sendWarn(message, `There is already a game running in <#${cah[gid].channel}>.\nYou can join that game with \`${prefix}cah join\``);
if (!message.guild.roles.exists('name', staffRole) || !message.author.id === message.guild.ownerID) return sendWarn(message, `Your server does not have the designated Staff Role \`${staffRole}\`.\nIt is required for some of my commands`);
if (!message.member.roles.exists('name', staffRole) || !message.author.id === message.guild.ownerID) return sendWarn(message, `To start a cards against humanity game you need the role \`${staffRole}\`.`);
cah[gid] = {};
cah[gid].id = gid;
cah[gid].channel = message.channel.id;
cah[gid].player = {};
cah[gid].czarNum = 1;
cah[gid].ansCollect = {};
cah[gid].guessNum = 0;
cah[gid].chosenCards = {};
cah[gid].czar = {};
cah[gid].player[message.author.id] = {};
cah[gid].player[message.author.id].id = message.author.id;
cah[gid].player[message.author.id].name = message.author.username;
cah[gid].player[message.author.id].score = 0;
cah[gid].player[message.author.id].isCzar = false;
let embed = {
color: 0xFDFBFB,
description: `${message.author} has started a cards against humanity game in ${message.channel}\n\nYou can join the game with \`${prefix}cah join\`\n\nThe game will start in 30 seconds if their are more than 2 players joined.`
}
message.channel.sendMessage("", {
embed
}).then(msg => msg.delete(30000));
setTimeout(() => {
setGame(message)
}, 30000);
}
let joinCah = message.channel.createCollector(m => m.author.bot === false);
joinCah.on('message', (m) => {
let gid = m.guild.id
let arg = m.content.split(" ");
if (m.content.includes("cah join") && arg[1] === "join" && arg[0].includes("cah")) {
if (!cah[gid].player.hasOwnProperty(m.author.id)) {
cah[gid].player[m.author.id] = {};
cah[gid].player[m.author.id].id = m.author.id;
cah[gid].player[m.author.id].score = 0;
cah[gid].player[m.author.id].name = m.author.username
cah[gid].player[m.author.id].isCzar = false;
let embed = {
color: 0x5EEF11,
author: {
name: "Success",
icon_url: "http://www.clker.com/cliparts/v/u/z/w/n/2/thumbsup-md.png"
},
description: `${m.author} Has joined the game.`
};
m.channel.sendMessage("", {
embed
}).then(msg => msg.delete(3000))
} else {
let embed = {
color: 0xFFFB0B,
author: {
name: "Warn",
icon_url: "http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png"
},
description: `You have already joined this game.\nYou can leave anytime with \`cah leave\``
};
m.channel.sendMessage("", {
embed
}).then(msg => msg.delete(3000))
}
}
if (m.content.includes("cah leave") && arg[1] === "leave" && arg[0].includes("cah")) {
if (cah[gid].player.hasOwnProperty(m.author.id)) {
delete cah[gid].player[message.author.id]
let embed = {
color: 0x5EEF11,
author: {
name: "Success",
icon_url: "http://www.clker.com/cliparts/v/u/z/w/n/2/thumbsup-md.png"
},
description: `${m.author} Has left the game.`
};
m.channel.sendMessage("", {
embed
}).then(msg => msg.delete(3000))
} else {
let embed = {
color: 0xFFFB0B,
author: {
name: "Warn",
icon_url: "http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png"
},
description: `You are not apart of any game.`
};
m.channel.sendMessage("", {
embed
}).then(msg => msg.delete(3000))
}
}
});
function setGame(m) {
let cards = require('cah-cards/answers');
let quests = require('cah-cards/pick1');
let gid = m.guild.id;
if (Object.keys(cah[gid].player).length < 2) {
let embed = {
color: 0xC60000,
author: {
name: "Error",
icon_url: "http://free-icon-download.com/modules/PDdownloads/images/screenshots/free-image-download-blank-not_allowed-sign.png"
},
description: `Game Ended: Too few players joined. You need some friends bud.`
};
return m.channel.sendMessage("", {
embed
}).then(msg => msg.delete(4000));
}
let newQuest = quests[Object.keys(quests)[rn({
min: 0,
max: Object.keys(quests).length - 1,
integer: true
})]];
let newCzar = cah[gid].player[Object.keys(cah[gid].player)[cah[gid].czarNum]];
cah[gid].player[newCzar.id].isCzar = true;
cah[gid].czarNum++
cah[gid].czar = newCzar;
if (cah[gid].czarNum > Object.keys(cah[gid].player).length - 1) cah[gid].czarNum = 0;
let qText = newQuest.text.replace(/_/g, " ___ ")
let embed = {
author: {
icon_url: bot.users.get(newCzar.id).avatarURL,
name: "Card Czar: " + newCzar.name
},
color: 0x000001,
footer: {
text: "Cards Against Humanity",
icon_url: "https://s-media-cache-ak0.pinimg.com/736x/12/5c/e3/125ce39845cf256666323527b896d379.jpg"
},
description: '\u200B\n**' + qText + '**\n\n\u200B'
}
m.channel.sendMessage("", {
embed
})
let playKeys = Object.keys(cah[gid].player);
playKeys.forEach(p => {
if (cah[gid].player[p].isCzar === false) {
let cardKey = Object.keys(cards)
let deck = []
for (i = 0; i < 7; i++) {
let random = rn({
min: 0,
max: Object.keys(cards).length - 1,
integer: true
})
let card = cards[cardKey[random]];
deck.push(card.id);
}
cah[gid].player[p].deck = deck;
let embed = {
author: {
icon_url: bot.users.get(newCzar.id).avatarURL,
name: "Card Czar: " + newCzar.name
},
color: 0x000001,
footer: {
text: "Cards Against Humanity",
icon_url: "https://s-media-cache-ak0.pinimg.com/736x/12/5c/e3/125ce39845cf256666323527b896d379.jpg"
},
description: '\u200B\n**' + qText + '**\n\n\u200B'
}
bot.users.get(p).sendMessage("", {
embed
});
embed = {
author: {
name: "Your Deck",
icon_url: bot.users.get(p).avatarURL
},
color: 0xFEFFFF,
description: `\u200B\n1. -=-=-=-=-=-=-=-=-=-=-=-=-\n**${cards[deck[0]].text}**\n\n\n2. -=-=-=-=-=-=-=-=-=-=-=-=-\n**${cards[deck[1]].text}**\n\n\n3. -=-=-=-=-=-=-=-=-=-=-=-=-\n**${cards[deck[2]].text}**\n\n\n4. -=-=-=-=-=-=-=-=-=-=-=-=-\n**${cards[deck[3]].text}**\n\n\n5. -=-=-=-=-=-=-=-=-=-=-=-=-\n**${cards[deck[4]].text}**\n\n\n6. -=-=-=-=-=-=-=-=-=-=-=-=-\n**${cards[deck[5]].text}**\n\n\n7. -=-=-=-=-=-=-=-=-=-=-=-=-\n**${cards[deck[6]].text}**\n\n\n\n**To Pick A Card, Type Its Number Here**`
}
bot.users.get(p).sendMessage("", {
embed
}).then(msg => {
let collect = msg.channel.createCollector(m => m.author.bot === false, {
time: 30000
})
collect.on('message', (m) => {
if (m > 0 && m < 8) {
cah[gid].guessNum++
embed = {
color: 0xFEFFFF,
description: `${cah[gid].guessNum}. -=-=-=-=-=-=-=-=-=-=-=-=-=-\n**${cards[cah[gid].player[m.author.id].deck[m.content-1]].text}**`
}
bot.channels.get(cah[gid].channel).sendMessage("", {
embed
})
cah[gid].chosenCards[cah[gid].guessNum] = {
card: cards[cah[gid].player[m.author.id].deck[m.content - 1]],
player: cah[gid].player[m.author.id]
}
collect.stop('sent');
} else {
sendWarn(m, "That is not a valid card.")
}
})
});
gid = m.guild.id
setTimeout(() => {
let embed = {
color: 0x000001,
description: "The Card Czar is picking the best answer..."
}
bot.channels.get(cah[gid].channel).sendMessage("", {
embed
})
let collector = bot.channels.get(cah[gid].channel).createCollector(m => m.author.id === cah[gid].czar.id);
collector.on('message', (m) => {
gid = m.guild.id
if (m.content < 0 || m.content > cah[gid].guessNum) {
sendWarn(m, "That is not a valid card number.")
} else {
console.log(cah[gid].chosenCards)
console.log(m.content)
cah[gid].player[cah[gid].chosenCards[m.content].player.id].score++
let score = [];
let keyOPlayer = Object.keys(cah[gid].player);
for (i = 0; i < keyOPlayer.length; i++) {
score.push(cah[gid].player[keyOPlayer[i]].name + ": " + cah[gid].player[keyOPlayer[i]].score)
}
let embed = {
color: 0x1AF40C,
author: {
name: "Winner: " + cah[gid].chosenCards[m.content].player.name,
icon_url: bot.users.get(cah[gid].chosenCards[m.content].player.id).avatarURL,
},
fields: [{
name: "Winning Card:",
value: "**" + cah[gid].chosenCards[m.content].card.text + "**"
}, {
name: "Scores:",
value: score.join("\n")
}]
}
bot.channels.get(cah[gid].channel).sendMessage("", {
embed
}).then(m => m.delete(5000))
setTimeout(() => {
bot.channels.get(cah[gid].channel).sendMessage("Starting next round...").then(m => {
cah[gid].ansCollect = {};
cah[gid].guessNum = 0;
cah[gid].chosenCards = {};
cah[gid].czar = {};
setGame(m);
m.delete(2000)
})
}, 5000)
}
})
collector.stop("success");
}, 31000);
}
})
};
}
exports.conf = {
coolDown: 500,
category: "Games",
alias: "cards",
deleteCommand: true,
perm: 3,
botPerm: ["SEND_MESSAGES"]
}
exports.help = {
help: "Play cards against humanity with your friends.",
helpExt: "Start a cards against humanity game. Since this game sends alot of messages generaly, it can only be started by staff.",
args: "start [INDEV]"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment