Skip to content

Instantly share code, notes, and snippets.

@MasterGroosha
Last active October 14, 2017 17:40
Show Gist options
  • Select an option

  • Save MasterGroosha/b4bb04b8bbb93554870f74be08e3b58e to your computer and use it in GitHub Desktop.

Select an option

Save MasterGroosha/b4bb04b8bbb93554870f74be08e3b58e to your computer and use it in GitHub Desktop.
Watch Telegram server config change.
# -*- coding: utf-8 -*-
import re
import ujson
import telebot
from telethon import TelegramClient
from telethon.tl.functions.help import GetConfigRequest
from vedis import Vedis
bot = telebot.TeleBot("token") # Your Telegram bot token
channel_id = -123456789 # Your channel ID to post notifies there
db = Vedis("config.vdb") # Connecting to Vedis single-file DB. This db should be pre-filled with values below
api_id = 123456 # Your API ID (after you registered Telegram app)
api_hash = "aaaaaa" # Your API Hash (after you registered Telegram app)
phone_number = "+36000000000" # Your phone number (to authorize in Telegram)
# You need to get authorization first, refer to Telethon docs for more info.
client = TelegramClient('second_account', api_id, api_hash)
client.connect()
keys = ["phonecalls_enabled", "chat_big_size", "forwarded_count_max", "stickers_recent_limit", "stickers_faved_limit",
"chat_size_max", "megagroup_size_max", "edit_time_limit", "saved_gifs_limit", "pinned_dialogs_count_max"]
# These are default values by the date this gist first published, they'll eventually change (or may not)
# values = {
# "phonecalls_enabled": True,
# "chat_big_size": 10, # [internal] for special Telegram occasions
# "forwarded_count_max": 100, # Forwarded messages
# "stickers_recent_limit": 30, # Recent stickers
# "stickers_faved_limit": 5, # Favourite stickers
# "chat_size_max": 200, # Normal groups max size
# "megagroup_size_max": 20000, # Supergroups max size
# "edit_time_limit": 172800, # Max messages edit time in seconds
# "saved_gifs_limit": 200, # Saved gifs
# "pinned_dialogs_count_max": 5, # Max pinned chats
# "disabled_features": [] # If Telegram remotely disables any feature
# }
result = client(GetConfigRequest()) # Getting config from Telegram
result_dict = result.__dict__
if result:
for item in keys:
if db[item] != str(result_dict.get(item)):
bot.send_message(
channel_id,
"📝 Value <b>\"{orig_name}\"</b> was changed from <b>{old_value}</b> to <b>{new_value}</b>".format(orig_name=item, old_value=db[item], new_value=config[item]),
parse_mode="HTML", disable_notification=True
)
db[item] = config[item]
db.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment