Advertisement
Guest User

Alpackle's Grimoire Bot

a guest
Jun 30th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Discord = require("discord.js");
  2.  
  3. var bot = new Discord.Client();
  4.  
  5. //Spell List
  6. all = [];
  7. sorcererList = [];
  8. wizardList = [];
  9. druidList = [];
  10. bardList = [];
  11.  
  12. //Name list function
  13. function readList(list){
  14.     outList = "";
  15.     for (var i = 0; i < list.length; i++){
  16.         outList += all[i].name + "\n";
  17.     }
  18.     return outList;
  19. }
  20.  
  21. // 'Contains' function for searching arrays
  22. function contains(list, obj){
  23.     for (var i = 0; i < list.length; i++){
  24.         if (list[i].id == obj) {
  25.             return true;
  26.         }
  27.     }
  28.     return false;
  29. }
  30.  
  31. // Spell Constructor
  32. function spell(id, name, type, castTime, range, components, duration, description, tags){
  33.     this.id = id;
  34.     this.name = name;
  35.     this.type = type;
  36.     this.castTime = castTime;
  37.     this.range = range;
  38.     this.components = components;
  39.     this.duration = duration;
  40.     this.description = description;
  41.     this.tags = tags;
  42.    
  43.     this.toString = function(){
  44.         return this.name + "\n" + this.type + "\n\nCasting Time: " +
  45.             this.castTime + "\n\nRange: " + this.range + "\n\nComponents: " + this.components + "\n\nDuration: "
  46.         + this.duration + "\n\n" + this.description
  47.     }
  48.    
  49.     //Add to 'all spell' list
  50.     all.push(this);
  51. }
  52.  
  53.  
  54. //Spells
  55. var acid_splash = new spell("acid_splash", "Acid Splash", "Conjuration Cantrip", "1 action", "60 feet", "V, S", "Instantaneous", "You hurl a bubble of acid. Choose one creature within range, or choose two creatures within range that are within 5 feet of each other. A target must succeed on a Dexterity saving throw or take 1d6 acid damage.\nThis spell’s damage increases by 1d6 when you reach 5th level (2d6), 11th level (3d6), and 17th level (4d6).", ["sorcerer", "wizard", "cantrip"]);
  56.  
  57. var blade_ward = new spell("blade_ward", "Blade Ward", "Abjuration Cantrip", "1 action", "Self", "V, S", "1 Round", "You extend your hand and trace a sigil of warding in the air. Until the end of your next turn, you have resistance against bludgeoning, piercing, and slashing damage dealt by weapon attacks.", ["bard", "sorcerer", "warlock", "wizard", "cantrip"]);
  58.  
  59. var booming_blade = new spell("booming_blade", "Booming Blade", "Evocation Cantrip", "1 action", "5 feet", "V, M (a weapon)", "1 round", "As part of the action used to cast this spell, you must make a melee attack with a weapon against one creature within the spell’s range, otherwise the spell fails. On a hit, the target suffers the attack’s normal effects, and it becomes sheathed in booming energy until the start of your next turn. If the target willingly moves before then, it immediately takes 1d8 thunder damage, and the spell ends.\n\nThis spell’s damage increases when you reach higher levels. At 5th level, the melee attack deals an extra 1d8 thunder damage to the target, and the damage the target takes for moving increases to 2d8. Both damage rolls increase by 1d8 at 11th level and 17th level.", ["sorcerer", "wizard", "warlock", "cantrip"]);
  60.  
  61. var chill_touch = new spell("chill_touch", "Chill Touch", "Necromancy cantrip", "1 action", "120 feet", "V, S", "1 round", "You create a ghostly, skeletal hand in the space of a creature within range. Make a ranged spell attack against the creature to assail it with the chill of the grave. On a hit, the target takes 1d8 necrotic damage, and it can’t regain hit points until the start of your next turn. Until then, the hand clings to the target.\n\nIf you hit an undead target, it also has disadvantage on attack rolls against you until the end of your next turn.\n\nThis spell’s damage increases by 1d8 when you reach 5th level (2d8), 11th level (3d8), and 17th level (4d8).", ["sorcerer", "warlock", "wizard", "cantrip"]);
  62.  
  63. var control_flames = new spell("control_flames", "Control Flames", "Transmutation cantrip", "1 action", "60 feet", "S", "Instantaneous or 1 hour (see below)", "You choose nonmagical flame that you can see within range and that fits within a 5-foot cube. You affect it in one of the following ways:\n\n- You instantaneously expand the flame 5 feet in one direction, provided that wood or other fuel is present in the new location.\n\n- You instantaneously extinguish the flames within the cube.\n\n- You double or halve the area of bright light and dim light cast by the flame, change its color, or both. The change lasts for 1 hour.\n\n- You cause simple shapes—such as the vague form of a creature, an inanimate object, or a location—to appear within the flames and animate as you like. The shapes last for 1 hour.\n\n- If you cast this spell multiple times, you can have up to three of its non-instantaneous effects active at a time, and you can dismiss such an effect as an action.", ["druid", "sorcerer", "wizard", "cantrip"]);
  64.  
  65. //List fills
  66. function tagFill(tag, arr){
  67.     for (var i = 0; i < all.length; i++){
  68.         for (var a = 0; a < all[i].tags.length; a++){
  69.             if (all[i].tags[a] == tag){
  70.                 arr.push(all[i]);
  71.             }
  72.         }
  73.     }
  74. }
  75.  
  76.  
  77. tagFill("druid", druidList);
  78. tagFill("bard", bardList);
  79. tagFill("wizard", wizardList);
  80. tagFill("sorcerer", sorcererList);
  81.  
  82. // Message Commands
  83. bot.on("message", function(message){
  84.     var input = message.content.toLowerCase();
  85.     var param = message.content.toLowerCase().split(" ");
  86.     var query1 = param[1];
  87.    
  88.     // Help Command
  89.     if (input == "_help"){
  90.         bot.sendMessage(message, "Grimoire Bot: d&d 5e Spellbook \n\nCommands: \n\n_list: List all spells of a certain type. Usage: _list <query>, where <query> is the spellbook you want listed. By default, _list spells will list every spell. \n\n_spell: Define the spell you select. Usage: _spell <spell_id>. Spell ID's are the name of the spell, with _ instead of spaces.")
  91.     }
  92.    
  93.     //List all Command
  94.     if (input.startsWith("_list")){
  95.        
  96.         if (query1 == "spells"){
  97.         bot.sendMessage(message, readList(all));
  98.         }
  99.        
  100.         if (query1 == "druid"){
  101.             bot.sendMessage(message, readList(druidList));
  102.         }
  103.         if (query1 == "sorcerer"){
  104.             bot.sendMessage(message, readList(sorcererList));
  105.         }
  106.         if (query1 == "bard"){
  107.             bot.sendMessage(message, readList(bardList));
  108.         }
  109.         if (query1 == "wizard"){
  110.             bot.sendMessage(message, readList(wizardList));
  111.         }
  112.     }
  113.     // Spell Command - Define the selected spell
  114.     if (input.startsWith("_spell")){
  115.        
  116.         if (contains(all, query1)){
  117.            
  118.             for (var i = 0; i < all.length; i++){
  119.                 if (query1 == all[i].id){
  120.                     bot.sendMessage(message, all[i].toString());
  121.                 }
  122.             }
  123.         }
  124.         else bot.sendMessage(message, "No such spell");
  125.         }
  126. })
  127.  
  128. bot.login("grimoirebot@gmail.com", "wellHeart").then("success").catch("err");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement