mirror of
https://github.com/Ratstail91/SANCTUM.git
synced 2025-11-28 18:14:28 +11:00
Did a bunch of refactoring
This commit is contained in:
14
ADAM/adam.js
14
ADAM/adam.js
@@ -24,15 +24,12 @@ dialog = function(baseDialog) {
|
||||
key += arg;
|
||||
}
|
||||
|
||||
let result = baseDialog(key, ...data);
|
||||
|
||||
if (result === "") {
|
||||
return dialog("noResult", key);
|
||||
}
|
||||
return result;
|
||||
return baseDialog(key, ...data);
|
||||
}
|
||||
}(dialog);
|
||||
|
||||
//TODO: noResult needs a better dialog message for each faction leader
|
||||
|
||||
//handle errors
|
||||
client.on('error', console.error);
|
||||
|
||||
@@ -136,10 +133,13 @@ function processBasicCommands(client, message) {
|
||||
case "ping":
|
||||
if (shared.IsAdmin(client, message.author)) {
|
||||
shared.SendPublicMessage(client, message.author, message.channel, "PONG!");
|
||||
shared.OnServerData("serverPing", (response) => {
|
||||
shared.SendPublicMessage(client, message.author, message.channel, response);
|
||||
});
|
||||
}
|
||||
return true;
|
||||
|
||||
case "wallet": //DEBUGGING TODO: add a ping command for the server
|
||||
case "wallet"://TODO: remove this from the server and ADAM
|
||||
shared.OnServerData("wallet", (amount) => {
|
||||
shared.SendPublicMessage(client, message.author, message.channel, "Wallet: " + amount);
|
||||
}, message.author.id);
|
||||
|
||||
46
ADAM/core.js
46
ADAM/core.js
@@ -4,6 +4,52 @@ let dataRequest = require("../Shared/data_request");
|
||||
let discord = require('discord.js');
|
||||
let shared = require("../Shared/shared");
|
||||
|
||||
//TODO: convert all doc comments to JSDoc format
|
||||
|
||||
//CheckValidDisplay
|
||||
//client - discord.js client
|
||||
//member - discord.js member OR username
|
||||
//channel - discord.js channel OR channel name
|
||||
//checkRole - check the member's role or not
|
||||
exports.CheckValidDisplay = function(client, member, channel, checkRole) { //See if the bot should display its message
|
||||
//handle member strings
|
||||
if (typeof(member) === "string") {
|
||||
//get the member
|
||||
let user = client.users.find(item => item.username === member || item.id === member);
|
||||
let guild = client.guilds.get(process.env.SANCTUM_ID);
|
||||
member = guild.members.get(user.id);
|
||||
}
|
||||
|
||||
//handle channel strings
|
||||
if (typeof(channel) === "string") {
|
||||
channel = client.channels.find(item => item.name === channel || item.id === channel);
|
||||
}
|
||||
|
||||
switch(client.user.username) {
|
||||
//NOTE: some copy/paste here that could be fixed
|
||||
case process.env.GROUP_A_LEADER_NAME:
|
||||
if (checkRole) {
|
||||
return channel.id == process.env.GROUP_A_CHANNEL_ID && member.roles.has(process.env.GROUP_A_ROLE);
|
||||
} else {
|
||||
return channel.id == process.env.GROUP_A_CHANNEL_ID;
|
||||
}
|
||||
|
||||
case process.env.GROUP_B_LEADER_NAME:
|
||||
if (checkRole) {
|
||||
return channel.id == process.env.GROUP_B_CHANNEL_ID && member.roles.has(process.env.GROUP_B_ROLE);
|
||||
} else {
|
||||
return channel.id == process.env.GROUP_B_CHANNEL_ID;
|
||||
}
|
||||
|
||||
case process.env.GROUP_C_LEADER_NAME:
|
||||
if (checkRole) {
|
||||
return channel.id == process.env.GROUP_C_CHANNEL_ID && member.roles.has(process.env.GROUP_C_ROLE);
|
||||
} else {
|
||||
return channel.id == process.env.GROUP_C_CHANNEL_ID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//ProcessGameplayCommands
|
||||
//client - discord.js client
|
||||
//message - discord.js message
|
||||
|
||||
@@ -23,12 +23,7 @@ dialog = function(baseDialog) {
|
||||
key += arg;
|
||||
}
|
||||
|
||||
let result = baseDialog(key, ...data);
|
||||
|
||||
if (result === "") {
|
||||
return dialog("noResult", key);
|
||||
}
|
||||
return result;
|
||||
return baseDialog(key, ...data);
|
||||
}
|
||||
}(dialog);
|
||||
|
||||
@@ -83,7 +78,7 @@ client.on('message', async message => {
|
||||
}
|
||||
|
||||
//check if can continue (used primarily by the faction leaders)
|
||||
if (!shared.CheckValidDisplay(client, message.member, message.channel)) {
|
||||
if (!core.CheckValidDisplay(client, message.member, message.channel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,12 +23,7 @@ dialog = function(baseDialog) {
|
||||
key += arg;
|
||||
}
|
||||
|
||||
let result = baseDialog(key, ...data);
|
||||
|
||||
if (result === "") {
|
||||
return dialog("noResult", key);
|
||||
}
|
||||
return result;
|
||||
return baseDialog(key, ...data);
|
||||
}
|
||||
}(dialog);
|
||||
|
||||
@@ -83,7 +78,7 @@ client.on('message', async message => {
|
||||
}
|
||||
|
||||
//check if can continue (used primarily by the faction leaders)
|
||||
if (!shared.CheckValidDisplay(client, message.member, message.channel)) {
|
||||
if (!core.CheckValidDisplay(client, message.member, message.channel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,12 +23,7 @@ dialog = function(baseDialog) {
|
||||
key += arg;
|
||||
}
|
||||
|
||||
let result = baseDialog(key, ...data);
|
||||
|
||||
if (result === "") {
|
||||
return dialog("noResult", key);
|
||||
}
|
||||
return result;
|
||||
return baseDialog(key, ...data);
|
||||
}
|
||||
}(dialog);
|
||||
|
||||
@@ -83,7 +78,7 @@ client.on('message', async message => {
|
||||
}
|
||||
|
||||
//check if can continue (used primarily by the faction leaders)
|
||||
if (!shared.CheckValidDisplay(client, message.member, message.channel)) {
|
||||
if (!core.CheckValidDisplay(client, message.member, message.channel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,12 +24,7 @@ dialog = function(baseDialog) {
|
||||
key += arg;
|
||||
}
|
||||
|
||||
let result = baseDialog(key, ...data);
|
||||
|
||||
if (result === "") {
|
||||
return baseDialog("noResult");
|
||||
}
|
||||
return result;
|
||||
return baseDialog(key, ...data);
|
||||
}
|
||||
}(dialog);
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
"description": "",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"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"
|
||||
"start": "forever -o forever.log -e error.log start bot-librarian.js",
|
||||
"restart": "forever -o forever.log -e error.log restart bot-librarian.js",
|
||||
"stop": "forever stop bot-librarian.js",
|
||||
"node": "node bot-librarian.js"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
|
||||
@@ -13,17 +13,6 @@ let shared = require("../Shared/shared");
|
||||
//dialog system
|
||||
let dialog = shared.GenerateDialogFunction(require("./dialog.json"));
|
||||
|
||||
//dialog decorator
|
||||
dialog = function(baseDialog) {
|
||||
return function(key, ...data) {
|
||||
let result = baseDialog(key, ...data);
|
||||
if (result === "") {
|
||||
return baseDialog("noResult");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}(dialog);
|
||||
|
||||
//global settings
|
||||
const itemCount = 3;
|
||||
const treatments = [
|
||||
@@ -4,10 +4,10 @@
|
||||
"description": "",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "forever -o forever.log -e error.log start mori.js",
|
||||
"restart": "forever -o forever.log -e error.log restart mori.js",
|
||||
"stop": "forever stop mori.js",
|
||||
"node": "node mori.js"
|
||||
"start": "forever -o forever.log -e error.log start bot-mori.js",
|
||||
"restart": "forever -o forever.log -e error.log restart bot-mori.js",
|
||||
"stop": "forever stop bot-mori.js",
|
||||
"node": "node bot-mori.js"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
"description": "",
|
||||
"main": "city.js",
|
||||
"scripts": {
|
||||
"start": "forever -o forever.log -e error.log start city.js",
|
||||
"restart": "forever -o forever.log -e error.log restart city.js",
|
||||
"stop": "forever stop city.js",
|
||||
"node": "node city.js"
|
||||
"start": "forever -o forever.log -e error.log start server-city.js",
|
||||
"restart": "forever -o forever.log -e error.log restart server-city.js",
|
||||
"stop": "forever stop server-city.js",
|
||||
"node": "node server-city.js"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
|
||||
@@ -42,6 +42,7 @@ io.on("connection", async (socket) => {
|
||||
console.log(socket.client.username + " disconnected");
|
||||
});
|
||||
|
||||
socket.on("serverPing", handleServerPing);
|
||||
socket.on("updateStamina", handleUpdateStamina);
|
||||
socket.on("conversion", handleConversion);
|
||||
socket.on("checkin", handleCheckin);
|
||||
@@ -59,6 +60,11 @@ io.on("connection", async (socket) => {
|
||||
server.listen(process.env.SERVER_PORT);
|
||||
console.log("listening on port " + process.env.SERVER_PORT);
|
||||
|
||||
//respond to a ping with a pong
|
||||
async function handleServerPing({ data }, fn) {
|
||||
return fn("SERVER PONG!");
|
||||
}
|
||||
|
||||
//update the playerbase's stamina on command
|
||||
async function handleUpdateStamina({ userID, data }) {
|
||||
let query = "UPDATE users SET stamina = stamina + 1 WHERE stamina < maxStamina;";
|
||||
@@ -116,7 +122,7 @@ async function handleConversion({ data }, fn) {
|
||||
}
|
||||
|
||||
//handle checkin, and add 1 XP
|
||||
async function handleCheckin({ data }, fn) {
|
||||
async function handleCheckin({ data }, fn) { //TODO: You already checked in with me today, you should check in again after X hours
|
||||
//handle checkins (grant crystal bonus)
|
||||
|
||||
//arguments to fn: ["available", time since last checkin], randomAmount
|
||||
@@ -124,7 +130,6 @@ async function handleCheckin({ data }, fn) {
|
||||
let randomAmount = calcRandom.Random(4, 9);
|
||||
|
||||
let query = "SELECT TIME_TO_SEC(TIMEDIFF(NOW(), lastCheckin)) FROM users WHERE userID = ? LIMIT 1;";
|
||||
|
||||
return dbConnection.query(query, [data[0]], (err, result) => {
|
||||
if (err) throw err;
|
||||
|
||||
@@ -150,7 +155,7 @@ async function handleWallet({ data }, fn) {
|
||||
dbConnection.query(query, [data[0]], (err, result) => {
|
||||
if (err) throw err;
|
||||
dbLog(data[0], "wallet query", "result: " + result[0].wallet);
|
||||
fn(result[0].wallet);
|
||||
return fn(result[0].wallet);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ exports.GenerateDialogFunction = function(dialogJson) {
|
||||
}
|
||||
|
||||
if (typeof(result) === "undefined") {
|
||||
return "";
|
||||
return dialogJson["noResult"];
|
||||
}
|
||||
|
||||
let counter = 0;
|
||||
@@ -97,76 +97,3 @@ exports.SplitArray = function(arr, chunkSize) {
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
//CheckValidDisplay
|
||||
//client - discord.js client
|
||||
//member - discord.js member OR username
|
||||
//channel - discord.js channel OR channel name
|
||||
//checkRole - check the member's role or not
|
||||
exports.CheckValidDisplay = function(client, member, channel, checkRole) { //See if the bot should display its message
|
||||
//handle member strings
|
||||
if (typeof(member) === "string") {
|
||||
//get the member
|
||||
let user = client.users.find(item => item.username === member || item.id === member);
|
||||
let guild = client.guilds.get(process.env.SANCTUM_ID);
|
||||
member = guild.members.get(user.id);
|
||||
}
|
||||
|
||||
//handle channel strings
|
||||
if (typeof(channel) === "string") {
|
||||
channel = client.channels.find(item => item.name === channel || item.id === channel);
|
||||
}
|
||||
|
||||
switch(client.user.username) {
|
||||
//NOTE: some copy/paste here that could be fixed
|
||||
case process.env.GROUP_A_LEADER_NAME:
|
||||
if (checkRole) {
|
||||
return channel.id == process.env.GROUP_A_CHANNEL_ID && member.roles.has(process.env.GROUP_A_ROLE);
|
||||
} else {
|
||||
return channel.id == process.env.GROUP_A_CHANNEL_ID;
|
||||
}
|
||||
|
||||
case process.env.GROUP_B_LEADER_NAME:
|
||||
if (checkRole) {
|
||||
return channel.id == process.env.GROUP_B_CHANNEL_ID && member.roles.has(process.env.GROUP_B_ROLE);
|
||||
} else {
|
||||
return channel.id == process.env.GROUP_B_CHANNEL_ID;
|
||||
}
|
||||
|
||||
case process.env.GROUP_C_LEADER_NAME:
|
||||
if (checkRole) {
|
||||
return channel.id == process.env.GROUP_C_CHANNEL_ID && member.roles.has(process.env.GROUP_C_ROLE);
|
||||
} else {
|
||||
return channel.id == process.env.GROUP_C_CHANNEL_ID;
|
||||
}
|
||||
|
||||
case process.env.GHOST_NAME: {
|
||||
// JSON
|
||||
let rooms = require('../TextAdv/rooms.json'); //TODO: should this be here?
|
||||
let roomExists = false;
|
||||
|
||||
// Loops for all rooms
|
||||
rooms.rooms.forEach(room => {
|
||||
if (channel.id === rooms[room].channel) {
|
||||
roomExists = true;
|
||||
}
|
||||
});
|
||||
|
||||
//if the given room exists
|
||||
if (roomExists) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//DEBUGGING: test channel
|
||||
if (channel.id == process.env.TEST_CHANNEL_ID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//otherwise
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
//default value: always show messages if not a faction leader
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user