Skip to content

Commit

Permalink
minor touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
Californ1a committed Sep 3, 2020
1 parent b32b3f5 commit 29350a7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
33 changes: 24 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const token = process.env.DISCORD_TOKEN;
const unoBotMad = ["ARRGH!", "This is getting annoying!", "RATS!", "*sigh*", "You're getting on my nerves >:/", "dfasdfjhweuryaeuwysadjkf", "I'm steamed.", "BAH"];

bot.webhooks = {};
bot.unoAwaitingPlayers = false;

bot.on("message", async (msg) => {
const hr = msg.createdAt.getHours();
Expand All @@ -31,9 +32,10 @@ bot.on("message", async (msg) => {
return;
}
if (msg.content.startsWith("!uno")) {
if (msg.channel.unoRunning) {
if (msg.channel.unoRunning && !bot.unoAwaitingPlayers) {
bot.unoAwaitingPlayers = true;
// return send(msg.channel, "Uno is already running");
await send(msg.channel, "Do you want to end Uno?");
await send(msg.channel, "Do you want to end Uno? [y/N]");
try {
const collected = await msg.channel.awaitMessages(r => (r.content === "y" || r.content === "yes" || r.content === "n" || r.content === "no") && msg.author.id === r.author.id, {
max: 1,
Expand All @@ -42,15 +44,20 @@ bot.on("message", async (msg) => {
});
if (collected.first().content === "n" || collected.first().content === "no") {
await send(msg.channel, "Uno will continue.");
bot.unoAwaitingPlayers = false;
return;
}
resetGame(bot, msg);
await resetGame(bot, msg);
await send(msg.channel, "Uno has been forced ended.");
bot.unoAwaitingPlayers = false;
return;
} catch (e) {
await send(msg.channel, "You took too long to respond. Uno will continue.");
await send(msg.channel, "Took too long to respond. Uno will continue.");
bot.unoAwaitingPlayers = false;
console.log(e);
}
} else {
} else if (!bot.unoAwaitingPlayers) {
bot.unoAwaitingPlayers = true;
if (!msg.channel.unoPlayers) {
msg.channel.unoPlayers = [];
}
Expand All @@ -63,16 +70,20 @@ bot.on("message", async (msg) => {
avatar: "https://i.imgur.com/fLMHXKh.jpg",
});
const check = await beginning(bot, hook, msg, players);
bot.unoAwaitingPlayers = false;
if (check) {
doBotTurn(bot, msg);
}
} else {
const hook = unobot;
const check = await beginning(bot, hook, msg, players);
bot.unoAwaitingPlayers = false;
if (check) {
doBotTurn(bot, msg);
}
}
} else {
await send(msg.channel, "Still waiting for players. You can end Uno after players have joined.");
}
} else if (msg.content.startsWith("play")) {
if (!(typeof msg.channel.unoRunning === "boolean" && msg.channel.unoRunning)) {
Expand Down Expand Up @@ -121,9 +132,12 @@ bot.on("message", async (msg) => {
return;
}
const betweenLength = Math.floor(Math.random() * unoBotMad.length);
const rand = betweenLength > Math.floor(unoBotMad.length / 3);
if (rand && bot.unogame.getPlayer(bot.user.id)
&& (bot.unogame.discardedCard.value.toString().includes("WILD") || bot.unogame.discardedCard.value.toString().includes("DRAW"))) {
let rand = betweenLength > Math.floor(unoBotMad.length / 2);
const value = bot.unogame.discardedCard.value.toString();
if (value.includes("DRAW")) { // Increase chance for bot to get mad for draw cards
rand = betweenLength > Math.floor(unoBotMad.length / 3);
}
if (rand && bot.unogame.getPlayer(bot.user.id) && (value.includes("DRAW") || value.includes("SKIP") || value.includes("REVERSE"))) {
await send(msg.channel, unoBotMad[Math.floor(Math.random() * unoBotMad.length)]);
}
const check = await nextTurn(bot, msg);
Expand All @@ -139,7 +153,8 @@ bot.on("message", async (msg) => {
bot.unogame.draw();
const card = bot.unogame.currentPlayer.hand[bot.unogame.currentPlayer.hand.length - 1];
const name = (card.color) ? card.toString() : card.value.toString();
await send(bot.webhooks.uno, `${msg.author} drew a ${name.toLowerCase().replace(/_/g, " ")}`);
const n2 = (name.includes("WILD_DRAW")) ? `${name.split(" ")[0]} WD4` : (name.includes("DRAW")) ? `${name.split(" ")[0]} DT` : name;
await send(bot.webhooks.uno, `${msg.author} drew a ${n2.toLowerCase()}`);
} else {
await send(msg.channel, "Uno isn't running.");
}
Expand Down
14 changes: 8 additions & 6 deletions util/doBotTurn.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ const delay = require("./delay");
const unoBotThink = ["*evil grin*..", "You'll pay for that...", "woooot..", "Dum de dum..", "hehe..", "Oh boy..", "hrm..", "Lets see here..", "uh..", "Hmm, you're good..", "Decisions decisions..", "Ahah!...", "Eeny Meeny Miney Moe..", "LOL..", "Oh dear..", "Errr..", "Ah me brain!..."];

async function doBotTurn(bot, msg) {
if (Math.floor(Math.random() * unoBotThink.length) < Math.floor(unoBotThink.length / 3)) {
await send(msg.channel, unoBotThink[Math.floor(Math.random() * unoBotThink.length)]);
}
await delay(5000);
const player = bot.unogame.currentPlayer;
let currentHand = player.hand;
let botMatchingHand = currentHand.filter(card => (card.color === bot.unogame.discardedCard.color
|| card.value === bot.unogame.discardedCard.value
|| card.value.toString().includes("WILD")));
if (botMatchingHand.length === 0) {
await delay(2000);
await send(msg.channel, "draw");
bot.unogame.draw();
console.log("bot drew");
// console.log("bot drew");
// console.log(`\n\n${game.currentPlayer.hand[game.currentPlayer.hand.length - 1]}\n\n`);
// console.log(`\n\n${botMatchingHand}\n\n`);
currentHand = bot.unogame.currentPlayer.hand;
Expand All @@ -35,7 +32,7 @@ async function doBotTurn(bot, msg) {
await delay(2000);
await send(msg.channel, "pass");
bot.unogame.pass();
console.log("bot passed");
// console.log("bot passed");
await delay(1000);
if (player.hand.length === 0) {
return;
Expand All @@ -49,6 +46,11 @@ async function doBotTurn(bot, msg) {
doBotTurn(bot, msg);
}
} else {
await delay(1000);
if (Math.floor(Math.random() * unoBotThink.length) < Math.floor(unoBotThink.length / 3)) {
await send(msg.channel, unoBotThink[Math.floor(Math.random() * unoBotThink.length)]);
await delay(2000);
}
// TODO: Improve logic on which card to pick

// wild and wd4 set color
Expand Down
7 changes: 6 additions & 1 deletion util/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ async function resetGame(bot, msg) {
}

async function nextTurn(bot, msg, players) {
if (!bot.unogame) {
return null;
}
const member = msg.guild.members.cache.get(bot.unogame.currentPlayer.name);
await send(bot.webhooks.uno, `You're up ${member} - Card: ${bot.unogame.discardedCard.toString().replace(/_/g, " ")}`, {
const name = bot.unogame.discardedCard.toString();
const n2 = (name.includes("WILD_DRAW")) ? `${name.split(" ")[0]} WD4` : (name.includes("DRAW")) ? `${name.split(" ")[0]} DT` : name;
await send(bot.webhooks.uno, `You're up ${member} - Card: ${n2}`, {
files: [getCardImage(bot.unogame.discardedCard)],
});
if (players) {
Expand Down

0 comments on commit 29350a7

Please sign in to comment.