ams-ssk
Version:
NestJS AMS Library for file management
75 lines • 2.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = require("@nestjs/config");
exports.default = (0, config_1.registerAs)('bot', () => {
const maxOps = parseInt(process.env.bot_BOT_MAX_OPERATIONS || '10');
const adminChatId = process.env.bot_ADMIN_CHAT_ID;
const channelConfigs = parseChannelConfigs();
if (!channelConfigs.length) {
console.warn('No bot channel configurations found!');
}
else {
console.log('Parsed channel configurations:', channelConfigs.map((channel) => ({
channelId: channel.channelId,
description: channel.description || 'no description',
botCount: channel.botTokens.length,
})));
}
const uniqueBotTokens = new Set();
const botChannelMapping = new Map();
channelConfigs.forEach((channel) => {
channel.botTokens.forEach((token) => {
uniqueBotTokens.add(token);
const channels = botChannelMapping.get(token) || [];
channels.push(channel.channelId);
botChannelMapping.set(token, channels);
});
});
if (!uniqueBotTokens.size) {
console.warn('No bot bot tokens found in channel configurations!');
}
const config = {
bots: Array.from(uniqueBotTokens).map((token) => ({
token: token.trim(),
maxConcurrentOperations: maxOps,
})),
channels: channelConfigs,
adminChatId,
};
console.log('Loaded bot configuration:', {
botsCount: config.bots.length,
channelsCount: config.channels.length,
botMappings: Array.from(botChannelMapping.entries()).map(([token, channels]) => ({
botToken: `${token.slice(0, 6)}...`,
channels,
})),
hasAdminChatId: !!config.adminChatId,
maxOpsPerBot: maxOps,
});
return config;
});
function parseChannelConfigs() {
const channelConfigs = [];
const envVars = Object.keys(process.env);
const channelConfigVars = envVars.filter((key) => key.startsWith('bot_CHANNEL_CONFIG_'));
for (const configVar of channelConfigVars) {
const channelConfig = process.env[configVar];
if (!channelConfig)
continue;
const [channelId, description, botTokensStr] = channelConfig.split('::');
if (!channelId || !botTokensStr) {
console.warn(`Invalid channel configuration format in ${configVar}`);
continue;
}
channelConfigs.push({
channelId: channelId.trim(),
description: description?.trim(),
botTokens: botTokensStr
.split(',')
.map((token) => token.trim())
.filter(Boolean),
});
}
return channelConfigs;
}
//# sourceMappingURL=bot.config.js.map