Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ jobs:
TREASURY_ID: ${{ vars.TREASURY_ID }}
TNIV_GROUP_ID: ${{ vars.TNIV_GROUP_ID }}
OFFICE_CODE: ${{ secrets.OFFICE_CODE }}
CL_API_KEY: ${{ secrets.CL_API_KEY }}
CL_CLAN_ID: ${{ secrets.CL_CLAN_ID }}
NODE_OPTIONS: --experimental-vm-modules
PUBLIC_DIRS: "admin-ui/login,login,api-docs,health"
run: |
Expand Down
2 changes: 1 addition & 1 deletion db/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function connectDB() {
isConnected = false;
console.warn('MongoDB disconnected.');
});
if (process.env.NODE_ENV === "development" || process.env.NODE_EJV === "test") {
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
mongoose.set("debug", true);
}
return mongoose.connection;
Expand Down
16 changes: 16 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,19 @@ describe("External Case Registries", () => {
});
});
});
describe("ClanLabs", () => {
test("Get blacklist for user", async () => {
await runTest("Get blacklist for user", async () => {
const getBlacklist = require(path.join(global.__basedir, 'utils/clanLabs.js'));
const result = await getBlacklist("User", "1478099365"); // goggybo
expect(result.name).toBe("goggybo");
});
});
test("Get blacklist for group", async () => {
await runTest("Get blacklist for group", async () => {
const getBlacklist = require(path.join(global.__basedir, 'utils/clanLabs.js'));
const result = await getBlacklist("Group", "35736046"); // Valax
expect(result.name).toBe("Valax ’");
});
});
});
29 changes: 29 additions & 0 deletions utils/clanLabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

const axios = require('axios');

/**
* @param {"User"|"Group"} type
* @param {string} id
* @return {Promise<object|false>} blacklist object, or false if not blacklisted
* @throws if the request fails for any reason other than "not found"
*/
async function getBlacklist(type, id) {
const response = await axios.get(
`https://api.clanlabs.co/v2/blacklists/${type}/${id}`,
{
headers: {
Authorization: "Bearer " + process.env.CL_API_KEY,
"X-Clan-Id": process.env.CL_CLAN_ID,
},
// don't throw on 404/204
validateStatus: (status) => (status >= 200 && status < 300) || status === 404,
}
);

if (response.status === 404 || response.status === 204) return false;

return response.data?.data ?? false;
}

module.exports = getBlacklist;

42 changes: 27 additions & 15 deletions utils/group.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const axios = require("axios");
const path = require("path");
const Case = require(path.join(global.__basedir, 'db/schemas/eic/case.js'));
const RegistryCase = require(path.join(global.__basedir, 'utils/registry.js'));
const RegistryCase = require(path.join(global.__basedir, 'utils/registry.js'));
const getBlacklist = require(path.join(global.__basedir, 'utils/clanLabs.js'));
// send webhook via api
async function sendAcceptedWebhook(userId, groupId, username) {
let target = process.env.pendingWebhookCode;
Expand Down Expand Up @@ -243,7 +244,7 @@ class Game extends Group {
//
try {
const response = await axios.get(
`https://apis.roblox.com/universes/v1/places/${placeid}/universe `,
`https://apis.roblox.com/universes/v1/places/${placeid}/universe`,
{ headers: { "x-api-key": process.env.TREASURY_API_KEY } }
);
return response.data;
Expand Down Expand Up @@ -276,7 +277,12 @@ class User {
}

class JoinRequest extends Group {
userId = '';
/**
* Creates an instance of JoinRequest.
* @param {string} [userId='']
* @param {integer} [groupId=process.env.TNIV_GROUP_ID]
* @memberof JoinRequest
*/
constructor(userId = '', groupId = process.env.TNIV_GROUP_ID) {
super(groupId);
this.userId = userId;
Expand Down Expand Up @@ -319,7 +325,7 @@ class JoinRequest extends Group {
}
}

async decline(reasonText,username) {
async decline(reasonText, username) {
try {
const response = await axios.post(
`https://apis.roblox.com/cloud/v2/groups/${this.groupId}/join-requests/${this.userId}:decline`,
Expand All @@ -339,28 +345,29 @@ class JoinRequest extends Group {
}
async processPending() {
const pending = await this.getJoinRequests();
const text = ""
let text = "";
if (!pending || pending.length === 0) {
return "No pending join requests found.";
}
for (const request of pending) {
const userId = request.user.split("/").slice(1).join("/");;
const userId = request.user.split("/").slice(1).join("/");
this.userId = userId;
try {
const result = await processUser(userId);
console.log(userId + result)
if (result.result === true) {
await this.accept(result.username);
text += result.username + ": Accepted\n"
text += result.username + ": Accepted\n";
} else {
await this.decline(result.reasonText,result.username);
text += result.username + ": Declined" + "\n"
await this.decline(result.reason, result.username);
text += result.username + ": Declined\n";
}
return text
} catch (err) {
console.error(`[processPending] Error processing user ${userId}:`, err?.response?.data || err.message);
sendErrorWebhook(err?.response?.data || err?.message, "Process Pending", "Pending Join Requests")
throw err
return "An error occurred."
sendErrorWebhook(err, "Process Pending", "Pending Join Requests");
text += `${userId}: Error (${err.message})\n`;
}
}
return text;
}
}

Expand Down Expand Up @@ -391,7 +398,12 @@ async function processUser(id) {
return { result: false, reason: `User ${cases[0].usernames} has active cases in registries: ${cases.map(c => c.source).join(", ")}. \n Category: ${cases[0].category} | Type: ${cases[0].type} | Strike: ${cases[0].strike} \n Notes: ${cases[0].notes} EndDate: ${cases[0].end_date}`, username };
}

// TODO CL BLs
// CL BLs

const blacklist = await getBlacklist("User", id);
if (blacklist) {
return { result: false, reason: `User is blacklisted in ClanLabs: ${blacklist.name} (${blacklist.reason})`, username };
}

// TODO rotector etc

Expand Down
14 changes: 12 additions & 2 deletions utils/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ let url = "https://api.keystone-swords.com/api/cases"

// TODO cache


/**
*
*
* @class RegistryCase
*/
class RegistryCase {
active = true
registry = false
/**
* Creates an instance of RegistryCase.
* @param {string} registry
* @param {string} userId
* @param {boolean} active
* @memberof RegistryCase
*/
constructor(registry, userId, active) {
this.registry = registry;
this.userId = userId;
Expand Down
Loading