|
@@ -6,6 +6,8 @@ import { NoctBotService } from "@shared/rpc/backend";
|
|
import { logger } from "./logging";
|
|
import { logger } from "./logging";
|
|
import { client } from "./client";
|
|
import { client } from "./client";
|
|
import { tryDo } from "@shared/common/async_utils";
|
|
import { tryDo } from "@shared/common/async_utils";
|
|
|
|
+import { getRepository } from "typeorm";
|
|
|
|
+import { GuildVerification } from "@shared/db/entity/GuildVerification";
|
|
|
|
|
|
const PORT = +(process.env.RPC_PORT ?? "8181");
|
|
const PORT = +(process.env.RPC_PORT ?? "8181");
|
|
|
|
|
|
@@ -17,9 +19,20 @@ const handler: ModuleRpcServer.ServiceHandlerFor<typeof NoctBotService> = {
|
|
},
|
|
},
|
|
|
|
|
|
async userInServer({ userId }): Promise<{ exists: boolean }> {
|
|
async userInServer({ userId }): Promise<{ exists: boolean }> {
|
|
- for (const g of client.bot.guilds.cache.values()) {
|
|
|
|
- const res = await tryDo(g.members.fetch(userId));
|
|
|
|
- if (res.ok) {
|
|
|
|
|
|
+ const verificationGuildRepo = getRepository(GuildVerification);
|
|
|
|
+ const guilds = await verificationGuildRepo.find({
|
|
|
|
+ select: [
|
|
|
|
+ "guildId"
|
|
|
|
+ ]
|
|
|
|
+ });
|
|
|
|
+ for (const guild of guilds) {
|
|
|
|
+ const guildInstance = await tryDo(client.bot.guilds.fetch(guild.guildId));
|
|
|
|
+ if (!guildInstance.ok) {
|
|
|
|
+ logger.error("Failed to fetch guild instance for guild %s: %s", guild.guildId, guildInstance.error);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ const user = await tryDo(guildInstance.result.members.fetch(userId));
|
|
|
|
+ if (user.ok) {
|
|
return { exists: true };
|
|
return { exists: true };
|
|
}
|
|
}
|
|
}
|
|
}
|