Skip to content

Instantly share code, notes, and snippets.

@berdanakyurek
Created February 13, 2023 08:38
Show Gist options
  • Save berdanakyurek/498305a587fa9777b238c6753daf880a to your computer and use it in GitHub Desktop.
Save berdanakyurek/498305a587fa9777b238c6753daf880a to your computer and use it in GitHub Desktop.
Telegram rose bot auto blocklist a list of words
from telethon import TelegramClient
import time
# User specific values.
#
# You can get those three from my.telegram.org!
api_id = 1111111
api_hash = 'API_HASH'
phone = '+111111111111'
# Path to your word list
fileName = 'filename.txt'
client = TelegramClient(phone, api_id, api_hash)
async def sendMessage(user, message):
await client.send_message(user, message)
with client:
roseUsername = '@MissRose_bot'
file = open(fileName, 'r')
cnt = 0
for line in file.readlines():
command = "/addblocklist \"" + line.strip() + "\""
print(command)
client.loop.run_until_complete(sendMessage(roseUsername, command))
cnt += 1
if cnt % 20 == 0:
print("Waiting")
time.sleep(10)
@berdanakyurek
Copy link
Author

This piece of code helps you create blocklists for groups for @MissRose_bot using Telegram API.

The program simply connects to Telegram API by Telethon, gets a list of banned words or sentences (each sentence/word in a new line), creates and sends commands to Rose Bot. At the end of execution, Rose will save all lines in the file as blocklisted words.

To use the code, replace api_id, api_hash, phone and fileName variables with your values. To get first three, visit my.telegram.org. Be sure you have a file containing desired blocklist filters seperated with newlines and it contains at most 200 lines. If it contains more lines, they will be sent to bot, however it won't be saved to bot due to the its 200 blocklist filter limitation.

Later, use /connect command to use the blocklist commands in PM instead of group.

Lastly, run the code and wait for it to end. Telethon may ask for your phone number and Telegram password in this step. Execution takes a long time then expected because due to message limitations of the bot, delays are used. In total, 200 second of extra time is used.

After the execution ends, use /blocklist command on @MissRose_bot to check if everything is correct or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment