rework auth a little
This commit is contained in:
39
src/setup/setup-env.ts
Normal file
39
src/setup/setup-env.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { promptForInput } from "../util/general.ts";
|
||||
import { logError, logSuccess, logWarning } from "../util/logger.ts";
|
||||
import { setupClient } from "./setup-client.ts";
|
||||
|
||||
const botname = await promptForInput("enter bot username: ");
|
||||
const developers = (
|
||||
await promptForInput("enter developer usernames (,separated): ")
|
||||
).split(",");
|
||||
|
||||
const getUid = async (username: string) => {
|
||||
const user = await setupClient.users.getUserByName(username);
|
||||
if (user?.id) {
|
||||
logSuccess(`${user.name} => ${user.id}`);
|
||||
return user.id;
|
||||
}
|
||||
logWarning(`no user with name ${username} found`);
|
||||
return "";
|
||||
};
|
||||
|
||||
const botId = await getUid(botname);
|
||||
if (!botId) {
|
||||
logError("bot not found. please check the configuration");
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
const developerIds = [];
|
||||
for (const dev of developers) {
|
||||
const devId = await getUid(dev);
|
||||
if (devId) {
|
||||
developerIds.push(devId);
|
||||
} else {
|
||||
logWarning(`dev '${dev}' not found. please check the configuration`);
|
||||
}
|
||||
}
|
||||
|
||||
logSuccess(`Userid of bot '${botname}' => '${botId}'`);
|
||||
logSuccess(
|
||||
`Userids of developers '${developers.join(",")}' => '${developerIds.join(",")}'`,
|
||||
);
|
||||
Reference in New Issue
Block a user