コード例 #1
0
def leaveGroup(bot, update):
    bd.startWithCommand(bot, update)

    if update.effective_chat != None and update.effective_chat.type != "private":
        admin = False

        if bd.message.chat.all_members_are_administrators:
            admin = True
        else:
            for adminMember in bd.message.chat.get_administrators():
                if adminMember['user']['id'] is bd.user_id:
                    admin = True

        if bd.user_id in bd.chat_id_authorized or admin:
            bot.sendMessage(chat_id=bd.chat_id,
                            text=ms.leaving,
                            reply_to_message_id=bd.message.message_id)
            bot.getChat(chat_id=bd.chat_id).leave()
        else:
            bot.sendMessage(chat_id=bd.chat_id,
                            text=ms.notAdmin[randint(0,
                                                     len(ms.notAdmin) - 1)],
                            reply_to_message_id=bd.message.message_id)
            bd.userNotAuthorizedMessage(bot, update)
    else:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.notGroupLeave,
                        reply_to_message_id=bd.message.message_id)
コード例 #2
0
def updateP(bot, update):
    bd.startWithCommand(bot, update)

    if bd.user_id in bd.chat_id_authorized:
        if system() == "Linux":
            try:
                bot.sendMessage(chat_id=bd.chat_id_authorized[1],
                                text=ms.updating)
                call(
                    "wget -qP /$HOME/EventsBot/ https://api.github.com/repos/javigines/EventsBot-CoreDumped/tarball/master",
                    shell=True)
                call("tar -xzf /$HOME/EventsBot/master -C $HOME", shell=True)
                call("rm -f /$HOME/EventsBot/master*", shell=True)
                call(
                    "cp -rf $HOME/javigines-EventsBot-CoreDumped-*/* $HOME/EventsBot/ ",
                    shell=True)
                call("rm -rf $HOME/javigines-EventsBot-CoreDumped-*/",
                     shell=True)

                bot.sendMessage(chat_id=bd.chat_id_authorized[1],
                                text=ms.updateDone)
            except Exception as e:
                bd.exceptionHandler(bot, update, __name__, e)

        else:
            bot.sendMessage(chat_id=bd.chat_id,
                            text=ms.updateWrongOS,
                            reply_to_message_id=bd.message.message_id)

    else:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.notAdmin[randint(0,
                                                 len(ms.notAdmin) - 1)],
                        reply_to_message_id=bd.message.message_id)
コード例 #3
0
def downloadP(bot, update, args):
    bd.startWithCommand(bot, update, args)

    if bd.user_id in bd.chat_id_authorized[:2]:
        try:
            if args == "" or args == None or args == [] or args == {}:
                bot.sendMessage(chat_id=bd.chat_id,
                                text=ms.downloadNoArgs,
                                reply_to_message_id=bd.message.message_id)
            else:
                bot.sendMessage(chat_id=bd.chat_id, text=ms.downloadInProgress)
                fileDocument = open("".join(args), mode="rb")
                bot.sendDocument(chat_id=bd.chat_id_authorized[1],
                                 document=fileDocument,
                                 reply_to_message_id=bd.message.message_id)
                fileDocument.close()
                bot.sendMessage(chat_id=bd.chat_id, text=ms.downloadComplete)
        except Exception as e:
            bd.exceptionHandler(bot, update, __name__, e, args)

    else:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.notAdmin[randint(0,
                                                 len(ms.notAdmin) - 1)],
                        reply_to_message_id=bd.message.message_id)
コード例 #4
0
def changelog(bot, update):
    bd.startWithCommand(bot, update)

    if bd.user_id in bd.chat_id_authorized or bd.user_id == bd.chat_id:
        try:
            changelogStr = ""
            changelog = open("CHANGELOG.md", mode="r")
            changelogTemp = changelog.read()
            changelog.close()
            changelogTemp = ms.changelogMessage.replace(
                '$args1', "## [" + changelogTemp.split("## [")[2]).replace(
                    '$args2', "## [" + changelogTemp.split("## [")[1])
            changelogTemp = changelogTemp.split("\n")
            for line in changelogTemp:
                if "###" in line:
                    line = line.replace("###", "_") + "_"
                if "##" in line:
                    line = line.replace("##", "*") + "*"
                changelogStr += line + "\n"
            bot.sendMessage(chat_id=bd.chat_id,
                            text=changelogStr,
                            reply_to_message_id=bd.message.message_id,
                            parse_mode="MARKDOWN")
        except Exception as e:
            bd.exceptionHandler(bot, update, __name__, e)

    else:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.groupChangelogUser,
                        reply_to_message_id=bd.message.message_id)
コード例 #5
0
def getLogP(bot, update):
    bd.startWithCommand(bot, update)

    if bd.user_id in bd.chat_id_authorized:
        try:
            bot.sendMessage(chat_id=bd.chat_id,
                            text=ms.downloadInProgress,
                            reply_to_message_id=bd.message.message_id)
            fileLog = open(
                logging.getLoggerClass().root.handlers[0].baseFilename, "rb")
            bot.sendDocument(chat_id=bd.chat_id_authorized[1],
                             document=fileLog)
            fileLog.close()
            bot.sendMessage(chat_id=bd.chat_id,
                            text=ms.downloadComplete,
                            reply_to_message_id=bd.message.message_id)
            log.info("Log Download By User")
        except Exception as e:
            bd.exceptionHandler(bot, update, __name__, e)

    else:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.notAdmin[randint(0,
                                                 len(ms.notAdmin) - 1)],
                        reply_to_message_id=bd.message.message_id)
コード例 #6
0
def start(bot, update):
    bd.startWithCommand(bot, update)

    if bd.user_id in bd.chat_id_authorized:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.helpOrStartAdmin,
                        reply_to_message_id=bd.message.message_id,
                        disable_web_page_preview=True,
                        parse_mode="MARKDOWN")
    else:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.helpOrStart,
                        reply_to_message_id=bd.message.message_id,
                        disable_web_page_preview=True,
                        parse_mode="MARKDOWN")
コード例 #7
0
def contact(bot, update, args):
    bd.startWithCommand(bot, update)

    if args is None or args == '' or args == []:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.contactNoMessage,
                        reply_to_message_id=bd.message.message_id)

    else:
        bot.sendMessage(
            chat_id=bd.chat_id_authorized[0],
            text=ms.contactMessage.replace('$args1', bd.username).replace(
                '$args2', str(bd.user_id)).replace('$args3', ' '.join(args)))
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.messageSend,
                        reply_to_message_id=bd.message.message_id)
コード例 #8
0
def birthdayRemove(bot, update, args=None):
    bd.startWithCommand(bot, update, args)

    if bot.get_chat_member(chat_id=bd.chat_id_CoreDumped,
                           user_id=bd.user_id).status in [
                               'creator', 'administrator', 'member'
                           ]:
        eventList = ef.birthdayListFunction(args=args)

        if bd.user_id not in bd.chat_id_authorized and bot.get_chat_member(
                chat_id=bd.chat_id_CoreDumped,
                user_id=bd.user_id).status not in ['creator', 'administrator']:
            bot.sendMessage(chat_id=bd.chat_id,
                            text=ms.notAdmin[randint(0,
                                                     len(ms.notAdmin) - 1)],
                            reply_to_message_id=bd.message.message_id)

        else:
            if not ef.birthdayCheckFunction(str(''.join(args))):
                bot.sendMessage(chat_id=bd.chat_id,
                                reply_to_message_id=bd.message.message_id,
                                text=ms.removeFailNotUser.replace(
                                    "$args1", str(''.join(args))))

            else:
                result = ef.birthdayRemoveFunction(args=args)
                if (result is None or result == {} or result == []
                        or result == ""):
                    bot.sendMessage(chat_id=bd.chat_id,
                                    reply_to_message_id=bd.message.message_id,
                                    text=ms.removeFailNotUser.replace(
                                        "$args1", str(''.join(args))))

                elif (result == 1):
                    bot.sendMessage(chat_id=bd.chat_id,
                                    text=ms.formatErrorRemoveB,
                                    reply_to_message_id=bd.message.message_id)

                else:
                    bot.sendMessage(chat_id=bd.chat_id,
                                    reply_to_message_id=bd.message.message_id,
                                    text=ms.removeBirthdayDone.replace(
                                        "$args1", str(''.join(args))))
    else:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.restrictBirthday,
                        reply_to_message_id=bd.message.message_id)
コード例 #9
0
def publiP(bot, update):
    bd.startWithCommand(bot, update)

    if bd.user_id in bd.chat_id_authorized:
        try:
            bot.sendMessage(chat_id=bd.chat_id,
                            text=ms.spamMessage[randint(
                                0,
                                len(ms.spamMessage) - 1)],
                            reply_to_message_id=bd.message.message_id)
        except Exception as e:
            bd.exceptionHandler(bot, update, __name__, e)

    else:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.notAdmin[randint(0,
                                                 len(ms.notAdmin) - 1)],
                        reply_to_message_id=bd.message.message_id)
コード例 #10
0
def birthdayAdd(bot, update, args=None):
    bd.startWithCommand(bot, update, args)

    if bot.get_chat_member(chat_id=bd.chat_id_CoreDumped,
                           user_id=bd.user_id).status in [
                               'creator', 'administrator', 'member'
                           ]:
        eventList = ef.birthdayListFunction(args=args)

        if ef.birthdayCheckFunction(str(bd.user_id)):
            bot.sendMessage(chat_id=bd.chat_id,
                            text=ms.askForDelete,
                            reply_to_message_id=bd.message.message_id)

        else:
            result = ef.birthdayAddFunction(args=args,
                                            summary=(bd.username + '|' +
                                                     str(bd.user_id)))
            if (result is None or result == {} or result == []
                    or result == ""):
                bot.sendMessage(chat_id=bd.chat_id,
                                text=ms.notDate,
                                reply_to_message_id=bd.message.message_id)

            elif (result == 1):
                bot.sendMessage(chat_id=bd.chat_id,
                                text=ms.formatErrorBirthday,
                                reply_to_message_id=bd.message.message_id)

            elif (result == 2):
                bot.sendMessage(chat_id=bd.chat_id,
                                text=ms.notValidBirthday,
                                reply_to_message_id=bd.message.message_id)

            else:
                bot.sendMessage(chat_id=bd.chat_id,
                                reply_to_message_id=bd.message.message_id,
                                text=ms.newBirthdayAdded.replace(
                                    "$args1", bd.username).replace(
                                        "$args2", ' '.join(args)))
    else:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.restrictBirthday,
                        reply_to_message_id=bd.message.message_id)
コード例 #11
0
def eventList(bot, update, args=None):
    bd.startWithCommand(bot, update, args)

    eventList = ef.eventListFunction(args=args)

    if (eventList is None or eventList == {} or eventList == []
            or eventList == ""):
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.noEventSaved,
                        reply_to_message_id=bd.message.message_id)

    elif (eventList == 1):
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.dateUnknown,
                        reply_to_message_id=bd.message.message_id)

    else:
        formatedEventList = ''
        lap = 1
        for event in eventList:
            date = timezone('UTC').localize(
                datetime.strptime(
                    event['start']['dateTime'],
                    '%Y-%m-%dT%H:%M:%SZ')).astimezone(
                        timezone('Europe/Madrid')).strftime("%d-%m-%Y %H:%M")
            formatedEventList += (str(lap) + '. ' + event['summary'] + ': ' +
                                  date + '\nMore Info: /info_' + event['id'] +
                                  '\n\n')
            lap += 1
        if bd.user_id in bd.chat_id_authorized or bot.get_chat_member(
                chat_id=bd.chat_id_CoreDumped,
                user_id=bd.user_id).status in ['creator', 'administrator']:
            bot.sendMessage(chat_id=bd.chat_id,
                            text=formatedEventList,
                            reply_to_message_id=bd.message.message_id)
        else:
            if (bd.chat_id != bd.user_id):
                bot.sendMessage(chat_id=bd.chat_id,
                                text=ms.groupListUser,
                                reply_to_message_id=bd.message.message_id)
            else:
                bot.sendMessage(chat_id=bd.chat_id,
                                text=formatedEventList,
                                reply_to_message_id=bd.message.message_id)
コード例 #12
0
def clearLogP(bot, update):
    bd.startWithCommand(bot, update)

    if bd.user_id in bd.chat_id_authorized:
        try:
            getLogP(bot, update)
            with open(logging.getLoggerClass().root.handlers[0].baseFilename,
                      "w"):
                pass
            bot.sendMessage(chat_id=bd.chat_id,
                            text=ms.clearlogComplete,
                            reply_to_message_id=bd.message.message_id)
            log.info("Log Clean By User")
        except Exception as e:
            bd.exceptionHandler(bot, update, __name__, e)

    else:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.notAdmin[randint(0,
                                                 len(ms.notAdmin) - 1)],
                        reply_to_message_id=bd.message.message_id)
コード例 #13
0
def eventRemove(bot, update, groups=None):
    bd.startWithCommand(bot, update, groups)

    if bd.user_id not in bd.chat_id_authorized and bot.get_chat_member(
            chat_id=bd.chat_id_CoreDumped,
            user_id=bd.user_id).status not in ['creator', 'administrator']:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.notAdmin[randint(0,
                                                 len(ms.notAdmin) - 1)],
                        reply_to_message_id=bd.message.message_id)

    else:
        args = bd.message.text.split(' ')[0][9:].replace(
            "@" + bot.username, "")
        if not ef.eventCheckFunction(str(''.join(args))):
            bot.sendMessage(chat_id=bd.chat_id,
                            reply_to_message_id=bd.message.message_id,
                            text=ms.removeFailNotEvent.replace(
                                "$args1", str(''.join(args))))

        else:
            result = ef.eventRemoveFunction(args=args)
            if (result is None or result == {} or result == []
                    or result == ""):
                bot.sendMessage(chat_id=bd.chat_id,
                                reply_to_message_id=bd.message.message_id,
                                text=ms.removeFailNotEvent.replace(
                                    "$args1", str(''.join(args))))

            elif (result == 1):
                bot.sendMessage(chat_id=bd.chat_id,
                                text=ms.formatErrorRemoveE,
                                reply_to_message_id=bd.message.message_id)

            else:
                bot.sendMessage(chat_id=bd.chat_id,
                                reply_to_message_id=bd.message.message_id,
                                text=ms.removeEventDone.replace(
                                    "$args1", str(''.join(args))))
コード例 #14
0
def restartP(bot, update):
    bd.startWithCommand(bot, update)

    if bd.user_id in bd.chat_id_authorized:
        if system() == "Linux":
            try:
                bot.sendMessage(chat_id=bd.chat_id,
                                text=ms.restarting,
                                reply_to_message_id=bd.message.message_id)
                call("./startBot.sh " + str(getpid()), shell=True)
            except Exception as e:
                bd.exceptionHandler(bot, update, __name__, e)

        else:
            bot.sendMessage(chat_id=bd.chat_id,
                            text=ms.restartWrongOS,
                            reply_to_message_id=bd.message.message_id)
    else:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.notAdmin[randint(0,
                                                 len(ms.notAdmin) - 1)],
                        reply_to_message_id=bd.message.message_id)
        bd.userNotAuthorizedMessage(bot, update)
コード例 #15
0
def eventAdd(bot, update, args=None):
    bd.startWithCommand(bot, update, args)

    if bd.user_id not in bd.chat_id_authorized and bot.get_chat_member(
            chat_id=bd.chat_id_CoreDumped,
            user_id=bd.user_id).status not in ['creator', 'administrator']:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.notAdmin[randint(0,
                                                 len(ms.notAdmin) - 1)],
                        reply_to_message_id=bd.message.message_id)

    else:
        result = ef.eventAddFunction(args=args,
                                     data=(bd.username + '|/|' +
                                           str(bd.user_id)))
        if (result is None or result == {} or result == [] or result == ""):
            bot.sendMessage(chat_id=bd.chat_id,
                            text=ms.formatErrorEvent,
                            reply_to_message_id=bd.message.message_id)

        elif (result == 1):
            bot.sendMessage(chat_id=bd.chat_id,
                            text=ms.formatErrorEvent,
                            reply_to_message_id=bd.message.message_id)

        else:
            date = timezone('UTC').localize(
                datetime.strptime(
                    result['start']['dateTime'],
                    '%Y-%m-%dT%H:%M:%SZ')).astimezone(
                        timezone('Europe/Madrid')).strftime("%d-%m-%Y %H:%M")
            bot.sendMessage(chat_id=bd.chat_id,
                            text=ms.newEventAdded.replace(
                                "$args1",
                                result['summary']).replace("$args2", date),
                            reply_to_message_id=bd.message.message_id)
コード例 #16
0
def birthdayList(bot, update, args=None):
    bd.startWithCommand(bot, update, args)

    if bot.get_chat_member(chat_id=bd.chat_id_CoreDumped,
                           user_id=bd.user_id).status in [
                               'creator', 'administrator', 'member'
                           ]:
        eventList = ef.birthdayListFunction(args=args)

        if (eventList is None or eventList == {} or eventList == []
                or eventList == ""):
            bot.sendMessage(chat_id=bd.chat_id,
                            text=ms.noBirthdaySaved,
                            reply_to_message_id=bd.message.message_id)

        elif (eventList == 1):
            bot.sendMessage(chat_id=bd.chat_id,
                            text=ms.dateUnknown,
                            reply_to_message_id=bd.message.message_id)

        else:
            formatedEventList = ''
            lap = 1
            for event in eventList:
                date = timezone('UTC').localize(
                    datetime.strptime(
                        event['start']['date'], '%Y-%m-%d')).astimezone(
                            timezone('Europe/Madrid')).strftime("%d-%m")
                if bd.user_id not in bd.chat_id_authorized and bot.get_chat_member(
                        chat_id=bd.chat_id_CoreDumped,
                        user_id=bd.user_id).status not in [
                            'creator', 'administrator'
                        ]:
                    formatedEventList += (str(lap) + '. ' + date + ': ' +
                                          event['summary'].split('|')[0] +
                                          '\n')
                else:
                    formatedEventList += (str(lap) + '. ' + date + '-' +
                                          event['summary'].split('|')[2] +
                                          ': ' +
                                          event['summary'].split('|')[0] +
                                          '\n')

                lap += 1
            if bd.user_id in bd.chat_id_authorized or bot.get_chat_member(
                    chat_id=bd.chat_id_CoreDumped,
                    user_id=bd.user_id).status in ['creator', 'administrator']:
                bot.sendMessage(chat_id=bd.chat_id,
                                text=formatedEventList,
                                reply_to_message_id=bd.message.message_id)
            else:
                if (bd.chat_id != bd.user_id):
                    bot.sendMessage(chat_id=bd.chat_id,
                                    text=ms.groupListUser,
                                    reply_to_message_id=bd.message.message_id)
                else:
                    bot.sendMessage(chat_id=bd.chat_id,
                                    text=formatedEventList,
                                    reply_to_message_id=bd.message.message_id)
    else:
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.restrictBirthday,
                        reply_to_message_id=bd.message.message_id)
コード例 #17
0
def eventInfo(bot, update, groups=None):
    bd.startWithCommand(bot, update, groups)
    event = ef.eventInfoFunction(
        bd.message.text.split(' ')[0][6:].replace("@" + bot.username, ""))
    if (not event or event is None or event == {} or event == []
            or event == ""):
        bot.sendMessage(chat_id=bd.chat_id,
                        text=ms.eventNotFound,
                        reply_to_message_id=bd.message.message_id)

    else:
        eventDescription = ms.eventDescription
        eventDescription = eventDescription.replace("$args1", event['summary'])
        date = timezone('UTC').localize(
            datetime.strptime(
                event['start']['dateTime'], '%Y-%m-%dT%H:%M:%SZ')).astimezone(
                    timezone('Europe/Madrid')).strftime("%d-%m-%Y %H:%M")
        eventDescription = eventDescription.replace("$args2", date)
        if (event['description'].split('/&/')[0].split('|/|')[1].strip()
            ) != "":
            eventDescription = eventDescription.replace(
                "$args3", event['description'].split('/&/')[0].split('|/|')[1])
        else:
            eventDescription = eventDescription.replace(
                "$args3", "(No definido)")
        if (event['description'].split('/&/')[0].split('|/|')[0].strip() !=
                ""):
            eventDescription = eventDescription.replace(
                "$args4", event['description'].split('/&/')[0].split('|/|')[0])
        else:
            eventDescription = eventDescription.replace(
                "$args4", "(No definido)")
        if (event['description'].split('/&/')[0].split('|/|')[2].strip() !=
                ""):
            eventDescription = eventDescription.replace(
                "$args5", event['description'].split('/&/')[0].split('|/|')[2])
        else:
            eventDescription = eventDescription.replace(
                "$args5", "(No definido)")

        admin = False
        if update.effective_chat != None and update.effective_chat.type != "private":
            if bd.message.chat.all_members_are_administrators:
                admin = True
            else:
                for adminMember in bd.message.chat.get_administrators():
                    if adminMember['user']['id'] == bd.user_id:
                        admin = True

        if bd.user_id in bd.chat_id_authorized or admin:
            eventDescription = eventDescription.replace(
                "$args6", "Event ID: " + event['id'])
            eventDescription = eventDescription.replace(
                "$args7", "Remove Event: /removeE_" + event['id'])
        else:
            eventDescription = eventDescription.replace("$args6", "")
            eventDescription = eventDescription.replace("$args7", "")

        bot.sendMessage(chat_id=bd.chat_id,
                        text=eventDescription,
                        reply_to_message_id=bd.message.message_id)