Advertisement
Guest User

Untitled

a guest
May 25th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. const DEBUG = true;
  3.  
  4. // ----------------------------------------
  5. // ------------ EPIC MATH WARS ------------
  6. // ----------------------------------------
  7.  
  8. const Discord = require("discord.js");
  9. const bot = new Discord.Client();
  10. const token = DEBUG ? "MjU3NDIzNjI1Mzk1NjM0MTc3.XOkQVA.KP1KvKkujgMafnoviKW__HUvzSc" : process.env.BOT_TOKEN;
  11.  
  12. const SLOT_NULL = 0;
  13. const SLOT_BACKPACK = 1;
  14. const SLOT_ACCESSORIES = 2;
  15. const SLOT_WEAPON = 3;
  16. const SLOT_HAT = 4;
  17. const SLOT_SHOE = 5;
  18.  
  19. const maxcarry = {
  20.     [SLOT_NULL]: 0,
  21.     [SLOT_BACKPACK]: 24,
  22.     [SLOT_ACCESSORIES]: 4,
  23.     [SLOT_WEAPON]: 1,
  24.     [SLOT_HAT]: 1,
  25.     [SLOT_SHOE]: 1
  26. }
  27.  
  28. const illegal_characters = "*`";
  29.  
  30. const TYPE_NULL = 0;
  31. const TYPE_CONSUMABLE = 1;
  32. const TYPE_EQUIP = 2;
  33. const TYPE_WEAPON = 3;
  34. const TYPE_HAT = 4;
  35. const TYPE_SHOE = 5;
  36. const TYPE_MATERIAL = 6;
  37.  
  38. const common_errors = {
  39.     invalid_user: "Invalid user!",
  40.     invalid_item: "Invalid item!",
  41.     invalid_religion: "Invalid religion!",
  42.     invalid_category: "Invalid category!"
  43. }
  44.  
  45. const stackable_types = {
  46.     [TYPE_CONSUMABLE]: true,
  47.     [TYPE_MATERIAL]: true
  48. }
  49.  
  50. const canlist = {
  51.     items: true,
  52.     characters: true,
  53.     religions: true
  54. }
  55.  
  56. // classy utils :cool_sunglasses:
  57. function numcomma(x) {var parts = x.toString().split("."); parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); return parts.join(".");}
  58. function rand(min, max) {return Math.floor(Math.random() * (max - min + 1)) + min;}
  59. function diff(a, b) {return Math.abs(a - b);}
  60. function msend(m, t) {return m.channel.send(t);}
  61. function mpriv(m, t) {return m.author.send(t);}
  62. function merror(m, e) {return msend(m, errorf(e));}
  63. function errorf(str) {return str + " :no_entry:";}
  64. function emotef(item) {return ":" + (item.emote == undefined ? item.name.toLowerCase() : item.emote) + ":";}
  65. function moneyf(amt) {return numcomma(amt) + " :yen:";}
  66. function contains(a, b) {for (let i = 0; i < a.length; i++) {if (a[i] == b) {return true;}} return false;}
  67. function conflict(a, b) {for (let i = 0; i < a.length; i++) {if (contains(b, a[i])) {return true;}} return false;}
  68. function statf(name, num) {return num < 0 ? num + " " + name : "+" + num + " " + name;}
  69. function objf(obj) {return emotef(obj) + " **" + obj.name + "**" + statsf(obj.stats);}
  70. function itemf(id) {return objf(wars.items[id]);}
  71. function validuser(id) {return wars.users[id] != undefined;}
  72. function statsf(starr)
  73. {
  74.     if (starr.length == 0) {return "";}
  75.     let str = "\n```";
  76.     for (let i = 0; i < starr.length; i++)
  77.     {
  78.         let loot_table = starr[i].loot
  79.         if (loot_table != undefined && loot_table.length > 0)
  80.         {
  81.             str += "This item can be opened.\nPossible contents:\n";
  82.             for (let j = 0; j < loot_table.length; j++)
  83.             {
  84.                 str += "  -" + wars.items[loot_table[j]].name;
  85.                 if (j + 1 < loot_table.length) {str += "\n";}
  86.             }
  87.             continue;
  88.         }
  89.         if (starr[i].lore == undefined)
  90.         {
  91.             tab = wars.stats[starr[i].id];
  92.             if (tab.custom_formatting == undefined)
  93.             {
  94.                 str += statf(tab.name, starr[i].lvl);
  95.             }
  96.             else
  97.             {
  98.                 str += tab.custom_formatting(starr[i].lvl);
  99.             }
  100.         }
  101.         else
  102.         {
  103.             str += starr[i].lore;
  104.         }
  105.         if (i + 1 < starr.length) {str += "\n";}
  106.     }
  107.     return str + "```";
  108. }
  109. function profilef(id)
  110. {
  111.     if (!validuser(id)) {return errorf(common_errors.invalid_user);}
  112.     let tab = wars.users[id];
  113.     let str = ":crossed_swords: " + tab.cached_name + " :crossed_swords:\n";
  114.     str += "\n";
  115.     str += "  " + emotef(wars.items[tab.equipped[SLOT_HAT]]) + "\n";
  116.     str += "  " + emotef(wars.characters[tab.character]) + "\n";
  117.     let shoe = emotef(wars.items[tab.equipped[SLOT_SHOE]])
  118.     str += shoe + shoe + "\n";
  119.     str += "\n";
  120.     str += "*" + tab.slogan + "*\n";
  121.     return str;
  122. }
  123. function recur_cmd(msg, txt, i)
  124. {
  125.     if (!i) {i = 0;}
  126.     if (!wars.commands[i]) {return;}
  127.     let cmd = wars.commands[i];
  128.     if (txt[0].toLowerCase() == wars.command_prefix + cmd.command.toLowerCase())
  129.     {
  130.         if (cmd.response != undefined)
  131.         {
  132.             return msend(msg, cmd.response);
  133.         }
  134.         if (cmd.alias != undefined)
  135.         {
  136.             txt[0] = wars.command_prefix + cmd.alias;
  137.             return recur_cmd(msg, txt, 0);
  138.         }
  139.         return cmd.func(msg, txt);
  140.     }
  141.     return recur_cmd(msg, txt, i + 1);
  142. }
  143. function getinv(id)
  144. {
  145.     if (!validuser(id)) return;
  146.     let tab = wars.users[id];
  147.     let inv = tab.inventory;
  148.     return inv; // FIXME
  149. }
  150. function hasitem(userid, itemid, amount)
  151. {
  152.     if (!validuser(userid)) return;
  153.     let tab = getinv(userid);
  154.     for (let i = 0; i < tab.length; i++)
  155.     {
  156.        
  157.     }
  158. }
  159. function listf(obj)
  160. {
  161.     let str = "";
  162.     for (let item in obj)
  163.     {
  164.         str += objf(obj[item]) + "\n";
  165.     }
  166.     return str;
  167. }
  168.  
  169. let wars = {
  170.     command_prefix: ".",
  171.     commands: [
  172.         {command:"all", alias:"list"},
  173.         {command:"list", func: function(msg, txt) {
  174.             let type = txt[1];
  175.             if (canlist[type])
  176.             {
  177.                 return msend(msg, listf(wars[type]))
  178.             }
  179.             return msend(errorf(common_errors.invalid_category) + "\nValid categories: items, characters, religions");
  180.         }},
  181.         {command:"lookup", alias:"info"},
  182.         {command:"wiki", alias:"info"},
  183.         {command:"info", func: function(msg, txt) {
  184.             let item = txt[1];
  185.             if (item == undefined || wars.items[item] == undefined)
  186.             {
  187.                 return merror(msg, common_errors.invalid_item);
  188.             }
  189.             msend(msg, itemf(item));
  190.         }},
  191.         {command:"catchphrase", alias:"slogan"},
  192.         {command:"slogan", func: function(msg, txt) {
  193.             txt[0] = "";
  194.             let slogan = txt.join(" ").trim();
  195.             if (slogan.length < 1)
  196.             {
  197.                 return merror(msg, "Slogan cannot be empty.")
  198.             }
  199.             if (slogan.length > 40)
  200.             {
  201.                 return merror(msg, "Slogan too long.")
  202.             }
  203.             if (conflict(slogan, illegal_characters))
  204.             {
  205.                 return merror(msg, "Slogan contains illegal characters.")
  206.             }
  207.             wars.users["template"].slogan = slogan; // TODO
  208.             msend(msg, "Your slogan has been set to ``" + slogan + "``.");
  209.         }},
  210.         {command:"me", alias:"profile"},
  211.         {command:"profile", func: function(msg, txt) {
  212.             msend(msg, profilef("template"));
  213.         }},
  214.         {command:"save", func: function(msg, txt) {
  215.             let data = Buffer.from(JSON.stringify(wars.users["template"])).toString("base64");
  216.             mpriv(msg, "Your data has been saved: ```" + data + "```");
  217.         }},
  218.         {command:"load", func: function(msg, txt) {
  219.             let str = txt[1];
  220.             let data = Buffer.from(str).toString("ascii");
  221.             mpriv(msg, "Your data has been loaded: ```" + data + "```");
  222.         }},
  223.     ],
  224.     stats: {
  225.         health: {name: "Health"},
  226.         energy: {name: "Energy"},
  227.         drunk: {name: "Drunkenness", custom_formatting: function(num) {return (num * 1.5) + "% Alcohol";}},
  228.         charm: {name: "Charm"},
  229.         damage: {name: "Damage"},
  230.         posion: {ame: "Poison"},
  231.         luck: {name: "Luck"},
  232.         alcohol_immune: {name: "Alcohol Immunity", custom_formatting: function(num) {return "Immune to the effects of Alcohol.";}}
  233.     },
  234.     items: {
  235.         knife: {
  236.             name: "Knife",
  237.             type: TYPE_WEAPON,
  238.             stats: [
  239.                 {id:"damage", lvl:5}
  240.             ]
  241.         },
  242.         bomb: {
  243.             name: "Bomb",
  244.             type: TYPE_WEAPON,
  245.             stats: [
  246.                 {id:"damage", lvl:8}
  247.             ]
  248.         },
  249.         gun: {
  250.             name: "Gun",
  251.             type: TYPE_WEAPON,
  252.             stats: [
  253.                 {id:"damage", lvl:12}
  254.             ]
  255.         },
  256.         apple: {
  257.             name: "Apple",
  258.             type: TYPE_CONSUMABLE,
  259.             stats: [
  260.                 {id:"energy", lvl:2}
  261.             ]
  262.         },
  263.         grapes: {
  264.             name: "Grapes",
  265.             type: TYPE_CONSUMABLE,
  266.             stats: [
  267.                 {id:"energy", lvl:1},
  268.                 {id:"lore", lore:"Used to craft Wine."}
  269.             ]
  270.         },
  271.         meat: {
  272.             name: "Meat",
  273.             emote: "poultry_leg",
  274.             type: TYPE_CONSUMABLE,
  275.             stats: [
  276.                 {id:"energy", lvl:8}
  277.             ]
  278.         },
  279.         bacon: {
  280.             name: "Bacon",
  281.             type: TYPE_CONSUMABLE,
  282.             stats: [
  283.                 {id:"energy", lvl:5}
  284.             ]
  285.         },
  286.         donut: {
  287.             name: "Donut",
  288.             emote: "doughnut",
  289.             type: TYPE_CONSUMABLE,
  290.             stats: [
  291.                 {id:"energy", lvl:4}
  292.             ]
  293.         },
  294.         candy: {
  295.             name: "Candy",
  296.             type: TYPE_CONSUMABLE,
  297.             stats: [
  298.                 {id:"energy", lvl:1}
  299.             ]
  300.         },
  301.         cookie: {
  302.             name: "Cookie",
  303.             type: TYPE_CONSUMABLE,
  304.             stats: [
  305.                 {id:"energy", lvl:2}
  306.             ]
  307.         },
  308.         ice_cream: {
  309.             name: "Ice Cream",
  310.             emote: "ice_cream",
  311.             type: TYPE_CONSUMABLE,
  312.             stats: [
  313.                 {id:"energy", lvl:6}
  314.             ]
  315.         },
  316.         beer: {
  317.             name: "Beer",
  318.             type: TYPE_CONSUMABLE,
  319.             stats: [
  320.                 {id:"drunk", lvl:3},
  321.                 {id:"health", lvl:4}
  322.             ]
  323.         },
  324.         wine: {
  325.             name: "Wine",
  326.             emote: "wine_glass",
  327.             type: TYPE_CONSUMABLE,
  328.             stats: [
  329.                 {id:"drunk", lvl:4},
  330.                 {id:"health", lvl:6}
  331.             ]
  332.         },
  333.         chocbox: {
  334.             name: "Box of Chocolates",
  335.             emote: "gift_heart",
  336.             type: TYPE_CONSUMABLE,
  337.             stats: [
  338.                 {id:"energy", lvl:2},
  339.                 {id:"lore", lore:"You never know what you're gonna get!"}
  340.             ]
  341.         },
  342.         cheese: {
  343.             name: "Cheese",
  344.             type: TYPE_CONSUMABLE,
  345.             stats: [
  346.                 {id:"energy", lvl:4},
  347.                 {id:"luck", lvl:-1}
  348.             ]
  349.         },
  350.         tophat: {
  351.             name: "Top Hat",
  352.             emote: "tophat",
  353.             type: TYPE_HAT,
  354.             stats: [
  355.                 {id:"health", lvl:5}
  356.             ]
  357.         },
  358.         crown: {
  359.             name: "Crown",
  360.             type: TYPE_HAT,
  361.             stats: [
  362.                 {id:"charm", lvl:5}
  363.             ]
  364.         },
  365.         gradcap: {
  366.             name: "Grad Cap",
  367.             emote: "mortar_board",
  368.             type: TYPE_HAT,
  369.             stats: [
  370.                 {id:"luck", lvl:5}
  371.             ]
  372.         },
  373.         flowerhat: {
  374.             name: "Flower Hat",
  375.             emote: "womans_hat",
  376.             type: TYPE_HAT,
  377.             stats: [
  378.                 {id:"health", lvl:3},
  379.                 {id:"charm", lvl:2}
  380.             ]
  381.         },
  382.         brownshoes: {
  383.             name: "Brown Shoes",
  384.             emote: "mans_shoe",
  385.             type: TYPE_SHOE,
  386.             stats: [
  387.                 {id:"health", lvl:1}
  388.             ]
  389.         },
  390.         blueshoes: {
  391.             name: "Blue Shoes",
  392.             emote: "athletic_shoe",
  393.             type: TYPE_SHOE,
  394.             stats: [
  395.                 {id:"health", lvl:2}
  396.             ]
  397.         },
  398.         boots: {
  399.             name: "Boots",
  400.             emote: "boot",
  401.             type: TYPE_SHOE,
  402.             stats: [
  403.                 {id:"health", lvl:3}
  404.             ]
  405.         },
  406.         sandals: {
  407.             name: "Sandals",
  408.             emote: "sandal",
  409.             type: TYPE_SHOE,
  410.             stats: [
  411.                 {id:"luck", lvl:2}
  412.             ]
  413.         },
  414.         heels: {
  415.             name: "High Heels",
  416.             emote: "high_heel",
  417.             type: TYPE_SHOE,
  418.             stats: [
  419.                 {id:"charm", lvl:3}
  420.             ]
  421.         },
  422.         ring: {
  423.             name: "Diamond Ring",
  424.             emote: "ring",
  425.             type: TYPE_EQUIP,
  426.             stats: [
  427.                 {id:"charm", lvl:3},
  428.                 {id:"lore", lore:"Sorry ladies, I'm married. To science."}
  429.             ]
  430.         },
  431.         rose: {
  432.             name: "Rose",
  433.             type: TYPE_EQUIP,
  434.             stats: [
  435.                 {id:"charm", lvl:2}
  436.             ]
  437.         },
  438.         clover: {
  439.             name: "Lucky Clover",
  440.             emote: "four_leaf_clover",
  441.             type: TYPE_EQUIP,
  442.             stats: [
  443.                 {id:"luck", lvl:4}
  444.             ]
  445.         },
  446.         present: {
  447.             name: "Present",
  448.             emote: "gift",
  449.             type: TYPE_CONSUMABLE,
  450.             stats: [
  451.                 {id:"loot", loot:["apple", "knife", "heels"]}
  452.             ]
  453.         }
  454.     },
  455.     recipes: {
  456.         wine: {
  457.             result: {id:"wine", amt:1},
  458.             ingredients: [
  459.                 {id:"grapes", amt:3}
  460.             ]
  461.         }
  462.     },
  463.     characters: {
  464.         chicken: {
  465.             name: "Chicken",
  466.             stats: [
  467.                 {id:"health", lvl:5},
  468.                 {id:"charm", lvl:5},
  469.             ]
  470.         },
  471.         cowboy: {
  472.             name: "Cowboy",
  473.             stats: [
  474.                 {id:"health", lvl:10},
  475.                 {id:"luck", lvl:5}
  476.             ]
  477.         },
  478.         santa: {
  479.             name: "Santa Claus",
  480.             emote: "santa",
  481.             stats: [
  482.                 {id:"health", lvl:20},
  483.                 {id:"charm", lvl:10}
  484.             ]
  485.         },
  486.         robot: {
  487.             name: "Robot",
  488.             stats: [
  489.                 {id:"health", lvl:12},
  490.                 {id:"alcohol_immune", lvl:1}
  491.             ]
  492.         },
  493.     },
  494.     religions: {
  495.         judaism: {
  496.             name: "Judaism",
  497.             emote: "star_of_david",
  498.             stats: [
  499.                 {id:"luck", lvl:5}
  500.             ]
  501.         },
  502.         christianity: {
  503.             name: "Christianity",
  504.             emote: "cross",
  505.             stats: [
  506.                 {id:"health", lvl:5}
  507.             ]
  508.         },
  509.         islam: {
  510.             name: "Islam",
  511.             emote: "star_and_crescent",
  512.             stats: [
  513.                 {id:"damage", lvl:5}
  514.             ]
  515.         },
  516.     },
  517.     users: {
  518.         ["template"]: {
  519.             cached_name: "Tyrone McNiggums",
  520.             slogan: "aight im boutta head out",
  521.             character: "chicken",
  522.             reliigon: "islam",
  523.             money: 2100,
  524.             equipped: {
  525.                 [SLOT_WEAPON]: "knife",
  526.                 [SLOT_HAT]: "gradcap",
  527.                 [SLOT_SHOE]: "heels"
  528.             },
  529.             inventory: [
  530.                 {id: "wine", amt: 3},
  531.                 {id: "knife", amt: 1}
  532.             ]
  533.         }
  534.     }
  535. }
  536.  
  537. bot.on("ready", () => {
  538.     // nuffin
  539. });
  540.  
  541. bot.on("message", message => {
  542.     let raw = message.content;
  543.     let txt = raw.split(" ");
  544.     let cmd = txt[0];
  545.     recur_cmd(message, txt);
  546. });
  547.  
  548. bot.login(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement