pyrogram-client 0.0.8.dev0__tar.gz → 0.0.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyrogram_client-0.0.8.dev0/pyrogram_client.egg-info → pyrogram_client-0.0.9}/PKG-INFO +1 -1
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/pyro_client/client/base.py +15 -23
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/pyro_client/client/bot.py +6 -3
- pyrogram_client-0.0.9/pyro_client/client/filler.py +157 -0
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/pyro_client/client/user.py +4 -1
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/pyro_client/storage.py +13 -1
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9/pyrogram_client.egg-info}/PKG-INFO +1 -1
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/pyrogram_client.egg-info/SOURCES.txt +1 -0
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/.env.sample +0 -0
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/.gitignore +0 -0
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/.pre-commit-config.yaml +0 -0
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/makefile +0 -0
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/pyproject.toml +0 -0
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/pyro_client/client/dc.json +0 -0
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/pyro_client/client/file.py +0 -0
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/pyro_client/loader.py +0 -0
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/pyrogram_client.egg-info/dependency_links.txt +0 -0
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/pyrogram_client.egg-info/requires.txt +0 -0
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/pyrogram_client.egg-info/top_level.txt +0 -0
- {pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/setup.cfg +0 -0
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
-
from collections import OrderedDict
|
|
3
2
|
from io import BytesIO
|
|
4
3
|
from typing import Literal
|
|
5
4
|
|
|
6
5
|
from pyrogram import Client
|
|
7
6
|
from pyrogram.errors import AuthKeyUnregistered, Unauthorized
|
|
8
|
-
from pyrogram.filters import chat, contact
|
|
7
|
+
from pyrogram.filters import chat, contact
|
|
9
8
|
from pyrogram.handlers import MessageHandler
|
|
10
9
|
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, ReplyKeyboardMarkup, KeyboardButton
|
|
11
10
|
from x_auth.models import Session, App, Username
|
|
@@ -41,7 +40,7 @@ class BaseClient(Client):
|
|
|
41
40
|
session = await Session.create(id=self.uid, api=app, user=username, is_bot=bt)
|
|
42
41
|
self.api_id = app.id
|
|
43
42
|
self.api_hash = app.hsh
|
|
44
|
-
await session.fetch_related("api")
|
|
43
|
+
# await session.fetch_related("api")
|
|
45
44
|
self.storage.session = session
|
|
46
45
|
|
|
47
46
|
async def start(self, use_qr: bool = False, except_ids: list[int] = None):
|
|
@@ -78,33 +77,26 @@ class BaseClient(Client):
|
|
|
78
77
|
else:
|
|
79
78
|
return await self.send_message(uid, txt, reply_markup=ikm)
|
|
80
79
|
|
|
81
|
-
|
|
80
|
+
def subscribe_for(self, uid: int, topic: str) -> tuple[MessageHandler, int]:
|
|
82
81
|
fltr = chat(uid)
|
|
83
82
|
if topic == "phone":
|
|
84
83
|
fltr &= contact
|
|
85
|
-
handler = MessageHandler(self.got_msg, fltr)
|
|
86
|
-
# handler, g = self.add_handler(handler, 1)
|
|
87
|
-
g = 0
|
|
88
|
-
if g not in self.dispatcher.groups:
|
|
89
|
-
self.dispatcher.groups[g] = []
|
|
90
|
-
self.dispatcher.groups = OrderedDict(sorted(self.dispatcher.groups.items()))
|
|
91
|
-
self.dispatcher.groups[g].append(handler)
|
|
92
84
|
self.storage.session.state |= {uid: {"waiting_for": topic}}
|
|
93
|
-
|
|
85
|
+
return self.add_handler(MessageHandler(self.got_msg, fltr))
|
|
86
|
+
|
|
87
|
+
async def wait_from(
|
|
88
|
+
self, uid: int, topic: str, hg: tuple[MessageHandler, int], past: int = 0, timeout: int = 10
|
|
89
|
+
) -> str | None:
|
|
94
90
|
while past < timeout:
|
|
95
91
|
if txt := self.storage.session.state.get(uid, {}).pop(topic, None):
|
|
96
|
-
|
|
97
|
-
self.dispatcher.groups[g].remove(handler)
|
|
98
|
-
#
|
|
92
|
+
self.remove_handler(*hg)
|
|
99
93
|
return txt
|
|
100
|
-
await asyncio.sleep(
|
|
101
|
-
past +=
|
|
102
|
-
return self.remove_handler(
|
|
94
|
+
await asyncio.sleep(2)
|
|
95
|
+
past += 2
|
|
96
|
+
return self.remove_handler(*hg)
|
|
103
97
|
|
|
104
98
|
async def got_msg(self, _, msg: Message):
|
|
105
99
|
if tpc := self.storage.session.state.get(msg.from_user.id, {}).pop("waiting_for", None):
|
|
106
|
-
self.storage.session.state[msg.from_user.id]
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
for gi, grp in self.dispatcher.groups.items():
|
|
110
|
-
[self.remove_handler(h, gi) for h in grp if isinstance(h.filters, AndFilter) and uid in h.filters.base]
|
|
100
|
+
self.storage.session.state[msg.from_user.id] = {
|
|
101
|
+
tpc: msg.contact.phone_number if tpc == "phone" else msg.text
|
|
102
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
1
3
|
from pyro_client.client.base import BaseClient, AuthTopic
|
|
2
|
-
from pyro_client.loader import TOKEN
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
class BotClient(BaseClient):
|
|
@@ -26,10 +27,12 @@ async def main():
|
|
|
26
27
|
|
|
27
28
|
_ = await init_db(TORM, True)
|
|
28
29
|
|
|
30
|
+
logging.basicConfig(level=logging.INFO)
|
|
31
|
+
|
|
29
32
|
bc: BotClient = BotClient(6806432376)
|
|
30
|
-
bc1: BotClient = BotClient(TOKEN)
|
|
33
|
+
# bc1: BotClient = BotClient(TOKEN)
|
|
31
34
|
await bc.start()
|
|
32
|
-
await bc1.start()
|
|
35
|
+
# await bc1.start()
|
|
33
36
|
await bc.stop()
|
|
34
37
|
|
|
35
38
|
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from enum import IntEnum
|
|
3
|
+
from inspect import isclass
|
|
4
|
+
from typing import Coroutine
|
|
5
|
+
|
|
6
|
+
from pyrogram.filters import chat, private
|
|
7
|
+
from pyrogram.handlers import CallbackQueryHandler, MessageHandler
|
|
8
|
+
from pyrogram.types import (
|
|
9
|
+
Message,
|
|
10
|
+
User,
|
|
11
|
+
ReplyKeyboardMarkup,
|
|
12
|
+
CallbackQuery,
|
|
13
|
+
KeyboardButton,
|
|
14
|
+
InlineKeyboardButton,
|
|
15
|
+
InlineKeyboardMarkup,
|
|
16
|
+
)
|
|
17
|
+
from xync_schema import models
|
|
18
|
+
from xync_schema.enums import SynonymType, Party, Slip, AbuserType, NameType
|
|
19
|
+
|
|
20
|
+
from pyro_client.client.file import FileClient
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
async def cbank(txt: str) -> list[tuple[int, str]]:
|
|
24
|
+
return await models.Pm.filter(norm__startswith=txt[0], bank=True).values_list("id", "norm")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
async def cppo(txt: str) -> list[tuple[int, str]]:
|
|
28
|
+
opts = re.findall(r"\d+", txt) or [1, 2, 3, 5, 10]
|
|
29
|
+
return [(o, str(o)) for o in opts]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
async def btns(typ: SynonymType.__class__, txt: str = None) -> InlineKeyboardMarkup | None:
|
|
33
|
+
if lst := synopts[typ]:
|
|
34
|
+
if isinstance(lst, list):
|
|
35
|
+
kb = [[InlineKeyboardButton(n, f"st:{typ.name}:{i}")] for i, n in enumerate(lst)]
|
|
36
|
+
elif isclass(lst) and issubclass(lst, IntEnum):
|
|
37
|
+
kb = [[InlineKeyboardButton(i.name, f"st:{typ.name}:{i.value}")] for i in lst]
|
|
38
|
+
else:
|
|
39
|
+
kb = [[InlineKeyboardButton(n, f"st:{typ.name}:{i}")] for i, n in await lst(txt)]
|
|
40
|
+
return InlineKeyboardMarkup(kb)
|
|
41
|
+
else:
|
|
42
|
+
return lst
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def get_val(typ: SynonymType.__class__, val: str) -> tuple[SynonymType | int | bool, str]:
|
|
46
|
+
if isinstance(val, str) and val.isnumeric():
|
|
47
|
+
val = int(val)
|
|
48
|
+
if isclass(lst := synopts[typ]) and issubclass(lst, IntEnum):
|
|
49
|
+
return (v := lst(val)), v.name
|
|
50
|
+
elif isinstance(lst, list):
|
|
51
|
+
return val, lst[val]
|
|
52
|
+
return val, val
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
synopts: dict[SynonymType, list[str] | IntEnum | None | Coroutine] = {
|
|
56
|
+
SynonymType.name: ["not_slavic", "slavic"],
|
|
57
|
+
SynonymType.ppo: cppo,
|
|
58
|
+
SynonymType.from_party: Party,
|
|
59
|
+
SynonymType.to_party: Party,
|
|
60
|
+
SynonymType.slip_req: Slip,
|
|
61
|
+
SynonymType.slip_send: Slip,
|
|
62
|
+
SynonymType.abuser: AbuserType,
|
|
63
|
+
SynonymType.scale: ["1", "10", "100", "1000"],
|
|
64
|
+
SynonymType.slavic: NameType,
|
|
65
|
+
SynonymType.mtl_like: None,
|
|
66
|
+
SynonymType.bank: cbank,
|
|
67
|
+
SynonymType.bank_side: ["except", "only"],
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class FillerClient(FileClient): ...
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
async def cond_start_handler(bot: FillerClient, msg: Message, *args, **kwargs):
|
|
75
|
+
me: User = msg.from_user
|
|
76
|
+
cond = await models.Cond.filter(parsed__isnull=True).order_by("-created_at").first().prefetch_related("parsed")
|
|
77
|
+
rm = ReplyKeyboardMarkup(
|
|
78
|
+
[
|
|
79
|
+
[KeyboardButton("ppo"), KeyboardButton("abuser")],
|
|
80
|
+
[KeyboardButton("from_party"), KeyboardButton("to_party")],
|
|
81
|
+
[KeyboardButton("slip_send"), KeyboardButton("slip_req")],
|
|
82
|
+
[KeyboardButton("name"), KeyboardButton("slavic")],
|
|
83
|
+
[KeyboardButton("scale"), KeyboardButton("mtl_like")],
|
|
84
|
+
[KeyboardButton("bank"), KeyboardButton("bank_side")],
|
|
85
|
+
]
|
|
86
|
+
)
|
|
87
|
+
bot.add_handler(MessageHandler(got_synonym, chat(me.id) & private))
|
|
88
|
+
bot.storage.session.state |= {me.id: {"synonym": {"id": cond.id}}}
|
|
89
|
+
|
|
90
|
+
return await msg.reply_text(await wrap_cond(cond.raw_txt), reply_markup=rm)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
async def wrap_cond(txt: str):
|
|
94
|
+
rs = {syn.txt: f'`{syn.txt}`||{syn.typ.name}="{syn.val}"||' for syn in await models.Synonym.all() if syn.txt in txt}
|
|
95
|
+
[txt := txt.replace(o, n) for o, n in rs.items()]
|
|
96
|
+
return txt
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
async def got_synonym(bot: FillerClient, msg: Message):
|
|
100
|
+
if not (msg.text in {st.name for st in SynonymType} and (typ := SynonymType[msg.text])):
|
|
101
|
+
return await msg.reply_text(
|
|
102
|
+
f'Нет раздела "{msg.text}", не пиши текст сам, выдели кусок из моего сообщения,'
|
|
103
|
+
f"ответь на него, выбери кнопку раздела"
|
|
104
|
+
)
|
|
105
|
+
if not msg.quote:
|
|
106
|
+
return await msg.reply_text(f"Вы забыли выделить кусок текста для {msg.text}")
|
|
107
|
+
me: User = msg.from_user
|
|
108
|
+
((state, cidd),) = bot.storage.session.state.get(me.id, {None: {}}).items()
|
|
109
|
+
if state == "synonym":
|
|
110
|
+
if typ := SynonymType[msg.text]:
|
|
111
|
+
bot.storage.session.state[me.id][state] |= {typ: msg.quote.text}
|
|
112
|
+
# bot.rm_handler(me.id)
|
|
113
|
+
await models.Synonym.update_or_create({"typ": typ}, txt=msg.quote.text)
|
|
114
|
+
bot.add_handler(CallbackQueryHandler(got_synonym_val, chat(me.id) & private))
|
|
115
|
+
if rm := await btns(typ, msg.quote.text):
|
|
116
|
+
return await msg.reply_text("Уточните", reply_to_message_id=msg.id, reply_markup=rm)
|
|
117
|
+
return await syn_result(bot, msg, f"st:{typ.name}:1")
|
|
118
|
+
elif state:
|
|
119
|
+
...
|
|
120
|
+
return await msg.reply_text("Не туда попал")
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
async def got_synonym_val(bot: FillerClient, cbq: CallbackQuery):
|
|
124
|
+
return await syn_result(bot, cbq.message, cbq.data)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
async def syn_result(bot: FillerClient, msg: Message, data: str):
|
|
128
|
+
t, st, sv = data.split(":")
|
|
129
|
+
if t == "st":
|
|
130
|
+
typ = SynonymType[st]
|
|
131
|
+
cid = bot.storage.session.state[msg.chat.id]["synonym"]["id"]
|
|
132
|
+
txt = bot.storage.session.state[msg.chat.id]["synonym"][typ]
|
|
133
|
+
val, hval = get_val(typ, sv)
|
|
134
|
+
syn, _ = await models.Synonym.update_or_create({"val": val}, typ=typ, txt=txt)
|
|
135
|
+
await models.CondParsed.update_or_create({typ.name: val}, cond_id=cid)
|
|
136
|
+
await msg.reply_text(
|
|
137
|
+
f'Текст "{txt}" определен как синоним для `{typ.name}` со значением {hval}',
|
|
138
|
+
reply_markup=InlineKeyboardMarkup(
|
|
139
|
+
[
|
|
140
|
+
[
|
|
141
|
+
InlineKeyboardButton("Готово! Давай новый", f"cond:complete:{cid}"),
|
|
142
|
+
# , InlineKeyboardButton('Хватит! Я устал', f'cond:complete:{cid}')
|
|
143
|
+
]
|
|
144
|
+
]
|
|
145
|
+
),
|
|
146
|
+
)
|
|
147
|
+
await wrap_cond(await models.Cond.get(id=cid).values_list("raw_txt", flat=True))
|
|
148
|
+
# await bot.edit_message_text(bot.me.id, msg.reply_to_message.reply_to_message_id, wrapped_txt)
|
|
149
|
+
await msg.reply_to_message.delete()
|
|
150
|
+
await msg.delete()
|
|
151
|
+
await msg.delete()
|
|
152
|
+
|
|
153
|
+
elif t == "cond":
|
|
154
|
+
await models.CondParsed.update_or_create({"parsed": True}, cond_id=int(sv))
|
|
155
|
+
await cond_start_handler(bot, msg)
|
|
156
|
+
else:
|
|
157
|
+
await msg.reply_text("Где я?")
|
|
@@ -175,11 +175,14 @@ async def main():
|
|
|
175
175
|
# await models.Proxy.load_list(WSToken)
|
|
176
176
|
# session = await models.Session.filter(is_bot__isnull=True).order_by("-date").prefetch_related("proxy").first()
|
|
177
177
|
bc: BotClient = BotClient(6806432376)
|
|
178
|
-
uc: UserClient = UserClient(
|
|
178
|
+
uc: UserClient = UserClient(193017646, bc)
|
|
179
179
|
# try:
|
|
180
180
|
await uc.start()
|
|
181
181
|
# b = await uc.resolve_peer('xyncnetbot')
|
|
182
182
|
await uc.send("/start", bc.me.username)
|
|
183
|
+
|
|
184
|
+
hg = uc.subscribe_for(1038938370, "code")
|
|
185
|
+
await uc.wait_from(1038938370, "code", hg)
|
|
183
186
|
# except Exception as e:
|
|
184
187
|
# print(e.MESSAGE)
|
|
185
188
|
# await uc.send(e.MESSAGE)
|
|
@@ -4,7 +4,7 @@ from typing import Any
|
|
|
4
4
|
from pyrogram import raw, utils
|
|
5
5
|
from pyrogram.storage import Storage
|
|
6
6
|
from x_auth.enums import PeerType
|
|
7
|
-
from x_auth.models import Username, Version, Session, Peer, UpdateState
|
|
7
|
+
from x_auth.models import Username, Version, Session, Peer, UpdateState, Dc
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
def get_input_peer(peer_id: int, access_hash: int, peer_type: PeerType):
|
|
@@ -14,6 +14,8 @@ def get_input_peer(peer_id: int, access_hash: int, peer_type: PeerType):
|
|
|
14
14
|
return raw.types.InputPeerChat(chat_id=-peer_id)
|
|
15
15
|
if peer_type in [PeerType.channel, PeerType.supergroup]:
|
|
16
16
|
return raw.types.InputPeerChannel(channel_id=utils.get_channel_id(peer_id), access_hash=access_hash)
|
|
17
|
+
if peer_type in [PeerType.forum]:
|
|
18
|
+
return raw.types.InputPeerChannel(channel_id=utils.get_channel_id(peer_id), access_hash=access_hash)
|
|
17
19
|
raise ValueError(f"Invalid peer type: {peer_type.name}")
|
|
18
20
|
|
|
19
21
|
|
|
@@ -136,3 +138,13 @@ class PgStorage(Storage):
|
|
|
136
138
|
return ver.number
|
|
137
139
|
else:
|
|
138
140
|
await Version.update_or_create(id=value)
|
|
141
|
+
|
|
142
|
+
async def server_address(self, value: str = ...) -> str:
|
|
143
|
+
if value is ...:
|
|
144
|
+
dc = await Dc[await self.dc_id()]
|
|
145
|
+
return dc.ip
|
|
146
|
+
dc = await Dc.get(ip=value)
|
|
147
|
+
await self.dc_id(dc.id)
|
|
148
|
+
|
|
149
|
+
async def port(self, value: int = 443) -> int:
|
|
150
|
+
return value
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pyrogram_client-0.0.8.dev0 → pyrogram_client-0.0.9}/pyrogram_client.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|