moodle-telegram-bot 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- moodle_telegram_bot-1.0.0/LICENSE +21 -0
- moodle_telegram_bot-1.0.0/PKG-INFO +235 -0
- moodle_telegram_bot-1.0.0/README.md +192 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/__init__.py +3 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/__main__.py +6 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/app.py +327 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/config.py +122 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/database/__init__.py +1 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/database/models.py +176 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/handlers/__init__.py +1 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/handlers/admin.py +431 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/handlers/auth.py +109 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/handlers/notifications.py +120 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/handlers/preferences.py +168 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/handlers/tasks.py +794 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/middlewares/__init__.py +1 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/middlewares/rate_limit.py +33 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/services/__init__.py +1 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/services/email_service.py +52 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/services/moodle_client.py +16 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/services/moodle_scraper.py +694 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/services/notifier.py +215 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/services/web_session.py +24 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/utils/__init__.py +1 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/utils/emojis.py +282 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/utils/html_escape.py +22 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/utils/rich_text.py +65 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/utils/send_long.py +53 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot/utils/telegram_helpers.py +19 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot.egg-info/PKG-INFO +235 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot.egg-info/SOURCES.txt +39 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot.egg-info/dependency_links.txt +1 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot.egg-info/entry_points.txt +2 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot.egg-info/requires.txt +15 -0
- moodle_telegram_bot-1.0.0/moodle_telegram_bot.egg-info/top_level.txt +1 -0
- moodle_telegram_bot-1.0.0/pyproject.toml +87 -0
- moodle_telegram_bot-1.0.0/setup.cfg +4 -0
- moodle_telegram_bot-1.0.0/tests/test_config.py +48 -0
- moodle_telegram_bot-1.0.0/tests/test_database.py +69 -0
- moodle_telegram_bot-1.0.0/tests/test_package.py +29 -0
- moodle_telegram_bot-1.0.0/tests/test_utils.py +55 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Abd Alrahman Shohada
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: moodle-telegram-bot
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Telegram bot that turns Moodle LMS into a personal academic assistant: courses, assignments, deadlines, grades and notifications.
|
|
5
|
+
Author: Abd Alrahman Shohada
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/abodjmal2004/moodle-telegram-bot
|
|
8
|
+
Project-URL: Repository, https://github.com/abodjmal2004/moodle-telegram-bot
|
|
9
|
+
Project-URL: Issues, https://github.com/abodjmal2004/moodle-telegram-bot/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/abodjmal2004/moodle-telegram-bot/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: moodle,telegram,telegram-bot,python-telegram-bot,lms,education,students,scraper
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Education
|
|
15
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Education
|
|
22
|
+
Classifier: Topic :: Communications :: Chat
|
|
23
|
+
Classifier: Natural Language :: Arabic
|
|
24
|
+
Classifier: Natural Language :: English
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: python-telegram-bot[job-queue]<21,>=20.7
|
|
29
|
+
Requires-Dist: aiohttp<4,>=3.9
|
|
30
|
+
Requires-Dist: beautifulsoup4<5,>=4.12
|
|
31
|
+
Requires-Dist: SQLAlchemy<3,>=2.0
|
|
32
|
+
Requires-Dist: python-dotenv<2,>=1.0
|
|
33
|
+
Requires-Dist: Flask<4,>=3.0
|
|
34
|
+
Requires-Dist: APScheduler<4,>=3.10
|
|
35
|
+
Requires-Dist: cryptography<44,>=41
|
|
36
|
+
Requires-Dist: cachetools<6,>=5.3
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
39
|
+
Requires-Dist: pytest-cov>=5; extra == "dev"
|
|
40
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
41
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# 🎓 Moodle Telegram Bot - Advanced Academic Assistant
|
|
45
|
+
|
|
46
|
+
[](https://github.com/abodjmal2004/moodle-telegram-bot/actions/workflows/ci.yml)
|
|
47
|
+
[](https://pypi.org/project/moodle-telegram-bot/)
|
|
48
|
+
[](https://www.python.org/)
|
|
49
|
+
[](https://core.telegram.org/bots)
|
|
50
|
+
[](https://python-telegram-bot.org/)
|
|
51
|
+
[](LICENSE)
|
|
52
|
+
[](CONTRIBUTING.md)
|
|
53
|
+
|
|
54
|
+
An advanced, feature-rich Telegram bot designed to integrate seamlessly with **Moodle LMS**. This bot serves as a personal academic assistant, helping students stay updated with their courses, assignments, and grades in real-time.
|
|
55
|
+
|
|
56
|
+
### 🤖 Live Demo
|
|
57
|
+
You can try the bot on Telegram: [@m_alaqsa_bot](https://t.me/m_alaqsa_bot)
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 🌟 Key Features
|
|
62
|
+
|
|
63
|
+
### 👨🎓 Student Dashboard
|
|
64
|
+
- **Course Overview**: View all enrolled courses with a single tap.
|
|
65
|
+
- **Assignments & Deadlines**: Stay on top of your tasks with upcoming deadline reminders.
|
|
66
|
+
- **Grades Tracking**: Instant access to your academic performance and grades.
|
|
67
|
+
- **Real-time Notifications**: Get notified immediately about new announcements, assignments, or grade updates.
|
|
68
|
+
- **Email Integration**: Receive academic updates directly in your inbox.
|
|
69
|
+
|
|
70
|
+
### 🛠 Admin & Management
|
|
71
|
+
- **Advanced Control Panel**: A comprehensive dashboard for bot administrators to monitor and manage the system.
|
|
72
|
+
- **Feature Toggles**: Enable or disable specific bot features (Notifications, Email, Admin Panel, etc.) globally without touching the code.
|
|
73
|
+
- **System Monitoring**: Track bot statistics, active users, and system health.
|
|
74
|
+
- **Security**: Robust encryption for user credentials using `cryptography`.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## 📸 Screenshots
|
|
79
|
+
|
|
80
|
+
<p align="center">
|
|
81
|
+
<img src="assets/screenshots/welcome.png" width="45%" alt="Welcome Screen">
|
|
82
|
+
<img src="assets/screenshots/user_dashboard.png" width="45%" alt="User Dashboard">
|
|
83
|
+
</p>
|
|
84
|
+
<p align="center">
|
|
85
|
+
<img src="assets/screenshots/admin_panel.png" width="45%" alt="Admin Panel">
|
|
86
|
+
<img src="assets/screenshots/features_control.png" width="45%" alt="Features Control">
|
|
87
|
+
</p>
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 🚀 Tech Stack
|
|
92
|
+
|
|
93
|
+
- **Language**: Python 3.10+
|
|
94
|
+
- **Bot Framework**: [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot) (v20.7)
|
|
95
|
+
- **Database**: [SQLAlchemy](https://www.sqlalchemy.org/) (ORM) with SQLite/PostgreSQL support.
|
|
96
|
+
- **Web Scraping**: [BeautifulSoup4](https://www.crummy.com/software/BeautifulSoup/) & `aiohttp`.
|
|
97
|
+
- **Scheduling**: [APScheduler](https://apscheduler.readthedocs.io/) for periodic background checks.
|
|
98
|
+
- **Security**: [Fernet Encryption](https://cryptography.io/en/latest/fernet/) for secure credential storage.
|
|
99
|
+
- **Admin Interface**: [Flask](https://flask.palletsprojects.com/) for the management dashboard.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 🛠 Installation & Setup
|
|
104
|
+
|
|
105
|
+
### Option A — install as a package
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
pip install moodle-telegram-bot
|
|
109
|
+
moodle-bot # or: python -m moodle_telegram_bot
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
> Until the first PyPI release you can install straight from GitHub:
|
|
113
|
+
> `pip install "git+https://github.com/abodjmal2004/moodle-telegram-bot.git"`
|
|
114
|
+
|
|
115
|
+
### Option B — run from source (development)
|
|
116
|
+
|
|
117
|
+
1. **Clone the repository**:
|
|
118
|
+
```bash
|
|
119
|
+
git clone https://github.com/abodjmal2004/moodle-telegram-bot.git
|
|
120
|
+
cd moodle-telegram-bot
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
2. **Create a virtual environment and install the project**:
|
|
124
|
+
```bash
|
|
125
|
+
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
126
|
+
pip install -e ".[dev]" # or: pip install -r requirements.txt
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
3. **Configure Environment Variables**:
|
|
130
|
+
Copy `.env.example` to `.env` and fill in your credentials:
|
|
131
|
+
```bash
|
|
132
|
+
cp .env.example .env
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
4. **Run the bot**:
|
|
136
|
+
```bash
|
|
137
|
+
moodle-bot # installed console script
|
|
138
|
+
python -m moodle_telegram_bot # module entry point
|
|
139
|
+
python main.py # thin compatibility wrapper
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Configuration
|
|
143
|
+
|
|
144
|
+
All settings are read from environment variables (or `.env`):
|
|
145
|
+
|
|
146
|
+
| Variable | Required | Default | Purpose |
|
|
147
|
+
| --- | --- | --- | --- |
|
|
148
|
+
| `BOT_TOKEN` | ✅ | — | Telegram bot token from [@BotFather](https://t.me/BotFather) |
|
|
149
|
+
| `ENCRYPTION_KEY` | ✅ | generated | Fernet key used to encrypt Moodle credentials (`openssl rand -base64 32`) |
|
|
150
|
+
| `ADMIN_IDS` | — | empty | Comma-separated Telegram IDs of bot administrators |
|
|
151
|
+
| `DATABASE_URL` | — | `sqlite:///bot.db` | SQLAlchemy URL (SQLite, PostgreSQL, MySQL) |
|
|
152
|
+
| `BASE_URL` | — | `https://moodle.alaqsa.edu.ps` | Moodle instance to scrape |
|
|
153
|
+
| `SMTP_HOST` / `SMTP_PORT` | — | `smtp.gmail.com` / `465` | SMTP server for email notifications |
|
|
154
|
+
| `SMTP_USER` / `SMTP_PASSWORD` | — | empty | SMTP credentials (use a Gmail App Password) |
|
|
155
|
+
| `NOTIFICATION_CHECK_INTERVAL_MINUTES` | — | `20` | How often the notification job scans Moodle |
|
|
156
|
+
| `NOTIFICATION_CONCURRENCY` | — | `3` | Parallel Moodle sessions during a scan |
|
|
157
|
+
| `FEATURES_<NAME>` | — | `1` | Per-feature switch, e.g. `FEATURES_NOTIFICATIONS=0` |
|
|
158
|
+
|
|
159
|
+
Available feature flags: `courses`, `content`, `news`, `assignments`, `deadlines`, `grades`, `notifications`, `per_course_notif`, `email_notifications`, `auto_relogin`, `rate_limit`, `admin_panel`.
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## 🏗 Architecture
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
moodle-telegram-bot/
|
|
167
|
+
├── moodle_telegram_bot/
|
|
168
|
+
│ ├── app.py # Application builder, handler registration, polling loop
|
|
169
|
+
│ ├── config.py # .env based settings + feature flags
|
|
170
|
+
│ ├── __main__.py # `python -m moodle_telegram_bot`
|
|
171
|
+
│ ├── handlers/ # auth, tasks (courses/grades), preferences, notifications, admin
|
|
172
|
+
│ ├── services/ # moodle_scraper (aiohttp + BeautifulSoup), notifier, email, sessions
|
|
173
|
+
│ ├── middlewares/ # per-user rate limiting
|
|
174
|
+
│ ├── database/ # SQLAlchemy models (users, seen_items, course_prefs, admins)
|
|
175
|
+
│ └── utils/ # HTML escaping, rich-text entities, emoji messages
|
|
176
|
+
├── tests/ # pytest suite (SQLite temp files, no network)
|
|
177
|
+
├── main.py # backwards-compatible entry point
|
|
178
|
+
└── pyproject.toml # PEP 621 metadata, dependencies, ruff & pytest config
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Request flow: a Telegram update passes the global gate in `app.py` (maintenance
|
|
182
|
+
mode → feature flags → rate limiting) and is then routed to a handler. Handlers
|
|
183
|
+
talk to Moodle through `services/moodle_client.py`, which wraps an async
|
|
184
|
+
`MoodleClient` session per user; credentials are decrypted on demand and stored
|
|
185
|
+
encrypted with Fernet. A background job (`services/notifier.py`) periodically
|
|
186
|
+
scans every logged-in user's courses and records what was already announced in
|
|
187
|
+
the `seen_items` table to avoid duplicate notifications.
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## 🔒 Security & Privacy
|
|
192
|
+
|
|
193
|
+
This project takes security seriously. All sensitive user credentials (like Moodle passwords) are encrypted before being stored in the database. The `ENCRYPTION_KEY` in your `.env` file is used to secure this data. **Never share your `.env` file or commit it to version control.**
|
|
194
|
+
|
|
195
|
+
Found a vulnerability? Please follow [SECURITY.md](SECURITY.md) instead of opening a public issue.
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## 🤝 Contributing
|
|
200
|
+
|
|
201
|
+
Contributions of all sizes are welcome — bug reports, documentation, new
|
|
202
|
+
commands, translations. Please read [CONTRIBUTING.md](CONTRIBUTING.md) and the
|
|
203
|
+
[Code of Conduct](CODE_OF_CONDUCT.md), then run the checks before opening a PR:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
pip install -e ".[dev]"
|
|
207
|
+
ruff check .
|
|
208
|
+
pytest -q
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## 👨💻 Developer
|
|
214
|
+
|
|
215
|
+
**Abodjmal** — Software Developer
|
|
216
|
+
|
|
217
|
+
Passionate about building modern applications, clean architecture, and smooth user experiences.
|
|
218
|
+
|
|
219
|
+
### 🌐 Connect With Me
|
|
220
|
+
|
|
221
|
+
[](https://t.me/xw_25aa)
|
|
222
|
+
[](https://instagram.com/xw_.0)
|
|
223
|
+
[](https://github.com/abodjmal2004)
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## 📄 License
|
|
228
|
+
|
|
229
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
<p align="center">
|
|
234
|
+
Developed with ❤️ for Students.
|
|
235
|
+
</p>
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# 🎓 Moodle Telegram Bot - Advanced Academic Assistant
|
|
2
|
+
|
|
3
|
+
[](https://github.com/abodjmal2004/moodle-telegram-bot/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/moodle-telegram-bot/)
|
|
5
|
+
[](https://www.python.org/)
|
|
6
|
+
[](https://core.telegram.org/bots)
|
|
7
|
+
[](https://python-telegram-bot.org/)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[](CONTRIBUTING.md)
|
|
10
|
+
|
|
11
|
+
An advanced, feature-rich Telegram bot designed to integrate seamlessly with **Moodle LMS**. This bot serves as a personal academic assistant, helping students stay updated with their courses, assignments, and grades in real-time.
|
|
12
|
+
|
|
13
|
+
### 🤖 Live Demo
|
|
14
|
+
You can try the bot on Telegram: [@m_alaqsa_bot](https://t.me/m_alaqsa_bot)
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 🌟 Key Features
|
|
19
|
+
|
|
20
|
+
### 👨🎓 Student Dashboard
|
|
21
|
+
- **Course Overview**: View all enrolled courses with a single tap.
|
|
22
|
+
- **Assignments & Deadlines**: Stay on top of your tasks with upcoming deadline reminders.
|
|
23
|
+
- **Grades Tracking**: Instant access to your academic performance and grades.
|
|
24
|
+
- **Real-time Notifications**: Get notified immediately about new announcements, assignments, or grade updates.
|
|
25
|
+
- **Email Integration**: Receive academic updates directly in your inbox.
|
|
26
|
+
|
|
27
|
+
### 🛠 Admin & Management
|
|
28
|
+
- **Advanced Control Panel**: A comprehensive dashboard for bot administrators to monitor and manage the system.
|
|
29
|
+
- **Feature Toggles**: Enable or disable specific bot features (Notifications, Email, Admin Panel, etc.) globally without touching the code.
|
|
30
|
+
- **System Monitoring**: Track bot statistics, active users, and system health.
|
|
31
|
+
- **Security**: Robust encryption for user credentials using `cryptography`.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 📸 Screenshots
|
|
36
|
+
|
|
37
|
+
<p align="center">
|
|
38
|
+
<img src="assets/screenshots/welcome.png" width="45%" alt="Welcome Screen">
|
|
39
|
+
<img src="assets/screenshots/user_dashboard.png" width="45%" alt="User Dashboard">
|
|
40
|
+
</p>
|
|
41
|
+
<p align="center">
|
|
42
|
+
<img src="assets/screenshots/admin_panel.png" width="45%" alt="Admin Panel">
|
|
43
|
+
<img src="assets/screenshots/features_control.png" width="45%" alt="Features Control">
|
|
44
|
+
</p>
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 🚀 Tech Stack
|
|
49
|
+
|
|
50
|
+
- **Language**: Python 3.10+
|
|
51
|
+
- **Bot Framework**: [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot) (v20.7)
|
|
52
|
+
- **Database**: [SQLAlchemy](https://www.sqlalchemy.org/) (ORM) with SQLite/PostgreSQL support.
|
|
53
|
+
- **Web Scraping**: [BeautifulSoup4](https://www.crummy.com/software/BeautifulSoup/) & `aiohttp`.
|
|
54
|
+
- **Scheduling**: [APScheduler](https://apscheduler.readthedocs.io/) for periodic background checks.
|
|
55
|
+
- **Security**: [Fernet Encryption](https://cryptography.io/en/latest/fernet/) for secure credential storage.
|
|
56
|
+
- **Admin Interface**: [Flask](https://flask.palletsprojects.com/) for the management dashboard.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 🛠 Installation & Setup
|
|
61
|
+
|
|
62
|
+
### Option A — install as a package
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install moodle-telegram-bot
|
|
66
|
+
moodle-bot # or: python -m moodle_telegram_bot
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
> Until the first PyPI release you can install straight from GitHub:
|
|
70
|
+
> `pip install "git+https://github.com/abodjmal2004/moodle-telegram-bot.git"`
|
|
71
|
+
|
|
72
|
+
### Option B — run from source (development)
|
|
73
|
+
|
|
74
|
+
1. **Clone the repository**:
|
|
75
|
+
```bash
|
|
76
|
+
git clone https://github.com/abodjmal2004/moodle-telegram-bot.git
|
|
77
|
+
cd moodle-telegram-bot
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
2. **Create a virtual environment and install the project**:
|
|
81
|
+
```bash
|
|
82
|
+
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
83
|
+
pip install -e ".[dev]" # or: pip install -r requirements.txt
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
3. **Configure Environment Variables**:
|
|
87
|
+
Copy `.env.example` to `.env` and fill in your credentials:
|
|
88
|
+
```bash
|
|
89
|
+
cp .env.example .env
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
4. **Run the bot**:
|
|
93
|
+
```bash
|
|
94
|
+
moodle-bot # installed console script
|
|
95
|
+
python -m moodle_telegram_bot # module entry point
|
|
96
|
+
python main.py # thin compatibility wrapper
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Configuration
|
|
100
|
+
|
|
101
|
+
All settings are read from environment variables (or `.env`):
|
|
102
|
+
|
|
103
|
+
| Variable | Required | Default | Purpose |
|
|
104
|
+
| --- | --- | --- | --- |
|
|
105
|
+
| `BOT_TOKEN` | ✅ | — | Telegram bot token from [@BotFather](https://t.me/BotFather) |
|
|
106
|
+
| `ENCRYPTION_KEY` | ✅ | generated | Fernet key used to encrypt Moodle credentials (`openssl rand -base64 32`) |
|
|
107
|
+
| `ADMIN_IDS` | — | empty | Comma-separated Telegram IDs of bot administrators |
|
|
108
|
+
| `DATABASE_URL` | — | `sqlite:///bot.db` | SQLAlchemy URL (SQLite, PostgreSQL, MySQL) |
|
|
109
|
+
| `BASE_URL` | — | `https://moodle.alaqsa.edu.ps` | Moodle instance to scrape |
|
|
110
|
+
| `SMTP_HOST` / `SMTP_PORT` | — | `smtp.gmail.com` / `465` | SMTP server for email notifications |
|
|
111
|
+
| `SMTP_USER` / `SMTP_PASSWORD` | — | empty | SMTP credentials (use a Gmail App Password) |
|
|
112
|
+
| `NOTIFICATION_CHECK_INTERVAL_MINUTES` | — | `20` | How often the notification job scans Moodle |
|
|
113
|
+
| `NOTIFICATION_CONCURRENCY` | — | `3` | Parallel Moodle sessions during a scan |
|
|
114
|
+
| `FEATURES_<NAME>` | — | `1` | Per-feature switch, e.g. `FEATURES_NOTIFICATIONS=0` |
|
|
115
|
+
|
|
116
|
+
Available feature flags: `courses`, `content`, `news`, `assignments`, `deadlines`, `grades`, `notifications`, `per_course_notif`, `email_notifications`, `auto_relogin`, `rate_limit`, `admin_panel`.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## 🏗 Architecture
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
moodle-telegram-bot/
|
|
124
|
+
├── moodle_telegram_bot/
|
|
125
|
+
│ ├── app.py # Application builder, handler registration, polling loop
|
|
126
|
+
│ ├── config.py # .env based settings + feature flags
|
|
127
|
+
│ ├── __main__.py # `python -m moodle_telegram_bot`
|
|
128
|
+
│ ├── handlers/ # auth, tasks (courses/grades), preferences, notifications, admin
|
|
129
|
+
│ ├── services/ # moodle_scraper (aiohttp + BeautifulSoup), notifier, email, sessions
|
|
130
|
+
│ ├── middlewares/ # per-user rate limiting
|
|
131
|
+
│ ├── database/ # SQLAlchemy models (users, seen_items, course_prefs, admins)
|
|
132
|
+
│ └── utils/ # HTML escaping, rich-text entities, emoji messages
|
|
133
|
+
├── tests/ # pytest suite (SQLite temp files, no network)
|
|
134
|
+
├── main.py # backwards-compatible entry point
|
|
135
|
+
└── pyproject.toml # PEP 621 metadata, dependencies, ruff & pytest config
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Request flow: a Telegram update passes the global gate in `app.py` (maintenance
|
|
139
|
+
mode → feature flags → rate limiting) and is then routed to a handler. Handlers
|
|
140
|
+
talk to Moodle through `services/moodle_client.py`, which wraps an async
|
|
141
|
+
`MoodleClient` session per user; credentials are decrypted on demand and stored
|
|
142
|
+
encrypted with Fernet. A background job (`services/notifier.py`) periodically
|
|
143
|
+
scans every logged-in user's courses and records what was already announced in
|
|
144
|
+
the `seen_items` table to avoid duplicate notifications.
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## 🔒 Security & Privacy
|
|
149
|
+
|
|
150
|
+
This project takes security seriously. All sensitive user credentials (like Moodle passwords) are encrypted before being stored in the database. The `ENCRYPTION_KEY` in your `.env` file is used to secure this data. **Never share your `.env` file or commit it to version control.**
|
|
151
|
+
|
|
152
|
+
Found a vulnerability? Please follow [SECURITY.md](SECURITY.md) instead of opening a public issue.
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## 🤝 Contributing
|
|
157
|
+
|
|
158
|
+
Contributions of all sizes are welcome — bug reports, documentation, new
|
|
159
|
+
commands, translations. Please read [CONTRIBUTING.md](CONTRIBUTING.md) and the
|
|
160
|
+
[Code of Conduct](CODE_OF_CONDUCT.md), then run the checks before opening a PR:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
pip install -e ".[dev]"
|
|
164
|
+
ruff check .
|
|
165
|
+
pytest -q
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## 👨💻 Developer
|
|
171
|
+
|
|
172
|
+
**Abodjmal** — Software Developer
|
|
173
|
+
|
|
174
|
+
Passionate about building modern applications, clean architecture, and smooth user experiences.
|
|
175
|
+
|
|
176
|
+
### 🌐 Connect With Me
|
|
177
|
+
|
|
178
|
+
[](https://t.me/xw_25aa)
|
|
179
|
+
[](https://instagram.com/xw_.0)
|
|
180
|
+
[](https://github.com/abodjmal2004)
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## 📄 License
|
|
185
|
+
|
|
186
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
<p align="center">
|
|
191
|
+
Developed with ❤️ for Students.
|
|
192
|
+
</p>
|