Найдите исполнителя для вашего проекта прямо сейчас!
Разместите заказ на фриланс-бирже и предложения поступят уже через несколько минут.

My role

I did all work myself. I was a manager, developer, ideas generator, wrote TS for myself and so on...

Project to see

School Help Telegram Bot

Some video and photos

Project goal

The main task of the bot

I needed to write a telegram bot that would send a link and code to the lesson via Zoom to school group. and also warned when the next lesson will be and which one will be. Also, it would be necessary to create an admin panel in the bot itself, so that in case of urgent need it would be possible to temporarily stop and resume the work of these algorithms using commands. Also, so that in cases of force majeure it is possible to change the lesson to the appointed time. For example, change from algebra to geometry for 12 o'clock.

Problems during development

The main problem that I encountered during this project is threads, we have two threads running: the first where messages are sent to the lesson; and the second where the bot warns us about the upcoming lesson. I also encountered a problem in changing a subject at a designated time while threads were running.

Another significant problem during development

A problem arose due to which it was necessary to completely recode the work with the database of subjects built into the code. The problem was that I stored time in seconds, and everything was stored according to the type: time: float => subject: string. and seems to be fine, but due to the fact that my code has a lot of work with time, I connected the additional arrow module, and there storing time in seconds, as it turned out, only works to indicate the time of day , and I have one time in cycle (the first lesson), which is repeated twice but in the interval of one day for looping. Well, they were layered on top of each other, thereby changing the value. As a result, I solved this problem by completely changing the logic of these databases. In addition, now it stores time not in seconds, but in Arrow objects.

Solution

Solution of the main problem

I had a pre-written template for working correctly with Aiogram. I wrote it myself while learning Aiogram. At first try I decided to solve the problem with two threads using a general manager for these threads, so that it would set up a sequence of tasks in which they need to be awaited, but at the moment when I realized that in this way it would not be possible to change the subject of the lesson at the right time. So I decided completely change the concept. As a result, I solved the problem using asynchrony. I made separate managers for the two threads, but they work in the same event loop, but they still work independently thanks to the algorithm for checking the right time. In addition to the fact that I solved the problem with threads, it was now possible to cancel an assigned task at any time and create a new one for the changed subject.

Additional added features

I added an additional algorithm that sends messages with wishes every morning and says what week and day of the week it is; it localizes the text through configs. Also for this algorithm, the bot added an additional command for admins so that this algorithm can be disabled if necessary. I also added the ability to pause algorithms for a specified amount of time.