|
@@ -15,7 +15,7 @@ const PORT = +(process.env.RPC_PORT ?? "8181");
|
|
|
|
|
|
const app = express();
|
|
|
|
|
|
-async function checkUser(userId: string, check: (user: GuildMember, verification: GuildVerification) => Promise<boolean>): Promise<boolean> {
|
|
|
+async function checkUser(action: string, userId: string, check: (user: GuildMember, verification: GuildVerification) => Promise<boolean>): Promise<boolean> {
|
|
|
const verificationGuildRepo = getRepository(GuildVerification);
|
|
|
const guilds = await verificationGuildRepo.find({
|
|
|
select: [
|
|
@@ -30,6 +30,9 @@ async function checkUser(userId: string, check: (user: GuildMember, verification
|
|
|
continue;
|
|
|
}
|
|
|
const user = await tryDo(guildInstance.result.members.fetch(userId));
|
|
|
+ if (!user.ok) {
|
|
|
+ logger.warn("Couldn't %s for user %s on server %s because: %s", action, userId, guild.guildId, user.error);
|
|
|
+ }
|
|
|
if (user.ok && await check(user.result, guild)) {
|
|
|
return true;
|
|
|
}
|
|
@@ -41,19 +44,17 @@ const handler: ModuleRpcServer.ServiceHandlerFor<typeof NoctBotService> = {
|
|
|
async getPing({ ping }): Promise<{ text: string }> {
|
|
|
return { text: `pong: ${ping}` };
|
|
|
},
|
|
|
-
|
|
|
async userInServer({ userId }): Promise<{ exists: boolean }> {
|
|
|
- return { exists: await checkUser(userId, async () => true) };
|
|
|
+ return { exists: await checkUser("check access" ,userId, async () => true) };
|
|
|
},
|
|
|
-
|
|
|
async userAuthorised({ userId }): Promise<{ authorised: boolean }> {
|
|
|
- return { authorised: await checkUser(userId, (user) => isAuthorisedAsync(user)) };
|
|
|
+ return { authorised: await checkUser("check auth", userId, (user) => isAuthorisedAsync(user)) };
|
|
|
},
|
|
|
async userVerified({ userId }): Promise<{ verified: boolean }> {
|
|
|
- return { verified: await checkUser(userId, async (user, guild) => user.roles.cache.has(guild.verifiedRoleId)) };
|
|
|
+ return { verified: await checkUser("check verified", userId, async (user, guild) => user.roles.cache.has(guild.verifiedRoleId)) };
|
|
|
},
|
|
|
async verifyUser({ userId }): Promise<{ ok: boolean }> {
|
|
|
- return { ok: !(await checkUser(userId, async (user, guild) => !(await tryDo(user.roles.add(guild.verifiedRoleId))).ok)) };
|
|
|
+ return { ok: !(await checkUser("verify", userId, async (user, guild) => !(await tryDo(user.roles.add(guild.verifiedRoleId))).ok)) };
|
|
|
}
|
|
|
};
|
|
|
|