def cmd_game(message): user_id = message.from_user.id db = Db(db_dir) user = db.get_user_by_id(user_id) if user[1]: markup = types.ReplyKeyboardMarkup() markup.row('1', '2', '3') markup.row('4', '5', '6') markup.row('7', '8', '9') bot.send_message(message.from_user.id, "Ваш ход:", reply_markup=markup)
def random(message): db = Db(db_dir) today = db.get_today_crusade() if today: bot.send_message(chat_id, 'Сегодня уже выбран - ' + str(today[0][0])) else: places = db.get_places_for_random() shuffle(places) db.add_crusade(places[0][0]) bot.send_message(chat_id, 'Выбор на сегодня - ' + str(places[0][1]))
def change(message): if is_admin(message): db = Db(db_dir) places = db.get_places() if places: keyboard = types.InlineKeyboardMarkup() for place in places: place_button = types.InlineKeyboardButton(text=str(place[1]), callback_data=u'{"action": "change", "id": "' + str( place[0]) + '"}') keyboard.add(place_button) bot.send_message(chat_id, "Выберите место на сегодня:", reply_markup=keyboard)
def bot_step(user_id, field): db = Db(db_dir) user = str(db.get_user_by_id(user_id)[1]) type_ = other_type(user) right_step = check_can_win_lose(field, type_) if right_step: return db.set_step(user_id, right_step, True) # if '0' == field[5]: # return db.set_step(user_id, 5, True) while True: pos = random.randint(1, 9) if '0' == field[pos]: return db.set_step(user_id, pos, True)
def addClassMsg(self, msg, pid): dbclass = Db('tp_function') data = {} for line in msg: data['pid'] = str(pid) data['function_name'] = line['function_name'] data['params'] = line['params'] data['class_extends'] = line['extends'] content = MySQLdb.escape_string(line['comments']) data['function_msg'] = content #data['classname']=line['className'] # print data; # exit() res = dbclass.insert(data)
def repeat_all_messages(message): user_id = message.from_user.id db = Db(db_dir) user = db.get_user_by_id(user_id) if not user: bot.send_message(user_id, "Вам нужно зарегистрироваться командой: /register") else: game_ = db.get_game(user_id) if not game_: markup = types.ReplyKeyboardMarkup() markup.row('X', 'O') bot.send_message(user_id, "Выбирите Х или О:", reply_markup=markup) else: cmd_game(message)
def change(message): if is_admin(message): db = Db(db_dir) places = db.get_places() if places: keyboard = types.InlineKeyboardMarkup() for place in places: place_button = types.InlineKeyboardButton( text=str(place[1]), callback_data=u'{"action": "change", "id": "' + str(place[0]) + '"}') keyboard.add(place_button) bot.send_message(chat_id, "Выберите место на сегодня:", reply_markup=keyboard)
def addFileMsg(self, msg, pid): print msg #msg : [level,filepath,file,pid,type][0, '/Users/baidu/doc/.editorconfig', '.editorconfig', 0, 'isfile'] db = Db('tp_file') data = {} data['level'] = msg[0] data['path_name'] = msg[1] data['file_name'] = msg[2] data['pid'] = msg[3] data['type'] = msg[4] if data['type'] == 'isdir': data['type'] = 0 else: data['type'] = 1 resid = db.insert(data) return resid
def softdelete(message): if is_admin(message): db = Db(db_dir) places = db.get_all_places() if places: keyboard = types.InlineKeyboardMarkup() for place in places: if 1 == place[3]: status = '👍' else: status = '👎' place_button = types.InlineKeyboardButton(text=str(place[1]) + ' ' + status, callback_data=u'{"action": "delete", "id": "' + str( place[0]) + '"}') keyboard.add(place_button) bot.send_message(chat_id, "Выберите место чтобы удалить или добавить:", reply_markup=keyboard)
def repeat_all_messages(message): db = Db(db_dir) res = db.get_top_10() if res: str_ = '<strong>Имя, побед/всего, процент побед:</strong>\n' for user in res: if None is not user[3]: str_ += '<b>' + str(user[0]) + '</b>: ' + str( user[1]) + '/' + str(user[2]) + ' ' + str(round( user[3], 2)) + '\n' if '<strong>Имя, побед/всего, процент побед:</strong>\n' != str_: bot.send_message(message.from_user.id, str(str_), parse_mode='HTML') else: bot.send_message(message.from_user.id, 'Статистики пока что нет')
def change(message, place_id): if message: db = Db(db_dir) place = db.get_place(place_id) today = db.get_today_crusade() if today: db.update_crusade(place[0]) else: db.add_crusade(place[0]) return str(place[1])
def softdelete(message): if is_admin(message): db = Db(db_dir) places = db.get_all_places() if places: keyboard = types.InlineKeyboardMarkup() for place in places: if 1 == place[3]: status = '👍' else: status = '👎' place_button = types.InlineKeyboardButton( text=str(place[1]) + ' ' + status, callback_data=u'{"action": "delete", "id": "' + str(place[0]) + '"}') keyboard.add(place_button) bot.send_message(chat_id, "Выберите место чтобы удалить или добавить:", reply_markup=keyboard)
def text_request(message): db = Db(db_dir) user_id = message.from_user.id text = message.text.split() if text: for word in text: word = word.lower() if db.get_word_by_user(user_id, word): db.add_word(user_id, word) else: db.new_word(user_id, word)
def text_request(message): db = Db(db_dir) user_id = message.from_user.id text = re.sub(r'(http.+?\s)|(http.+$)', r' ', message.text) text = re.sub(r'[_+-.,!@#$%^&*();/|<>"\']', r' ', text).split() if text: for word in text: word = word.lower() if db.get_word_by_user(user_id, word): db.add_word(user_id, word) else: db.new_word(user_id, word)
def end_game(message): user_id = message.from_user.id db = Db(db_dir) user = db.get_user_by_id(user_id) if not user: return False if user[5]: markup = types.ReplyKeyboardHide() db.set_type_to_user(user_id, None) db.end_game(user_id) bot.send_message(message.from_user.id, "Игра окончена!", reply_markup=markup)
def register(message): db = Db(db_dir) user = db.get_user_by_id(message.from_user.id) if not user: if message.from_user.username: db.add_user(message.from_user.id, message.from_user.username) elif message.from_user.first_name: db.add_user(message.from_user.id, message.from_user.first_name) else: bot.send_message( chat_id, "У Вас нету имени, бот не может Вас зарегистрировать!") bot.send_message(chat_id, "Поздравляем с регистрацией!") else: print(user)
def register(message): db = Db(db_dir) user = db.get_user_by_id(message.from_user.id) if not user: if message.from_user.username: db.add_user(message.from_user.id, message.from_user.username) elif message.from_user.first_name: db.add_user(message.from_user.id, message.from_user.first_name) else: bot.send_message(chat_id, "У Вас нету имени, бот не может Вас зарегистрировать!") bot.send_message(chat_id, "Поздравляем с регистрацией!") else: print(user)
def random(message): if is_admin(message): db = Db(db_dir) db.delete_today()
def crusades(message): db = Db(db_dir) _crusades = db.get_crusades() _str = list_to_str('Топ слов', _crusades, [1, 0]) if _str: bot.send_message(chat_id, str(_str), parse_mode='HTML')
def place_list_for_random(message): db = Db(db_dir) places = db.get_places_for_random() _str = list_to_str('Список возможных мест на сегодня мест', places, [1]) if _str: bot.send_message(chat_id, str(_str), parse_mode='HTML')
def place_list(message): db = Db(db_dir) places = db.get_places() _str = list_to_str('Список мест', places, [1]) if _str: bot.send_message(chat_id, str(_str), parse_mode='HTML')
def my_words(message): db = Db(db_dir) words = db.get_frequency_by_id(message.from_user.id, get_cmd_param(message, 3)) _str = list_to_str('Топ слов', words, [0, 1]) if _str: bot.send_message(message.chat.id, str(_str), parse_mode='HTML')
def topword(message): db = Db(db_dir) words = db.get_frequency() _str = list_to_str('Топ слов', words, [0, 1]) if _str: bot.send_message(chat_id, str(_str), parse_mode='HTML')
def repeat_all_messages(message): user_id = message.from_user.id db = Db(db_dir) user = db.get_user_by_id(user_id) if user: if user[1]: if message.text in ['1', '2', '3', '4', '5', '6', '7', '8', '9']: pos = int(message.text) user_game = db.get_game(user_id) if '0' == user_game[2][pos]: field = db.set_step(user_id, pos) winner = who_win(field) if winner: markup = types.ReplyKeyboardHide() field = draw_field(field) bot.send_message(user_id, field + "\n" + winner, reply_markup=markup, parse_mode='HTML') db.set_type_to_user(user_id, None) if 'Ничья' == winner: db.user_draw(user_id) else: db.user_win(user_id) db.end_game(user_id) return True field = bot_step(user_id, field) winner = who_win(field) if winner: markup = types.ReplyKeyboardHide() field = draw_field(field) bot.send_message(user_id, field + "\n" + winner, reply_markup=markup, parse_mode='HTML') db.set_type_to_user(user_id, None) if 'Ничья' == winner: db.user_draw(user_id) else: db.user_lose(user_id) db.end_game(user_id) return True field = draw_field(field) bot.send_message(user_id, field, parse_mode='HTML') else: bot.send_message(user_id, 'Так сходить нельзя') else: markup = types.ReplyKeyboardHide() if message.text in ['X', 'O']: db.set_type_to_user(user_id, message.text) bot.send_message(user_id, 'Вы выбрали ' + str(message.text) + '!', reply_markup=markup) db.create_game(user_id) cmd_game(message)
def delete(message, place_id): if message: db = Db(db_dir) place = db.get_place(place_id) db.set_delete(place_id, int(not bool(place[3]))) return str(place[1])