예제 #1
0
def mentionOneVideo(bot, message):
    if message.chat.type != 'private':
        listUser = []
        repliedUser = ''
        if message.caption is not None:
            listUser = botFunctions.mentionedList(message.chat.id, message.caption)
        if message.reply_to_message is not None:
            mentionedUser = botFunctions.getName(message.reply_to_message.from_user)
            if not message.reply_to_message.from_user.is_bot:
                if botFunctions.memberInTheGroup(bot, message.chat.id, message.reply_to_message.from_user.id):
                    if botFunctions.memberInTheGroup(bot, message.chat.id, message.reply_to_message.from_user.id) and str(message.from_user.id) != str(message.reply_to_message.from_user.id):
                        try:
                            bot.send_message(chat_id=message.reply_to_message.from_user.id,
                                             text=botFunctions.getName(
                                                 message.from_user) + ' @ <b>' + message.chat.title + '</b> : reply as a Video',
                                             parse_mode='HTML')
                        except:
                            print('reply to video failed')
                        listUser.append(str(message.reply_to_message.from_user.id))
                        listUser = list(set(listUser))
                    else:
                        if str(message.reply_to_message.from_user.id) in listUser:
                            listUser.remove(str(message.reply_to_message.from_user.id))
        else:
            mentionedUser = botFunctions.getName(message.from_user)
        if len(listUser) > 0:
            for uname in listUser:
                if botFunctions.memberInTheGroup(bot, message.chat.id, uname) and str(message.from_user.id) != uname:
                    text = None
                    if message.caption is not None:
                        text = message.caption
                        listSUB = re.split('\W+', message.caption)
                        listSUB = list(set(listSUB))
                        for subName in botFunctions.getSubscribeName(uname):
                            for sname in listSUB:
                                if sname.lower() == subName.lower():
                                    for i in range(text.count(sname)):
                                        botFunctions.updateSubscribeNameCount(sname, uname)
                                    p = re.compile(r"\b{0}\b".format(sname))
                                    text = p.sub("<b>" + sname + "</b>", text)
                        if str(repliedUser) != uname:
                            try:
                                bot.send_message(chat_id=uname,
                                                 text=mentionedUser + ' @ <b>' + message.chat.title + '</b> : mention you in a video',
                                                 parse_mode='HTML')
                            except:
                                print("single mention/subscribe failed in video")
                    try:
                        bot.send_video(chat_id=uname, data=message.video.file_id, caption=text, parse_mode='HTML')
                    except:
                        print('single mention/subscribe failed in video')
예제 #2
0
def mentionOneText(bot, message):
    if message.chat.type != 'private':
        listUsers = botFunctions.mentionedList(message.chat.id, message.text)
        if message.reply_to_message is not None and not message.reply_to_message.from_user.is_bot and botFunctions.memberInTheGroup(bot,
                message.chat.id,
                message.reply_to_message.from_user.id):
            listUsers.append(str(message.reply_to_message.from_user.id))
            listUsers = list(set(listUsers))
        listSUB = re.split('\W+', message.text)
        listSUB = list(set(listSUB))
        if len(listUsers) > 0:
            mentionedUser = botFunctions.getName(message.from_user)
            for uname in listUsers:
                if botFunctions.memberInTheGroup(bot, message.chat.id, uname) and str(message.from_user.id) != uname:
                    content = message.text
                    for subName in botFunctions.getSubscribeName(uname):
                        for sname in listSUB:
                            if sname.lower() == subName.lower():
                                for i in range(content.count(sname)):
                                    botFunctions.updateSubscribeNameCount(sname, uname)
                                p = re.compile(r"\b{0}\b".format(sname))
                                content = p.sub("<b>" + sname + "</b>", content)
                    text = mentionedUser + ' @ <b>' + message.chat.title + '</b> : ' + content
                    try:
                        splitted_text = util.split_string(text, 3000)
                        for text in splitted_text:
                            bot.send_message(chat_id=uname, text=text, parse_mode='HTML')
                    except:
                        print('single mention/subscribe failed')
                    if message.reply_to_message is not None and str(message.reply_to_message.from_user.id) != uname:
                        try:
                            bot.forward_message(chat_id=uname, from_chat_id=message.chat.id,
                                                message_id=message.reply_to_message.message_id)
                        except:
                            print('single mention/subscribe forward failed')
예제 #3
0
def mentionAllVideo(bot, message):
    if botFunctions.checkAdmin(bot, message.chat.id, message.from_user.id) and message.chat.type != 'private':
        mentionedUser = botFunctions.getName(message.from_user)
        text = mentionedUser + ' @ <b>' + message.chat.title + '</b> : ' + message.caption
        for userid in botFunctions.getAllUsers(message.chat.id):
            if botFunctions.memberInTheGroup(bot, message.chat.id, userid):
                try:
                    bot.send_video(chat_id=userid, data=message.video.file_id, caption=text, parse_mode='HTML')
                except:
                    print('@all mention failed')
예제 #4
0
def pinnedPost(bot, message):
    mentionedUser = botFunctions.getName(message.from_user)
    text = mentionedUser + ' pinned a post @ <b>' + message.chat.title + '</b> : '
    for userid in botFunctions.getAllUsers(message.chat.id):
        if botFunctions.memberInTheGroup(bot, message.chat.id, userid):
            try:
                bot.send_message(chat_id=userid, text=text, parse_mode='HTML')
                bot.forward_message(
                    chat_id=userid,
                    from_chat_id=message.chat.id,
                    message_id=message.pinned_message.message_id)
            except:
                print('@all mention failed')
예제 #5
0
def start(bot, message):
    if botFunctions.addToAllUser(message.from_user) == 'failed':
        if botFunctions.updateToAllUser(message.from_user) == 'failed':
            try:
                bot.send_message(chat_id=message.from_user.id,
                                 text='Cannot update your details ' +
                                 botFunctions.getName(message.from_user) +
                                 " " + +emojiList.failFaceIcon)
            except:
                print('User update failed')
                bot.send_message(chat_id=admin,
                                 text='Cannot update details for ' +
                                 botFunctions.getName(message.from_user))
        else:
            try:
                bot.send_message(chat_id=message.from_user.id,
                                 text='You Already STARTed me ' +
                                 botFunctions.getName(message.from_user) +
                                 ' and updated your personal details ' +
                                 emojiList.successFaceIcon)
            except:
                print('User update failed')
    else:
        try:
            bot.send_message(chat_id=admin,
                             text='Bot started for ' +
                             botFunctions.getName(message.from_user))
            bot.send_message(chat_id=message.from_user.id,
                             text='Thank you for STARTing me ' +
                             botFunctions.getName(message.from_user) + " " +
                             emojiList.successFaceIcon)
        except:
            print('User start failed')
    if message.chat.type == 'private':
        if botFunctions.memberInTheGroup(bot, configuration.RsLKID,
                                         message.from_user.id):
            try:
                bot.send_message(chat_id=message.from_user.id,
                                 text=welcomeMessage.formDetails(
                                     botFunctions.getName(message.from_user)),
                                 parse_mode='HTML')
            except:
                print('formDetails sending failed')
        try:
            bot.send_message(chat_id=message.from_user.id,
                             text=importantNotice.subscribeNotice(),
                             parse_mode='HTML')
        except:
            print('subscribeNotice sending failed')
def replyToSticker(bot, message, types):
    if botFunctions.memberInTheGroup(
            bot, message.chat.id,
            message.reply_to_message.from_user.id) and str(
                message.from_user.id) != str(
                    message.reply_to_message.from_user.id):
        try:
            bot.send_message(chat_id=message.reply_to_message.from_user.id,
                             text=botFunctions.getName(message.from_user) +
                             ' @ <b>' + message.chat.title +
                             '</b> : reply as a Sticker',
                             parse_mode='HTML')
            bot.send_sticker(chat_id=message.reply_to_message.from_user.id,
                             data=message.sticker.file_id)
        except:
            botFunctions.exceptionHandling(message, bot, types,
                                           message.from_user)
예제 #7
0
def mentionAllText(bot, message):
    if botFunctions.checkAdmin(bot, message.chat.id, message.from_user.id) and message.chat.type != 'private':
        mentionedUser = botFunctions.getName(message.from_user)
        text = mentionedUser + ' @ <b>' + message.chat.title + '</b> : ' + message.text
        for userid in botFunctions.getAllUsers(message.chat.id):
            if botFunctions.memberInTheGroup(bot, message.chat.id, userid):
                try:
                    splitted_text = util.split_string(text, 3000)
                    for text in splitted_text:
                        bot.send_message(chat_id=userid, text=text, parse_mode='HTML')
                except:
                    print('@all mention failed')
                if message.reply_to_message is not None:
                    try:
                        bot.forward_message(chat_id=userid, from_chat_id=message.chat.id,
                                            message_id=message.reply_to_message.message_id)
                    except:
                        print('@all forward failed')
예제 #8
0
def replyToLocation(bot, message, types):
    if botFunctions.memberInTheGroup(
            bot, message.chat.id,
            message.reply_to_message.from_user.id) and str(
                message.from_user.id) != str(
                    message.reply_to_message.from_user.id):
        try:
            bot.send_message(chat_id=message.reply_to_message.from_user.id,
                             text=botFunctions.getName(message.from_user) +
                             ' @ <b>' + message.chat.title +
                             '</b> : reply as a Location',
                             parse_mode='HTML')
            bot.send_location(chat_id=message.reply_to_message.from_user.id,
                              longitude=message.location.longitude,
                              latitude=message.location.latitude)
        except:
            botFunctions.exceptionHandling(message, bot, types,
                                           message.from_user)
예제 #9
0
def mentionAllPhoto(bot, message):
    if botFunctions.checkAdmin(
            bot, message.chat.id,
            message.from_user.id) and message.chat.type != 'private':
        mentionedUser = botFunctions.getName(message.from_user)
        text = mentionedUser + ' @ <b>' + message.chat.title + '</b> : mention @all in a photo'
        for userid in botFunctions.getAllUsers(message.chat.id):
            if botFunctions.memberInTheGroup(bot, message.chat.id, userid):
                try:
                    bot.send_message(chat_id=userid,
                                     text=text,
                                     parse_mode='HTML')
                    bot.send_photo(chat_id=userid,
                                   photo=message.photo[-1].file_id,
                                   caption=message.caption,
                                   parse_mode='HTML')
                except:
                    print('@all mention failed')
예제 #10
0
def replyToContact(bot, message, types):
    if botFunctions.memberInTheGroup(
            bot, message.chat.id,
            message.reply_to_message.from_user.id) and str(
                message.from_user.id) != str(
                    message.reply_to_message.from_user.id):
        try:
            bot.send_message(chat_id=message.reply_to_message.from_user.id,
                             text=botFunctions.getName(message.from_user) +
                             ' @ <b>' + message.chat.title +
                             '</b> : reply as a Contact',
                             parse_mode='HTML')
            if message.contact.last_name is not None:
                bot.send_contact(chat_id=message.reply_to_message.from_user.id,
                                 phone_number=message.contact.phone_number,
                                 first_name=message.contact.first_name,
                                 last_name=message.contact.last_name)
            else:
                bot.send_contact(chat_id=message.reply_to_message.from_user.id,
                                 phone_number=message.contact.phone_number,
                                 first_name=message.contact.first_name)
        except:
            botFunctions.exceptionHandling(message, bot, types,
                                           message.from_user)