diff --git a/.envdev b/.envdev index 8d2073a..05d6cd5 100644 --- a/.envdev +++ b/.envdev @@ -69,6 +69,7 @@ MONTGOMERY_GENESIS_TOKEN="" DAIRO_HAND_TOKEN="" LIBRARIAN_TOKEN="" MORI_TOKEN="" +GRAZE_TOKEN="" # Channel access roles (must match roles in your server) # Replace them with your own on a sandbox server! diff --git a/BOT_Graze/bot-graze.js b/BOT_Graze/bot-graze.js new file mode 100644 index 0000000..d885270 --- /dev/null +++ b/BOT_Graze/bot-graze.js @@ -0,0 +1,91 @@ +// .env Variables +require('dotenv').config({path: '../.env'}); + +// Node Modules +let discord = require('discord.js'); +let client = new discord.Client(); + +// Bot Modules +let npcSettings = require('./npcSettings'); +let shared = require("../Shared/shared"); + +//dialog system +let dialog = shared.GenerateDialogFunction(require("./dialog.json")); + +//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); + } + + // 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; + } + + //skip the statis channel + if (message.channel.id === process.env.STASIS_CHANNEL_ID) { + return; + } + + //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; + } +}); + +//Log our bot in +client.login(npcSettings.token); + +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; + + default: + shared.SendPublicMessage(client, message.author, message.channel, dialog(command)); + return true; + } + + return false; +} diff --git a/BOT_Graze/dialog.json b/BOT_Graze/dialog.json new file mode 100644 index 0000000..78ca07d --- /dev/null +++ b/BOT_Graze/dialog.json @@ -0,0 +1,3 @@ +{ + "noResult": "I have no idea what you just said." +} diff --git a/BOT_Graze/npcSettings.js b/BOT_Graze/npcSettings.js new file mode 100644 index 0000000..f62b0a9 --- /dev/null +++ b/BOT_Graze/npcSettings.js @@ -0,0 +1,7 @@ +require('dotenv').config({path: '../.env'}); + +module.exports = { + activity: "for upgrade requests.", + type: "WATCHING", + token: process.env.GRAZE_TOKEN, +} diff --git a/BOT_Graze/package.json b/BOT_Graze/package.json new file mode 100644 index 0000000..bd1ca4a --- /dev/null +++ b/BOT_Graze/package.json @@ -0,0 +1,20 @@ +{ + "name": "Librarian", + "version": "1.0.0", + "description": "", + "main": "server.js", + "scripts": { + "start": "forever -o forever.log -e error.log start bot-graze.js", + "restart": "forever -o forever.log -e error.log restart bot-graze.js", + "stop": "forever stop bot-graze.js", + "node": "node bot-graze.js" + }, + "author": "", + "license": "ISC", + "dependencies": { + "discord.js": "^11.4.2", + "dotenv": "^6.1.0", + "forever": "^0.15.3", + "node-cron": "^1.2.1" + } +} diff --git a/package.json b/package.json index 488e8ff..15b6ecc 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "installdairo": "cd ADAM_Dairo && npm install", "installlibrarian": "cd BOT_Librarian && npm install", "installmori": "cd BOT_Mori && npm install", + "installgraze": "cd BOT_Graze && npm install", "startcity": "cd SERVER_City && npm start", "startadam": "cd ADAM && npm start", "startkamala": "cd ADAM_Kamala && npm start", @@ -18,6 +19,7 @@ "startdairo": "cd ADAM_Dairo && npm start", "startlibrarian": "cd BOT_Librarian && npm start", "startmori": "cd BOT_Mori && npm start", + "startgraze": "cd BOT_Graze && npm start", "restartcity": "cd SERVER_City && npm restart", "restartadam": "cd ADAM && npm restart", "restartkamala": "cd ADAM_Kamala && npm restart", @@ -25,6 +27,7 @@ "restartdairo": "cd ADAM_Dairo && npm restart", "restartlibrarian": "cd BOT_Librarian && npm restart", "restartmori": "cd BOT_Mori && npm restart", + "restartgraze": "cd BOT_Graze && npm restart", "stopcity": "cd SERVER_City && npm stop", "stopadam": "cd ADAM && npm stop", "stopkamala": "cd ADAM_Kamala && npm stop", @@ -32,10 +35,11 @@ "stopdairo": "cd ADAM_Dairo && npm stop", "stoplibrarian": "cd BOT_Librarian && npm stop", "stopmori": "cd BOT_Mori && npm stop", - "installall": "npm install && concurrently \"cd Shared && npm install\" \"npm run installcity\" \"npm run installadam\" \"npm run installkamala\" \"npm run installcptmon\" \"npm run installdairo\" \"npm run installlibrarian\" \"npm run installmori\"", - "startall": "concurrently \"npm run startcity\" \"npm run startadam\" \"npm run startkamala\" \"npm run startcptmon\" \"npm run startdairo\" \"npm run startlibrarian\" \"npm run startmori\"", - "restartall": "concurrently \"npm run restartcity\" \"npm run restartadam\" \"npm run restartkamala\" \"npm run restartcptmon\" \"npm run restartdairo\" \"npm run restartlibrarian\" \"npm run restartmori\"", - "stopall": "concurrently \"npm run stopcity\" \"npm run stopadam\" \"npm run stopkamala\" \"npm run stopcptmon\" \"npm run stopdairo\" \"npm run stoplibrarian\" \"npm run stopmori\"" + "stopgraze": "cd BOT_Graze && npm stop", + "installall": "npm install && concurrently \"cd Shared && npm install\" \"npm run installcity\" \"npm run installadam\" \"npm run installkamala\" \"npm run installcptmon\" \"npm run installdairo\" \"npm run installlibrarian\" \"npm run installmori\" \"npm run installgraze\"", + "startall": "concurrently \"npm run startcity\" \"npm run startadam\" \"npm run startkamala\" \"npm run startcptmon\" \"npm run startdairo\" \"npm run startlibrarian\" \"npm run startmori\" \"npm run startgraze\"", + "restartall": "concurrently \"npm run restartcity\" \"npm run restartadam\" \"npm run restartkamala\" \"npm run restartcptmon\" \"npm run restartdairo\" \"npm run restartlibrarian\" \"npm run restartmori\" \"npm run restartgraze\"", + "stopall": "concurrently \"npm run stopcity\" \"npm run stopadam\" \"npm run stopkamala\" \"npm run stopcptmon\" \"npm run stopdairo\" \"npm run stoplibrarian\" \"npm run stopmori\" \"npm run stopgraze\"" }, "author": "", "license": "ISC",