Added shared.CheckValidDisplay()

This commit is contained in:
2018-10-20 13:56:12 +11:00
parent 31a13e000d
commit ce295efd31
3 changed files with 80 additions and 34 deletions

18
.envdev
View File

@@ -43,6 +43,14 @@ GROUP_A_NAME="Obsidian Technologies"
GROUP_B_NAME="Genesis Command" GROUP_B_NAME="Genesis Command"
GROUP_C_NAME="The Hand" GROUP_C_NAME="The Hand"
GROUP_A_CHANNEL_ID="493972208616603658"
GROUP_B_CHANNEL_ID="493972336190685185"
GROUP_C_CHANNEL_ID="493972354137849856"
GROUP_A_LEADER_NAME="Kamala, Obsidian Vice President"
GROUP_B_LEADER_NAME="Captain Montgomery"
GROUP_C_LEADER_NAME="Dairo, High Prophet of The Hand"
# Channel IDs # Channel IDs
# Replace them with your own on a sandbox server! # Replace them with your own on a sandbox server!
CODEX_CHANNEL_ID="457580831284789249" CODEX_CHANNEL_ID="457580831284789249"
@@ -56,12 +64,6 @@ DEADLANDS_CHANNEL_ID="459196395119837195"
HELLS_GATE_CHANNEL_ID="464238060243124245" HELLS_GATE_CHANNEL_ID="464238060243124245"
TEST_CHANNEL_ID="464838060262293514" TEST_CHANNEL_ID="464838060262293514"
# Bot Channels in SANCTUM (A = Obsidian, B = Genesis, C = Hand)
# Replace them with your own on a sandbox server!
GROUP_A_BOT_ID="493972208616603658"
GROUP_B_BOT_ID="493972336190685185"
GROUP_C_BOT_ID="493972354137849856"
# Bot IDs # Bot IDs
# Replace them with your own on a sandbox server! # Replace them with your own on a sandbox server!
MORI_ID="461294299515191306" MORI_ID="461294299515191306"
@@ -76,6 +78,10 @@ KAMALA_OBSIDIAN_ID="482644250354384906"
DAIRO_HAND_ID="482644985318211594" DAIRO_HAND_ID="482644985318211594"
LIBRARIAN_ID="458033243481047082" LIBRARIAN_ID="458033243481047082"
# Bot Names
# Replace them with your own on a sandbox server!
GHOST_NAME="Ghost 5.0.1"
# Bot Tokens # Bot Tokens
ADAM_TOKEN="" ADAM_TOKEN=""
RAVAGER_TOKEN="" RAVAGER_TOKEN=""

View File

@@ -33,7 +33,7 @@ client.on("message", function(msg) {
switch(command) { switch(command) {
//used for debugging //used for debugging
case "ping": case "ping":
shared.SendPublicMessage(client, "Ratstail91", "bot-spam", "pong", 3000); console.log(shared.CheckValidDisplay(client, "Ratstail91", "bot-spam", true));
break; break;
} }
}); });

View File

@@ -44,34 +44,74 @@ exports.SplitArray = function(arr, chunkSize) {
return groups; return groups;
} }
/*
// See if the bot should display its message // See if the bot should display its message
function checkValidDisplay(member, channelID, checkRole) { //client - discord.js client
if (client.user.username == "Kamala, Obsidian Vice President" && channelID === process.env.GROUP_A_BOT_ID) { //member - discord.js member OR username
if (checkRole) { if (member.roles.has(process.env.GROUP_A_ROLE)) return true; } else true; //channel - discord.js channel OR channel name
} //checkRole - check the member's role or not
else if (client.user.username == "Captain Montgomery" && channelID === process.env.GROUP_B_BOT_ID) { exports.CheckValidDisplay = function(client, member, channel, checkRole) {
if (checkRole) { if (member.roles.has(process.env.GROUP_B_ROLE)) return true; } else true; //handle member strings
} if (typeof(member) === "string") {
else if (client.user.username == "Dairo, High Prophet of The Hand" && channelID === process.env.GROUP_C_BOT_ID) { //get the member
if (checkRole) { if (member.roles.has(process.env.GROUP_C_ROLE)) return true; } else true; //NOTE: I think the bot needs to run inside a single server only, otherwise I don't know what will happen here due to the [0] part
} member = client.guilds.map(guild => guild.members.filter(mbr => mbr.user.username === member))[0].first();
else if (client.user.username == "Ghost 5.0.1") {
// JSON
const rooms = require('../TextAdv/rooms.json');
var roomExists = false;
// Loops for all rooms
rooms.rooms.forEach(element => {
if (channelID === rooms[element].channel) roomExists = true;
});
if (!roomExists) {
if (channelID === process.env.TEST_CHANNEL_ID) return true;
} else return true;
} }
return false; //handle channel strings
if (typeof(channel) === "string") {
channel = client.channels.find(item => item.name === 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
return false;
}
} }
*/