H3y-sam commited on
Commit
89f8708
Β·
verified Β·
1 Parent(s): a7e39ae

Upload 48 files

Browse files
bot.py CHANGED
@@ -97,24 +97,49 @@ class BotHandler(BaseHTTPRequestHandler):
97
  self._send(200, "text/html", "<h2>Bot Running 🟒</h2>")
98
  return
99
 
100
- if path in ("/health", "/api/health"):
101
  self._send(200, "text/plain", "Bot Running 🟒")
102
  return
103
 
104
- if path == "/api/status":
105
- from content.config_manager import config_manager
106
- from content.user_registry import get_user_count
107
  from scheduler.job_scheduler import get_all_jobs
 
 
 
 
 
 
 
108
  self._json(200, {
109
  "ok": True,
110
- "channels": config_manager.channels,
111
- "schedule": config_manager.schedule,
112
- "settings": config_manager.settings,
113
- "user_count": get_user_count(),
114
- "jobs": len([j for j in get_all_jobs() if j.next_run_time])
 
115
  })
116
  return
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  if path == "/api/syllabus":
119
  from content.syllabus_manager import syllabus_manager
120
  self._json(200, {"ok": True, "syllabus": syllabus_manager.syllabus})
 
97
  self._send(200, "text/html", "<h2>Bot Running 🟒</h2>")
98
  return
99
 
100
+ if path == "/health":
101
  self._send(200, "text/plain", "Bot Running 🟒")
102
  return
103
 
104
+ if path == "/api/health":
105
+ import time
 
106
  from scheduler.job_scheduler import get_all_jobs
107
+ from config import GROQ_MODEL
108
+
109
+ # Basic subsystem check
110
+ scheduler_ok = True
111
+ try: get_all_jobs()
112
+ except: scheduler_ok = False
113
+
114
  self._json(200, {
115
  "ok": True,
116
+ "ts": time.strftime("%H:%M:%S"),
117
+ "checks": {
118
+ "scheduler": {"ok": scheduler_ok, "msg": f"{len(get_all_jobs())} jobs active" if scheduler_ok else "Scheduler error"},
119
+ "groq": {"ok": True, "msg": f"Model: {GROQ_MODEL}"},
120
+ "telegram": {"ok": True, "msg": "API Online"}
121
+ }
122
  })
123
  return
124
 
125
+ if path == "/api/status":
126
+ try:
127
+ from content.config_manager import config_manager
128
+ from content.user_registry import get_user_count
129
+ from scheduler.job_scheduler import get_all_jobs
130
+ self._json(200, {
131
+ "ok": True,
132
+ "channels": config_manager.channels,
133
+ "schedule": config_manager.schedule,
134
+ "settings": config_manager.settings,
135
+ "user_count": get_user_count(),
136
+ "jobs": len([j for j in get_all_jobs() if j.next_run_time])
137
+ })
138
+ except Exception as e:
139
+ logger.error(f"Status API Error: {e}")
140
+ self._json(500, {"ok": False, "error": str(e)})
141
+ return
142
+
143
  if path == "/api/syllabus":
144
  from content.syllabus_manager import syllabus_manager
145
  self._json(200, {"ok": True, "syllabus": syllabus_manager.syllabus})
content/config_manager.py CHANGED
@@ -178,7 +178,7 @@ class ConfigManager:
178
  "mcq_poll_delay_min": 60,
179
  "mcq_poll_delay_max": 90,
180
  "disabled_content_types": disabled,
181
- "footer": "πŸ“’ Share with your batch!\nπŸ”— @xCrazyLearners",
182
  "button_text": "",
183
  "button_url": "",
184
  "hashtags": {
 
178
  "mcq_poll_delay_min": 60,
179
  "mcq_poll_delay_max": 90,
180
  "disabled_content_types": disabled,
181
+ "footer": "πŸ“’ Share with your batch!\nπŸ”— @xcrazylearners",
182
  "button_text": "",
183
  "button_url": "",
184
  "hashtags": {
content/generator.py CHANGED
@@ -139,7 +139,7 @@ def _footer(channel_key: str, tag_key: str) -> str:
139
  footer = cfg.get("footer", "✨ *Study Hard, Score High!*")
140
  hashtag = cfg.get("hashtags", {}).get(tag_key, "")
141
 
142
- brand = "πŸš€ *Join for more:* @CrazyLearners"
143
  sep = "━━━━━━━━━━━━━━━━━━"
144
 
145
  if hashtag:
 
139
  footer = cfg.get("footer", "✨ *Study Hard, Score High!*")
140
  hashtag = cfg.get("hashtags", {}).get(tag_key, "")
141
 
142
+ brand = "πŸš€ *Join for more:* @xcrazylearners"
143
  sep = "━━━━━━━━━━━━━━━━━━"
144
 
145
  if hashtag:
content/news_scraper.py CHANGED
@@ -73,5 +73,5 @@ def get_news_message(item):
73
  f"πŸ”” *NEW NTA UPDATE*\n\n"
74
  f"πŸ“Œ {item['title']}\n\n"
75
  f"πŸ”— [Read Official Notice]({item['link']})\n\n"
76
- f"πŸš€ *CrazyLearners* | @CrazyLearners"
77
  )
 
73
  f"πŸ”” *NEW NTA UPDATE*\n\n"
74
  f"πŸ“Œ {item['title']}\n\n"
75
  f"πŸ”— [Read Official Notice]({item['link']})\n\n"
76
+ f"πŸš€ *CrazyLearners* | @xcrazylearners"
77
  )
content/remote_storage.py CHANGED
@@ -1,12 +1,11 @@
1
  import json
2
  import logging
3
  import requests
4
- from config import GIST_ID, GIST_TOKEN, HISTORY_FILE_NAME
5
-
6
  logger = logging.getLogger(__name__)
7
 
8
  def pull_from_gist(filename: str) -> dict:
9
  """Pull a specific JSON file from the GitHub Gist."""
 
10
  if not GIST_ID or not GIST_TOKEN:
11
  return None
12
 
@@ -34,6 +33,7 @@ def pull_from_gist(filename: str) -> dict:
34
 
35
  def push_to_gist(filename: str, data_dict: dict):
36
  """Push a dictionary to a specific file in the GitHub Gist."""
 
37
  if not GIST_ID or not GIST_TOKEN:
38
  return
39
 
@@ -64,7 +64,9 @@ def push_to_gist(filename: str, data_dict: dict):
64
 
65
  # ── Legacy Wrappers (to avoid breaking other files) ───────────────────────────
66
  def pull_history_from_gist() -> dict:
 
67
  return pull_from_gist(HISTORY_FILE_NAME)
68
 
69
  def push_history_to_gist(history_dict: dict):
 
70
  push_to_gist(HISTORY_FILE_NAME, history_dict)
 
1
  import json
2
  import logging
3
  import requests
 
 
4
  logger = logging.getLogger(__name__)
5
 
6
  def pull_from_gist(filename: str) -> dict:
7
  """Pull a specific JSON file from the GitHub Gist."""
8
+ from config import GIST_ID, GIST_TOKEN
9
  if not GIST_ID or not GIST_TOKEN:
10
  return None
11
 
 
33
 
34
  def push_to_gist(filename: str, data_dict: dict):
35
  """Push a dictionary to a specific file in the GitHub Gist."""
36
+ from config import GIST_ID, GIST_TOKEN
37
  if not GIST_ID or not GIST_TOKEN:
38
  return
39
 
 
64
 
65
  # ── Legacy Wrappers (to avoid breaking other files) ───────────────────────────
66
  def pull_history_from_gist() -> dict:
67
+ from config import HISTORY_FILE_NAME
68
  return pull_from_gist(HISTORY_FILE_NAME)
69
 
70
  def push_history_to_gist(history_dict: dict):
71
+ from config import HISTORY_FILE_NAME
72
  push_to_gist(HISTORY_FILE_NAME, history_dict)
handlers/callbacks.py CHANGED
@@ -40,7 +40,7 @@ async def button_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
40
 
41
  await context.bot.send_message(
42
  chat_id=query.from_user.id,
43
- text=f"πŸ’‘ *Detailed Explanation:*\n\n{explanation}\n\nπŸš€ Keep practicing! @CrazyLearners",
44
  parse_mode="Markdown"
45
  )
46
  return
 
40
 
41
  await context.bot.send_message(
42
  chat_id=query.from_user.id,
43
+ text=f"πŸ’‘ *Detailed Explanation:*\n\n{explanation}\n\nπŸš€ Keep practicing! @xcrazylearners",
44
  parse_mode="Markdown"
45
  )
46
  return
handlers/commands.py CHANGED
@@ -406,7 +406,7 @@ async def broadcast_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
406
  try:
407
  await context.bot.send_message(
408
  chat_id=uid,
409
- text=f"πŸ“¬ *Announcement from CrazyLearners:*\n\n{broadcast_text}\n\nπŸ”— @xCrazyLearners",
410
  parse_mode="Markdown"
411
  )
412
  sent += 1
@@ -472,7 +472,7 @@ async def leaderboard_command(update: Update, context: ContextTypes.DEFAULT_TYPE
472
  name = f"@{uname}" if uname != "Anonymous" else fname
473
  text += f"{medal} *{i}. {name}* β€” {score} pts\n"
474
 
475
- text += "\n✨ *Keep learning, keep winning!*\nπŸš€ @CrazyLearners"
476
  await update.message.reply_text(text, parse_mode="Markdown")
477
 
478
 
 
406
  try:
407
  await context.bot.send_message(
408
  chat_id=uid,
409
+ text=f"πŸ“¬ *Announcement from CrazyLearners:*\n\n{broadcast_text}\n\nπŸ”— @xcrazylearners",
410
  parse_mode="Markdown"
411
  )
412
  sent += 1
 
472
  name = f"@{uname}" if uname != "Anonymous" else fname
473
  text += f"{medal} *{i}. {name}* β€” {score} pts\n"
474
 
475
+ text += "\n✨ *Keep learning, keep winning!*\nπŸš€ @xcrazylearners"
476
  await update.message.reply_text(text, parse_mode="Markdown")
477
 
478
 
scheduler/job_scheduler.py CHANGED
@@ -210,7 +210,7 @@ async def post_mcq_session(app: Application, channel_key: str):
210
  f"━━━━━━━━━━━━━━━━━━\n"
211
  f"πŸ“Š Score yourself out of *{total}* in the comments below! 🎯\n\n"
212
  f"✨ *Keep learning, keep growing.*\n\n"
213
- f"πŸš€ Join our main community: @CrazyLearners"),
214
  parse_mode="Markdown"
215
  )
216
  await _notify_admins(app, f"βœ… MCQ Session done β€” {total} polls for *{cfg.get('label')}*")
@@ -252,7 +252,7 @@ async def reset_leaderboard_job(app: Application):
252
  name = f"@{uname}" if uname != "Anonymous" else fname
253
  text += f"{medals[i]} *{name}* β€” {score} pts\n"
254
 
255
- text += "\nπŸ”₯ *New week starts now!* Can you top the list?\nπŸš€ @CrazyLearners"
256
  await _safe_send_message(app, ch_cfg["id"], text, parse_mode="Markdown")
257
 
258
  clear_weekly_scores()
 
210
  f"━━━━━━━━━━━━━━━━━━\n"
211
  f"πŸ“Š Score yourself out of *{total}* in the comments below! 🎯\n\n"
212
  f"✨ *Keep learning, keep growing.*\n\n"
213
+ f"πŸš€ Join our main community: @xcrazylearners"),
214
  parse_mode="Markdown"
215
  )
216
  await _notify_admins(app, f"βœ… MCQ Session done β€” {total} polls for *{cfg.get('label')}*")
 
252
  name = f"@{uname}" if uname != "Anonymous" else fname
253
  text += f"{medals[i]} *{name}* β€” {score} pts\n"
254
 
255
+ text += "\nπŸ”₯ *New week starts now!* Can you top the list?\nπŸš€ @xcrazylearners"
256
  await _safe_send_message(app, ch_cfg["id"], text, parse_mode="Markdown")
257
 
258
  clear_weekly_scores()
web_app/dashboard.html CHANGED
@@ -750,6 +750,10 @@ h1, h2, h3, .sidebar-brand h2, .page-title, .card-title, .btn {
750
 
751
  <script>
752
  // Auto-detect API base path for Hugging Face or direct access
 
 
 
 
753
  const API = "";
754
  const tg = window.Telegram?.WebApp;
755
  if (tg) { tg.ready(); tg.expand(); }
 
750
 
751
  <script>
752
  // Auto-detect API base path for Hugging Face or direct access
753
+ if (!window.location.pathname.endsWith('/') && !window.location.pathname.includes('.')) {
754
+ window.location.pathname += '/';
755
+ }
756
+
757
  const API = "";
758
  const tg = window.Telegram?.WebApp;
759
  if (tg) { tg.ready(); tg.expand(); }