33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
import os
|
|
|
|
def load_watchlist():
|
|
try:
|
|
with open("watchlist.txt", "r", encoding="utf-8") as f:
|
|
return [line.strip().lower() for line in f if line.strip()]
|
|
except FileNotFoundError:
|
|
return []
|
|
|
|
def on_user_joined(user, bot):
|
|
try:
|
|
bot_channel_id = bot.ttclient.get_my_channel_id()
|
|
if user.channelid == bot_channel_id:
|
|
welcome_msg = f"👋 Hello {user.nickname}, welcome to the channel!"
|
|
bot.send_channel_message(welcome_msg)
|
|
except Exception as e:
|
|
print(f"[ERROR] Failed to send welcome message: {e}")
|
|
|
|
def on_user_loggedin(user, bot):
|
|
try:
|
|
watchlist = load_watchlist()
|
|
username = user.nickname.lower()
|
|
|
|
for badname in watchlist:
|
|
if badname in username:
|
|
reason = "🚫 You are kicked because your nickname contains inappropriate words."
|
|
bot.send_private_message(user.userid, reason)
|
|
bot.kick_user(user.userid, bot.ttclient.get_my_channel_id())
|
|
print(f"[INFO] Kicked user: {user.nickname}")
|
|
break
|
|
except Exception as e:
|
|
print(f"[ERROR] Failed to check user login: {e}")
|