def get_ranking_gasta_puntos(): con = demi_utils.create_connection() try: with con.cursor() as cur: cur.execute( 'SELECT UserId, Veces FROM Usos GROUP BY UserId, Veces ORDER BY Veces DESC' ) rows = cur.fetchall() if rows[0][1] == 0: top = '💸 Ranking puntos gastados:\n*1º - %s (%d ptos)*\n' % ( utils.get_name(rows[0][0]), rows[0][1]) else: top = '💸 Ranking puntos gastados:\n*1º - %s (-%d ptos)*\n' % ( utils.get_name(rows[0][0]), rows[0][1]) for row, pos in zip(rows[1:], range(2, len(rows) + 1)): if row[1] == 0: top += '%dº - %s (%d ptos)\n' % (pos, utils.get_name( row[0]), row[1]) else: top += '%dº - %s (-%d ptos)\n' % ( pos, utils.get_name(row[0]), row[1]) return top except Exception: logger.error('Fatal error in get_ranking_gasta_puntos', exc_info=True) finally: if con: con.close()
def pipas_selected(bot, update, user_data, job_queue): query = update.callback_query query_data = query.data.split('_') query_selected = int(query_data[0]) event_id = str(query_data[1]) user_id = query.from_user.id if demi_utils.get_vote(event_id, user_id) == query_selected: bot.answer_callback_query(query.id, 'Ya has votado esa opción') return False elif demi_utils.flooder(user_data, job_queue): bot.answer_callback_query(query.id, 'Has realizado demasiados votos') return False if int(event_id) not in demi_utils.get_events(): bot.answer_callback_query(query.id, 'Quedada terminada') return False if query_selected == 0: selected = 'Sí' else: selected = 'No' bot.edit_message_text(text="Has elegido: %s" % selected, chat_id=query.message.chat_id, message_id=query.message.message_id) keyboard = [[ InlineKeyboardButton("Sí", callback_data='0_%s' % event_id), InlineKeyboardButton("No", callback_data='1_%s' % event_id) ]] keyboard[0][query_selected].text = '[%s]' % selected reply_markup = InlineKeyboardMarkup(keyboard) bot.edit_message_reply_markup(reply_markup=reply_markup, chat_id=query.message.chat_id, message_id=query.message.message_id) if query_selected == 0: bot.send_message( group_id, '¡%s sale!' % utils.get_name(user_id), reply_to_message_id=demi_utils.get_event_message_id(event_id)) elif query_selected == 1 and demi_utils.get_vote(event_id, user_id) == 0: bot.send_message( group_id, '¡%s hace achu achu!' % utils.get_name(user_id), reply_to_message_id=demi_utils.get_event_message_id(event_id)) demi_utils.add_participant_event(event_id, user_id, query_selected) bot.answer_callback_query(query.id, 'Votado correctamente')
def cuenta_all(bot, user_ids): con = demi_utils.create_connection() for user_id in user_ids: chat_member = bot.get_chat_member(group_id, user_id) user_data = report_variables.user_data_dict[user_id] try: user_data['ban_time'] = reports.variables.ban_time if chat_member.status == 'kicked': if 'ban_time' in user_data and user_data['ban_time'] > 0 and chat_member.until_date is not None: user_data['ban_time'] = chat_member.until_date.timestamp()-time.time()+reports.variables.ban_time sti = io.BufferedReader(io.BytesIO(pkgutil.get_data('reportTelegram', 'data/stickers/%s.webp' % reports.variables.sticker))) bot.send_sticker(user_id, sti) sti.close() m, s = divmod(user_data['ban_time'], 60) text = 'Expulsado durante %02d:%02d minutos\n\n⚠️Esto no es un **** contador⚠' % (m, s) bot.send_message(user_id, text) bot.kick_chat_member(group_id, user_id, until_date=time.time()+user_data['ban_time']) except: logger.error('Fatal error in cuenta_all kicks', exc_info=True) time.sleep(reports.variables.ban_time) for user_id in user_ids: try: bot.unban_chat_member(group_id, user_id) with con.cursor() as cur: cur.execute('DELETE FROM Reports WHERE Reported = %s', (str(user_id),)) cur.execute('UPDATE Flamers SET Kicks = Kicks + 1 WHERE UserId = %s', (str(user_id),)) button = InlineKeyboardButton('Invitación', url=variables.link) markup = InlineKeyboardMarkup([[button]]) bot.send_message(user_id, 'Ya puedes entrar %s, usa esta invitación:' % utils.get_name(user_id), reply_markup=markup) except: logger.error('Fatal error in cuenta_all unban', exc_info=True) if con: con.commit() con.close()
def get_ranking(): con = demi_utils.create_connection() try: with con.cursor() as cur: cur.execute('SELECT UserId, Points FROM Ranking GROUP BY UserId, Points ORDER BY Points DESC') rows = cur.fetchall() top = '🏆 Ranking:\n*1º - %s (%d ptos)*\n' % (utils.get_name(rows[0][0]), rows[0][1]) for row, pos in zip(rows[1:], range(2, len(rows)+1)): top += '%dº - %s (%d ptos)\n' % (pos, utils.get_name(row[0]), row[1]) top += '\n🔫 Duelo por %d ptos.\n🤐 Mute por %d ptos.\n🎯 Headshot por %d ptos.\n🐺 Perros por %d ptos.\n☢ Nuke por %d ptos.' % \ (DUELO, MUTE, HEADSHOT, PERROS, NUKE) return top except Exception: logger.error('Fatal error in get_ranking', exc_info=True) finally: if con: con.close()
def get_participants_event(event_id): con = create_connection() user_ids = [[], [], []] try: with con.cursor() as cur: cur.execute( "SELECT userId, selected FROM PipasVotes WHERE eventId = %s", (str(event_id), )) rows = cur.fetchall() for row in rows: if row[1] == 0: user_ids[0].append(report_utils.get_name(row[0])) if row[1] == 1: user_ids[1].append(report_utils.get_name(row[0])) except Exception as exception: print(exception) finally: if con: con.close() return user_ids
def duelo(bot, update, job_queue): import random message = update.message user_id = message.from_user.id name = update.message.text con = demi_utils.create_connection() random = random.randint(0, 1) if not check_points(bot, update, DUELO): return ConversationHandler.END try: bot.send_document(group_id, 'https://i.imgur.com/eK86rUd.gif') msg = bot.send_message(group_id, 'Es hora del DU DU DU DUELO!', parse_mode='Markdown') for i in range(3, 0, -1): time.sleep(1) if random == 0: reported = user_id bot.send_message(variables.group_id, name + ' tenía una carta trampa y pierdes') name = utils.get_name(reported) resource = 'data/gifs/duelo/bewd.mp4' else: reported = utils.get_user_id(name) bot.send_message(variables.group_id, 'Sacas a Exodia y ganas automáticamente') resource = 'data/gifs/duelo/exodia.mp4' gif_path = os.path.join(os.path.dirname(sys.modules['demiReportTelegram'].__file__), resource) if os.path.isfile(gif_path): gif1, gif2 = open(gif_path, 'rb'), open(gif_path, 'rb') else: gif1 = gif2 = 'data/gifs/duelo/exodia.mp4' with con.cursor() as cur: cur.execute('UPDATE Ranking SET Points = Points - %s WHERE UserId = %s', (str(DUELO), str(user_id))) cur.execute('UPDATE Usos SET Veces = Veces + %s WHERE UserId = %s', (str(DUELO), str(user_id))) if message.chat.type == 'private': bot.send_document(user_id, gif2, reply_to_message_id=message.message_id, reply_markup=ReplyKeyboardRemove(selective=True)) bot.send_document(group_id, gif1) else: bot.send_document(group_id, gif1, reply_to_message_id=message.message_id, reply_markup=ReplyKeyboardRemove(selective=True)) if not isinstance(gif1, str): gif1.close() gif2.close() thr1 = threading.Thread(target=reports.counter, args=(bot, name, reported, job_queue)) thr1.start() except Exception: logger.error('Fatal error in duelo', exc_info=True) finally: if con: con.commit() con.close() return ConversationHandler.END
def inline_result(bot, update): result = update.chosen_inline_result res = int(result.result_id) sel = res resource = 'data/music/%s.ogg' % str(sel) audio = open( os.path.join( os.path.dirname(sys.modules['demiReportTelegram'].__file__), resource), 'rb') if sel == 17: bot.send_document(group_id, 'http://i.imgur.com/vABnMpR.gif') comentario = 'Sent by %s' % utils.get_name(result.from_user.id) bot.send_audio(group_id, audio, caption=comentario) audio.close()
def set_troll(target): con = pymysql.connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) try: with con.cursor() as cur: trolls = demi_utils.get_trolls() if not utils.is_from_group(target): return 'User_id incorrecto' elif target in trolls: username = utils.get_name(target) cur.execute('DELETE FROM Trolls WHERE UserId = %s', (str(target), )) return '❤️ %s eliminado de la lista de trolls' % username else: username = utils.get_name(target) cur.execute('INSERT INTO Trolls VALUES(%s)', (str(target), )) return '💔 %s añadido a la lista de trolls' % username except Exception: logger.error('Fatal error in set_troll', exc_info=True) finally: if con: con.commit() con.close()
def send_wanted_word(bot, update): message = update.message user_id = message.from_user.id words = list() for wanted_word in wanted_words: word = re.search('\\b' + wanted_word + '\\b', message.text, re.IGNORECASE) if word: words.append(word.group(0)) targets = list() for word in words: targets.extend(demi_utils.get_users_from_word(word)) for target_id in set(targets): if int(target_id) == int(admin_id) and target_id != user_id: pushover.Client(variables.pushover_client) \ .send_message(update.message.text, title=utils.get_name(user_id), priority=-1) elif target_id != user_id: bot.forward_message(target_id, message.chat.id, message.message_id)