import os
import telebot
from telebot import types
from datetime import datetime
Initialize the bot securely using an environment variable for the token
TOKEN = os.getenv(‘7299628253:AAHPpK9sGicrbI-R8B9K8rtfZC6him5s4Xk’)
bot = telebot.TeleBot(TOKEN)
Admin ID
OWNER_ID = 5604898924 # Admin’s Telegram ID here
banned_users =
Log file
log_file = f"fearlog_{datetime.now().strftime(‘%Y%m%d_%H%M%S’)}.txt"
Logging function
def log_message(message):
with open(log_file, ‘a’) as f:
f.write(f"{datetime.now()} - {message}\n")
Bot activated check
print(‘BOT AKTİF KRAL ’)
log_message(“Bot activated successfully.”)
Help command
@bot.message_handler(commands=[‘help’])
def send_help(message):
help_text = (
“ Bot Komutları
\n\n”
“/admin - Adminlere bir kullanıcıyı bildirin.\n”
“/ban - Bir kullanıcıyı yasakla (bir mesajı yanıtlayarak kullanın).\n”
“/unban - Bir kullanıcının yasağını kaldır (bir mesajı yanıtlayarak kullanın).\n”
“/warn - Bir kullanıcıyı uyar (bir mesajı yanıtlayarak kullanın).\n”
“/mute - Bir kullanıcıyı sustur (bir mesajı yanıtlayarak kullanın).\n”
“/unmute - Bir kullanıcının susturmasını kaldır (bir mesajı yanıtlayarak kullanın).\n\n”
“Komutları doğru kullanmak için bir mesajı yanıtlamayı unutmayın!”
)
bot.reply_to(message, help_text, parse_mode=‘Markdown’)
Admin Commands
@bot.message_handler(commands=[‘admin’])
def report_user(message):
if message.reply_to_message:
bot.reply_to(message, “Bu kişi adminlere report edildi.”)
else:
bot.reply_to(message, “Lütfen bir mesajı yanıtlayarak bu komutu kullanın.”)
@bot.message_handler(commands=[‘ban’])
def ban_user(message):
if message.reply_to_message:
user_to_ban = message.reply_to_message.from_user
reason = " “.join(message.text.split()[1:]) if len(message.text.split()) > 1 else “Belirtilmedi”
banned_users.append(user_to_ban.id)
bot.reply_to(
message,
f" Ban İşlemi Tamamlandı!
\n\n”
f" Banlayan Yetkili: {message.from_user.first_name}\n"
f" Banlanan Kişi: {user_to_ban.first_name}\n"
f" Sebep: {reason}\n\n"
f" Sonuç: Kullanıcı yasaklandı!
",
parse_mode=‘Markdown’
)
else:
bot.reply_to(message, “Lütfen bir mesajı yanıtlayarak bu komutu kullanın.”)
@bot.message_handler(commands=[‘warn’])
def warn_user(message):
if message.reply_to_message:
user_to_warn = message.reply_to_message.from_user
reason = " “.join(message.text.split()[1:]) if len(message.text.split()) > 1 else “Belirtilmedi”
bot.reply_to(
message,
f" Uyarı!
\n\n”
f" Uyaran Yetkili: {message.from_user.first_name}\n"
f" Uyarılan Kişi: {user_to_warn.first_name}\n"
f" Sebep: {reason}\n\n"
f" Lütfen daha dikkatli ol!
",
parse_mode=‘Markdown’
)
else:
bot.reply_to(message, “Lütfen bir mesajı yanıtlayarak bu komutu kullanın.”)
@bot.message_handler(commands=[‘mute’])
def mute_user(message):
if message.reply_to_message:
user_to_mute = message.reply_to_message.from_user
reason = " “.join(message.text.split()[1:]) if len(message.text.split()) > 1 else “Belirtilmedi”
bot.restrict_chat_member(message.chat.id, user_to_mute.id, can_send_messages=False)
bot.reply_to(
message,
f" Susturma İşlemi!
\n\n”
f" Susturan Yetkili: {message.from_user.first_name}\n"
f" Susturulan Kişi: {user_to_mute.first_name}\n"
f" Sebep: {reason}\n\n"
f" Süre: Belirtilen süre boyunca sessiz kalacaksınız.",
parse_mode=‘Markdown’
)
else:
bot.reply_to(message, “Lütfen bir mesajı yanıtlayarak bu komutu kullanın.”)
@bot.message_handler(commands=[‘unmute’])
def unmute_user(message):
if message.reply_to_message:
user_to_unmute = message.reply_to_message.from_user
bot.restrict_chat_member(message.chat.id, user_to_unmute.id, can_send_messages=True)
bot.reply_to(message, f" Susturma Kaldırıldı! {user_to_unmute.first_name}", parse_mode=‘Markdown’)
else:
bot.reply_to(message, “Lütfen bir mesajı yanıtlayarak bu komutu kullanın.”)
@bot.message_handler(commands=[‘unban’])
def unban_user(message):
if message.reply_to_message:
user_to_unban = message.reply_to_message.from_user
if user_to_unban.id in banned_users:
banned_users.remove(user_to_unban.id)
bot.reply_to(message, f" Ban kaldırıldı: {user_to_unban.first_name}", parse_mode=‘Markdown’)
else:
bot.reply_to(message, “Kullanıcı zaten yasaklı değil.”)
else:
bot.reply_to(message, “Lütfen bir mesajı yanıtlayarak bu komutu kullanın.”)
Handle unknown commands
@bot.message_handler(func=lambda message: True)
def handle_unknown_command(message):
if message.text.startswith(‘/’):
bot.reply_to(message, “Böyle bir komutum yok”, parse_mode=‘html’)
log_message(f"Unknown command used by {message.chat.id}: {message.text}")
Start the bot
bot.polling(none_stop=True) bu koddak hatalari düzeltirmisin