mirror of
https://github.com/Ratstail91/SANCTUM.git
synced 2025-11-29 10:34:26 +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);
|
||||
|
||||
48
ADAM/core.js
48
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
|
||||
@@ -238,4 +284,4 @@ exports.HandleLevelUp = function(client, member, channel, dialog, next) {
|
||||
}
|
||||
|
||||
shared.LevelUp(client, member, handleResponse);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user