Light Armor Bot
Browse files- Light Armor +52 -0
Light Armor
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from telegram import Update
|
| 2 |
+
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
|
| 3 |
+
|
| 4 |
+
# Replace with your bot token
|
| 5 |
+
TOKEN = '7339830560:AAE43s3Uv025zSX-vvu2k4GbWaHr-P9UDTc'
|
| 6 |
+
|
| 7 |
+
# Welcome handler
|
| 8 |
+
def welcome(update: Update, context: CallbackContext):
|
| 9 |
+
# Check for new members
|
| 10 |
+
new_members = update.message.new_chat_members
|
| 11 |
+
if new_members:
|
| 12 |
+
for member in new_members:
|
| 13 |
+
welcome_message = f"Welcome {member.full_name}! 👋\nEnjoy your time here!"
|
| 14 |
+
update.message.reply_text(welcome_message)
|
| 15 |
+
|
| 16 |
+
# Ban handler
|
| 17 |
+
def ban_user(update: Update, context: CallbackContext):
|
| 18 |
+
chat_id = update.message.chat_id
|
| 19 |
+
user_id = update.message.reply_to_message.from_user.id if update.message.reply_to_message else None
|
| 20 |
+
|
| 21 |
+
# Only allow admins to use the ban command
|
| 22 |
+
if update.message.from_user.id == update.message.chat.admins[0].user.id: # Check if the bot is an admin
|
| 23 |
+
if user_id:
|
| 24 |
+
context.bot.ban_chat_member(chat_id, user_id)
|
| 25 |
+
update.message.reply_text(f"User {user_id} has been banned.")
|
| 26 |
+
else:
|
| 27 |
+
update.message.reply_text("Please reply to a user's message you want to ban.")
|
| 28 |
+
else:
|
| 29 |
+
update.message.reply_text("You don't have permission to ban users!")
|
| 30 |
+
|
| 31 |
+
# Main function
|
| 32 |
+
def main():
|
| 33 |
+
# Set up the Updater with the bot token
|
| 34 |
+
updater = Updater(TOKEN, use_context=True)
|
| 35 |
+
|
| 36 |
+
# Get the dispatcher to register handlers
|
| 37 |
+
dp = updater.dispatcher
|
| 38 |
+
|
| 39 |
+
# Register the welcome handler (for new members)
|
| 40 |
+
dp.add_handler(MessageHandler(Filters.status_update.new_chat_members, welcome))
|
| 41 |
+
|
| 42 |
+
# Register the ban handler (for banning users)
|
| 43 |
+
dp.add_handler(CommandHandler('ban', ban_user, pass_args=True, filters=Filters.reply))
|
| 44 |
+
|
| 45 |
+
# Start polling
|
| 46 |
+
updater.start_polling()
|
| 47 |
+
|
| 48 |
+
# Run the bot until you manually stop it (Ctrl + C)
|
| 49 |
+
updater.idle()
|
| 50 |
+
|
| 51 |
+
if __name__ == '__main__':
|
| 52 |
+
main()
|