コード例 #1
0
async def raw_say(message: Message, name, collection):
    user = message.new_chat_members[0] if name == "Welcome" \
        else message.left_chat_member
    user_dict = await userge.get_user_dict(user.id)
    user_dict.update(
        {'chat': message.chat.title if message.chat.title else "this group"})

    found = collection.find_one({'_id': message.chat.id}, {
        'media': 0,
        'name': 0
    })

    caption = found['data']
    file_type = found['type'] if 'type' in found else ''
    file_id = found['fid'] if 'fid' in found else ''
    file_ref = found['fref'] if 'fref' in found else ''

    if caption:
        caption = caption.format_map(SafeDict(**user_dict))

    if file_id:
        try:
            await send_proper_type(message, caption, file_type, file_id,
                                   file_ref)

        except (FileIdInvalid, FileReferenceEmpty, BadRequest):
            found = collection.find_one({'_id': message.chat.id}, {
                'media': 1,
                'name': 1
            })

            file_name = found['name']
            media = found['media']

            tmp_media_path = os.path.join(Config.DOWN_PATH, file_name)

            with open(tmp_media_path, "wb") as media_file:
                media_file.write(base64.b64decode(media))

            file_id, file_ref = await send_proper_type(message, caption,
                                                       file_type,
                                                       tmp_media_path)

            collection.update_one({'_id': message.chat.id},
                                  {"$set": {
                                      'fid': file_id,
                                      'fref': file_ref
                                  }},
                                  upsert=True)

            os.remove(tmp_media_path)

    else:
        await message.reply(caption, del_in=Config.WELCOME_DELETE_TIMEOUT)

    message.stop_propagation()
コード例 #2
0
ファイル: welcome.py プロジェクト: souvik30/userge
async def raw_say(message: Message, name, collection):
    users = message.new_chat_members if name == "Welcome" else [message.left_chat_member]
    for user in users:
        found = await collection.find_one({'_id': message.chat.id})
        if 'mid' not in found:
            return
        await CHANNEL.forward_stored(client=message.client,
                                     message_id=found['mid'],
                                     chat_id=message.chat.id,
                                     user_id=user.id,
                                     reply_to_message_id=message.message_id,
                                     del_in=Config.WELCOME_DELETE_TIMEOUT)
    message.stop_propagation()