-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
12 additions
and
104 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,13 @@ | ||
import { rockpaper } from "@mrwhale-io/commands"; | ||
import { Message } from "@mrwhale-io/gamejolt-client"; | ||
|
||
import { GameJoltCommand } from "../../client/command/gamejolt-command"; | ||
|
||
export default class extends GameJoltCommand { | ||
constructor() { | ||
super({ | ||
name: "rockpaper", | ||
description: "Rock. Paper. Scissors.", | ||
type: "game", | ||
usage: "<prefix>rockpaper <rock|paper|scissors>", | ||
examples: ["<prefix>rockpaper scissors"], | ||
aliases: ["rps"], | ||
}); | ||
} | ||
|
||
private compare(first: string, second: string) { | ||
if (first === second) { | ||
return "It's a tie!"; | ||
} else if (first === "scissors") { | ||
if (second === "paper") return "Scissors wins! ✌"; | ||
else return "Rock wins! 👊"; | ||
} else if (first === "rock") { | ||
if (second === "scissors") return "Rock wins! 👊"; | ||
else return "Paper wins! ✋"; | ||
} else if (first === "paper") { | ||
if (second === "rock") return "Paper wins! ✋"; | ||
else return "Scissors wins! ✌"; | ||
} | ||
super(rockpaper.data); | ||
} | ||
|
||
async action(message: Message, [choice]: [string]): Promise<Message> { | ||
if (!choice || choice === "") { | ||
return message.reply("Please pass a choice."); | ||
} | ||
|
||
const userChoice = choice.trim().toLowerCase(); | ||
const compChoice = Math.random(); | ||
let compChoiceStr = ""; | ||
|
||
const validChoices = /\b(rock|paper|scissors)\b/; | ||
|
||
if (!message.textContent.match(validChoices)) { | ||
return message.reply("Please pass rock, paper, scissors."); | ||
} | ||
|
||
if (compChoice < 0.34) { | ||
compChoiceStr = "rock"; | ||
} else if (compChoice <= 0.67) { | ||
compChoiceStr = "paper"; | ||
} else { | ||
compChoiceStr = "scissors"; | ||
} | ||
|
||
const result = this.compare(userChoice, compChoiceStr); | ||
|
||
return message.reply(`${compChoiceStr}. ${result}`); | ||
return message.reply(rockpaper.action(choice)); | ||
} | ||
} |