Skip to content

Commit b15401d

Browse files
committed
Fix: Improve kicked user handler
1 parent 7afc032 commit b15401d

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

tg_bot/modules/sql/users_sql.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@ def __repr__(self):
2828

2929

3030
class RemovedUser(BASE):
31-
__tablename__ == "removed_user"
31+
__tablename__ = "removed_user"
3232
user_id = Column(BigInteger, primary_key=True)
3333
chat_id = Column(String(14), primary_key=True)
34+
username = Column(UnicodeText)
3435

35-
def __init__(self, user_id, chat_id):
36+
def __init__(self, user_id, chat_id, username):
3637
self.user_id = user_id
3738
self.chat_id = str(chat_id)
39+
self.username = str(username)
3840

3941
def __repr__(self):
40-
return f"<RemovedUser {self.user_id} | {self.chat_id}>"
42+
return f"<RemovedUser {self.user_id}, {self.username} | {self.chat_id}>"
4143

4244

4345
class Chats(BASE):
@@ -211,11 +213,11 @@ def migrate_chat(old_chat_id, new_chat_id):
211213
ensure_bot_in_db()
212214

213215

214-
def remove_user(user_id, chat_id):
216+
def remove_user(user_id, chat_id, username):
215217
with INSERTION_LOCK:
216218
user = SESSION.query(RemovedUser).get((user_id, chat_id))
217219
if not user:
218-
user = RemovedUser(user_id, chat_id)
220+
user = RemovedUser(user_id, chat_id, username)
219221
SESSION.add(user)
220222
SESSION.flush()
221223
SESSION.commit()

tg_bot/modules/welcome.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ def new_member(bot: Bot, update: Update):
253253
"Diamine, non riesco a bannare questo utente."
254254
)
255255
else:
256-
# Kicking the user because of the username
256+
# Kicking the user because of the empty username
257257
user_id = new_mem.id
258258
chat.kick_member(user_id, until_date=time.time() + 300)
259-
user_sql.remove_user(user_id, chat.id) # Keep track of whom we removed and where
260-
bot.delete_message(chat.id, message.message_id) # Delete " user joined group" message
259+
user_sql.remove_user(user_id, chat.id, new_mem.first_name) # Keep track of whom we removed and where
260+
bot.delete_message(chat.id, message.message_id) # Delete "user joined group" message
261261

262262
prev_welc = sql.get_clean_pref(chat.id)
263263
if prev_welc:

0 commit comments

Comments
 (0)