forked from TamilanBotsZ/AwesomeFilterPro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection.py
147 lines (130 loc) · 6.17 KB
/
connection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from pyrogram import filters, Client, enums
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from database.connections_mdb import add_connection, all_connections, if_active, delete_connection
from info import ADMINS
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)
@Client.on_message((filters.private | filters.group) & filters.command('connect'))
async def addconnection(client, message):
userid = message.from_user.id if message.from_user else None
if not userid:
return await message.reply(f"Yᴏᴜ ᴀʀᴇ ᴀɴᴏɴʏᴍᴏᴜꜱ ᴀᴅᴍɪɴ. Uꜱᴇ/connect {message.chat.id} in PM")
chat_type = message.chat.type
if chat_type == enums.ChatType.PRIVATE:
try:
cmd, group_id = message.text.split(" ", 1)
except:
await message.reply_text(
"<b>ᴇɴᴛᴇʀ ɪɴ ᴄᴏʀʀᴇᴄᴛ ғᴏʀᴍᴀᴛ !</b>\n\n"
"<code>/connect ɢʀᴏᴜᴘ ɪᴅ</code>\n\n"
"<i>Gᴇᴛ ʏᴏᴜʀ Gʀᴏᴜᴘ ɪᴅ ʙʏ ᴀᴅᴅɪɴɢ ᴛʜɪꜱ ʙᴏᴛ ᴛᴏ ʏᴏᴜʀ ɢʀᴏᴜᴘ ᴀɴᴅ ᴜꜱᴇ <code>/id</code></i>",
quote=True
)
return
elif chat_type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
group_id = message.chat.id
try:
st = await client.get_chat_member(group_id, userid)
if (
st.status != enums.ChatMemberStatus.ADMINISTRATOR
and st.status != enums.ChatMemberStatus.OWNER
and userid not in ADMINS
):
await message.reply_text("Yᴏᴜ ꜱʜᴏᴜʟᴅ ʙᴇ ᴀɴ ᴀᴅᴍɪɴ ɪɴ Gɪᴠᴇɴ ɢʀᴏᴜᴘ!", quote=True)
return
except Exception as e:
logger.exception(e)
await message.reply_text(
"ɪɴᴠᴀʟɪᴅ ɢʀᴏᴜᴘ ɪᴅ!\n\nIғ ᴄᴏʀʀᴇᴄᴛ, Mᴀᴋᴇ ꜱᴜʀᴇ I'ᴍ ᴘʀᴇꜱᴇɴᴛ ɪɴ ʏᴏᴜʀ ɢʀᴏᴜᴘ!!",
quote=True,
)
return
try:
st = await client.get_chat_member(group_id, "me")
if st.status == enums.ChatMemberStatus.ADMINISTRATOR:
ttl = await client.get_chat(group_id)
title = ttl.title
addcon = await add_connection(str(group_id), str(userid))
if addcon:
await message.reply_text(
f"sᴜᴄᴄᴇssғᴜʟʟ ᴄᴏɴɴᴇᴄᴛᴇᴅ ɪɴ **{title}**\nɴᴏᴡ ᴍᴀɴᴀɢᴇ ᴜʀ ɢʀᴏᴜᴘ ɪɴ ʙᴏᴛ ᴘᴍ",
quote=True,
parse_mode=enums.ParseMode.MARKDOWN
)
if chat_type in ["group", "supergroup"]:
await client.send_message(
userid,
f"ᴄᴏɴɴᴇᴄᴛᴇᴅ ᴛᴏ **{title}** !",
parse_mode=enums.ParseMode.MARKDOWN
)
else:
await message.reply_text(
"ʏᴏᴜ'ʀᴇ ᴀʟʀᴇᴀᴅʏ ᴄᴏɴɴᴇᴄᴛᴇᴅ ᴛᴏ ᴛʜɪs ᴄʜᴀᴛ",
quote=True
)
else:
await message.reply_text("ᴀᴅᴅ ᴍᴇ ᴀs ᴀᴅᴍɪɴ ɪɴ ᴛʜɪs ɢʀᴏᴜᴘ", quote=True)
except Exception as e:
logger.exception(e)
await message.reply_text('sᴏᴍᴇ ᴇʀʀᴏʀ ᴏᴄᴄᴜʀs ᴛʀʏ ᴀɢᴀɪɴ ʟᴀᴛᴇʀ !.', quote=True)
return
@Client.on_message((filters.private | filters.group) & filters.command('disconnect'))
async def deleteconnection(client, message):
userid = message.from_user.id if message.from_user else None
if not userid:
return await message.reply(f"Yᴏᴜ ᴀʀᴇ ᴀɴᴏɴʏᴍᴏᴜꜱ ᴀᴅᴍɪɴ. Uꜱᴇ /connect {message.chat.id} in PM")
chat_type = message.chat.type
if chat_type == enums.ChatType.PRIVATE:
await message.reply_text("ʀᴜɴ /connections ᴛᴏ ᴠɪᴇᴡs ᴏʀ ᴅɪsᴄᴏɴɴᴇᴄᴛ ᴀɴʏ ɢʀᴏᴜᴘ!", quote=True)
elif chat_type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
group_id = message.chat.id
st = await client.get_chat_member(group_id, userid)
if (
st.status != enums.ChatMemberStatus.ADMINISTRATOR
and st.status != enums.ChatMemberStatus.OWNER
and str(userid) not in ADMINS
):
return
delcon = await delete_connection(str(userid), str(group_id))
if delcon:
await message.reply_text("sᴜᴄᴄᴇsғᴜʟʟʏ ᴅɪsᴄᴏɴɴᴇᴄᴛᴇᴅ ᴛᴏ ᴛʜᴇ ᴄʜᴀᴛ", quote=True)
else:
await message.reply_text("ᴛʜɪs ᴄʜᴀᴛ ɪs'ɴᴛ ᴄᴏɴɴᴇᴄᴛ ᴛᴏ ᴍᴇ \nDo /connect ᴛᴏ ᴄᴏɴɴᴇᴄᴛ.", quote=True)
@Client.on_message(filters.private & filters.command(["connections"]))
async def connections(client, message):
userid = message.from_user.id
groupids = await all_connections(str(userid))
if groupids is None:
await message.reply_text(
"ᴛʜᴇʀᴇ ᴀʀᴇ ɴᴏ ᴀᴄᴛɪᴠᴇ ᴄᴏɴɴᴇᴄᴛɪᴏɴs!! ᴄᴏɴɴᴇᴄᴛ sᴏᴍᴇ ɢʀᴏᴜᴘs ғɪʀsᴛ",
quote=True
)
return
buttons = []
for groupid in groupids:
try:
ttl = await client.get_chat(int(groupid))
title = ttl.title
active = await if_active(str(userid), str(groupid))
act = " - ACTIVE" if active else ""
buttons.append(
[
InlineKeyboardButton(
text=f"{title}{act}", callback_data=f"groupcb:{groupid}:{act}"
)
]
)
except:
pass
if buttons:
await message.reply_text(
"ʏᴏᴜʀ ᴄᴏɴɴᴇᴄᴛᴇᴅ ɢʀᴏᴜᴘ ᴅᴇᴛᴀɪʟs ;\n\n",
reply_markup=InlineKeyboardMarkup(buttons),
quote=True
)
else:
await message.reply_text(
"ᴛʜᴇʀᴇ ᴀʀᴇ ɴᴏ ᴀᴄᴛɪᴠᴇ ᴄᴏɴɴᴇᴄᴛɪᴏɴs!! ᴄᴏɴɴᴇᴄᴛ sᴏᴍᴇ ɢʀᴏᴜᴘs ғɪʀsᴛ.",
quote=True
)