def addDataToJson(text): global downloadData msg = Utils.replaceStr(text, "miguelito mete") msgSplitted = msg.split("#") msg = Utils.replaceStr(msg, msgSplitted[0]) # add randoms messages if msgSplitted[0] == "random": botDict['randomMsg'].append(msgSplitted[1]) elif msgSplitted[0] == "dinosaurio": botDict['dinofaurioPath'].append(msg) elif msgSplitted[0] == "mimimi": botDict['mimimimiStickerPath'].append(msg) else: msgToCheck = [] for item in msgSplitted[2].split("--"): print(item) itemSplitted = item.split("__") print(itemSplitted) msgToCheck.append( {"text": itemSplitted[0], "type": itemSplitted[1]}) downloadData = { "type": msgSplitted[0], "regexpValue": [msgSplitted[1].split("--")] if len(msgSplitted[1]) > 0 else [], "msgToCheck": msgToCheck, "randomMaxValue": int(msgSplitted[3]), "lastTimeSentIt": msgSplitted[4], "timeToIncrement": int(msgSplitted[5]), "kindTime": msgSplitted[6], "doubleMsg": bool(msgSplitted[7]), "doubleObj": {}, "notIn": [msgSplitted[8].split("--")] if len(msgSplitted[1]) > 0 else [], "isReply": False } if len(msgSplitted) > 10 and msgSplitted[10] == "true": downloadData["doubleObj"] = { "type": msgSplitted[11], "path": [], "isReply": False } if msgSplitted[0] == "text": downloadData["path"] = msgSplitted[9].split("--") botDict["keywords"].append(downloadData) saveDictionary()
def rememberJobs(bot, update, msg): #compare time with the dateConfig.json timeObject = checkTimeToRemember(msg) # check is have username in the msg usernameToNotify, msg = getUsernameToNotify(msg, update) # with key words in config json if timeObject != None: msg = msg.replace(timeObject["name"] + " ", "", 1) msg, timeObject = checkHourToRemember(msg, timeObject) msgArray = msg.split(" ") msg = Utils.replaceStr(msg, "que") now = datetime.now() now = Utils().checkRememberDate(now, timeObject, None) if datetime.now() > now: now = now + timedelta(days=1) # with dd/mm/yyyy config elif re.search(r'([0-9]+/[0-9]+/[0-9]+)', msg): msgArray = msg.split(" ") msg = Utils.replaceStr(msg, "el") dateWithoutSplit = re.search(r'([0-9]+/[0-9]+/[0-9]+)', msg) dateString = dateWithoutSplit.group(0) dateSplitted = dateString.split('/') now = datetime.now() msg = Utils.replaceStr(msg, dateString) msg = Utils.replaceStr(msg, "que") now = now.replace(int(dateSplitted[2]), int( dateSplitted[1]), int(dateSplitted[0])) timeObject = {} msg, timeObject = checkHourToRemember(msg, timeObject) now = Utils().checkRememberDate(now, timeObject, None) if datetime.now() > now: now = now + timedelta(days=1) # with weekday config or hh:mm else: msgArray = msg.split(" ") msg = Utils.replaceStr(msg, "el") found = None index = 0 while index < len(weekdayConstant) and found != True: if weekdayConstant[index] in msg: found = True msg = msg.replace(weekdayConstant[index] + " ", "", 1) else: index += 1 now = datetime.now() todayNumber = now.weekday() diffDayCount = 0 # check how many days is from today if found: if int(todayNumber) < index: diffDayCount = index - int(todayNumber) + 1 else: diffDayCount = (6 - int(todayNumber)) + index + 1 msg = Utils.replaceStr(msg, "que") timeObject = {} msg, timeObject = checkHourToRemember(msg, timeObject) now = Utils().checkRememberDate(now, timeObject, True) diffDayCount = checkDayDifference( diffDayCount, datetime.now(), timeObject) now = now + timedelta(days=diffDayCount) update.message.reply_text( "Vale", reply_to_message_id=update.message.message_id) now = now.replace(second=0) saveMessageToRemember( usernameToNotify, msg, now.isoformat()) return now