Created
November 11, 2017 12:07
-
-
Save sae13/29960f5e865b8196e230d5b29972f4e3 to your computer and use it in GitHub Desktop.
a bot for deleting android applications which sent to telegram messenger groups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters) | |
import logging | |
group_admins = {} | |
# Enable logging | |
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', | |
level=logging.INFO) | |
logger = logging.getLogger(__name__) | |
def start(bot, update): | |
if update.message.chat.type == 'private': | |
update.message.reply_text( | |
"Hi there, I have One simple Job in Groups, deleting apk s from group " | |
"\n add me as Group Admin And I`ll delete any APK files are coming In your Group" | |
"\n My God : Http://t.me/saeb_m" | |
"\n yoU can find my Source in : http://sae13.ir") | |
def error(bot, update, error): | |
"""Log Errors caused by Updates.""" | |
logger.warning('Update "%s" caused error "%s"', update, error) | |
def apkdel(bot, update): | |
if update.message.chat.type != 'private': | |
global group_admins | |
tmp_admins = bot.getChatAdministrators(update.message.chat_id) | |
tmp_admins_ids = [] | |
group_admins[update.message.chat_id]=[] | |
for i in tmp_admins: | |
tmp_admins_ids.append(i.user.id) | |
if update.message.from_user.id not in tmp_admins_ids: | |
#print (update.message) | |
if update.message.document.mime_type == 'application/vnd.android.package-archive': | |
bot.deleteMessage(update.message.chat_id, update.message.message_id) | |
bot.restrictChatMember(update.message.chat_id, update.message.from_user.id) | |
else: | |
print(update.message) | |
def main(): | |
# Create the Updater and pass it your bot's token. | |
updater = Updater("TOKEN") | |
# Get the dispatcher to register handlers | |
dp = updater.dispatcher | |
# Add conversation handler with the states GENDER, PHOTO, LOCATION and BIO | |
dp.add_handler(CommandHandler("start",start)) | |
dp.add_handler(MessageHandler(Filters.document,apkdel)) | |
# log all errors | |
dp.add_error_handler(error) | |
# Start the Bot | |
updater.start_polling() | |
# Run the bot until you press Ctrl-C or the process receives SIGINT, | |
# SIGTERM or SIGABRT. This should be used most of the time, since | |
# start_polling() is non-blocking and will stop the bot gracefully. | |
updater.idle() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment