def tomato_bell_reply(msg): try: if msg['Text'] in reply_url: return "【欢迎访问小鲜果儿~】\n主页:\nhttp://liguo.zzl99.cn:8000/admin/remind/remind/" \ "\n去注册:\nhttp://liguo.zzl99.cn:8000/" elif check_tomato_bell(msg['Text']): # 定时番茄钟 # fqz 个数 分钟数 提醒内容 fruiter = Fruiter.objects.filter(wechat_remark_name=msg['User']['RemarkName']).first() if not fruiter: return '请先注册小鲜果儿账号,点这里:http://liguo.zzl99.cn:8000/' tmb = TomatoBell.objects.filter(fruiter=fruiter, turn_on=True).first() if tmb: return '已创建番茄钟,请集中精力完成,切不可贪心哦~' else: _, amount, minutes, *tomato_name = msg['Text'].split() tomato_name = ' '.join(tomato_name) amount, minutes = int(amount), int(minutes) data = dict(fruiter=fruiter, amount=amount, minutes=minutes, tomato_name=tomato_name, turn_on=True) TomatoBell.objects.create(**data) global scheduler_tomato_bell scheduler_tomato_bell = BackgroundScheduler() run_date = (datetime.now() + timedelta(minutes=minutes)).replace(microsecond=0) # run_date = (datetime.now() + timedelta(seconds=minutes)).replace(microsecond=0) for i in range(amount): # 在指定的时间,只执行一次 tomato_bell_no = i + 1 scheduler_tomato_bell.add_job(send_wechat_tomato_bell, 'date', run_date=run_date, args=[tomato_bell_no, amount, tomato_name, msg, ], id=msg['User']['RemarkName'] + str(tomato_bell_no)) run_date += timedelta(minutes=minutes) # run_date += timedelta(seconds=minutes) scheduler_tomato_bell.start() return '您的番茄钟已设定成功' elif msg['Text'] in ['fq', 'fqz', '番茄钟']: # 番茄钟格式说明 return '【番茄钟格式】\nfqz <个数> <分钟数> <提醒内容>\n如:设定3个番茄钟,每个10分钟\n例:fqz 3 10 我是番茄钟~(空格间隔)\n取消番茄钟:qxfqz' elif msg['Text'] in ['qxfqz']: fruiter = Fruiter.objects.filter(wechat_remark_name=msg['User']['RemarkName']).first() if not fruiter: return '请先注册小鲜果儿账号,点这里:http://liguo.zzl99.cn:8000/' tmb = TomatoBell.objects.filter(fruiter=fruiter, turn_on=True).first() if not tmb: return '您还没有设定番茄钟' tmb.turn_on = False tmb.save() try: scheduler_tomato_bell.shutdown() except SchedulerNotRunningError: pass return '您的番茄钟已删除' except Exception as e: logger.exception(e)
def test_over_30_words_symbols(self): """ 超过30个字符数逗号 """ tomato_bell_reply = 'fqz 2 15 清华东区网红好的欠我一千万,都为技巧哦为绝地枪王为我就去玩为偶奇气温会丢失富瀚微,绯闻红为和非为违反为我覅偶还未发货未of维护' self.assertIs(check_tomato_bell(tomato_bell_reply), True)
def test_ens_space(self): """英文空格""" tomato_bell_reply = "fqz 2 15 Let's Go here we go!" self.assertIs(check_tomato_bell(tomato_bell_reply), True)
def test_ens_symbols(self): """英文逗号""" tomato_bell_reply = "fqz 2 15 Let's Go,here we go!" self.assertIs(check_tomato_bell(tomato_bell_reply), True)
def test_over_30_words_space(self): """ 超过30个字符数空格 """ tomato_bell_reply = 'fqz 2 15 清华东区网红好的欠我一千万 都为技巧哦为绝地枪王为我就去玩为偶奇气温会丢失富瀚微 绯闻红为和我覅偶还未待确定未群多群发货未of维护' self.assertIs(check_tomato_bell(tomato_bell_reply), True)