aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/colorfind.js441
-rwxr-xr-xmodules/registers.js8
2 files changed, 449 insertions, 0 deletions
diff --git a/modules/colorfind.js b/modules/colorfind.js
new file mode 100644
index 0000000..8ffe808
--- /dev/null
+++ b/modules/colorfind.js
@@ -0,0 +1,441 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2022- Minteck
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+const Database = require('../data/data.json');
+let db = {};
+
+for (let entry of Object.keys(Database)) {
+ search = {};
+
+ for (let e of Object.keys(Database[entry].search)) {
+ search[e] = Database[entry].search[e].filter(i => i !== null);
+ }
+
+ db[entry] = search;
+}
+
+module.exports = (query, uid, gid) => {
+ console.log("Running color search");
+ matches = {};
+
+ keys_l1 = query.toLowerCase().split(" ");
+ keys_l2 = [];
+ keys_l3 = {
+ "coat": [],
+ "mane": [],
+ "eyes": []
+ };
+
+ keys = {
+ "coat": [],
+ "mane": [],
+ "eyes": []
+ };
+
+ for (let key of keys_l1) {
+ if (key.split(":").length > 1) keys_l2.push({
+ key: key.split(":")[0].trim(),
+ value: key.split(":")[1].trim()
+ });
+ }
+
+ for (let item of keys_l2) {
+ let key = item.key;
+ let value = item.value;
+
+ switch (key) {
+ case "coat":
+ case "co":
+ case "coa":
+ case "skin":
+ case "sk":
+ case "ski":
+ case "s":
+ case "peau":
+ case "pea":
+ case "pe":
+ case "manteau":
+ case "mante":
+ case "mantea":
+ case "mant":
+ case "fur":
+ case "fu":
+ case "fourrure":
+ case "fou":
+ case "four":
+ case "fourr":
+ case "fourru":
+ case "fourrur":
+ case "fo":
+ case "f":
+ keys_l3["coat"].push(value);
+ break;
+
+ case "eyes":
+ case "ey":
+ case "eye":
+ case "e":
+ case "yeux":
+ case "ye":
+ case "yeu":
+ case "y":
+ case "oeil":
+ case "oe":
+ case "oei":
+ case "o":
+ case "pupil":
+ case "pupi":
+ case "pup":
+ case "pu":
+ case "pupille":
+ case "p":
+ keys_l3["eyes"].push(value);
+ break;
+
+ case "m":
+ case "mane":
+ case "ma":
+ case "man":
+ case "manes":
+ case "crinière":
+ case "cri":
+ case "crin":
+ case "crini":
+ case "criniè":
+ case "crinie":
+ case "crinièr":
+ case "crinier":
+ case "cr":
+ case "criniere":
+ case "hair":
+ case "ha":
+ case "hai":
+ case "h":
+ case "hairs":
+ case "cheveux":
+ case "che":
+ case "chev":
+ case "cheve":
+ case "cheveu":
+ case "ch":
+ keys_l3["mane"].push(value);
+ break;
+ }
+ }
+
+ for (let key of Object.keys(keys_l3)) {
+ let values = keys_l3[key];
+
+ for (let value of values) {
+ switch (value) {
+ case "blac":
+ case "black":
+ case "k":
+ case "n":
+ case "no":
+ case "noi":
+ case "noir":
+ case "d":
+ case "da":
+ case "dar":
+ case "dark":
+ if (keys[key] === null) keys[key] = [];
+ keys[key].push(0);
+ break
+
+ case "blan":
+ case "blanc":
+ case "w":
+ case "wh":
+ case "whi":
+ case "whit":
+ case "white":
+ case "l":
+ case "li":
+ case "lig":
+ case "ligh":
+ case "light":
+ if (keys[key] === null) keys[key] = [];
+ keys[key].push(1);
+ break
+
+ case "gra":
+ case "gray":
+ case "grey":
+ case "gri":
+ case "gris":
+ if (keys[key] === null) keys[key] = [];
+ keys[key].push(2);
+ break
+
+ case "r":
+ case "ro":
+ case "rou":
+ case "roug":
+ case "rouge":
+ case "re":
+ case "red":
+ if (keys[key] === null) keys[key] = [];
+ keys[key].push(3);
+ break
+
+ case "o":
+ case "or":
+ case "ora":
+ case "oran":
+ case "orang":
+ case "orange":
+ case "go":
+ case "gol":
+ case "gold":
+ if (keys[key] === null) keys[key] = [];
+ keys[key].push(4);
+ break
+
+ case "y":
+ case "ye":
+ case "yel":
+ case "yell":
+ case "yello":
+ case "yellow":
+ case "j":
+ case "jau":
+ case "jaun":
+ case "jaune":
+ if (keys[key] === null) keys[key] = [];
+ keys[key].push(5);
+ break
+
+ case "g":
+ case "gr":
+ case "gre":
+ case "gree":
+ case "green":
+ case "v":
+ case "ve":
+ case "ver":
+ case "vert":
+ if (keys[key] === null) keys[key] = [];
+ keys[key].push(6);
+ break
+
+ case "b":
+ case "bl":
+ case "ble":
+ case "blu":
+ case "bleu":
+ case "blue":
+ case "s":
+ case "sk":
+ case "sky":
+ case "c":
+ case "ci":
+ case "cie":
+ case "ciel":
+ case "t":
+ case "tu":
+ case "tur":
+ case "turq":
+ case "turqu":
+ case "turquo":
+ case "turquoi":
+ case "turquois":
+ case "turquoise":
+ case "cy":
+ case "cya":
+ case "cyan":
+ if (keys[key] === null) keys[key] = [];
+ keys[key].push(7);
+ break
+
+ case "vi":
+ case "vio":
+ case "viol":
+ case "viole":
+ case "violet":
+ case "p":
+ case "pu":
+ case "pur":
+ case "purp":
+ case "purpl":
+ case "purple":
+ case "m":
+ case "ma":
+ case "mag":
+ case "mage":
+ case "magen":
+ case "magent":
+ case "magenta":
+ if (keys[key] === null) keys[key] = [];
+ keys[key].push(8);
+ break
+
+ case "ros":
+ case "rose":
+ case "pi":
+ case "pin":
+ case "pink":
+ if (keys[key] === null) keys[key] = [];
+ keys[key].push(9);
+ break
+
+ case "br":
+ case "bro":
+ case "brow":
+ case "brown":
+ case "mar":
+ case "marr":
+ case "marro":
+ case "marron":
+ if (keys[key] === null) keys[key] = [];
+ keys[key].push(10);
+ break
+ }
+ }
+ }
+
+ for (let criteria of Object.keys(keys)) {
+ let values = keys[criteria];
+
+ for (let pony of Object.keys(db)) {
+ let data = db[pony];
+
+ for (let value of values) {
+ if (data[criteria].includes(value)) {
+ if (typeof matches[pony] !== "number") matches[pony] = 0;
+ matches[pony]++;
+ }
+ }
+ }
+ }
+
+ sorted = Object.keys(matches).sort(function(a,b){return matches[a]-matches[b]}).reverse();
+ sortedMatches = {};
+ sortedMatchesFirst = {};
+
+ index = 0;
+ for (let item of sorted) {
+ if (index < 30) sortedMatches[item] = matches[item];
+ index++;
+ }
+
+ index = 0;
+ for (let item of sorted) {
+ if (index < 5) sortedMatchesFirst[item] = matches[item];
+ index++;
+ }
+
+ queryItems = [];
+
+ maneColor = [ l("any color", "de n'importe quelle couleur", uid, gid) ];
+ coatColor = [ l("any color", "de n'importe quelle couleur", uid, gid) ];
+ eyesColor = [ l("any color", "de n'importe quelle couleur", uid, gid) ];
+
+ if (keys["mane"].length > 0) maneColor = [];
+ if (keys["coat"].length > 0) coatColor = [];
+ if (keys["eyes"].length > 0) eyesColor = [];
+
+ operations = 0;
+ for (let value of keys["mane"]) {
+ operations++;
+ switch (value) {
+ case 0: maneColor.push(l("black", "noire", uid, gid)); break;
+ case 1: maneColor.push(l("white", "blanche", uid, gid)); break;
+ case 2: maneColor.push(l("gray", "grise", uid, gid)); break;
+ case 3: maneColor.push(l("red", "rouge", uid, gid)); break;
+ case 4: maneColor.push(l("orange", "orange", uid, gid)); break;
+ case 5: maneColor.push(l("yellow", "jaune", uid, gid)); break;
+ case 6: maneColor.push(l("green", "verte", uid, gid)); break;
+ case 7: maneColor.push(l("blue", "bleue", uid, gid)); break;
+ case 8: maneColor.push(l("purple", "violette", uid, gid)); break;
+ case 9: maneColor.push(l("pink", "rose", uid, gid)); break;
+ case 10: maneColor.push(l("brown", "marron", uid, gid)); break;
+ }
+ }
+
+ for (let value of keys["coat"]) {
+ operations++;
+ switch (value) {
+ case 0: coatColor.push(l("black", "noire", uid, gid)); break;
+ case 1: coatColor.push(l("white", "blanche", uid, gid)); break;
+ case 2: coatColor.push(l("gray", "grise", uid, gid)); break;
+ case 3: coatColor.push(l("red", "rouge", uid, gid)); break;
+ case 4: coatColor.push(l("orange", "orange", uid, gid)); break;
+ case 5: coatColor.push(l("yellow", "jaune", uid, gid)); break;
+ case 6: coatColor.push(l("green", "verte", uid, gid)); break;
+ case 7: coatColor.push(l("blue", "bleue", uid, gid)); break;
+ case 8: coatColor.push(l("purple", "violette", uid, gid)); break;
+ case 9: coatColor.push(l("pink", "rose", uid, gid)); break;
+ case 10: coatColor.push(l("brown", "marron", uid, gid)); break;
+ }
+ }
+
+ for (let value of keys["eyes"]) {
+ operations++;
+ switch (value) {
+ case 0: eyesColor.push(l("black", "noirs", uid, gid)); break;
+ case 1: eyesColor.push(l("white", "blancs", uid, gid)); break;
+ case 2: eyesColor.push(l("gray", "gris", uid, gid)); break;
+ case 3: eyesColor.push(l("red", "rouges", uid, gid)); break;
+ case 4: eyesColor.push(l("orange", "oranges", uid, gid)); break;
+ case 5: eyesColor.push(l("yellow", "jaunes", uid, gid)); break;
+ case 6: eyesColor.push(l("green", "verts", uid, gid)); break;
+ case 7: eyesColor.push(l("blue", "bleus", uid, gid)); break;
+ case 8: eyesColor.push(l("purple", "violets", uid, gid)); break;
+ case 9: eyesColor.push(l("pink", "roses", uid, gid)); break;
+ case 10: eyesColor.push(l("brown", "marrons", uid, gid)); break;
+ }
+ }
+
+ final = l(maneColor.join(", ") + " mane; " + coatColor.join(", ") + " coat; " + eyesColor.join(", ") + " eyes", "crinière " + maneColor.join(", ") + " ; peau " + coatColor.join(", ") + " ; yeux " + eyesColor.join(", "), uid, gid);
+
+ if (operations > 3) {
+ finalTrimmed = operations + " conditions";
+ } else {
+ if (final.length > 180) {
+ finalTrimmed = final.substring(0, 180) + "...";
+ } else {
+ finalTrimmed = final;
+ }
+ }
+
+ max = 0;
+ for (let match of Object.keys(sortedMatches)) {
+ if (sortedMatches[match] > max) max = sortedMatches[match];
+ }
+
+ exact = [];
+ for (let match of Object.keys(sortedMatches)) {
+ if (sortedMatches[match] === max) exact.push(match);
+ }
+
+ return {
+ results: Object.keys(sortedMatches),
+ first: Object.keys(sortedMatchesFirst),
+ exact,
+ query: finalTrimmed,
+ full: final
+ }
+} \ No newline at end of file
diff --git a/modules/registers.js b/modules/registers.js
index a8f2e7f..9ed0a74 100755
--- a/modules/registers.js
+++ b/modules/registers.js
@@ -59,6 +59,14 @@ module.exports = [
.setAutocomplete(true)
),
new SlashCommandBuilder()
+ .setName('color')
+ .setDescription("Searches for a pony from their coat, mane or eyes color(s)")
+ .addStringOption(option =>
+ option.setName("query")
+ .setDescription("The criteria. Run the command without a query to get help.")
+ .setRequired(false)
+ ),
+ new SlashCommandBuilder()
.setName('info')
.setDescription("Gets stats and info about the bot"),
new SlashCommandBuilder()