mirror of
https://github.com/wah-su/stickerbridge.git
synced 2025-04-17 14:54:40 +00:00
Single status code for MatrixReuploader
This commit is contained in:
parent
0f41c6f0b7
commit
f5529744f6
2 changed files with 29 additions and 31 deletions
|
@ -46,31 +46,31 @@ class Command:
|
||||||
pack_name = self.args[0]
|
pack_name = self.args[0]
|
||||||
reuploader = MatrixReuploader(self.client, self.room, exporter=self.tg_exporter)
|
reuploader = MatrixReuploader(self.client, self.room, exporter=self.tg_exporter)
|
||||||
async for status in reuploader.import_stickerset_to_room(pack_name):
|
async for status in reuploader.import_stickerset_to_room(pack_name):
|
||||||
|
text = 'Warning: Unknown status'
|
||||||
if status == MatrixReuploader.STATUS_DOWNLOADING:
|
if status == MatrixReuploader.STATUS_DOWNLOADING:
|
||||||
text = f'Downloading stickerpack {pack_name}...'
|
text = f'Downloading stickerpack {pack_name}...'
|
||||||
if status == MatrixReuploader.STATUS_UPLOADING:
|
if status == MatrixReuploader.STATUS_UPLOADING:
|
||||||
text = f'Uploading stickerpack {pack_name}...'
|
text = f'Uploading stickerpack {pack_name}...'
|
||||||
if status == MatrixReuploader.STATUS_UPDATING_ROOM_STATE:
|
if status == MatrixReuploader.STATUS_UPDATING_ROOM_STATE:
|
||||||
text = f'Updating room state...️'
|
text = f'Updating room state...️'
|
||||||
await send_text_to_room(self.client, self.room.room_id, text)
|
|
||||||
|
|
||||||
if reuploader.result == MatrixReuploader.RESULT_OK:
|
if status == MatrixReuploader.STATUS_OK:
|
||||||
text = 'Done 😄'
|
text = 'Done 😄'
|
||||||
if reuploader.result == MatrixReuploader.RESULT_NO_PERMISSION:
|
if status == MatrixReuploader.STATUS_NO_PERMISSION:
|
||||||
text = (
|
text = (
|
||||||
'I do not have permissions to create any stickerpack in this room\n'
|
'I do not have permissions to create any stickerpack in this room\n'
|
||||||
'Please, give me mod 🙏'
|
'Please, give me mod 🙏'
|
||||||
)
|
)
|
||||||
if reuploader.result == MatrixReuploader.RESULT_PACK_EXISTS:
|
if status == MatrixReuploader.STATUS_PACK_EXISTS:
|
||||||
text = (
|
text = (
|
||||||
f"Stickerpack '{pack_name}' already exists.\n"
|
f"Stickerpack '{pack_name}' already exists.\n"
|
||||||
'Please delete it first.'
|
'Please delete it first.'
|
||||||
)
|
)
|
||||||
if reuploader.result == MatrixReuploader.RESULT_PACK_EMPTY:
|
if status == MatrixReuploader.STATUS_PACK_EMPTY:
|
||||||
text = (
|
text = (
|
||||||
f'Warning: Telegram pack {pack_name} find out empty or not existing.'
|
f'Warning: Telegram pack {pack_name} find out empty or not existing.'
|
||||||
)
|
)
|
||||||
await send_text_to_room(self.client, self.room.room_id, text)
|
await send_text_to_room(self.client, self.room.room_id, text)
|
||||||
|
|
||||||
async def _unknown_command(self):
|
async def _unknown_command(self):
|
||||||
await send_text_to_room(
|
await send_text_to_room(
|
||||||
|
|
|
@ -9,14 +9,14 @@ from telegram_exporter import TelegramExporter
|
||||||
|
|
||||||
class MatrixReuploader:
|
class MatrixReuploader:
|
||||||
|
|
||||||
RESULT_OK = 0
|
STATUS_OK = 0
|
||||||
RESULT_NO_PERMISSION = 1
|
STATUS_NO_PERMISSION = 1
|
||||||
RESULT_PACK_EXISTS = 2
|
STATUS_PACK_EXISTS = 2
|
||||||
RESULT_PACK_EMPTY = 3
|
STATUS_PACK_EMPTY = 3
|
||||||
|
|
||||||
STATUS_DOWNLOADING = 1
|
STATUS_DOWNLOADING = 4
|
||||||
STATUS_UPLOADING = 2
|
STATUS_UPLOADING = 5
|
||||||
STATUS_UPDATING_ROOM_STATE = 3
|
STATUS_UPDATING_ROOM_STATE = 6
|
||||||
|
|
||||||
def __init__(self, client: AsyncClient, room: MatrixRoom, exporter: TelegramExporter = None,
|
def __init__(self, client: AsyncClient, room: MatrixRoom, exporter: TelegramExporter = None,
|
||||||
pack: list[Sticker] = None):
|
pack: list[Sticker] = None):
|
||||||
|
@ -29,19 +29,17 @@ class MatrixReuploader:
|
||||||
self.exporter = exporter
|
self.exporter = exporter
|
||||||
self.pack = pack
|
self.pack = pack
|
||||||
|
|
||||||
self.result = -1
|
|
||||||
|
|
||||||
async def _has_permission_to_upload(self) -> bool:
|
async def _has_permission_to_upload(self) -> bool:
|
||||||
return await has_permission(self.client, self.room.room_id, 'state_default')
|
return await has_permission(self.client, self.room.room_id, 'state_default')
|
||||||
|
|
||||||
async def import_stickerset_to_room(self, pack_name: str):
|
async def import_stickerset_to_room(self, pack_name: str):
|
||||||
if not await self._has_permission_to_upload():
|
if not await self._has_permission_to_upload():
|
||||||
self.result = self.RESULT_NO_PERMISSION
|
yield self.STATUS_NO_PERMISSION
|
||||||
return
|
return
|
||||||
|
|
||||||
stickerset = MatrixStickerset(pack_name)
|
stickerset = MatrixStickerset(pack_name)
|
||||||
if await is_stickerpack_existing(self.client, self.room.room_id, stickerset.name()):
|
if await is_stickerpack_existing(self.client, self.room.room_id, stickerset.name()):
|
||||||
self.result = self.RESULT_PACK_EXISTS
|
yield self.STATUS_PACK_EXISTS
|
||||||
return
|
return
|
||||||
|
|
||||||
yield self.STATUS_DOWNLOADING
|
yield self.STATUS_DOWNLOADING
|
||||||
|
@ -54,10 +52,10 @@ class MatrixReuploader:
|
||||||
stickerset.add_sticker(sticker_mxc, sticker.alt_text)
|
stickerset.add_sticker(sticker_mxc, sticker.alt_text)
|
||||||
|
|
||||||
if not stickerset.count():
|
if not stickerset.count():
|
||||||
self.result = self.RESULT_PACK_EMPTY
|
yield self.STATUS_PACK_EMPTY
|
||||||
return
|
return
|
||||||
|
|
||||||
yield self.STATUS_UPDATING_ROOM_STATE
|
yield self.STATUS_UPDATING_ROOM_STATE
|
||||||
await upload_stickerpack(self.client, self.room.room_id, stickerset)
|
await upload_stickerpack(self.client, self.room.room_id, stickerset)
|
||||||
|
|
||||||
self.result = self.RESULT_OK
|
yield self.STATUS_OK
|
||||||
|
|
Loading…
Add table
Reference in a new issue