mirror of
https://github.com/Ratstail91/SANCTUM.git
synced 2025-11-29 02:24:27 +11:00
Created an empty shell of a server
This commit is contained in:
@@ -2,16 +2,22 @@
|
||||
exports = module.exports = {};
|
||||
|
||||
require("dotenv").config({path: "../.env"});
|
||||
let request = require("sync-request");
|
||||
|
||||
exports.LoadServerData = function(dataType, usersID = "") {
|
||||
let response = request("GET", `${process.env.SERVER_ADDRESS}/getData.php?pk=${process.env.SERVER_PASS_KEY}&dataType=${dataType}&userid=${usersID}`);
|
||||
// console.log(response.getBody());
|
||||
return response.getBody();
|
||||
//socket tools
|
||||
let io = require("socket.io-client")(`${process.env.SERVER_ADDRESS}:${process.env.SERVER_PORT}`);
|
||||
|
||||
//SendServerData
|
||||
//dataType - the type of data being sent
|
||||
//userID (optional) - the id of the user to be bundled with the data
|
||||
//...data (optional) - any data you wish to send
|
||||
exports.SendServerData = function(dataType, userID = "", ...data){
|
||||
io.emit(dataType, { userID: userID, data: data });
|
||||
}
|
||||
|
||||
exports.SendServerData = function(dataType, usersID = "", dataToSend="", dataToSend2 = ""){
|
||||
let response = request("GET", `${process.env.SERVER_ADDRESS}/sendData.php?pk=${process.env.SERVER_PASS_KEY}&dataType=${dataType}&userid=${usersID}&dataToSend=${dataToSend}&dataToSend2=${dataToSend2}`);
|
||||
// console.log(response.getBody());
|
||||
return response.getBody();
|
||||
//OnServerData
|
||||
//dataType - the type of data being sent and received
|
||||
//fn (optional) - the aknowledgement function that is called on the other end (takes the result as an argument)
|
||||
//...data (optional) - any data you wish to send
|
||||
exports.OnServerData = function(dataType, fn, ...data) {
|
||||
io.emit(dataType, { data: data }, fn);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ exports.GetFactionChannel = function(factionRole) {
|
||||
//factionRole - a faction role
|
||||
//channel - discord.js channel OR channel name
|
||||
//member - discord.js member
|
||||
exports.ChangeFaction = async function(client, factionRole, channel, member) {
|
||||
exports.ChangeFaction = function(client, factionRole, channel, member, fn) {
|
||||
//factionRole must be a faction role
|
||||
if (!exports.CheckFaction(factionRole)) {
|
||||
throw "factionRole is not a faction!";
|
||||
@@ -79,31 +79,23 @@ exports.ChangeFaction = async function(client, factionRole, channel, member) {
|
||||
|
||||
if (member.roles.has(factionRole)) {
|
||||
//can't change to this faction
|
||||
return "alreadyJoined";
|
||||
fn("alreadyJoined");
|
||||
}
|
||||
|
||||
if (dataRequest.LoadServerData("hasConvertedToday", member.user.id) == 1) {
|
||||
//can't change too fast
|
||||
return "hasConvertedToday";
|
||||
}
|
||||
let handleResponse = async function(response) {
|
||||
if (response === "conversionLocked") { //can't change too fast
|
||||
fn(response);
|
||||
return;
|
||||
}
|
||||
|
||||
//Creates a new user
|
||||
var newUserResponse = String(dataRequest.SendServerData("newUser", member.user.id, "New user."));
|
||||
//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);
|
||||
|
||||
//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);
|
||||
fn(response);
|
||||
};
|
||||
|
||||
//send the server the info (for logging)
|
||||
dataRequest.SendServerData("conversion", member.user.id, "Converted to " + exports.GetFactionName(factionRole));
|
||||
|
||||
if (newUserResponse === "createdUser") {
|
||||
//send the private welcoming message
|
||||
return newUserResponse;
|
||||
} else {
|
||||
//send the public welcoming message
|
||||
return "joined";
|
||||
}
|
||||
dataRequest.OnServerData("conversion", handleResponse, member.user.id);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "shared",
|
||||
"name": "Shared",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "calc_random.js",
|
||||
"main": "shared.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
@@ -10,6 +10,6 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dotenv": "^6.1.0",
|
||||
"sync-request": "^6.0.0"
|
||||
"socket.io-client": "^2.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ exports.AddXP = function(client, user, amount) {
|
||||
//LevelUp
|
||||
//client - discord.js client
|
||||
//member - member to get the level up
|
||||
exports.LevelUp = function(client, member) { //NOTE: why is this called separately?
|
||||
//fn - function to pass the result to
|
||||
exports.LevelUp = function(client, member, fn) {
|
||||
//handle member strings
|
||||
if (typeof(member) === "string") {
|
||||
//get the member
|
||||
@@ -32,22 +33,12 @@ exports.LevelUp = function(client, member) { //NOTE: why is this called separate
|
||||
if (client.user.username == process.env.GROUP_B_LEADER_NAME && !member.roles.has(process.env.GROUP_B_ROLE)) return;
|
||||
if (client.user.username == process.env.GROUP_C_LEADER_NAME && !member.roles.has(process.env.GROUP_C_ROLE)) return;
|
||||
|
||||
let response = String(dataRequest.SendServerData("getLevelUp", member.user.id));
|
||||
let responseArray = response.split(",");
|
||||
|
||||
let responseMessage = responseArray[0];
|
||||
let level = Math.floor(parseFloat(responseArray[1]));
|
||||
let statPoints = parseFloat(responseArray[2]);
|
||||
|
||||
let rankUp = exports.RankUp(client, member, level);
|
||||
|
||||
if (rankUp == "rankUp") {
|
||||
return [rankUp, level, statPoints];
|
||||
} else if (responseMessage === "levelup") {
|
||||
return ["levelUp", level, statPoints];
|
||||
} else {
|
||||
return ["", level, statPoints];
|
||||
let handleResponse = function(response, level, statPoints) {
|
||||
let rankUp = exports.RankUp(client, member, level);
|
||||
fn(rankUp === "rankUp" ? rankUp : response, level, statPoints);
|
||||
}
|
||||
|
||||
dataRequest.OnServerData("levelUp", handleResponse, member.user.id);
|
||||
}
|
||||
|
||||
//GetLevelUp
|
||||
|
||||
Reference in New Issue
Block a user