📜 ⬆️ ⬇️

Telegram bot to remove spam

I decided to write this post because I 'm tired of explaining the same thing to people who want to use my telegram bot @daysandbox_bot . So, a few months ago I developed a bot to remove spam on a very simple basis: if a person went into the chat and spent less than a day in it, then any links or forward messages from this person are deleted. Everything. No neural grids, frequency analysis, moderated white- and black-sheets and other complex things. Surprisingly, the bot has gained some popularity and is already working in more than six hundred chatikas. Next, I will try to describe in detail the principle of the bot, to continue to give a link to this article.


The principle of the bot


From the moment of adding to the chat, the bot keeps track of events when new users enter the group and thus knows when someone has entered the chat and how much time he has already spent in the chat. Due to the limitations of the telegram API, I cannot find out when those users who were already at the time of adding the bot to the chat joined the chat. The bot does not analyze messages from users that exist at the time of adding the bot. So, the bot knows when new users entered the chat. If the bot sees, the user spent less than a day in the chat and posted a message that meets the definition of spam, the bot deletes the message. He does not ban the user, does not give him read-only rights, the bot simply deletes the spam message. If the user posts a non-spam message, it will be posted. What messages are considered spam? First, any messages containing a link: URL, email or username . Secondly, any forward messages i. Messages forwarded from another chat. For the username rule there is an exception, if username refers to the user, then such a message is allowed. The bot deletes only those messages with username that refer to the group or channel. This is done so that there are no false positives, when a new user simply tries to contact some chat participant by his username.


What the daysandbox_bot bot does NOT do



How to add a bot to chat


I describe the algorithm for the desktop client. It is implied that you are admin chat and can add other admins to it.



Bot settings


The bot has several settings.


Write in the chat /daysandbox_set safe_hours=N to set the time during which messages from new users are analyzed for signs of spam. By default, this period is equal to days. You can specify the number of hours from zero to 8760 (one year). A period of zero hours essentially deactivates the bot.


Write in the chat /daysandbox_set publog=yes to allow the bot to write messages in the chat that the message of a user has been deleted. By default, the bot does just that.


The current values ​​of these two settings can be obtained with the /daysandbox_config .


Some statistics


I’m too lazy to draw beautiful graphics, I’ll just say that the bot removes from 10 to 15 thousand messages a day and works in more than 600 posts.


Open source


The bot's sources are publicly available on github .
UPD (February 11, 2019): currently the source code for the outdated version of the bot is in the repository. I do not provide the source code for the current version of the bot.


My other bots


You may be interested in other bots that I developed. The full list of bots can be found at https://tgdev.io


Contact us


Groups to discuss my bots:



')

Source: https://habr.com/ru/post/348800/


All Articles