-
Notifications
You must be signed in to change notification settings - Fork 0
/
lock_the_chat.py
50 lines (48 loc) · 2.02 KB
/
lock_the_chat.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
"""
Echo plugin example
"""
import core
global locked
locked = []
PLUGINVERSION = 2
# Always name this variable as `plugin`
# If you dont, module loader will fail to load the plugin!
plugin = core.Plugin()
@plugin.message(regex=".*") # You pass regex pattern
def lock_check(bot, update):
if update.message.chat_id in locked:
for admin in update.message.chat.get_administrators():
if admin.user.username == update.message.from_user.username:
return
update.message.delete()
return
@plugin.command(command="/lock",
description="Locks chat",
inline_supported=True,
hidden=False)
def lock(bot, update, user, args):
if update.message.chat_id in locked:
return core.message("Chat is already locked")
if update.message.chat.type != "private":
for admin in update.message.chat.get_administrators():
if admin.user.username == update.message.from_user.username:
for admin in update.message.chat.get_administrators():
if admin.user.username == bot.get_me().username:
locked.append(update.message.chat_id)
return core.message("Chat locked")
return core.message("I am not admin of this chat...")
return core.message(text="Hey! You are not admin of this chat!", photo="https://pbs.twimg.com/media/C_I2Xv1WAAAkpiv.jpg")
else:
return core.message("Why would you lock a private converstaion?")
@plugin.command(command="/unlock",
description="Unlocks chat",
inline_supported=True,
hidden=False)
def unlock(bot, update, user, args):
if update.message.chat_id in locked:
for admin in update.message.chat.get_administrators():
if admin.user.username == update.message.from_user.username:
locked.remove(update.message.chat_id)
return core.message("Chat unlocked")
else:
return core.message("This chat wasnt locked at all")