-
Notifications
You must be signed in to change notification settings - Fork 1
/
conv.py
60 lines (46 loc) · 1.46 KB
/
conv.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
# Copyright (C) 2020-2022 TeamDerUntergang <https://github.com/TeamDerUntergang>
#
# This file is part of TeamDerUntergang project,
# and licensed under GNU Affero General Public License v3.
# See the GNU Affero General Public License for more details.
#
# All rights reserved. See COPYING, AUTHORS.
#
from os import remove
from time import sleep
from sedenbot import CONVERSATION, app
class PyroConversation:
def __init__(self, client, chat_id):
self.client = client or app
self.chat_id = chat_id
self.count = 0
def send_msg(self, text):
self.client.send_message(self.chat_id, text)
def send_doc(self, doc, delete=False):
self.client.send_document(self.chat_id, doc)
if delete:
remove(doc)
def recv_msg(self, read=True):
conv = CONVERSATION[self.chat_id]
count = 0
while len(conv) == self.count and count < 100:
count += 1
sleep(0.2)
if count > 99:
raise Exception
msg = conv[self.count]
self.count = len(conv)
if read:
self.client.read_history(chat_id=self.chat_id)
return msg
def forward_msg(self, msg):
return msg.forward(self.chat_id)
def init(self):
CONVERSATION[self.chat_id] = []
def stop(self):
CONVERSATION[self.chat_id] = None
def __enter__(self):
self.init()
return self
def __exit__(self, a, b, c):
self.stop()