Exemplo n.º 1
0
def welcome(bot: Bot, update: Update, session):
    newbie(bot, update)
    global last_welcome
    print('welcome')
    if update.message.chat.type in ['group', 'supergroup']:
        group = update_group(update.message.chat, session)
        for new_chat_member in update.message.new_chat_members:
            user = add_user(new_chat_member, session)
            print(user)
            administrator = session.query(Admin).filter_by(
                user_id=user.id).all()
            allow_anywhere = False
            for adm in administrator:
                if adm.admin_type == AdminType.FULL.value:
                    allow_anywhere = True
                    break
            print(update.message.chat.id)
            print(VENTURE_CHAT_ID == update.message.chat.id)
            if str(update.message.chat.id) == VENTURE_CHAT_ID:
                print('equal')
                if group.welcome_enabled:
                    print('enable_welcome')
                    welcome_msg = session.query(WelcomeMsg).filter_by(
                        chat_id=group.id).first()
                    send_async(bot,
                               chat_id=update.message.chat.id,
                               text=fill_template(welcome_msg.message, user))
            elif user is None and not allow_anywhere and user.id != bot.id:
                send_async(bot, chat_id=update.message.chat.id)
                bot.restrictChatMember(update.message.chat.id,
                                       new_chat_member.id)

            else:
                if group.welcome_enabled:
                    welcome_msg = session.query(WelcomeMsg).filter_by(
                        chat_id=group.id).first()
                    if welcome_msg is None:
                        welcome_msg = WelcomeMsg(chat_id=group.id,
                                                 message=MSG_WELCOME_DEFAULT)
                        session.add(welcome_msg)

                    welcomed = session.query(Wellcomed).filter_by(
                        user_id=new_chat_member.id,
                        chat_id=update.message.chat.id).first()
                    if welcomed is None:
                        if time() - last_welcome > 30:
                            send_async(bot,
                                       chat_id=update.message.chat.id,
                                       text=fill_template(
                                           welcome_msg.message, user))
                            last_welcome = time()
                        welcomed = Wellcomed(user_id=new_chat_member.id,
                                             chat_id=update.message.chat.id)
                        session.add(welcomed)
                    session.commit()
Exemplo n.º 2
0
def newbie(bot: Bot, update: Update):
    if update.message.chat.id in [-1001045426965]:
        if update.message.new_chat_member is not None:
            session = Session()
            user = session.query(User).filter(
                User.id == update.message.new_chat_member.id).first()
            if user is None:
                group = session.query(Group).filter(
                    Group.id == -1001146975451).first()
                if group is not None:
                    send_async(bot,
                               chat_id=group.id,
                               text=fill_template(
                                   MSG_NEWBIE, update.message.new_chat_member))
Exemplo n.º 3
0
def newbie(bot: Bot, update: Update, session):
    if ACADEM_CHAT_ID and CASTLE_CHAT_ID:
        if update.message.chat.id in [CASTLE_CHAT_ID]:
            for new_chat_member in update.message.new_chat_members:
                user = session.query(User).filter(
                    User.id == new_chat_member.id).first()
                if user is None:
                    group = session.query(Group).filter(
                        Group.id == ACADEM_CHAT_ID).first()
                    if group is not None:
                        send_async(bot,
                                   chat_id=group.id,
                                   text=fill_template(MSG_NEWBIE,
                                                      new_chat_member))
Exemplo n.º 4
0
def welcome(bot: Bot, update: Update):
    newbie(bot, update)
    global last_welcome
    if update.message.chat.type in ['group', 'supergroup']:
        group = update_group(update.message.chat)
        for new_chat_member in update.message.new_chat_members:
            session = Session()
            user = add_user(new_chat_member)
            administrator = session.query(Admin).filter_by(
                user_id=user.id).all()
            allow_anywhere = False
            for adm in administrator:
                if adm.admin_type == AdminType.FULL.value:
                    allow_anywhere = True
                    break
            if len(group.squad) == 1 and group.squad[0].thorns_enabled and user.id != 386494081 and \
                    (user.member or user.member not in group.squad[0].members) and not allow_anywhere:
                send_async(bot,
                           chat_id=update.message.chat.id,
                           text=MSG_THORNS.format(str(user)))
                bot.kickChatMember(update.message.chat.id, new_chat_member.id)
                bot.unbanChatMember(update.message.chat.id, new_chat_member.id)
            else:
                if group.welcome_enabled:
                    welcome_msg = session.query(WelcomeMsg).filter_by(
                        chat_id=group.id).first()
                    if welcome_msg is None:
                        welcome_msg = WelcomeMsg(chat_id=group.id,
                                                 message=MSG_WELCOME_DEFAULT)
                        session.add(welcome_msg)

                    welcomed = session.query(Wellcomed).filter_by(
                        user_id=new_chat_member.id,
                        chat_id=update.message.chat.id).first()
                    if welcomed is None:
                        if time() - last_welcome > 30:
                            send_async(bot,
                                       chat_id=update.message.chat.id,
                                       text=fill_template(
                                           welcome_msg.message, user))
                            last_welcome = time()
                        welcomed = Wellcomed(user_id=new_chat_member.id,
                                             chat_id=update.message.chat.id)
                        session.add(welcomed)
                    session.commit()