mirror of
https://github.com/Ratstail91/SANCTUM.git
synced 2025-11-29 02:24:27 +11:00
Completed faction code
This commit is contained in:
@@ -1,24 +1,47 @@
|
||||
//initialize the exports
|
||||
exports = module.exports = {};
|
||||
|
||||
dataRequest = require("../modules/dataRequest");
|
||||
messaging = require("./messaging");
|
||||
|
||||
//CheckFaction
|
||||
//factionRole - the value to check
|
||||
exports.CheckFaction = function(factionRole) {
|
||||
switch(factionRole) {
|
||||
case process.env.GROUP_A_ROLE:
|
||||
case process.env.GROUP_B_ROLE:
|
||||
case process.env.GROUP_C_ROLE:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//GetFactionName
|
||||
//factionID - the discord role ID of the faction
|
||||
exports.GetFactionName = function(factionID) {
|
||||
switch(factionID) {
|
||||
//factionRole - the discord role ID of the faction
|
||||
exports.GetFactionName = function(factionRole) {
|
||||
//factionRole must be a faction role
|
||||
if (!exports.CheckFaction(factionRole)) {
|
||||
throw "factionRole is not a faction!";
|
||||
}
|
||||
|
||||
switch(factionRole) {
|
||||
case process.env.GROUP_A_ROLE:
|
||||
return process.env.GROUP_A_NAME;
|
||||
case process.env.GROUP_B_ROLE:
|
||||
return process.env.GROUP_B_NAME;
|
||||
case process.env.GROUP_C_ROLE:
|
||||
return process.env.GROUP_C_NAME;
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
//GetFactionChannel
|
||||
//user - discord.js user
|
||||
exports.GetFactionChannel = function(user) {
|
||||
//factionRole must be a faction role
|
||||
if (!exports.CheckFaction(factionRole)) {
|
||||
throw "factionRole is not a faction!";
|
||||
}
|
||||
|
||||
if (user.roles.has(process.env.GROUP_A_ROLE)) {
|
||||
return process.env.GROUP_A_BOT_ID;
|
||||
}
|
||||
@@ -28,73 +51,57 @@ exports.GetFactionChannel = function(user) {
|
||||
if (user.roles.has(process.env.GROUP_C_ROLE)) {
|
||||
return process.env.GROUP_C_BOT_ID;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
// Change Faction
|
||||
exports.ChangeFaction = async function(factionID, channelID, userID, member, botChannelID) {
|
||||
if (member.roles.has(factionID)) {
|
||||
if (factionID === process.env.GROUP_A_ROLE)
|
||||
sendMessage(channelID, dialog.getDialog("orderAlreadyJoined", userID));
|
||||
else if (factionID === process.env.GROUP_B_ROLE)
|
||||
sendMessage(channelID, dialog.getDialog("anarchyAlreadyJoined", userID));
|
||||
else if (factionID === process.env.GROUP_C_ROLE)
|
||||
sendMessage(channelID, dialog.getDialog("religionAlreadyJoined", userID));
|
||||
} else {
|
||||
if (dataRequest.loadServerData("hasConvertedToday", userID) == 1) {
|
||||
sendMessage(channelID, dialog.getDialog("alreadyConvertedToday", userID));
|
||||
} else {
|
||||
// Creates new user
|
||||
var response = String(dataRequest.sendServerData("newUser", "New user.", userID));
|
||||
//ChangeFaction
|
||||
//client - discord.js client
|
||||
//factionRole - a faction role
|
||||
exports.ChangeFaction = async function(client, factionRole, channel, member) {
|
||||
//factionRole must be a faction role
|
||||
if (!exports.CheckFaction(factionRole)) {
|
||||
throw "factionRole is not a faction!";
|
||||
}
|
||||
|
||||
//var response = "createdUser"
|
||||
// Obsidian Tech.
|
||||
if (factionID === process.env.GROUP_A_ROLE) {
|
||||
await member.removeRole(process.env.GROUP_B_ROLE);
|
||||
await member.removeRole(process.env.GROUP_C_ROLE);
|
||||
await member.addRole(process.env.GROUP_A_ROLE);
|
||||
//handle channel strings
|
||||
if (typeof(channel) === "string") {
|
||||
channel = client.channels.find(item => item.name === channel);
|
||||
}
|
||||
|
||||
dataRequest.sendServerData("conversion", "Converted to The Order.", userID);
|
||||
//handle member strings
|
||||
if (typeof(member) === "string") {
|
||||
//get the member
|
||||
let user = client.users.find(item => item.username === member);
|
||||
let guild = client.guilds.get(process.env.SANCTUM_ID);
|
||||
member = guild.members.get(user.id);
|
||||
}
|
||||
|
||||
if (response == "createdUser") {
|
||||
client.users.get(userID).send(dialog.getDialog("newUserPM", userID, getFactionName(factionID)));
|
||||
sendMessage(botChannelID, dialog.getDialog("newUserWelcome", userID, `<#${getFactionName(factionID)}>`));
|
||||
} else {
|
||||
sendMessage(channelID, dialog.getDialog("orderJoin", userID));
|
||||
}
|
||||
if (member.roles.has(factionRole)) {
|
||||
//can't change to this faction
|
||||
return messaging.SendPublicMessage(client, member.user, channel, "You have already joined that faction.");
|
||||
}
|
||||
|
||||
// Genesis Command
|
||||
} else if (factionID === process.env.GROUP_B_ROLE) {
|
||||
await member.removeRole(process.env.GROUP_C_ROLE);
|
||||
await member.removeRole(process.env.GROUP_A_ROLE);
|
||||
await member.addRole(process.env.GROUP_B_ROLE);
|
||||
if (dataRequest.loadServerData("hasConvertedToday", member.user.id) == 1) {
|
||||
return messaging.SendPublicMessage(client, member.user, channel, "You have already converted today.");
|
||||
}
|
||||
|
||||
dataRequest.sendServerData("conversion", "Converted to the Anarchy.", userID);
|
||||
//Creates a new user
|
||||
var newUserResponse = String(dataRequest.sendServerData("newUser", "New user.", member.user.id));
|
||||
|
||||
if (response == "createdUser") {
|
||||
client.users.get(userID).send(dialog.getDialog("newUserPM", userID, getFactionName(factionID)));
|
||||
sendMessage(botChannelID, dialog.getDialog("newUserWelcome", userID, `<#${getFactionName(factionID)}>`));
|
||||
} else {
|
||||
sendMessage(channelID, dialog.getDialog("anarchyJoin", userID));
|
||||
}
|
||||
//joins the new faction
|
||||
await member.removeRole(process.env.GROUP_A_ROLE);
|
||||
await member.removeRole(process.env.GROUP_B_ROLE);
|
||||
await member.removeRole(process.env.GROUP_C_ROLE);
|
||||
await member.addRole(factionRole);
|
||||
|
||||
// The Hand
|
||||
} else if (factionID === process.env.GROUP_C_ROLE) {
|
||||
await member.removeRole(process.env.GROUP_A_ROLE);
|
||||
await member.removeRole(process.env.GROUP_B_ROLE);
|
||||
await member.addRole(process.env.GROUP_C_ROLE);
|
||||
//send the server the info (for logging)
|
||||
dataRequest.sendServerData("conversion", "Converted to " + exports.GetFactionName(factionRole), member.user.id);
|
||||
|
||||
dataRequest.sendServerData("conversion", "Converted to The Religion.", userID);
|
||||
//send the public welcoming message
|
||||
messaging.SendPublicMessage(client, member.user, channel, "Welcome to " + exports.GetFactionName(factionRole));
|
||||
|
||||
if (response == "createdUser") {
|
||||
client.users.get(userID).send(dialog.getDialog("newUserPM", userID, getFactionName(factionID)));
|
||||
sendMessage(botChannelID, dialog.getDialog("newUserWelcome", userID, `<#${getFactionName(factionID)}>`));
|
||||
} else {
|
||||
sendMessage(channelID, dialog.getDialog("religionJoin", userID));
|
||||
}
|
||||
}
|
||||
}
|
||||
//send the private welcoming message
|
||||
if (newUserResponse === "createdUser") {
|
||||
//TODO: more dialog from adam & other faction leaders
|
||||
messaging.SendPrivateMessage(client, member.user, "Welcome to SANCTUM.");
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -33,10 +33,12 @@ client.on("message", function(msg) {
|
||||
switch(command) {
|
||||
//used for debugging
|
||||
case "ping":
|
||||
console.log(shared.CheckValidDisplay(client, "Ratstail91", "bot-spam", true));
|
||||
shared.ChangeFaction(client, process.env.GROUP_B_ROLE, msg.channel, msg.member);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
//actually log in
|
||||
client.login(process.env.DEVELOPER_TOKEN);
|
||||
|
||||
//TODO: change usernames to tags throughout the shared library
|
||||
@@ -53,8 +53,9 @@ exports.CheckValidDisplay = function(client, member, channel, checkRole) { //See
|
||||
//handle member strings
|
||||
if (typeof(member) === "string") {
|
||||
//get the member
|
||||
//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();
|
||||
let user = client.users.find(item => item.username === member);
|
||||
let guild = client.guilds.get(process.env.SANCTUM_ID);
|
||||
member = guild.members.get(user.id);
|
||||
}
|
||||
|
||||
//handle channel strings
|
||||
|
||||
Reference in New Issue
Block a user