teamx-cloner commited on
Commit
9565139
·
1 Parent(s): ec9ed8d

Delete plugins/watcher.py

Browse files
Files changed (1) hide show
  1. plugins/watcher.py +0 -116
plugins/watcher.py DELETED
@@ -1,116 +0,0 @@
1
- from pytdbot import Client, types
2
-
3
- from src.database import db
4
- from src.logger import LOGGER
5
- from src.modules.utils.admins import load_admin_cache
6
- from src.modules.utils.buttons import AddMeButton
7
- from src.modules.utils.cacher import chat_cache
8
-
9
-
10
- async def handle_non_supergroup(client: Client, chat_id: int):
11
- """Handles cases where the bot is added to a non-supergroup chat."""
12
- text = f"""{chat_id} is not a supergroup yet.
13
- <b>⚠️: Please convert this chat to a supergroup and add me as admin.</b>
14
-
15
- If you don't know how to convert, use this guide:
16
- 🔗 https://te.legra.ph/How-to-Convert-a-Group-to-a-Supergroup-01-02
17
-
18
- If you have any questions, join our support group:
19
- """
20
- reply = await client.sendTextMessage(
21
- chat_id, text, parse_mode="HTML", reply_markup=AddMeButton
22
- )
23
- if isinstance(reply, types.Error):
24
- LOGGER.warning(f"Error sending message: {reply}")
25
-
26
- ok = await client.leaveChat(chat_id)
27
- if isinstance(ok, types.Error):
28
- LOGGER.warning(f"Error leaving chat: {ok}")
29
-
30
-
31
- @Client.on_updateChatMember()
32
- async def chat_member(client: Client, update: types.UpdateChatMember):
33
- """Handles member updates in the chat (joins, leaves, promotions, demotions, bans, and unbans)."""
34
- chat_id = update.chat_id
35
- # Non supergroup
36
- if chat_id > 0:
37
- return await handle_non_supergroup(client, chat_id)
38
-
39
- await db.add_chat(chat_id)
40
- user_id = update.new_chat_member.member_id.user_id
41
- old_status = update.old_chat_member.status["@type"]
42
- new_status = update.new_chat_member.status["@type"]
43
-
44
- # User Joined (New Member)
45
- if old_status == "chatMemberStatusLeft" and new_status in {
46
- "chatMemberStatusMember",
47
- "chatMemberStatusAdministrator",
48
- }:
49
- LOGGER.info(f"User {user_id} joined the chat {chat_id}.")
50
- return
51
-
52
- # User Left (Left or Kicked)
53
- if (
54
- old_status in {"chatMemberStatusMember", "chatMemberStatusAdministrator"}
55
- and new_status == "chatMemberStatusLeft"
56
- ):
57
- LOGGER.info(f"User {user_id} left or was kicked from {chat_id}.")
58
- return
59
-
60
- # User Banned
61
- if new_status == "chatMemberStatusBanned":
62
- LOGGER.info(f"User {user_id} was banned in {chat_id}.")
63
- return
64
-
65
- # User Unbanned
66
- if old_status == "chatMemberStatusBanned" and new_status == "chatMemberStatusLeft":
67
- LOGGER.info(f"User {user_id} was unbanned in {chat_id}.")
68
- return
69
-
70
- is_promoted = (
71
- old_status != "chatMemberStatusAdministrator"
72
- and new_status == "chatMemberStatusAdministrator"
73
- )
74
- # Bot Promoted
75
- if user_id == client.options["my_id"] and is_promoted:
76
- LOGGER.info(f"Bot was promoted in {chat_id}, reloading admin permissions.")
77
- await load_admin_cache(client, chat_id, True)
78
- return
79
-
80
- # User Promoted
81
- if is_promoted:
82
- LOGGER.info(f"User {user_id} was promoted in {chat_id}.")
83
- await load_admin_cache(client, chat_id, True)
84
- return
85
-
86
- # User Demoted
87
- is_demoted = (
88
- old_status == "chatMemberStatusAdministrator"
89
- and new_status != "chatMemberStatusAdministrator"
90
- )
91
- if is_demoted:
92
- LOGGER.info(f"User {user_id} was demoted in {chat_id}.")
93
- if user_id == client.options["my_id"] or client.me.id:
94
- return
95
- await load_admin_cache(client, chat_id, True)
96
- return
97
-
98
- return
99
-
100
-
101
- @Client.on_updateNewMessage(position=1)
102
- async def new_message(_: Client, update: types.UpdateNewMessage):
103
- if not hasattr(update, "message"):
104
- return
105
- message = update.message
106
- if isinstance(message.content, types.MessageVideoChatEnded):
107
- LOGGER.info(f"Video chat ended in {message.chat_id}")
108
- await chat_cache.clear_chat(message.chat_id)
109
- return
110
- elif isinstance(message.content, types.MessageVideoChatStarted):
111
- LOGGER.info(f"Video chat started in {message.chat_id}")
112
- await chat_cache.clear_chat(message.chat_id)
113
- return
114
-
115
- LOGGER.debug(f"New message in {message.chat_id}: {message}")
116
- return