Esempio n. 1
0
async def _(event):
    if event.fwd_from:
        return
    msg = await event.get_reply_message()
    if msg:
        if get_current_welcome_settings(event.chat_id):
            msg_o = await event.client.forward_messages(
                entity=Config.PRIVATE_CHANNEL_BOT_API_ID,
                messages=msg,
                from_peer=event.chat_id,
                silent=True
            )
            add_welcome_setting(event.chat_id, True, 0, msg_o.id)
            await event.edit("Welcome Message updated. ")
        else:
            msg_o = await event.client.forward_messages(
                entity=Config.PRIVATE_CHANNEL_BOT_API_ID,
                messages=msg,
                from_peer=event.chat_id,
                silent=True
            )
            add_welcome_setting(event.chat_id, True, 0, msg_o.id)
            await event.edit("Welcome Message saved. ")
    else:
        input_str = event.text.split(None, 1)
        if get_current_welcome_settings(event.chat_id):
            rm_welcome_setting(event.chat_id)
            add_welcome_setting(event.chat_id, input_str[1], True, 0)
            await event.edit("Welcome Message updated. ")
        else:
            add_welcome_setting(event.chat_id, input_str[1], True, 0)
            await event.edit("Welcome Message saved. ")
Esempio n. 2
0
async def _(event):
    cws = get_current_welcome_settings(event.chat_id)
    if cws:
        # logger.info(event.stringify())
        """user_added=True,
        user_joined=True,
        user_left=False,
        user_kicked=False,"""
        if event.user_joined:
            if cws.should_clean_welcome:
                try:
                    await borg.delete_messages(  # pylint:disable=E0602
                        event.chat_id,
                        cws.previous_welcome
                    )
                except Exception as e:  # pylint:disable=C0103,W0703
                    logger.warn(str(e))  # pylint:disable=E0602
            a_user = await event.get_user()
            current_saved_welcome_message = cws.custom_welcome_message
            mention = "[{}](tg://user?id={})".format(a_user.first_name, a_user.id)
            current_message = await event.reply(
                current_saved_welcome_message.format(mention=mention),
                file=cws.media_file_id
            )
            update_previous_welcome(event.chat_id, current_message.id)
Esempio n. 3
0
async def _(event):
    cws = get_current_welcome_settings(event.chat_id)
    if cws:
        # logger.info(event.stringify())
        """user_added=False,
        user_joined=True,
        user_left=False,
        user_kicked=False,"""
        if event.user_joined or event.user_added:
            if cws.should_clean_welcome:
                try:
                    await event.client.delete_messages(event.chat_id,
                                                       cws.previous_welcome)
                except Exception as e:  # pylint:disable=C0103,W0703
                    logger.warn(str(e))  # pylint:disable=E0602
            a_user = await event.get_user()
            msg_o = await event.client.get_messages(
                entity=Config.PRIVATE_CHANNEL_BOT_API_ID,
                ids=int(cws.f_mesg_id))
            current_saved_welcome_message = msg_o.message
            mention = "[{}](tg://user?id={})".format(a_user.first_name,
                                                     a_user.id)
            file_media = msg_o.media
            current_message = await event.reply(
                current_saved_welcome_message.format(mention=mention),
                file=file_media)
            update_previous_welcome(event.chat_id, current_message.id)
Esempio n. 4
0
async def _(event):
    cws = get_current_welcome_settings(event.chat_id)
    if cws:
        # logger.info(event.stringify())
        """user_added=False,
        user_joined=True,
        user_left=False,
        user_kicked=False,"""
        if event.user_joined:
            if cws.should_clean_welcome:
                try:
                    await borg.delete_messages(  # pylint:disable=E0602
                        event.chat_id,
                        cws.previous_welcome
                    )
                except Exception as e:  # pylint:disable=C0103,W0703
                    logger.warn(str(e))  # pylint:disable=E0602
            try:
                user_ids = event.action_message.action.users
            except AttributeError:
                user_ids = [event.action_message.from_id]
            for user_id in user_ids:
                current_saved_welcome_message = cws.custom_welcome_message
                user_obj = await borg.get_entity(user_id)  # pylint:disable=E0602
                mention = "[{}](tg://user?id={})".format(user_obj.first_name, user_id)
                current_message = await event.reply(
                    current_saved_welcome_message.format(mention=mention)
                )
                update_previous_welcome(event.chat_id, current_message.id)
Esempio n. 5
0
async def _(event):
    cws = get_current_welcome_settings(event.chat_id)
    if cws:
        # logger.info(event.stringify())
        """user_added=False,
        user_joined=True,
        user_left=False,
        user_kicked=False,"""
        if event.user_joined or event.user_added:
            if cws.should_clean_welcome:
                try:
                    await borg.delete_messages(  # pylint:disable=E0602
                        event.chat_id, cws.previous_welcome)
                except Exception as e:  # pylint:disable=C0103,W0703
                    logger.warn(str(e))  # pylint:disable=E0602
            a_user = await event.get_user()
            current_saved_welcome_message = cws.custom_welcome_message
            mention = "[{}](tg://user?id={})".format(a_user.first_name,
                                                     a_user.id)
            file_media = None
            if cws.message_type == TYPE_PHOTO:
                file_media = types.InputPhoto(int(cws.media_id),
                                              int(cws.media_access_hash),
                                              cws.media_file_reference)
            elif cws.message_type == TYPE_DOCUMENT:
                file_media = types.InputDocument(int(cws.media_id),
                                                 int(cws.media_access_hash),
                                                 cws.media_file_reference)
            else:
                file_media = None
            #
            current_message = await event.reply(
                current_saved_welcome_message.format(mention=mention),
                file=file_media)
            update_previous_welcome(event.chat_id, current_message.id)
Esempio n. 6
0
async def _(event):
    if event.fwd_from:
        return
    cws = get_current_welcome_settings(event.chat_id)
    rm_welcome_setting(event.chat_id)
    await event.edit(
        "Welcome Message cleared. " + \
        "The previous welcome message was `{}`.".format(cws.custom_welcome_message)
    )
Esempio n. 7
0
async def _(event):
    if event.fwd_from:
        return
    cws = get_current_welcome_settings(event.chat_id)
    rm_welcome_setting(event.chat_id)
    await event.edit(
        "Welcome note cleared. " +
        "[This](https://t.me/c/{}/{}) was your previous welcome message.".
        format(str(Config.PRIVATE_CHANNEL_BOT_API_ID)[4:], cws.f_mesg_id))
Esempio n. 8
0
async def _(event):
    if event.fwd_from:
        return
    cws = get_current_welcome_settings(event.chat_id)
    rm_welcome_setting(event.chat_id)
    await event.edit(
        "`Welcome Note Cleared.` " +
        "[THIS](https://t.me/c/{}/{}) `Was Your Previous Welcome Message.`".
        format(str(Config.PRIVATE_CHANNEL_BOT_API_ID)[4:], cws.f_mesg_id))
Esempio n. 9
0
async def _(event):
    if event.fwd_from:
        return
    cws = get_current_welcome_settings(event.chat_id)
    if hasattr(cws, 'custom_welcome_message'):
        await event.edit("Welcome note found. " +
                         "Your welcome message is\n\n`{}`.".format(
                             cws.custom_welcome_message))
    else:
        await event.edit("No Welcome Message found")
Esempio n. 10
0
async def _(event):
    if event.fwd_from:
        return
    cws = get_current_welcome_settings(event.chat_id)
    if hasattr(cws, 'custom_welcome_message'):
        await event.edit(
            "Welcome Message found.\n " + \
            "Your Welcome Message is as follows:\n `{}`.".format(cws.custom_welcome_message)
        )
        return
    else:
        await event.edit("No Welcome Message found")
Esempio n. 11
0
async def _(event):
    if event.fwd_from:
        return
    msg = await event.get_reply_message()
    if msg and msg.media:
        bot_api_file_id = pack_bot_file_id(msg.media)
        if get_current_welcome_settings(event.chat_id):
            rm_welcome_setting(event.chat_id)
            add_welcome_setting(event.chat_id, msg.message, True, 0, bot_api_file_id)
            await event.edit("Welcome Message updated. ")
        else:
            add_welcome_setting(event.chat_id, msg.message, True, 0, bot_api_file_id)
            await event.edit("Welcome Message saved. ")
    else:
        input_str = event.text.split(None, 1)
        if get_current_welcome_settings(event.chat_id):
            rm_welcome_setting(event.chat_id)
            add_welcome_setting(event.chat_id, input_str[1], True, 0)
            await event.edit("Welcome Message updated. ")
        else:
            add_welcome_setting(event.chat_id, input_str[1], True, 0)
            await event.edit("Welcome Message saved. ")
Esempio n. 12
0
async def _(event):
    cws = get_current_welcome_settings(event.chat_id)
    if cws:
        # logger.info(event.stringify())
        """user_added=False,
        user_joined=True,
        user_left=False,
        user_kicked=False,"""
        if event.user_joined or event.user_added:
            if cws.should_clean_welcome:
                try:
                    await borg.delete_messages(event.chat_id,
                                               cws.previous_welcome)
                except Exception as e:  # pylint:disable=C0103,W0703
                    logger.warn(str(e))  # pylint:disable=E0602
            a_user = await event.get_user()
            chat = await event.get_chat()

            title = chat.title if chat.title else "this chat"
            participants = await event.client.get_participants(chat)
            count = len(participants)
            msg_o = await event.client.get_messages(
                entity=Config.PRIVATE_CHANNEL_BOT_API_ID,
                ids=int(cws.f_mesg_id))
            current_saved_welcome_message = msg_o.message
            file_media = msg_o.media
            mention = "[{}](tg://user?id={})".format(a_user.first_name,
                                                     a_user.id)
            first = a_user.first_name
            last = a_user.last_name
            if last:
                fullname = f"{first} {last}"
            else:
                fullname = first
            username = f"@{a_user.username}" if a_user.username else mention
            userid = a_user.id
            current_saved_welcome_message = cws.custom_welcome_message
            mention = "[{}](tg://user?id={})".format(a_user.first_name,
                                                     a_user.id)

            current_message = await event.reply(
                current_saved_welcome_message.format(mention=mention,
                                                     title=title,
                                                     count=count,
                                                     first=first,
                                                     last=last,
                                                     fullname=fullname,
                                                     username=username,
                                                     userid=userid),
                file=cws.file_media)
            update_previous_welcome(event.chat_id, current_message.id)
Esempio n. 13
0
async def _(event):
    if event.fwd_from:
        return
    cws = get_current_welcome_settings(event.chat_id)
    if hasattr(cws, 'custom_welcome_message'):
        await event.edit(
            "Welcome Message found.\n " + \
            "[This](https://t.me/c/{}/{}) is your welcome message.".format(
            Config.PRIVATE_CHANNEL_BOT_API_ID[4:],
            cws.f_mesg_id
        ))
    else:
        await event.edit(
            "No Welcome Message found"
        )