def location(a): settings = read_settings() for name, city in settings['city_list'].items(): for member in city['members']: if a.FromQQ == member[0]: settings['city_list'][name]['members'].remove(member) update_settings(settings) send(a.FromQQ, f"已将您从“{name}”中移除,请发送【天气】重设地区") return send(a.FromQQ, f"您还没有注册过地区,请发送【天气】设置")
def handleMessage(msg): e = msg if e['data'] == 'User has connected!': print(e['data']) else: notification = Notifications(user_id=current_user.id, accion=e['data'], other_user=e['other_user']) db.session.add(notification) db.session.commit() send(msg, broadcast=True, json=True)
def message_handler(msg): logger.debug('Message: %s', msg) if msg['text'] in bad_words or len(msg['text']) < 2 or len( msg['text']) > 229: flash('Message contains bad words or message length is inappropriate') return redirect(url_for('index')) else: Message.create(text=msg['text'], sender=msg['sender'], category=msg['category']) send(msg, broadcast=True)
def sendmorning(): """检查时间是否到点发送早安""" settings = read_settings() for city in settings['city_list'].keys(): # settings['city_list'][city]['time_zone'] = await tz_calc(settings['city_list'][city]['code']) # await update_settings(settings) # print('test timer') for member in settings['city_list'][city]['members']: if datetime.now().hour == member[1] and datetime.now().minute == 1: weather_data = get_weather_data( settings['city_list'][city]['code']) weather_str = format_msg(weather_data, settings['city_list'][city]) send(member[0], weather_str)
def weather(a): settings = read_settings() # 如果用户注册过,直接返回实时#天气 city_name = member_in_list(settings, a.FromQQ) if city_name: current_weather_data = get_current_weather_data( settings['city_list'][city_name]['code']) send( a.FromQQ, format_msg(current_weather_data, settings['city_list'][city_name], current=True)) # 如果没有注册过,自动进入注册流程 else: send(a.FromQQ, '您还没有注册过推送地区\n请发送命令#注册(如:#注册 威远县)') #没有会话来get只能结束对话让对方发送新指令到下个函数 return
def signup(a): # 如果搜索的地区别人已经注册过了,直接添加至该列表 settings = read_settings() key_word = a.Content.split(' ')[1] if key_word in settings['city_list']: settings['city_list'][key_word]['members'].append([a.FromQQ, 6]) update_settings(settings) send( a.FromQQ, f'“{key_word}”已经存在,已将您的推送地区设置为“{key_word}”\n修改时间请发送【更改时间】\n修改地区请发送【更改地区】' ) return search_results = get_search_results(key_word) if search_results == []: send( a.FromQQ, '没有查到任何结果,请发送“#天气”重新查询\n\n请确认您的输入为中文名,且仅为城市名,如:\n维多利亚(√)\n维多利亚哥伦比亚(×)\n维多利亚加拿大(×)' ) return # send(a.FromQQ,"回复序号例如(# 0)") with open('tempselction.json', 'w') as f: json.dump(search_results, f) format_str = format_results(search_results) send(a.FromQQ, "回复序号例如(# 0)\n" + format_str) return
def selection(a): settings = read_settings() selection = int(a.Content.split(' ')[1]) with open('tempselction.json', 'r') as f: search_results = json.load(f) format_str = format_results(search_results) print('in selection ') # session.get('selection', prompt="回复序号确认地区", arg_filters=[extractors.extract_text, str.strip, validators.not_empty('输入不能为空'), validators.match_regex(r'\d', message='序号必须为数字', fullmatch=True), int]) code = search_results[selection]['code'] city = search_results[selection] settings['city_list'][city['local']] = { 'code': code, 'local': city['local'], 'admin': city['admin'], 'country': city['country'], 'time_zone': 0, 'members': [[a.FromQQ, 7]] } update_settings(settings) send( a.FromQQ, f"已将您的天气推送地区设为:\n {format_str.splitlines()[selection]}\n天气会每天7点自动推送\n修改时间请发送【更改时间】\n修改地区请发送【更改地区】" )
def handle_message(msg): print('Message: ' + msg) send(msg, broadcast=True)