-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
79 lines (63 loc) · 2.37 KB
/
main.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
import re
import json
from pyrogram import Client, filters
from pyrogram.types import Message
try:
with open("config.json", "r", encoding="utf-8") as f:
data = json.load(f)
api_id = data['api_id']
api_hash = data['api_hash']
prefix = data['prefix']
except FileNotFoundError:
api_id = input("Введите api_id: ")
api_hash = input("Введите api_hash: ")
prefix = "дд"
data = {"api_id": api_id,
"api_hash": api_hash,
"prefix": "дд"}
with open("config.json", "w", encoding="utf-8") as f:
json.dump(data, f, indent=4, ensure_ascii=False)
app = Client("my_account", api_id = api_id, api_hash = api_hash)
async def prefix_filter(_, __, msg: Message):
if msg.outgoing:
return msg.text.lower().startswith(prefix)
return False
cmd_filter = filters.create(prefix_filter)
@app.on_message(cmd_filter & filters.me)
async def delete_messages(client: Client, msg: Message):
if msg.reply_to_message_id:
await app.delete_messages(msg.chat.id, [msg.id, msg.reply_to_message_id])
return
count = re.findall(prefix + r'\s?(\d+)', msg.text.lower())
if count:
count = int(count[0]) + 1
else:
count = 2
message_ids = []
offset = 0
find = True
while find:
async for message in app.get_chat_history(chat_id=msg.chat.id, limit=100, offset=offset):
if message.from_user.id == msg.from_user.id:
message_ids.append(message.id)
if len(message_ids) == count:
find = False
break
offset += 100
if offset >= 1000:
break
await app.delete_messages(msg.chat.id, message_ids)
@app.on_message(filters.command(commands="нст", prefixes="") & filters.me)
async def edit_prefix(сlient: Client, msg: Message):
global prefix
res = re.findall(r"нст (.+)", msg.text.lower())
if res:
await msg.edit(f'Теперь префикс "{res[0]}"')
prefix = res[0]
data['prefix'] = prefix
with open("config.json", "w", encoding="utf-8") as f:
json.dump(data, f, indent=4, ensure_ascii=False)
else:
await msg.edit(f"Укажите новый префикс")
app.run()
# Written with love. By Alexey Kuznetsov.