Compare commits
5 Commits
edd87375c3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| bb7118242b | |||
| d3a295d598 | |||
| d97abc00e2 | |||
| cada5487bf | |||
| 2f9c65512b |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@chatenium/chatenium-sdk",
|
||||
"version": "1.1.13",
|
||||
"version": "1.2.2",
|
||||
"description": "A library for interacting with the Chatenium API",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
@@ -23,7 +23,6 @@
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
],
|
||||
"license": "GPL-3.0-or-later",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "vitest run",
|
||||
|
||||
32
src/core/permissions.ts
Normal file
32
src/core/permissions.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
export const permissions = {
|
||||
createAndEditCategories: 2,
|
||||
deleteCategories: 4,
|
||||
createAndEditChannels: 8,
|
||||
deleteChannels: 16,
|
||||
deleteAnyMessage: 32,
|
||||
pinMessages: 64,
|
||||
createAndEditRanks: 128,
|
||||
deleteRanks: 256,
|
||||
changeNetworkNamePictureAndVisibility: 512,
|
||||
createEmojis: 1024,
|
||||
deleteEmojis: 2048,
|
||||
manageEmbed: 4096,
|
||||
createWebhooks: 8192,
|
||||
deleteWebhooks: 16384,
|
||||
createInvites: 32768,
|
||||
deleteInvites: 65536,
|
||||
sendMessages: 131072,
|
||||
seeChannels: 262144,
|
||||
banMembers: 524288,
|
||||
kickMembers: 1048576,
|
||||
unAndAssignRanksToMember: 2097152,
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the set of permissions includes the permission. Note that network owners have regular permissions just like the other members, so if the userid matches with the network's creator ID, then the permission is automatically granted. This logic is not included in this function.
|
||||
* @param permissions
|
||||
* @param permission
|
||||
*/
|
||||
export function permissionGranted(permissions: number, permission: number): Boolean {
|
||||
return (permissions & permission) === permission;
|
||||
}
|
||||
@@ -100,21 +100,23 @@ export class SessionManager {
|
||||
* Validates and updates all sessions and returns with a new session list
|
||||
* @param sessions
|
||||
*/
|
||||
updateSessions(sessions: Session[]): Session[] {
|
||||
sessions.forEach(async session => {
|
||||
const index = sessions.indexOf(session)
|
||||
async updateSessions(sessions: Session[]): Promise<Session[]> {
|
||||
const activeSessions: Session[] = [];
|
||||
|
||||
for (const session of sessions) {
|
||||
if (!await this.validateSession(session.token)) {
|
||||
this.database.delete("sessions", session.userData.userid)
|
||||
this.keyring.delete(session.userData.userid)
|
||||
sessions.splice(index, 1)
|
||||
this.database.delete("sessions", session.userData.userid);
|
||||
this.keyring.delete(session.userData.userid);
|
||||
console.warn(`Validating session for user ${session.userData.userid} failed. Deleting session...`)
|
||||
continue;
|
||||
}
|
||||
|
||||
const updatedUserData = await this.updateUserData(session)
|
||||
this.database.set("sessions", session.userData.userid, updatedUserData)
|
||||
sessions[index] = updatedUserData
|
||||
})
|
||||
const updatedUserData = await this.updateUserData(session);
|
||||
this.database.set("sessions", session.userData.userid, JSON.stringify(updatedUserData.userData));
|
||||
activeSessions.push(updatedUserData);
|
||||
}
|
||||
|
||||
return sessions
|
||||
return activeSessions;
|
||||
}
|
||||
|
||||
private async validateSession(token: string): Promise<boolean> {
|
||||
|
||||
Reference in New Issue
Block a user