Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const DEBUG = true;
- // ----------------------------------------
- // ------------ EPIC MATH WARS ------------
- // ----------------------------------------
- const Discord = require("discord.js");
- const bot = new Discord.Client();
- const token = DEBUG ? "MjU3NDIzNjI1Mzk1NjM0MTc3.XOkQVA.KP1KvKkujgMafnoviKW__HUvzSc" : process.env.BOT_TOKEN;
- const SLOT_NULL = 0;
- const SLOT_BACKPACK = 1;
- const SLOT_ACCESSORIES = 2;
- const SLOT_WEAPON = 3;
- const SLOT_HAT = 4;
- const SLOT_SHOE = 5;
- const maxcarry = {
- [SLOT_NULL]: 0,
- [SLOT_BACKPACK]: 24,
- [SLOT_ACCESSORIES]: 4,
- [SLOT_WEAPON]: 1,
- [SLOT_HAT]: 1,
- [SLOT_SHOE]: 1
- }
- const illegal_characters = "*`";
- const TYPE_NULL = 0;
- const TYPE_CONSUMABLE = 1;
- const TYPE_EQUIP = 2;
- const TYPE_WEAPON = 3;
- const TYPE_HAT = 4;
- const TYPE_SHOE = 5;
- const TYPE_MATERIAL = 6;
- const common_errors = {
- invalid_user: "Invalid user!",
- invalid_item: "Invalid item!",
- invalid_religion: "Invalid religion!",
- invalid_category: "Invalid category!"
- }
- const stackable_types = {
- [TYPE_CONSUMABLE]: true,
- [TYPE_MATERIAL]: true
- }
- const canlist = {
- items: true,
- characters: true,
- religions: true
- }
- // classy utils :cool_sunglasses:
- function numcomma(x) {var parts = x.toString().split("."); parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); return parts.join(".");}
- function rand(min, max) {return Math.floor(Math.random() * (max - min + 1)) + min;}
- function diff(a, b) {return Math.abs(a - b);}
- function msend(m, t) {return m.channel.send(t);}
- function mpriv(m, t) {return m.author.send(t);}
- function merror(m, e) {return msend(m, errorf(e));}
- function errorf(str) {return str + " :no_entry:";}
- function emotef(item) {return ":" + (item.emote == undefined ? item.name.toLowerCase() : item.emote) + ":";}
- function moneyf(amt) {return numcomma(amt) + " :yen:";}
- function contains(a, b) {for (let i = 0; i < a.length; i++) {if (a[i] == b) {return true;}} return false;}
- function conflict(a, b) {for (let i = 0; i < a.length; i++) {if (contains(b, a[i])) {return true;}} return false;}
- function statf(name, num) {return num < 0 ? num + " " + name : "+" + num + " " + name;}
- function objf(obj) {return emotef(obj) + " **" + obj.name + "**" + statsf(obj.stats);}
- function itemf(id) {return objf(wars.items[id]);}
- function validuser(id) {return wars.users[id] != undefined;}
- function statsf(starr)
- {
- if (starr.length == 0) {return "";}
- let str = "\n```";
- for (let i = 0; i < starr.length; i++)
- {
- let loot_table = starr[i].loot
- if (loot_table != undefined && loot_table.length > 0)
- {
- str += "This item can be opened.\nPossible contents:\n";
- for (let j = 0; j < loot_table.length; j++)
- {
- str += " -" + wars.items[loot_table[j]].name;
- if (j + 1 < loot_table.length) {str += "\n";}
- }
- continue;
- }
- if (starr[i].lore == undefined)
- {
- tab = wars.stats[starr[i].id];
- if (tab.custom_formatting == undefined)
- {
- str += statf(tab.name, starr[i].lvl);
- }
- else
- {
- str += tab.custom_formatting(starr[i].lvl);
- }
- }
- else
- {
- str += starr[i].lore;
- }
- if (i + 1 < starr.length) {str += "\n";}
- }
- return str + "```";
- }
- function profilef(id)
- {
- if (!validuser(id)) {return errorf(common_errors.invalid_user);}
- let tab = wars.users[id];
- let str = ":crossed_swords: " + tab.cached_name + " :crossed_swords:\n";
- str += "\n";
- str += " " + emotef(wars.items[tab.equipped[SLOT_HAT]]) + "\n";
- str += " " + emotef(wars.characters[tab.character]) + "\n";
- let shoe = emotef(wars.items[tab.equipped[SLOT_SHOE]])
- str += shoe + shoe + "\n";
- str += "\n";
- str += "*" + tab.slogan + "*\n";
- return str;
- }
- function recur_cmd(msg, txt, i)
- {
- if (!i) {i = 0;}
- if (!wars.commands[i]) {return;}
- let cmd = wars.commands[i];
- if (txt[0].toLowerCase() == wars.command_prefix + cmd.command.toLowerCase())
- {
- if (cmd.response != undefined)
- {
- return msend(msg, cmd.response);
- }
- if (cmd.alias != undefined)
- {
- txt[0] = wars.command_prefix + cmd.alias;
- return recur_cmd(msg, txt, 0);
- }
- return cmd.func(msg, txt);
- }
- return recur_cmd(msg, txt, i + 1);
- }
- function getinv(id)
- {
- if (!validuser(id)) return;
- let tab = wars.users[id];
- let inv = tab.inventory;
- return inv; // FIXME
- }
- function hasitem(userid, itemid, amount)
- {
- if (!validuser(userid)) return;
- let tab = getinv(userid);
- for (let i = 0; i < tab.length; i++)
- {
- }
- }
- function listf(obj)
- {
- let str = "";
- for (let item in obj)
- {
- str += objf(obj[item]) + "\n";
- }
- return str;
- }
- let wars = {
- command_prefix: ".",
- commands: [
- {command:"all", alias:"list"},
- {command:"list", func: function(msg, txt) {
- let type = txt[1];
- if (canlist[type])
- {
- return msend(msg, listf(wars[type]))
- }
- return msend(errorf(common_errors.invalid_category) + "\nValid categories: items, characters, religions");
- }},
- {command:"lookup", alias:"info"},
- {command:"wiki", alias:"info"},
- {command:"info", func: function(msg, txt) {
- let item = txt[1];
- if (item == undefined || wars.items[item] == undefined)
- {
- return merror(msg, common_errors.invalid_item);
- }
- msend(msg, itemf(item));
- }},
- {command:"catchphrase", alias:"slogan"},
- {command:"slogan", func: function(msg, txt) {
- txt[0] = "";
- let slogan = txt.join(" ").trim();
- if (slogan.length < 1)
- {
- return merror(msg, "Slogan cannot be empty.")
- }
- if (slogan.length > 40)
- {
- return merror(msg, "Slogan too long.")
- }
- if (conflict(slogan, illegal_characters))
- {
- return merror(msg, "Slogan contains illegal characters.")
- }
- wars.users["template"].slogan = slogan; // TODO
- msend(msg, "Your slogan has been set to ``" + slogan + "``.");
- }},
- {command:"me", alias:"profile"},
- {command:"profile", func: function(msg, txt) {
- msend(msg, profilef("template"));
- }},
- {command:"save", func: function(msg, txt) {
- let data = Buffer.from(JSON.stringify(wars.users["template"])).toString("base64");
- mpriv(msg, "Your data has been saved: ```" + data + "```");
- }},
- {command:"load", func: function(msg, txt) {
- let str = txt[1];
- let data = Buffer.from(str).toString("ascii");
- mpriv(msg, "Your data has been loaded: ```" + data + "```");
- }},
- ],
- stats: {
- health: {name: "Health"},
- energy: {name: "Energy"},
- drunk: {name: "Drunkenness", custom_formatting: function(num) {return (num * 1.5) + "% Alcohol";}},
- charm: {name: "Charm"},
- damage: {name: "Damage"},
- posion: {ame: "Poison"},
- luck: {name: "Luck"},
- alcohol_immune: {name: "Alcohol Immunity", custom_formatting: function(num) {return "Immune to the effects of Alcohol.";}}
- },
- items: {
- knife: {
- name: "Knife",
- type: TYPE_WEAPON,
- stats: [
- {id:"damage", lvl:5}
- ]
- },
- bomb: {
- name: "Bomb",
- type: TYPE_WEAPON,
- stats: [
- {id:"damage", lvl:8}
- ]
- },
- gun: {
- name: "Gun",
- type: TYPE_WEAPON,
- stats: [
- {id:"damage", lvl:12}
- ]
- },
- apple: {
- name: "Apple",
- type: TYPE_CONSUMABLE,
- stats: [
- {id:"energy", lvl:2}
- ]
- },
- grapes: {
- name: "Grapes",
- type: TYPE_CONSUMABLE,
- stats: [
- {id:"energy", lvl:1},
- {id:"lore", lore:"Used to craft Wine."}
- ]
- },
- meat: {
- name: "Meat",
- emote: "poultry_leg",
- type: TYPE_CONSUMABLE,
- stats: [
- {id:"energy", lvl:8}
- ]
- },
- bacon: {
- name: "Bacon",
- type: TYPE_CONSUMABLE,
- stats: [
- {id:"energy", lvl:5}
- ]
- },
- donut: {
- name: "Donut",
- emote: "doughnut",
- type: TYPE_CONSUMABLE,
- stats: [
- {id:"energy", lvl:4}
- ]
- },
- candy: {
- name: "Candy",
- type: TYPE_CONSUMABLE,
- stats: [
- {id:"energy", lvl:1}
- ]
- },
- cookie: {
- name: "Cookie",
- type: TYPE_CONSUMABLE,
- stats: [
- {id:"energy", lvl:2}
- ]
- },
- ice_cream: {
- name: "Ice Cream",
- emote: "ice_cream",
- type: TYPE_CONSUMABLE,
- stats: [
- {id:"energy", lvl:6}
- ]
- },
- beer: {
- name: "Beer",
- type: TYPE_CONSUMABLE,
- stats: [
- {id:"drunk", lvl:3},
- {id:"health", lvl:4}
- ]
- },
- wine: {
- name: "Wine",
- emote: "wine_glass",
- type: TYPE_CONSUMABLE,
- stats: [
- {id:"drunk", lvl:4},
- {id:"health", lvl:6}
- ]
- },
- chocbox: {
- name: "Box of Chocolates",
- emote: "gift_heart",
- type: TYPE_CONSUMABLE,
- stats: [
- {id:"energy", lvl:2},
- {id:"lore", lore:"You never know what you're gonna get!"}
- ]
- },
- cheese: {
- name: "Cheese",
- type: TYPE_CONSUMABLE,
- stats: [
- {id:"energy", lvl:4},
- {id:"luck", lvl:-1}
- ]
- },
- tophat: {
- name: "Top Hat",
- emote: "tophat",
- type: TYPE_HAT,
- stats: [
- {id:"health", lvl:5}
- ]
- },
- crown: {
- name: "Crown",
- type: TYPE_HAT,
- stats: [
- {id:"charm", lvl:5}
- ]
- },
- gradcap: {
- name: "Grad Cap",
- emote: "mortar_board",
- type: TYPE_HAT,
- stats: [
- {id:"luck", lvl:5}
- ]
- },
- flowerhat: {
- name: "Flower Hat",
- emote: "womans_hat",
- type: TYPE_HAT,
- stats: [
- {id:"health", lvl:3},
- {id:"charm", lvl:2}
- ]
- },
- brownshoes: {
- name: "Brown Shoes",
- emote: "mans_shoe",
- type: TYPE_SHOE,
- stats: [
- {id:"health", lvl:1}
- ]
- },
- blueshoes: {
- name: "Blue Shoes",
- emote: "athletic_shoe",
- type: TYPE_SHOE,
- stats: [
- {id:"health", lvl:2}
- ]
- },
- boots: {
- name: "Boots",
- emote: "boot",
- type: TYPE_SHOE,
- stats: [
- {id:"health", lvl:3}
- ]
- },
- sandals: {
- name: "Sandals",
- emote: "sandal",
- type: TYPE_SHOE,
- stats: [
- {id:"luck", lvl:2}
- ]
- },
- heels: {
- name: "High Heels",
- emote: "high_heel",
- type: TYPE_SHOE,
- stats: [
- {id:"charm", lvl:3}
- ]
- },
- ring: {
- name: "Diamond Ring",
- emote: "ring",
- type: TYPE_EQUIP,
- stats: [
- {id:"charm", lvl:3},
- {id:"lore", lore:"Sorry ladies, I'm married. To science."}
- ]
- },
- rose: {
- name: "Rose",
- type: TYPE_EQUIP,
- stats: [
- {id:"charm", lvl:2}
- ]
- },
- clover: {
- name: "Lucky Clover",
- emote: "four_leaf_clover",
- type: TYPE_EQUIP,
- stats: [
- {id:"luck", lvl:4}
- ]
- },
- present: {
- name: "Present",
- emote: "gift",
- type: TYPE_CONSUMABLE,
- stats: [
- {id:"loot", loot:["apple", "knife", "heels"]}
- ]
- }
- },
- recipes: {
- wine: {
- result: {id:"wine", amt:1},
- ingredients: [
- {id:"grapes", amt:3}
- ]
- }
- },
- characters: {
- chicken: {
- name: "Chicken",
- stats: [
- {id:"health", lvl:5},
- {id:"charm", lvl:5},
- ]
- },
- cowboy: {
- name: "Cowboy",
- stats: [
- {id:"health", lvl:10},
- {id:"luck", lvl:5}
- ]
- },
- santa: {
- name: "Santa Claus",
- emote: "santa",
- stats: [
- {id:"health", lvl:20},
- {id:"charm", lvl:10}
- ]
- },
- robot: {
- name: "Robot",
- stats: [
- {id:"health", lvl:12},
- {id:"alcohol_immune", lvl:1}
- ]
- },
- },
- religions: {
- judaism: {
- name: "Judaism",
- emote: "star_of_david",
- stats: [
- {id:"luck", lvl:5}
- ]
- },
- christianity: {
- name: "Christianity",
- emote: "cross",
- stats: [
- {id:"health", lvl:5}
- ]
- },
- islam: {
- name: "Islam",
- emote: "star_and_crescent",
- stats: [
- {id:"damage", lvl:5}
- ]
- },
- },
- users: {
- ["template"]: {
- cached_name: "Tyrone McNiggums",
- slogan: "aight im boutta head out",
- character: "chicken",
- reliigon: "islam",
- money: 2100,
- equipped: {
- [SLOT_WEAPON]: "knife",
- [SLOT_HAT]: "gradcap",
- [SLOT_SHOE]: "heels"
- },
- inventory: [
- {id: "wine", amt: 3},
- {id: "knife", amt: 1}
- ]
- }
- }
- }
- bot.on("ready", () => {
- // nuffin
- });
- bot.on("message", message => {
- let raw = message.content;
- let txt = raw.split(" ");
- let cmd = txt[0];
- recur_cmd(message, txt);
- });
- bot.login(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement