diff --git a/ADAM/npcSettings.js b/ADAM/npcSettings.js index ed4e094..726b83a 100644 --- a/ADAM/npcSettings.js +++ b/ADAM/npcSettings.js @@ -1,8 +1,8 @@ require('dotenv').config({path: '../.env'}); module.exports = { - activity: "Automated Data Analysis Machine.", - type: "PLAYING", - token: process.env.ADAM_TOKEN, - botChannel: "default" + activity: "Automated Data Analysis Machine.", + type: "PLAYING", + token: process.env.ADAM_TOKEN, + botChannel: "default" } diff --git a/ADAM_CptMon/npcSettings.js b/ADAM_CptMon/npcSettings.js index 1a34acd..59aa9aa 100644 --- a/ADAM_CptMon/npcSettings.js +++ b/ADAM_CptMon/npcSettings.js @@ -1,8 +1,8 @@ require('dotenv').config({path: '../.env'}); module.exports = { - activity: "for !genesis recruits.", - type: "WATCHING", - token: process.env.MONTGOMERY_GENESIS_TOKEN, - botChannel: process.env.GROUP_B_BOT_ID + activity: "for !genesis recruits.", + type: "WATCHING", + token: process.env.MONTGOMERY_GENESIS_TOKEN, + botChannel: process.env.GROUP_B_BOT_ID } \ No newline at end of file diff --git a/ADAM_Dairo/npcSettings.js b/ADAM_Dairo/npcSettings.js index 4c5fc8d..1845455 100644 --- a/ADAM_Dairo/npcSettings.js +++ b/ADAM_Dairo/npcSettings.js @@ -1,8 +1,8 @@ require('dotenv').config({path: '../.env'}); module.exports = { - activity: "for !hand recruits.", - type: "WATCHING", - token: process.env.DAIRO_HAND_TOKEN, - botChannel: process.env.GROUP_C_BOT_ID + activity: "for !hand recruits.", + type: "WATCHING", + token: process.env.DAIRO_HAND_TOKEN, + botChannel: process.env.GROUP_C_BOT_ID } diff --git a/ADAM_Kamala/npcSettings.js b/ADAM_Kamala/npcSettings.js index 396fbc0..f595683 100644 --- a/ADAM_Kamala/npcSettings.js +++ b/ADAM_Kamala/npcSettings.js @@ -1,8 +1,8 @@ require('dotenv').config({path: '../.env'}); module.exports = { - activity: "for !obsidian recruits.", - type: "WATCHING", - token: process.env.KAMALA_OBSIDIAN_TOKEN, - botChannel: process.env.GROUP_A_BOT_ID + activity: "for !obsidian recruits.", + type: "WATCHING", + token: process.env.KAMALA_OBSIDIAN_TOKEN, + botChannel: process.env.GROUP_A_BOT_ID } diff --git a/Librarian/dialog.json b/Librarian/dialog.json new file mode 100644 index 0000000..cd8e066 --- /dev/null +++ b/Librarian/dialog.json @@ -0,0 +1,6 @@ +{ + "help": "PLEASE CHOOSE A SUBJECT: help [subject]", + "lore": "PLEASE CHOOSE A SUBJECT: lore [subject]", + + "unknown": "UNKNOWN" +} \ No newline at end of file diff --git a/Librarian/librarian.js b/Librarian/librarian.js index 05f810f..ce25cf0 100644 --- a/Librarian/librarian.js +++ b/Librarian/librarian.js @@ -2,131 +2,116 @@ require('dotenv').config({path: '../.env'}); // Node Modules -const Discord = require('discord.js'); -const client = new Discord.Client(); -const cron = require('node-cron'); +let discord = require('discord.js'); +let client = new discord.Client(); +//let cron = require('node-cron'); // Bot Modules -const dataRequest = require('../modules/dataRequest'); -const calcRandom = require('../modules/calcRandom'); +let npcSettings = require('./npcSettings'); +let shared = require("../Shared/shared"); -// State Machine (Uncomment if needed) -var BotEnumState = { - WAITING: 0, - ACTIVE: 1 -} -var botState = BotEnumState.ACTIVE; +//dialog system +let dialog = shared.GenerateDialogFunction(require("./dialog.json")); -const playingMessage = 'Scribe of the Codex'; -const breakMessage = "Taking a break..." +//ADAM dialog decorator +//NOTE: This isn't strictly necessary for the bots +dialog = function(baseDialog) { + return function(key, ...data) { + if ( (key === "help" || key === "lore") && typeof(data[0]) !== "undefined") { + //force the arg into camelCase + arg = data[0].toLowerCase(); + arg = arg.charAt(0).toUpperCase() + arg.substr(1); + key += arg; + } -// The ready event is vital, it means that your bot will only start reacting to information -// from Discord _after_ ready is emitted + let result = baseDialog(key, ...data); + + if (result === "") { + return "No result for \"" + key + "\""; + } + return result; + } +}(dialog); + +//handle errors +client.on('error', console.error); + +// The ready event is vital, it means that your bot will only start reacting to information from discord _after_ ready is emitted client.on('ready', async () => { - // Generates invite link - try { - let link = await client.generateInvite(["ADMINISTRATOR"]); - console.log("Invite Link: " + link); - } catch(e) { - console.log(e.stack); - } + // Generates invite link + try { + let link = await client.generateInvite(["ADMINISTRATOR"]); + console.log("Invite Link: " + link); + } catch(e) { + console.log(e.stack); + } - // You can set status to 'online', 'invisible', 'away', or 'dnd' (do not disturb) - client.user.setStatus('online'); - // Sets your "Playing" - client.user.setActivity(playingMessage); - console.log(`Connected! \ - \nLogged in as: ${client.user.username} - (${client.user.id})`); + // You can set status to 'online', 'invisible', 'away', or 'dnd' (do not disturb) + client.user.setStatus('online'); + + // Sets your "Playing" + if (npcSettings.activity) { + client.user.setActivity(npcSettings.activity, { type: npcSettings.type }) + //DEBUGGING + .then(presence => console.log("Activity set to " + (presence.game ? presence.game.name : 'none')) ) + .catch(console.error); + } + + console.log("Logged in as: " + client.user.username + " - " + client.user.id); }); // Create an event listener for messages client.on('message', async message => { - // Ignores ALL bot messages - if (message.author.bot) return; - // Message has to be in Outskirts (should be edited later) - if (!(message.channel.id === process.env.TAVERN_CHANNEL_ID - || message.channel.id === process.env.TEST_CHANNEL_ID)) return; - // Has to be (prefix)command - if (message.content.indexOf(process.env.PREFIX) !== 0) return; + // Ignores ALL bot messages + if (message.author.bot) { + return; + } - // "This is the best way to define args. Trust me." - // - Some tutorial dude on the internet - const args = message.content.slice(process.env.PREFIX.length).trim().split(/ +/g); - const command = args.shift().toLowerCase(); + //skip the statis channel + if (message.channel.id === process.env.STASIS_CHANNEL_ID) { + return; + } - switch (command) { - case "ping": - if (isAdmin(message.author.id)) - message.reply("Pong!"); - break; - case "summon": - if (isAdmin(message.author.id)) { - console.log("Summon the bot!"); - BotTurnOnline(process.env.TAVERN_CHANNEL_ID); - } - break; - case "vanish": - if (isAdmin(message.author.id)) { - BotTurnOffline(process.env.TAVERN_CHANNEL_ID); - } - break; - } + //skip the gate channel + if (message.channel.id === process.env.GATE_CHANNEL_ID) { + return; + } + + // Has to be (prefix)command + if (message.content.indexOf(process.env.PREFIX) !== 0) { + return; + } + + if (processBasicCommands(client, message)) { + return; + } }); -client.on('error', console.error); +//Log our bot in +client.login(npcSettings.token); -// Turn online and turn offline -function BotTurnOnline(channel) { - sendMessage(channel, `Insert Online Message here. \ - \n\n***SOME BOLD AND ITALIC TEXT***`); - client.user.setStatus('online'); - client.user.setActivity(playingMessage); - botState = BotEnumState.ACTIVE; +function processBasicCommands(client, message) { + // "This is the best way to define args. Trust me." + // - Some tutorial dude on the internet + let args = message.content.slice(process.env.PREFIX.length).trim().split(/ +/g); + let command = args.shift().toLowerCase(); + + switch (command) { + case "ping": + if (shared.IsAdmin(client, message.author)) { + shared.SendPublicMessage(client, message.author, message.channel, "PONG!"); + } + return true; + + case "help": + case "lore": + shared.SendPublicMessage(client, message.author, message.channel, dialog(command, args[0])); + return true; + + default: + shared.SendPublicMessage(client, message.author, message.channel, dialog("unknown")); + return true; + } + + return false; } - -function BotTurnOffline(channel) { - sendMessage(channel, `Insert Offline Message here. \ - \n\n***SOME BOLD AND ITALIC TEXT***`); - client.user.setStatus('invisible'); - client.user.setActivity(''); - botState = BotEnumState.WAITING; -} - -// You may use cron normally -cron.schedule('* * * * Saturday', function() { - console.log('Saturday join.'); -}); - -// Async Waiting -function sleep(time) { - return new Promise((resolve, reject) => { - setTimeout(resolve, time); - }); -} - -// Gets if user has an Overseers rank -function isAdmin(userID) { - var guild = client.guilds.get(process.env.SANCTUM_ID); - return guild.members.get(userID).roles.find(role => role.name === "Overseers"); -} - -// Send message handler -function sendMessage(userID, channelID, message) { - // Handle optional first argument (so much for default arugments in node) - if (message === undefined) { - message = channelID; - channelID = userID; - userID = null; - } - - // Utility trick (@userID with an optional argument) - if (userID != null) { - message = "<@" + userID + "> " + message; - } - - // Sends message (needs client var, therefore I think external script won't work) - client.channels.get(channelID).send(message); -} - -// Log our bot in (change the token by looking into the .env file) -client.login(process.env.LIBRARIAN_TOKEN); \ No newline at end of file diff --git a/Librarian/npcSettings.js b/Librarian/npcSettings.js new file mode 100644 index 0000000..7dbbd5c --- /dev/null +++ b/Librarian/npcSettings.js @@ -0,0 +1,7 @@ +require('dotenv').config({path: '../.env'}); + +module.exports = { + activity: "for the signal.", + type: "WATCHING", + token: process.env.LIBRARIAN_TOKEN, +} \ No newline at end of file diff --git a/Librarian/package.json b/Librarian/package.json index 69163ab..f65fd82 100644 --- a/Librarian/package.json +++ b/Librarian/package.json @@ -1,29 +1,20 @@ { - "name": "sanctum-deploypackage", - "version": "1.0.1", - "description": "Universal package for all SANCTUM bots, using pm2.", - "main": "", + "name": "nodejs-elasticbeanstalk", + "version": "1.0.0", + "description": "", + "main": "server.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "echo \"Error: you need to use the bot name as a command.\" && exit 1", - "alexis": "pm2 start alexis.js -i max --watch", - "graze": "pm2 start graze.js -i max --watch", - "librarian": "pm2 start librarian.js -i max --watch", - "mainframe": "pm2 start mainframe.js -i max --watch", - "mori": "pm2 start mori.js -i max --watch", - "mosiah": "pm2 start mosiah.js -i max --watch", - "ravager": "pm2 start ravager.js -i max --watch", - "rey": "pm2 start rey.js -i max --watch", - "troll": "pm2 start troll.js -i max --watch" + "start": "forever -o forever.log -e error.log start librarian.js", + "restart": "forever -o forever.log -e error.log restart librarian.js", + "stop": "forever stop librarian.js", + "node": "node librarian.js" }, "author": "", "license": "ISC", "dependencies": { "discord.js": "^11.4.2", "dotenv": "^6.0.0", - "express": "^4.16.3", - "node-cron": "^1.2.1", - "socket.io": "^2.1.1", - "socket.io-request": "^0.8.0" + "forever": "^0.15.3", + "node-cron": "^1.2.1" } }