Skip to content

Instantly share code, notes, and snippets.

@kaecy
Last active November 24, 2020 13:42
Show Gist options
  • Save kaecy/0648dd9353ad0950302d2fff2ff7d025 to your computer and use it in GitHub Desktop.
Save kaecy/0648dd9353ad0950302d2fff2ff7d025 to your computer and use it in GitHub Desktop.
A basic security bot in TelegramBotFramework.
import TelegramBotFramework as tbf
from TelegramBotFramework import Bot
# Check user info.
def __cmd__id(message, chat, extras):
if extras['replyMsg']:
user = extras['replyingToMsgUserObj']
userInfo = f"""Info for *{user.first_name}*```\n id: {user.id}\nfirst name: {user.first_name}\n last name: {user.last_name}\n username: {user.username}\n```"""
chat.sendMessage(userInfo, tbf.Markdown)
# Place restrictions on user.
# Syntax: /rs on,off
def __cmd__rs(message, chat, extras):
if extras['replyMsg']:
user = extras['replyingToMsgUserObj']
if extras['senderId'] in chat.getAdminsIds():
if message == "on":
if chat.restrict(user.id, True):
chat.sendMessage("Restricted: " + user.first_name)
elif message == "off":
if chat.restrict(user.id, False):
chat.sendMessage("Released: " + user.first_name)
# Pin the blame on the user.
def __cmd__pin(message, chat, extras):
if extras['replyMsg']:
if extras['senderId'] in chat.getAdminsIds():
chat.pin(extras['replyingToMsgId'])
while True:
try:
bot = Bot("100:AAAA")
bot.start(globals())
except ConnectionResetError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment