content = open('/home/ubuntu/loopuman-backend/scheduler.js').read()

addition = """
  const { runCompetitionScheduler } = require('./competition_module');
  const _compNotify = async (telegramId, msg) => {
    try {
      const axios = require('axios');
      await axios.post('https://api.telegram.org/bot' + process.env.TELEGRAM_BOT_TOKEN + '/sendMessage', { chat_id: String(telegramId), text: msg, parse_mode: 'HTML' });
    } catch(e) {}
  };
  setInterval(async () => {
    try { await runCompetitionScheduler(supabase, db, _compNotify, fmt); }
    catch(e) { console.error('[Scheduler] Competition error:', e.message); }
  }, 60 * 60 * 1000);
  console.log('[Scheduler] Competition scheduler registered (hourly)');
"""

target = "  console.log(`[Scheduler] Started!"
if target in content:
    content = content.replace(target, addition + target, 1)
    open('/home/ubuntu/loopuman-backend/scheduler.js', 'w').write(content)
    print('Done - competition scheduler added')
else:
    print('ERROR - target line not found')
