async def on_message(self, message): if message.author.id in cmds.BOT_IDS: return split = message.content.split(' ', 1) # separate mom?[cmd] from args cmd = split[0] args = split[1].split(' ') if len(split) > 1 else None # Retrieve user from database and create if non-existing user = db.user_exists(message.author.id) if not user: db.adduser(message.author.id) prefix = db.get_prefix(message.author.id) # Check if a bot command if not cmd.startswith(f"mom{prefix}"): return # Debugging stuff name = author_name(message.author) print(f"{name} issued {cmd} command. <{args}>") cur_cmd = None try: suffix = cmd[4:] # Get command suffix cur_cmd = COMMANDS[suffix]['cmd'] await cur_cmd(self, message, args) except Exception as error: if not cur_cmd: return await cmds.error_message(message, title=f"Unknown command '{suffix}'") cmds.ERRORS += [time.ctime() + ': ' + str(error)] cmd = cmds.format_cmd(prefix, "report") await cmds.error_message(message, title=f"The command {suffix} failed...", desc=f"Please use ``{cmd}`` if you think it's an unexpected behaviour")
def process_subgroup_step(message): try: id = message.chat.id user = user_dict[id] subgroup = message.text if subgroup != '1' and subgroup != '2': raise Exception("Не верная подгруппа") user.subgroup = int(subgroup) user.last_message = get_time() user.username = message.chat.username user.first_name = message.chat.first_name user.last_name = message.chat.last_name if database.getuser(id) == None: database.adduser(user) else: database.updateuser(user) user_dict.pop(id) bot.send_message(id, 'Спасибо, можете выбрать нужный вам день!', reply_markup=get_main_markup()) except Exception as e: bot.reply_to(message, 'Что-то пошло не так :/ Попробуйте команду /help') logger.error("{0}|{1}|{2}: {3} - ERROR_MSG: {4}".format( message.chat.username, message.chat.first_name, message.chat.last_name, message.text, e))
def apply(): username = request.values.get("username") sex = request.values.get("sex") grade = request.values.get("grade") location = request.values.get("location") academy = request.values.get("academy") phone = request.values.get("phone") first = request.values.get("first") second = request.values.get("second") adjust = request.values.get("adjust") time = request.values.get("time") introduce = request.values.get("introduce") # username = "******" # sex = "0" # grade = "1" # location = "第三次调试" # academy = "软件学院" # phone = "15564660744" # first = "软件" # second = "医学" # adjust = "0" # time = '2020-4-5' # introduce = "我爱学习" #print('hello1') if check1(username, sex, grade, location, academy, phone, first, adjust, time, introduce): #print('check函数正常') result = adduser(username, sex, grade, location, academy, phone, first, second, adjust, time, introduce) else: result = {'errmsg': 'error2'} #print('hello2') return Response(json.dumps(result), content_type="applation/json")
def register(): form = registerform() if request.method == 'POST': if request.form['action'] == 'Register': email = form.email.data.lower() if form.validate_on_submit() == False: flash_errors(form) return render_template('register.html',form=form) elif verifyemail(email) == False: flash('Email has already been used','error') return render_template('register.html',form=form) else: #collect data from form to submit to database newuser = { "name" : { "first" : form.firstname.data, "last" : form.lastname.data }, "email" : form.email.data.lower(), "phone" : form.phone.data, "password": form.password.data, "address" : { "street" : form.address.data, "city" : form.address.data, "state" : form.state.data, "zip" : form.zipcode.data, }, "date": datetime.now() } #insert into database collection adduser(newuser) flash('Registration Complete!','flashok') return redirect(url_for('home')) elif request.form['action'] == 'Login': return redirect(url_for('home')) elif request.method == 'GET': return render_template('register.html',form=form)
def register(): form = registerform() if request.method == 'POST': if request.form['action'] == 'Register': email = form.email.data.lower() if form.validate_on_submit() == False: flash_errors(form) return render_template('register.html',form=form) elif verifyemail(email) == False: flash('Email has already been used','error') return render_template('register.html',form=form) else: #collect data from form to submit to database newuser = { "name" : { "first" : form.firstname.data, "last" : form.lastname.data }, "email" : form.email.data.lower(), "phone" : form.phone.data, "password": form.password.data, "address" : { "street" : form.address.data, "city" : form.address.data, "state" : form.state.data, "zip" : form.zipcode.data, }, "date": datetime.now() } #insert into database collection adduser(newuser) flash('Registration Complete!','flashok') return redirect(url_for('home')) elif request.form['action'] == 'Login': return redirect(url_for('home')) elif request.method == 'GET': return render_template('register.html',form=form)
def processMessage(message): if message['MsgType'] == 'text': # 根据用户发来的消息返回对应的消息 if message['Content'] in ['?', 'help', u'?', u'帮助']: # 帮助信息 articles = getHelpInfoArticles() return makeNewsMessage(message['FromUserName'], message['ToUserName'], articles) elif isConsultingLibrary(message['Content']): # 用户查询人文图书馆座位信息 # 以文字消息形式返回 response = getLibrarySeatText() return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif message['Content'].startswith('/:'): # 用户发送表情则返回音乐 response = getMusicByExpression(message['Content']) if (type(response) is types.UnicodeType) or (type(response) is types.StringType): return makeTextMessage(message['FromUserName'], message['ToUserName'], response) else: return makeMusicMessage(message['FromUserName'], message['ToUserName'], response) elif u'教' in message['Content']: # 查询教室排课信息, 处理的是文字输入 response = classroom(message['Content']) return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif isTypeOfMusic(message['Content']): # 根据音乐类型返回音乐消息 dict = getTypeDict(message['Content']) music = getRandomMusicByType(dict) if music['Title'] == '': return makeTextMessage(message['FromUserName'], message['ToUserName'], '抱歉,未找到该类型的音乐,换个类型试试吧~') else: return makeMusicMessage(message['FromUserName'], message['ToUserName'], music) elif 'test' in message['Content']: # 测试通道 response = message['Content'] return makeTextMessage(message['FromUserName'], message['ToUserName'], response) else: # 判断输入是否为某个教室 # 若是一个教室则返回教室信息 # 否则原样返回 response = getRoomCourseInfo(message['Content']) return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif message['MsgType'] == 'event': # 响应用户事件 if message['Event'] == 'subscribe': # 响应订阅事件 # 订阅号欢迎消息 #response = u'欢迎关注清华自习小助手,请发送“帮助”或“help”查看帮助信息~' # 服务号欢迎消息 adduser(message['FromUserName']) response = u'欢迎关注清华自习小助手,请使用帮助菜单查看帮助信息~也可回复“帮助”或“help”哦~' return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif message['Event'] == 'unsubscribe': # 取消订阅事件 # 订阅号欢送消息 #response = u'快点重新关注清华助手!' deluser(message['FromUserName']) response = u'快点重新关注清华助手!' return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif message['Event'] == 'CLICK': # 响应点击服务号菜单事件 if message['EventKey'] == 'COURSE': # 教室排课查询 response = u'查询某教室今天的排课情况\n您可以输入教室编号:\n“6A301”\n“4302”' return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif message['EventKey'] == 'LIBRARY': # 文图座位查询 articles = getLibrarySeatNews() return makeNewsMessage(message['FromUserName'], message['ToUserName'], articles) elif message['EventKey'] == 'CLASSROOM': # 空闲教室查询 response = u'查询某教学楼空闲教室情况\n您可以输入关键词:\n' \ u'“四教”\n“六教C区”\n“三教三段2层”\n“今天第三节五教”\n“明天第二节四教三层”\n\n' \ u'其中教学楼名称必须指定\n目前支持一到六教' return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif message['EventKey'] == 'MEAL': # 推荐吃饭地点 articles = food_articles() return makeNewsMessage(message['FromUserName'], message['ToUserName'], articles) elif message['EventKey'] == 'STUDY': # 推荐自习室 response = recommend_classroom() return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif message['EventKey'] == 'MUSIC': # 推荐音乐 articles = formMusicTypeList() return makeNewsMessage(message['FromUserName'], message['ToUserName'], articles) elif message['EventKey'] == 'SIGNIN': # 签到功能 times = signin(message['FromUserName'], message['CreateTime']) response = str(times) return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif message['EventKey'] == 'HELP': # 帮助功能 articles = getHelpInfoArticles() return makeNewsMessage(message['FromUserName'], message['ToUserName'], articles) else: # 其他事件不响应 response = u'抱歉...暂不支持响应此事件' return makeTextMessage(message['FromUserName'], message['ToUserName'], response) else: # 其他类型的消息不支持 response = u'暂不支持非文字消息' return makeTextMessage(message['FromUserName'], message['ToUserName'], response)
def processMessage(message): if message['MsgType'] == 'text': # 取出首尾空格和换行 message['Content'] = message['Content'].strip('\n') message['Content'] = message['Content'].strip(' ') # 根据用户发来的消息返回对应的消息 if message['Content'] in ['?', 'help', u'?', u'帮助']: # 帮助信息 articles = getHelpInfoArticles() return makeNewsMessage(message['FromUserName'], message['ToUserName'], articles) elif isConsultingLibrary(message['Content']): # 用户查询人文图书馆座位信息 # 以图文消息形式返回 articles = getLibrarySeatNews() return makeNewsMessage(message['FromUserName'], message['ToUserName'], articles) elif message['Content'].startswith('/:'): # 用户发送表情则返回音乐 response = getMusicByExpression(message['Content']) if (type(response) is types.UnicodeType) or (type(response) is types.StringType): return makeTextMessage(message['FromUserName'], message['ToUserName'], response) else: return makeMusicMessage(message['FromUserName'], message['ToUserName'], response) elif u'教' in message['Content']: # 查询空闲教室信息, 处理的是文字输入 response = classroom(message['Content']) return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif is_classroom(message['Content']): # 查询教室排课信息 response = getRoomCourseInfo(message['Content']) return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif isTypeOfMusic(message['Content']): # 根据音乐类型返回音乐消息 dict = getTypeDict(message['Content']) music = getRandomMusicByType(dict) if music['Title'] == '': return makeTextMessage(message['FromUserName'], message['ToUserName'], '抱歉,未找到该类型的音乐,换个类型试试吧~') else: return makeMusicMessage(message['FromUserName'], message['ToUserName'], music) elif message['Content'] == u'签到': # 输文字签到 response = signin(message['FromUserName'], message['CreateTime']) return makeNewsMessage(message['FromUserName'], message['ToUserName'], response) else: # 处理用户的其他输入 response = u'亲~无法识别您的输入,请输入教室代码、文图相关词语、教室查询字符串或音乐类型等与功能相关的文字。详细情况请查看帮助。' return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif message['MsgType'] == 'event': # 响应用户事件 if message['Event'] == 'subscribe': # 订阅事件欢迎消息 adduser(message['FromUserName']) response = [{ 'Title': u'清华助手,带您走向人生巅峰!', 'PicUrl': URL_WELCOME_IMAGE, 'Url': URL_HELP }, { 'Title': u'清华自习助手提供了人文馆查座、教学楼空闲教室及教室排课查询功能,给我们的自习提供方便;此外还具有听音乐、推荐清华美食、自习签到等功能,等待您的探索~', 'Url': URL_HELP }, { 'Title': u'点击此消息查看帮助', 'Url': URL_HELP }] return makeNewsMessage(message['FromUserName'], message['ToUserName'], response) elif message['Event'] == 'unsubscribe': # 取消订阅事件 deluser(message['FromUserName']) response = u'谢谢您关注本产品,再见~' return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif message['Event'] == 'CLICK': # 响应点击服务号菜单事件 if message['EventKey'] == 'COURSE': # 教室排课查询 response = u'查询某教室今天的排课情况\n您可以输入教室编号:\n“6A301”\n“4302”' return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif message['EventKey'] == 'LIBRARY': # 文图座位查询 articles = getLibrarySeatNews() return makeNewsMessage(message['FromUserName'], message['ToUserName'], articles) elif message['EventKey'] == 'CLASSROOM': # 空闲教室查询 response = u'查询某教学楼空闲教室情况\n您可以输入关键词:\n' \ u'“四教”\n“六教C区”\n“三教三段2层”\n“今天第三节五教”\n“明天第二节四教三层”\n\n' \ u'其中教学楼名称必须指定\n目前支持一到六教' return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif message['EventKey'] == 'MEAL': # 推荐吃饭地点 articles = food_articles() return makeNewsMessage(message['FromUserName'], message['ToUserName'], articles) elif message['EventKey'] == 'STUDY': # 推荐自习室 response = recommend_classroom() return makeTextMessage(message['FromUserName'], message['ToUserName'], response) elif message['EventKey'] == 'MUSIC': # 推荐音乐 articles = formMusicTypeList() return makeNewsMessage(message['FromUserName'], message['ToUserName'], articles) elif message['EventKey'] == 'SIGNIN': # 签到功能 response = signin(message['FromUserName'], message['CreateTime']) return makeNewsMessage(message['FromUserName'], message['ToUserName'], response) elif message['EventKey'] == 'HELP': # 帮助功能 articles = getHelpInfoArticles() return makeNewsMessage(message['FromUserName'], message['ToUserName'], articles) else: # 其他事件不响应 response = u'抱歉...暂不支持响应此事件' return makeTextMessage(message['FromUserName'], message['ToUserName'], response) else: # 其他类型的消息不支持 response = u'暂不支持非文字消息' return makeTextMessage(message['FromUserName'], message['ToUserName'], response)