xync-bot 0.3.1__tar.gz → 0.3.2__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.
Potentially problematic release.
This version of xync-bot might be problematic. Click here for more details.
- {xync_bot-0.3.1/xync_bot.egg-info → xync_bot-0.3.2}/PKG-INFO +1 -1
- {xync_bot-0.3.1 → xync_bot-0.3.2}/xync_bot/handlers/main.py +94 -4
- xync_bot-0.3.2/xync_bot/handlers/order.py +12 -0
- xync_bot-0.3.2/xync_bot/handlers/xicon.png +0 -0
- {xync_bot-0.3.1 → xync_bot-0.3.2/xync_bot.egg-info}/PKG-INFO +1 -1
- {xync_bot-0.3.1 → xync_bot-0.3.2}/xync_bot.egg-info/SOURCES.txt +3 -1
- {xync_bot-0.3.1 → xync_bot-0.3.2}/.env.dist +0 -0
- {xync_bot-0.3.1 → xync_bot-0.3.2}/.gitignore +0 -0
- {xync_bot-0.3.1 → xync_bot-0.3.2}/.pre-commit-config.yaml +0 -0
- {xync_bot-0.3.1 → xync_bot-0.3.2}/makefile +0 -0
- {xync_bot-0.3.1 → xync_bot-0.3.2}/pyproject.toml +0 -0
- {xync_bot-0.3.1 → xync_bot-0.3.2}/setup.cfg +0 -0
- {xync_bot-0.3.1 → xync_bot-0.3.2}/test_main.http +0 -0
- {xync_bot-0.3.1 → xync_bot-0.3.2}/xync_bot/__init__.py +0 -0
- {xync_bot-0.3.1 → xync_bot-0.3.2}/xync_bot/handlers/__init__.py +0 -0
- {xync_bot-0.3.1 → xync_bot-0.3.2}/xync_bot/handlers/vpn.py +0 -0
- {xync_bot-0.3.1 → xync_bot-0.3.2}/xync_bot/shared.py +0 -0
- {xync_bot-0.3.1 → xync_bot-0.3.2}/xync_bot.egg-info/dependency_links.txt +0 -0
- {xync_bot-0.3.1 → xync_bot-0.3.2}/xync_bot.egg-info/requires.txt +0 -0
- {xync_bot-0.3.1 → xync_bot-0.3.2}/xync_bot.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import logging
|
|
2
|
+
from os import path
|
|
3
|
+
|
|
2
4
|
from aiogram import Router, F
|
|
3
|
-
from aiogram.
|
|
5
|
+
from aiogram.enums import ContentType
|
|
6
|
+
from aiogram.filters import CommandStart, CommandObject, IS_MEMBER, IS_NOT_MEMBER, ChatMemberUpdatedFilter
|
|
4
7
|
from aiogram.filters.callback_data import CallbackData
|
|
5
8
|
from aiogram.types import (
|
|
6
9
|
User as TgUser,
|
|
@@ -9,11 +12,14 @@ from aiogram.types import (
|
|
|
9
12
|
InlineKeyboardMarkup,
|
|
10
13
|
InlineKeyboardButton,
|
|
11
14
|
CallbackQuery,
|
|
15
|
+
ChatJoinRequest,
|
|
16
|
+
WebAppInfo,
|
|
17
|
+
FSInputFile,
|
|
12
18
|
)
|
|
13
19
|
from aiogram.utils.deep_linking import create_start_link
|
|
14
20
|
from aiogram.utils.web_app import WebAppUser
|
|
15
21
|
from tg_auth import Lang
|
|
16
|
-
from xync_schema.models import User, UserStatus
|
|
22
|
+
from xync_schema.models import User, UserStatus, Order, Msg, Forum
|
|
17
23
|
|
|
18
24
|
from xync_bot.shared import NavCallbackData
|
|
19
25
|
|
|
@@ -137,10 +143,94 @@ async def user_upsert(u: TgUser | WebAppUser, status: UserStatus = None) -> (Use
|
|
|
137
143
|
@main.my_chat_member()
|
|
138
144
|
async def user_set_status(my_chat_member: ChatMemberUpdated):
|
|
139
145
|
u: TgUser = my_chat_member.from_user
|
|
140
|
-
new_status = my_chat_member.new_chat_member.status
|
|
146
|
+
new_status = UserStatus[my_chat_member.new_chat_member.status.upper()]
|
|
141
147
|
await user_upsert(u, status=new_status)
|
|
142
148
|
|
|
143
149
|
|
|
144
|
-
@main.
|
|
150
|
+
@main.chat_member(ChatMemberUpdatedFilter(IS_MEMBER >> IS_NOT_MEMBER))
|
|
151
|
+
async def on_user_leave(member: ChatMemberUpdated):
|
|
152
|
+
forum = await Forum[member.chat.id]
|
|
153
|
+
if not forum.joined:
|
|
154
|
+
resp = (
|
|
155
|
+
f"{member.from_user.username or member.from_user.full_name}#{member.from_user.id} "
|
|
156
|
+
f"already leaved from {member.chat.title}#{member.chat.id}"
|
|
157
|
+
)
|
|
158
|
+
logging.error(resp)
|
|
159
|
+
else:
|
|
160
|
+
forum.joined = False
|
|
161
|
+
await forum.save()
|
|
162
|
+
resp = "Bye!"
|
|
163
|
+
return await member.bot.send_message(member.new_chat_member.user.id, resp)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@main.chat_join_request()
|
|
167
|
+
async def on_join_request(req: ChatJoinRequest):
|
|
168
|
+
forum = await Forum[req.chat.id]
|
|
169
|
+
if forum.user_id != req.from_user.id:
|
|
170
|
+
resp = f"{req.chat.title} is chat for user#{forum.user_id}"
|
|
171
|
+
logging.error(resp)
|
|
172
|
+
forum.joined = not await req.decline()
|
|
173
|
+
else:
|
|
174
|
+
resp = "Welcome!"
|
|
175
|
+
forum.joined = await req.approve()
|
|
176
|
+
cp = (await req.bot.get_chat(req.chat.id)).photo
|
|
177
|
+
if not cp:
|
|
178
|
+
pth = path.join(path.dirname(path.abspath(__file__)), "xicon.png")
|
|
179
|
+
await req.chat.set_photo(FSInputFile(pth))
|
|
180
|
+
await forum.save()
|
|
181
|
+
return await req.bot.send_message(req.user_chat_id, resp)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
@main.chat_member(ChatMemberUpdatedFilter(IS_NOT_MEMBER >> IS_MEMBER))
|
|
185
|
+
async def on_user_join(member: ChatMemberUpdated):
|
|
186
|
+
forum = await Forum[member.chat.id]
|
|
187
|
+
rm = None
|
|
188
|
+
if forum.user_id != member.from_user.id:
|
|
189
|
+
if member.from_user.id in (6806432376, forum.created_by):
|
|
190
|
+
return
|
|
191
|
+
resp = f"{member.chat.title} is chat for user#{forum.user_id}"
|
|
192
|
+
logging.error(resp)
|
|
193
|
+
await member.bot.ban_chat_member(member.chat.id, member.from_user.id)
|
|
194
|
+
else:
|
|
195
|
+
resp = "Welcome to XyncNetwork"
|
|
196
|
+
rm = InlineKeyboardMarkup(
|
|
197
|
+
inline_keyboard=[[InlineKeyboardButton(text="Go!", web_app=WebAppInfo(url="https://t.me/XyncNetBot/test"))]]
|
|
198
|
+
)
|
|
199
|
+
return await member.bot.send_message(member.new_chat_member.user.id, resp, reply_markup=rm)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
@main.message(F.is_topic_message)
|
|
203
|
+
async def order_msg(msg: Message):
|
|
204
|
+
sender = await User[msg.from_user.id]
|
|
205
|
+
cid = msg.chat.shifted_id
|
|
206
|
+
assert sender.forum == cid, "sender is not client"
|
|
207
|
+
if order := await Order.get_or_none(taker__user_id=sender.id, taker_topic=msg.message_thread_id):
|
|
208
|
+
is_taker = True
|
|
209
|
+
elif order := await Order.get_or_none(ad__agent__user_id=sender.id, maker_topic=msg.message_thread_id):
|
|
210
|
+
is_taker = False
|
|
211
|
+
else:
|
|
212
|
+
return await msg.answer("No such order")
|
|
213
|
+
# raise Exception("No such order")
|
|
214
|
+
receiver: User = await (order.ad.agent.user if is_taker else order.taker.user)
|
|
215
|
+
rcv_topic = order.taker_topic if is_taker else order.maker_topic
|
|
216
|
+
await Msg.create(tgid=msg.message_id, txt=msg.text, order_id=order.id, receiver=receiver)
|
|
217
|
+
return await msg.send_copy(receiver.forum, message_thread_id=rcv_topic)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
@main.message(
|
|
221
|
+
F.content_type.not_in(
|
|
222
|
+
{
|
|
223
|
+
# ContentType.NEW_CHAT_MEMBERS,
|
|
224
|
+
ContentType.FORUM_TOPIC_CLOSED,
|
|
225
|
+
ContentType.GENERAL_FORUM_TOPIC_HIDDEN,
|
|
226
|
+
# ContentType.LEFT_CHAT_MEMBER,
|
|
227
|
+
ContentType.SUPERGROUP_CHAT_CREATED,
|
|
228
|
+
ContentType.NEW_CHAT_PHOTO,
|
|
229
|
+
# ContentType.FORUM_TOPIC_CREATED,
|
|
230
|
+
# ContentType.FORUM_TOPIC_EDITED,
|
|
231
|
+
# ContentType.FORUM_TOPIC_CLOSED,
|
|
232
|
+
}
|
|
233
|
+
)
|
|
234
|
+
)
|
|
145
235
|
async def del_cbq(msg: Message):
|
|
146
236
|
await msg.delete()
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from aiogram import Router, F
|
|
2
|
+
from aiogram.types import Message
|
|
3
|
+
from xync_schema.models import User
|
|
4
|
+
|
|
5
|
+
r = Router()
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# @main.message(F.chat.is_forum)
|
|
9
|
+
@r.message(F.is_topic_message)
|
|
10
|
+
async def order_msg(msg: Message):
|
|
11
|
+
await User[msg.from_user.id]
|
|
12
|
+
msg.message_thread_id
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|