pythonSnake5036 commited on
Commit
b230fe2
·
1 Parent(s): cf32a82

Add marshmallow mode

Browse files
commands/activate.js CHANGED
@@ -29,6 +29,10 @@ module.exports = {
29
  {
30
  name: "Binary",
31
  value: "bin"
 
 
 
 
32
  }
33
  )),
34
  async execute(interaction) {
 
29
  {
30
  name: "Binary",
31
  value: "bin"
32
+ },
33
+ {
34
+ name: "Marshmallow",
35
+ value: "marshmallow"
36
  }
37
  )),
38
  async execute(interaction) {
number-converters/get-converter.js CHANGED
@@ -11,6 +11,8 @@ module.exports = {
11
  return require("./hex.js");
12
  case "bin":
13
  return require("./bin.js");
 
 
14
  default:
15
  console.log(`ERROR: No converter found for mode ${mode}, returning null`);
16
  return null;
 
11
  return require("./hex.js");
12
  case "bin":
13
  return require("./bin.js");
14
+ case "marshmallow":
15
+ return require("./marshmallow.js");
16
  default:
17
  console.log(`ERROR: No converter found for mode ${mode}, returning null`);
18
  return null;
number-converters/marshmallow.js ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const { checkNumber } = require("./normal");
2
+
3
+ function countToMarshmallow(count) {
4
+ return Math.floor((Math.sqrt(24 * count + 9) - 3) / 6) + 1;
5
+ }
6
+
7
+ function marshmallowToCount(marshmallows) {
8
+ return (marshmallows - 1) / 2 * (marshmallows * 3);
9
+ }
10
+
11
+ function countToText(count) {
12
+ let marshmallows = countToMarshmallow(count);
13
+ let marshmallowStart = marshmallowToCount(marshmallows);
14
+
15
+ let curCounted = count - marshmallowStart;
16
+
17
+ if (curCounted < marshmallows) {
18
+ return `${marshmallows} marshmallow`;
19
+ } else if (curCounted < marshmallows * 2) {
20
+ return "check it out";
21
+ } else {
22
+ return "woo";
23
+ }
24
+ }
25
+
26
+ let marshmallowRegex = /^(\d+) marshmallow/;
27
+ let checkItOutRegex = /^check it out/;
28
+ let wooRegex = /^woo/;
29
+
30
+ function isValidText(text) {
31
+ return marshmallowRegex.test(text) || checkItOutRegex.test(text) || wooRegex.test(text);
32
+ }
33
+
34
+ module.exports = {
35
+ toString(num) {
36
+ return countToText(num);
37
+ },
38
+ checkNumber(curNum, string) {
39
+ const valid = isValidText(text);
40
+
41
+ const text = countToText(curNum - 1); // Subtract one since count for countToText starts at 0
42
+ const correct = string.toLowerCase().startsWith(text.toLowerCase());
43
+
44
+ return correct ? 2 : (valid ? 1 : 0);
45
+ }
46
+ }