diff --git a/README.md b/README.md index 03182a9..d9ecca3 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ## 4.- Las funcionalidades del bot están en bot.py -> https://github.com/boterostg/botBasicoGlitch/blob/master/bot.py y en https://glitch.com/~botbasico -## *Este proyecto surge del grupo de Telegram http://t.me/boterostg . Dado que hay mucha gente con ganas de aprender, hemos decidido crear un bot desde cero con https://glitch.com/ y Python3. Se utilizará el bot como ejemplo mientras se dan clases/charlas y poco a poco irá aumentando el código de dicho bot. Cualquier duda sobre el código o gente interesada en colaborar solo tiene que entrar al grupo http://t.me/boterostg :) +## *Este proyecto surge del grupo de Telegram http://t.me/boterostg . Dado que hay mucha gente con ganas de aprender, hemos decidido crear un bot desde cero con https://glitch.com/ y Python3. Se utilizará el bot como ejemplo mientras se dan clases/charlas y poco a poco irá aumentando el código de dicho bot. Cualquier duda sobre el código o gente interesada en colaborar solo tiene que entrar al grupo :) ## *Esto es posible gracias a https://github.com/sanguchi que creó toda la estructura del proyecto y el siguiente tutorial de como utilizarlo: http://telegra.ph/Creando-Bots-en-Telegram-06-09 @@ -121,25 +121,3 @@ def ruleta(message): bot.send_message(cid, "Te has salvado amigo @" + nombreUsuario) ``` - -## [3] Tercera clase 08/08/2018 Explicación de como utilizar split y random para simular un sorteo. - -```python -@bot.message_handler(func=lambda message: True) # Respuestas del bot -def echo_message(message): - if message.text.lower().startswith('participo con el numero'): - - cid = message.chat.id - mensaje=message.text - rnd = randrange(0, int(9)) - respuesta = ' '.join(mensaje.split(" ")[4:]) - - #bot.send_message(cid, "la respuesta es: " + respuesta) - #bot.send_message(cid, str(rnd)) - - if int(respuesta) == rnd: - bot.send_message(cid, "Has acertado") - - else: - bot.send_message(cid, "Has fallado, el número era " + str(rnd)) -``` diff --git a/ban.py b/ban.py index 7e15a77..36b44f6 100644 --- a/ban.py +++ b/ban.py @@ -1,3 +1,4 @@ + #Importaciones. import datetime import time @@ -38,3 +39,122 @@ def setTempBan(secB,minB,hourB,dayB,monthB,yearB): print(unixBan) #Printeamos el resultado de la fecha Unix del ban para asegurar que está bien. return unixBan #Devolvemos el valor del tiempo de la sanción del baneado en Unix. + + +#Función para definir el tipo de muteo. +def setTypeMute(typeMute): + + sendMessages = False + sendMedia = False + sendOtherMessages = False + sendWebPage = False + + typeBanList = [["sendMessages",sendMessages],["sendMedia",sendMedia],["sendOtherMessages",sendOtherMessages],["sendWebPage",sendWebPage]] + + print(typeBanList) + + if typeMute == "all": + print("Entramos en all") + typeBanList = [ [x[0],True] if x[1] == False else x for x in typeBanList ] + + elif typeMute == "media": + print("Entramos en media") + typeBanList = [ [x[0],True] if x[0] == "sendMedia" else x for x in typeBanList ] + + elif typeMute == "other": + print("Entramos en media") + typeBanList = [ [x[0],True] if x[0] == "sendOtherMessages" else x for x in typeBanList ] + + elif typeMute == "web": + print("Entramos en media") + typeBanList = [ [x[0],True] if x[0] == "sendWebPage" else x for x in typeBanList ] + + elif typeMute == "message": + print("Entramos en media") + typeBanList = [ [x[0],True] if x[0] == "sendMessages" else x for x in typeBanList ] + + print(typeBanList) + + return typeBanList + +typeBan = setTypeMute("message") + + +def banlevel(idChatGroup,idUser,level,typeMute): + + cid = idChatGroup + idUsuario =idUser + + if level == 1 : + + typeMuteo = setTypeMute(typeMute) + tiempoban = setTempBan(0,30,0,0,0,0) + print("El usuario tiene un ban de nivel 1 " + str(idUsuario) + "estara baneado de: " + str(typeMuteo) + "con este tiempo: " + str(tiempoban) ) + + if level == 2 : + + typeMuteo = setTypeMute(typeMute) + tiempoban = setTempBan(0,0,8,0,0,0) + print("El usuario tiene un ban de nivel 2 " + str(idUsuario) + "estara baneado de: " + str(typeMuteo) + "con este tiempo: " + str(tiempoban) ) + + if level == 3 : + + typeMuteo = setTypeMute(typeMute) + tiempoban = setTempBan(0,0,0,1,0,0) + print("El usuario tiene un ban de nivel 3 " + str(idUsuario) + "estara baneado de: " + str(typeMuteo) + "con este tiempo: " + str(tiempoban) ) + + if level == 4 : + + typeMuteo = setTypeMute(typeMute) + tiempoban = setTempBan(0,0,0,7,0,0) + print("El usuario tiene un ban de nivel 4 " + str(idUsuario) + "estara baneado de: " + str(typeMuteo) + "con este tiempo: " + str(tiempoban) ) + + if level == 5 : + + typeMuteo = setTypeMute(typeMute) + tiempoban = setTempBan(0,0,0,0,1,0) + print("El usuario tiene un ban de nivel 5 " + str(idUsuario) + "estara baneado de: " + str(typeMuteo) + "con este tiempo: " + str(tiempoban) ) + + if level == 6 : + + typeMuteo = setTypeMute(typeMute) + tiempoban = setTempBan(0,0,0,0,3,0) + print("El usuario tiene un ban de nivel 6 " + str(idUsuario) + "estara baneado de: " + str(typeMuteo) + "con este tiempo: " + str(tiempoban) ) + + if level == 7 : + + typeMuteo = setTypeMute(typeMute) + tiempoban = setTempBan(0,0,0,0,0,1) + print("El usuario tiene un ban de nivel 7 " + str(idUsuario) + "estara baneado de: " + str(typeMuteo) + "con este tiempo: " + str(tiempoban) ) + + +#Funcion para configurar el flood de cada grupo +def antiFloodConfig(idChatGroup,numMessages,typeMute,timeBan): + + db_config = read_db_config() + + # prepare query and data + query = """ UPDATE Group + SET maxMessages = %s, mute = typeMute + WHERE id = %s """ + + data = (title, book_id) + + try: + conn = MySQLConnection(**db_config) + + # update book title + cursor = conn.cursor() + cursor.execute(query, data) + + # accept the changes + conn.commit() + + except Error as error: + print(error) + + finally: + cursor.close() + conn.close() + +banlevel(12312323,4121223,7,"media") \ No newline at end of file diff --git a/bot.py b/bot.py index 6d60a8a..b8de449 100644 --- a/bot.py +++ b/bot.py @@ -1,5 +1,3 @@ -#IMPORTACIONES - import telebot from telebot import * from os import environ @@ -9,22 +7,40 @@ import json import requests +from configBan import * + + bot = telebot.TeleBot(environ['TELEGRAM_TOKEN']) #Token del bot # Variable que se utilizará en el comando /start para enviarlo como el texto del mensaje del bot bot_text = ''' -El bot está creado en https://glitch.com/~{} +Howdy, how are you doing? +Source code on https://glitch.com/~{} '''.format(environ['PROJECT_NAME']) -#Keyboard del menú + + menuKeyboard = types.InlineKeyboardMarkup() menuKeyboard.add(types.InlineKeyboardButton('Ayuda', callback_data='ayuda'), types.InlineKeyboardButton('Creador', callback_data='creador')) -#Keyboard para apuntarse a la lista yoNuncaKeyboard = types.InlineKeyboardMarkup() yoNuncaKeyboard.add(types.InlineKeyboardButton('Me apunto', callback_data='yo')) +propuestaInlineKeyboard = types.InlineKeyboardMarkup() +propuestaInlineKeyboard.add(types.InlineKeyboardButton('Me apunto', callback_data='inlineApuntado')) + + + + + + +@bot.message_handler(commands=['menu']) +def menu(m): + + cid = m.chat.id + bot.send_message(cid, "Menu", reply_markup=menuKeyboard, parse_mode="Markdown") + @bot.callback_query_handler(func=lambda call: call.data in ['ayuda', 'creador']) def callback_handlerMenu(call): @@ -44,9 +60,349 @@ def callback_handlerMenu(call): #bot.send_message(cid, "Entramos en " + str(info)) bot.edit_message_text("Mi creador es : @batichico" , cid, mid, reply_markup=menuKeyboard , parse_mode="Markdown") - - -# Inicio lección 1- 19/07/2018 + + +@bot.inline_handler(lambda query: query.query.startswith('propuesta') and len(query.query.split()) > 1) +def function_propuesta(q): + + cid = q.from_user.id + txt = q.query.split(None, 1)[1] + + keyboard = types.InlineKeyboardMarkup() + keyboard.add(types.InlineKeyboardButton("Me apunto", callback_data="propuesta {}".format(txt))) + + article = types.InlineQueryResultArticle(1, "Enviar propuesta", types.InputTextMessageContent(txt), reply_markup=keyboard) + bot.answer_inline_query(q.id, [article], cache_time=1) + + + + +@bot.callback_query_handler(func=lambda call: call.data.startswith('propuesta')) +def function_button(call): + + mensaje = call.data.split(None, 1)[1] + + + + idUsuario = call.from_user.id + nombreUsuario = call.from_user.username + nombreUsuario = "@"+nombreUsuario + + todoCall = call + print(str(todoCall)) + + + mid = call.inline_message_id + + + contenido = mensaje + "\n\n" + + apuntados = mensaje.split("\n\n")[1:] + + #bot.answer_callback_query(call.id , str(mensaje) , show_alert=True) + + if nombreUsuario not in mensaje: + + mensaje = contenido + nombreUsuario + + bot.answer_callback_query(call.id , "Vamos a apuntarte, apuntados: " + str(apuntados) , show_alert=True) + bot.edit_message_text(mensaje, inline_message_id=call.inline_message_id , reply_markup=propuestaInlineKeyboard, parse_mode="Markdown") + + + apuntados = mensaje.split("\n\n")[1:] + + + else : + + apuntadosS = "" + + apuntados = mensaje.split("\n\n")[1:] + + contenido = mensaje.split("\n\n")[0] + + contenido = contenido + "\n\n" + + apuntados.remove(str(nombreUsuario)) + + + bot.answer_callback_query(call.id , str(apuntados) , show_alert=True) + + + + + ''' + + + + mid = call.message.message_id + mensaje = call.message.text + + contenido = mensaje + "\n\n" + + apuntados = mensaje.split("\n\n")[1:] + + + else : + + apuntadosS = "" + + apuntados = mensaje.split("\n\n")[1:] + + contenido = mensaje.split("\n\n")[0] + + contenido = contenido + "\n\n" + + apuntados.remove(str(nombreUsuario)) + + if len(apuntados) == 0 : + + bot.edit_message_text(contenido, cid, mid, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") + + elif len(apuntados) == 1 : + mensaje = contenido + apuntados[0] + bot.edit_message_text(mensaje, cid, mid, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") + + elif len(apuntados) >= 1 : + for apuntado in apuntados: + apuntadosS = apuntadosS + apuntado + "\n\n" + + mensaje = contenido + apuntadosS + bot.edit_message_text(mensaje, cid, mid, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") + + + + + + + + + + + + + else : + + apuntadosS = "" + + apuntados = mensaje.split("\n\n")[1:] + + contenido = mensaje.split("\n\n")[0] + + contenido = contenido + "\n\n" + + apuntados.remove(str(nombreUsuario)) + + if len(apuntados) == 0 : + + bot.edit_message_text(contenido, cid, mid, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") + + elif len(apuntados) == 1 : + mensaje = contenido + apuntados[0] + bot.edit_message_text(mensaje, cid, mid, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") + + elif len(apuntados) >= 1 : + for apuntado in apuntados: + apuntadosS = apuntadosS + apuntado + "\n\n" + + mensaje = contenido + apuntadosS + bot.edit_message_text(mensaje, cid, mid, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") + + ''' + +@bot.callback_query_handler(func=lambda call: call.data in ['yosi']) +def callback_handlerYoNunca(call): + + cid = call.message.chat.id + idUsuario = call.from_user.id + nombreUsuario = call.from_user.first_name + + mid = call.message.message_id + mensaje = call.message.text + + arrayApuntados = arrayUsuarios + + nombreUsuarioClick = call.message.from_user.first_name + + if idUsuario not in arrayApuntados or len(arrayApuntados) == 0 : + + añadirUser = {mid:{idUsuario:nombreUsuario}} + + arrayApuntados.append(añadirUser) + + nombreNuevoUser = arrayApuntados[-1][mid][idUsuario] + + mensaje = mensaje + "\n\n" + nombreNuevoUser + bot.edit_message_text(mensaje, cid, mid, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") + + bot.send_message(cid, str(arrayApuntados)) + + elif idUsuario in arrayApuntados : + arrayApuntados.pop(idUsuario) + + + +@bot.callback_query_handler(func=lambda call: call.data in ['inlineApuntado']) +def callback_handlerPropuesta(call): + + print("Entramos en handler") + + print("CALL: " + str(call)) + + print(str(call.id)) + + #cid = call.message.chat.id + idUsuario = call.from_user.id + nombreUsuario = call.from_user.username + nombreUsuario = "@"+nombreUsuario + + print(str(nombreUsuario)) + + mid = call.inline_message_id + + print(str(mid)) + + #mensaje = call.message.text + + #mensaje = call.data.split(None, 1)[1] + + mensaje = call.data + + + contenido = mensaje + "Contenido\n\n" + + #contenido = mensaje + "\n\n" + + apuntados = mensaje.split("\n\n")[1:] + + print("Apuntados: " + str(apuntados)) + + + #bot.answer_callback_query(mid , str(apuntados) , show_alert=True) + + if nombreUsuario not in mensaje: + + print ("entramos en if" + nombreUsuario + "\n" + mensaje) + + mensaje = contenido + nombreUsuario + + apuntados = mensaje.split("\n\n")[1:] + + print("Mensaje metido: " + mensaje) + + print("Apuntados: " + str(apuntados)) + + #bot.answer_callback_query(call.id , "Vamos a apuntarte, apuntados: " + str(apuntados) , show_alert=True) + bot.edit_message_text(mensaje, inline_message_id=call.inline_message_id , reply_markup=propuestaInlineKeyboard, parse_mode="Markdown") + + print("Mensaje despues metido: " + mensaje) + + #bot.edit_message_text(mensaje, inline_message_id=mid, reply_markup=propuestaInlineKeyboard, parse_mode="Markdown") + + #bot.edit_message_text(mensaje, cid, mid, reply_markup=propuestaInlineKeyboard, parse_mode="Markdown") + + + + else : + + #print ("entramos en else") + + apuntadosS = "" + + apuntados = mensaje.split("\n\n")[1:] + + #print (apuntados) + + contenido = mensaje.split("\n\n")[0] + + contenido = contenido + "\n\n" + + apuntados.remove(str(nombreUsuario)) + + if len(apuntados) == 0 : + + bot.edit_message_text(contenido, cid, mid, reply_markup=propuestaInlineKeyboard, parse_mode="Markdown") + + elif len(apuntados) == 1 : + mensaje = contenido + apuntados[0] + bot.edit_message_text(mensaje, cid, mid, reply_markup=propuestaInlineKeyboard, parse_mode="Markdown") + + elif len(apuntados) >= 1 : + for apuntado in apuntados: + apuntadosS = apuntadosS + apuntado + "\n\n" + + mensaje = contenido + apuntadosS + bot.edit_message_text(mensaje, cid, mid, reply_markup=propuestaInlineKeyboard, parse_mode="Markdown") + + + + + + + +@bot.callback_query_handler(func=lambda call: call.data in ['yo']) +def callback_handlerYoNunca(call): + + cid = call.message.chat.id + idUsuario = call.from_user.id + + if (call.from_user.username is None): + bot.answer_callback_query(call.id, "Tienes que tener nickname, @ lo que sea", show_alert=True) + else: + nombreUsuario = call.from_user.username + nombreUsuario = "@"+nombreUsuario + + mid = call.message.message_id + mensaje = call.message.text + + contenido = mensaje + "\n\n" + + apuntados = mensaje.split("\n\n")[1:] + + + if nombreUsuario == "@elraro": + + #print(str(call.id) + " " + nombreUsuario) + bot.answer_callback_query(call.id, "HDP", show_alert=True) + + else: + + if nombreUsuario not in mensaje: + + mensaje = contenido + nombreUsuario + bot.edit_message_text(mensaje, cid, mid, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") + + apuntados = mensaje.split("\n\n")[1:] + else : + + apuntadosS = "" + + apuntados = mensaje.split("\n\n")[1:] + + contenido = mensaje.split("\n\n")[0] + + contenido = contenido + "\n\n" + + apuntados.remove(str(nombreUsuario)) + + if len(apuntados) == 0 : + + bot.edit_message_text(contenido, cid, mid, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") + + elif len(apuntados) == 1 : + mensaje = contenido + apuntados[0] + bot.edit_message_text(mensaje, cid, mid, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") + + elif len(apuntados) >= 1 : + for apuntado in apuntados: + apuntadosS = apuntadosS + apuntado + "\n\n" + + mensaje = contenido + apuntadosS + bot.edit_message_text(mensaje, cid, mid, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") + +# Inicio charla 1- 19/07/2018 + + + @bot.message_handler(commands=['start', 'help']) # Comando /start o /help . Cuando un usuario escriba cualquiera de los comandos def send_welcome(message): @@ -58,31 +414,42 @@ def ayuda(message): bot.reply_to(message, 'ahora mismo te ayudo') # El bot responde 'ahora mismo te ayudo' al mensaje #Inicio charla 2 - 31/07/2018 - -#Comando para simular una ruleta rusa en grupos de Telegram + + @bot.message_handler(commands=['ruleta']) def ruleta(message): - cid = message.chat.id #Id del chat - nombreUsuario = message.from_user.username #Nicknmae del usuario - idUsuario = message.from_user.id #Id del usuario - rnd = randrange(0, int(5)) #Generación de número aleatorio entre 0 y 5 + cid = message.chat.id + nombreUsuario = message.from_user.username + idUsuario = message.from_user.id + rnd = randrange(0, int(5)) - if rnd == 4: #Si el número aleatorio es igual a 4 - - bot.send_message(cid, "Pummmm estas muerto @" + nombreUsuario ) #El bot envía mensaje de que has muerto y añade el nickname del usuario en el mensaje - bot.kick_chat_member(cid,idUsuario) #El bot expulsa al usuario del grupo restringiendolo del grupo - bot.unban_chat_member(cid, idUsuario) #El bot quita la restrinción al usuario para que así pueda volver al grupo + if rnd == 4: + bot.send_message(cid, "Pummmm tas muelto @" + nombreUsuario ) + bot.kick_chat_member(cid,idUsuario) + bot.unban_chat_member(cid, idUsuario) - else: #Si el número aleatorio es diferente de 4 + else: - bot.send_message(cid, "Te has salvado amigo @" + nombreUsuario) #El bot envía un mensaje diciendo que se ha salvado añadiendo el nickname del usuario + bot.send_message(cid, "Te has salvado amijo @" + nombreUsuario) #Fin charla 2 - 31/07/2018 @bot.message_handler(func=lambda message: True) # Respuestas del bot def echo_message(message): cid = message.chat.id # Guardamos en la variale cid el id de el mensaje recibido + idUsu = message.from_user.id + + if message.text.lower() == "bot vete" : + + if idUsu== 239822769: + bot.send_message(cid, 'vale :C, adios mi gente!') + bot.leave_chat(cid) + + + if "ban" in message.text.lower().split() : + + bot.send_message(cid, 'estas ban') if message.text.lower() == "holi": # Comparamos el texto el mensaje si es igual a 'holi' @@ -95,7 +462,7 @@ def echo_message(message): if id == 239822769: # Comparamos el id guardado del usuario con un id que le hemos pasado - bot.send_message( cid, 'Hola mi creador 😙') # Si es igual responde el mensaje que hemos introducido al chat indicado + bot.send_message( cid, 'Hola mi creador 😙') # Si es igual responde el mensaje que hemos introducido al chat indicado elif id == 270803389 : # En este caso el id lo comparamos con otra id diferente @@ -108,47 +475,63 @@ def echo_message(message): bot.send_message( cid, 'No estás registrado') # Enviará por el chat el mensaje 'No estás registrado' - if message.text.lower() == "mensaje": # Aquí probamos un if comparandolo con un String(una cadena de carácteres) + elif message.text.lower() == "mensaje": # Aquí probamos un if comparandolo con un String(una cadena de carácteres) bot.send_message( cid, 'mensaje') # Si es así contestará 'mensaje' + + -#Fin lección 1 - 19/07/218 - -#Inicio charla 3 - 08/08/2018 - if message.text.lower().startswith('participo con el numero'): #Escribimos Participo con el numero X (El que sea dentro del 0-10 - - cid = message.chat.id # Guardamos en la variale cid el id de el mensaje recibido. - mensaje=message.text # Guardamos el mensaje completo. - rnd = randrange(0, int(11)) # Generamos un número aleatorio del 0 al 10. - respuesta = ' '.join(mensaje.split(" ")[4:]) # Obtenemos el numero X del mensaje indicado. - - # Comparamos el número obtenido con el número aleatorio. +#Fin charla 1 - 19/07/218 + if message.text.lower().startswith('/'): + idMensaje = message.message_id + idUsuario = call.from_user.id + + bot.delete_message(cid,idMensaje) + + dt = datetime.datetime(2018, 8, 21, 16, 00) + unixTime = time.mktime(dt.timetuple()) + + bot.restrict_chat_member(self, cid, idUsuario, until_date=None, can_send_messages=False, + can_send_media_messages=False, can_send_other_messages=False, + can_add_web_page_previews=False) + + #Inicio charla 3 - 08/08/2018 + if message.text.lower().startswith('participo con el numero'): - if int(respuesta) == rnd: # Si el número obtenido == número aleatorio. - bot.send_message(cid, "Has acertado") # El bot envía el mensaje "Has acertado". + cid = message.chat.id + mensaje=message.text + rnd = randrange(0, int(9)) + respuesta = ' '.join(mensaje.split(" ")[4:]) - else: # Por no es igual. - - bot.send_message(cid, "Has fallado, el número era " + str(rnd)) # El bot envía el mensaje Has fallado, el número era (el número correspondiente) + #bot.send_message(cid, "la respuesta es: " + respuesta) + #bot.send_message(cid, str(rnd)) -#Fin charla 3 - 08/08/2018 + if int(respuesta) == rnd: + bot.send_message(cid, "Has acertado") + else: + bot.send_message(cid, "Has fallado, el número era " + str(rnd)) -#Inicio charla 2 - 31/07/2018 + #Fin charla 3 - 08/08/2018 + + if message.text.lower().startswith("propuesta") and len(message.text)>1: + cid = message.chat.id + nombre = message.from_user.first_name + mensaje = message.text + + respuesta = ' '.join(mensaje.split(" ")[1:]) + bot.send_message(cid, respuesta, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") - if message.text.lower().startswith('bot di'): # Comprobamos si el texto el empieza por "bot di" - - cid = message.chat.id #Id del chat - mensaje=message.text #Mensaje completo + #Inicio charla 2 - 31/07/2018 - respuesta = ' '.join(mensaje.split(" ")[2:]) #Respuesta = el texto que venga detrás de bot di. - #Ejemplo bot di hola. Con este código se guardará el "hola" porque se guardará - # todo lo que se escriba a partir del tercer espacio. - - bot.send_message(cid, respuesta) #El bot envía la respuesta + if "boti di" in message.text.lower(): # Comparamos el texto el mensaje si es igual a "boti di" + cid = message.chat.id #Id del chat + mensaje=message.text #Mensaje completo + respuesta = ' '.join(mensaje.split(" ")[2:]) #Respuesta + bot.send_message(cid, respuesta) #El bot envía la respuesta #Respuesta a la entrada de un usuario al grupo @@ -157,7 +540,32 @@ def command_bienvenida(m): cid = m.chat.id #Id del chat cname = m.chat.title #Nombre del grupo bienvenida = "" #Variable dónde guardaremos el mensaje de bienvenida + + infoMesaje = str(m) + nuevoUsuarioId = m.new_chat_member.id + nuevoUsuarioName = m.new_chat_member.username + añadidoPorId = m.from_user.id + añadidoPor = m.from_user.username + + #bot.send_message(cid, infoMesaje) + if nuevoUsuarioName == "Botinutilbot": + + if cid != -1001318959349: + + bot.send_message(cid, añadidoPor + " , para que hostias me metes, este no es mi grupo joderrr!") + bot.leave_chat(cid) + + + if añadidoPorId == nuevoUsuarioId: + bot.send_message(cid, 'Entrado por enlace de invitación') + + + #bot.send_message(cid, infoMesaje) + else: + bot.send_message(cid, 'añadido por: ' + añadidoPor) + bot.send_message(cid, str(cid)) + if (m.new_chat_member.username is None): #Si el usuario no tiene nickname nun = m.new_chat_member.first_name #Guardamos el primer nombre del usuario @@ -177,6 +585,7 @@ def command_bienvenida(m): bot.send_message(cid, str(bienvenida) + str(nun)) #Se envía el mensaje de bienvenida concatenando el nombre/nickname del usuario + #Respuesta a la salida de un usuario del grupo @bot.message_handler(func=lambda message: True, content_types=['left_chat_member']) def command_bye(m): @@ -197,7 +606,38 @@ def command_bye(m): bot.send_message(cid, str(despedida) + str(nun)) #Se envía el mensaje de despedida concatenando el nombre/nickname del usuario - #Fin charla 2 - 31/07/2018 - + +#Fin charla 2 - 31/07/2018 + +''' + +APUNTESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSs + +import random +from itertools import izip_longest + +def grouper(iterable, n, fillvalue=None): + "Collect data into fixed-length chunks or blocks" + # Taken from itertools recipes: + # https://docs.python.org/2/library/itertools.html#recipes + # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx + args = [iter(iterable)] * n + return izip_longest(fillvalue=fillvalue, *args) + +apuntados = ["peter","alice","andy","patxi","richard","ana"] +parejas = "" + +print(str(apuntados)) + +random.shuffle(apuntados) +print(len(apuntados)) +if len(apuntados) >1: + for primero, segundo in grouper(apuntados, 2): + parejas = parejas + str(primero) + " y " + str(segundo) +"\n" +else: + bot.send_message(cid,"solo hay uno") +print(parejas) + +''' bot.set_webhook("https://{}.glitch.me/{}".format(environ['PROJECT_NAME'], environ['TELEGRAM_TOKEN'])) diff --git a/configBan.py b/configBan.py new file mode 100644 index 0000000..987a40d --- /dev/null +++ b/configBan.py @@ -0,0 +1,30 @@ +import json +import requests +import telebot +from telebot import * +from os import environ + +bot = telebot.TeleBot(environ['TELEGRAM_TOKEN']) + +banConf = types.InlineKeyboardMarkup() +banConf.add(types.InlineKeyboardButton('Configuración Grupo', callback_data='config')) +banConf.add(types.InlineKeyboardButton('Nivel Flanders', callback_data='creador')) +banConf.add(types.InlineKeyboardButton('Configuración Flanders', callback_data='creador')) + + +@bot.message_handler(commands=['config']) +def start_handler(m): + cid = m.chat.id + bot.send_message(cid, "Vamos a configurar el grupo", reply_markup=banConf, parse_mode="Markdown") + + + + + + + + + + + + diff --git a/plugins/leccion1.py b/plugins/leccion1.py new file mode 100644 index 0000000..3c414b0 --- /dev/null +++ b/plugins/leccion1.py @@ -0,0 +1,60 @@ +from config import * + +# Inicio leccion 1- 19/07/2018 + +# Variable que se utilizará en el comando /start para enviarlo como el texto del mensaje del bot +bot_text = ''' +Howdy, how are you doing? +Source code on https://glitch.com/~{} +'''.format(environ['PROJECT_NAME']) + +@bot.message_handler(commands=['start', 'help']) # Comando /start o /help . Cuando un usuario escriba cualquiera de los comandos +def send_welcome(message): + bot.reply_to(message, bot_text) # El bot responde con el contenido de la variable bot_text al mensaje. + + +@bot.message_handler(commands=['ayuda']) # Ejemplo de comando /ayuda que en vez de pasarle una variable, directamente escribimos +def ayuda(message): + bot.reply_to(message, 'ahora mismo te ayudo') # El bot responde 'ahora mismo te ayudo' al mensaje + +@bot.message_handler(func=lambda message: True) # Respuestas del bot +def echo_message(message): + cid = message.chat.id # Guardamos en la variale cid el id de el mensaje recibido + idUsu = message.from_user.id + + if "ban" in message.text.lower().split() : + + bot.send_message(cid, 'estas ban') + + if message.text.lower() == "holi": # Comparamos el texto el mensaje si es igual a 'holi' + + id = message.from_user.id # Guardamos en una variable el id del usuario que envió el mensaje + + nombre = message.from_user.first_name # Guardamos en una variable el nombre del usuario que envió el mensaje + + bot.send_message(cid, 'holi ' + nombre ) # El bot responde 'holi' y después el nombre del usuario que guardamos en la variable da arriba + + + if id == 239822769: # Comparamos el id guardado del usuario con un id que le hemos pasado + + bot.send_message( cid, 'Hola mi creador 😙') # Si es igual responde el mensaje que hemos introducido al chat indicado + + elif id == 270803389 : # En este caso el id lo comparamos con otra id diferente + + bot.send_message( cid, 'Holi manuel') # Aquí envia al chat que le hemos hablado 'Holi manuel' + + bot.send_message( 115659666, 'Holi manuel') # Aquí probamos a pasarle en vez de cid, un id de un usuario y le enviará el mensaje por mensaje + #privado + + else: # Si no se da ninguno de los resultados de arriba hará lo siguiente: + + bot.send_message( cid, 'No estás registrado') # Enviará por el chat el mensaje 'No estás registrado' + + elif message.text.lower() == "mensaje": # Aquí probamos un if comparandolo con un String(una cadena de carácteres) + + bot.send_message( cid, 'mensaje') # Si es así contestará 'mensaje' + + + + +#Fin charla 1 - 19/07/218 \ No newline at end of file diff --git a/plugins/leccion2.py b/plugins/leccion2.py new file mode 100644 index 0000000..4815c96 --- /dev/null +++ b/plugins/leccion2.py @@ -0,0 +1,107 @@ +from config import * +#Inicio charla 2 - 31/07/2018 + +@bot.message_handler(commands=['ruleta']) +def ruleta(message): + + cid = message.chat.id + nombreUsuario = message.from_user.username + idUsuario = message.from_user.id + rnd = randrange(0, int(5)) + + if rnd == 4: + bot.send_message(cid, "Pummmm tas muelto @" + nombreUsuario ) + bot.kick_chat_member(cid,idUsuario) + bot.unban_chat_member(cid, idUsuario) + + else: + + bot.send_message(cid, "Te has salvado amijo @" + nombreUsuario) + + +@bot.message_handler(func=lambda message: True) # Respuestas del bot +def echo_message(message): + cid = message.chat.id # Guardamos en la variale cid el id de el mensaje recibido + idUsu = message.from_user.id + + if "boti di" in message.text.lower(): # Comparamos el texto el mensaje si es igual a "boti di" + + cid = message.chat.id #Id del chat + mensaje=message.text #Mensaje completo + respuesta = ' '.join(mensaje.split(" ")[2:]) #Respuesta + bot.send_message(cid, respuesta) #El bot envía la respuesta + + +#Respuesta a la entrada de un usuario al grupo +@bot.message_handler(func=lambda message: True, content_types=['new_chat_members']) +def command_bienvenida(m): + cid = m.chat.id #Id del chat + cname = m.chat.title #Nombre del grupo + bienvenida = "" #Variable dónde guardaremos el mensaje de bienvenida + + infoMesaje = str(m) + + nuevoUsuarioId = m.new_chat_member.id + nuevoUsuarioName = m.new_chat_member.username + añadidoPorId = m.from_user.id + añadidoPor = m.from_user.username + + #bot.send_message(cid, infoMesaje) + if nuevoUsuarioName == "Botinutilbot": + + if cid != -1001318959349: + + bot.send_message(cid, añadidoPor + " , para que hostias me metes, este no es mi grupo joderrr!") + bot.leave_chat(cid) + + + if añadidoPorId == nuevoUsuarioId: + bot.send_message(cid, 'Entrado por enlace de invitación') + + + #bot.send_message(cid, infoMesaje) + else: + bot.send_message(cid, 'añadido por: ' + añadidoPor) + bot.send_message(cid, str(cid)) + + if (m.new_chat_member.username is None): #Si el usuario no tiene nickname + nun = m.new_chat_member.first_name #Guardamos el primer nombre del usuario + + if (m.new_chat_member.last_name is not None): #Si el usuario tiene apellido + nun += " " + nun += m.new_chat_member.last_name #Se guarda el apellido + + else: #Si no tiene apellido + bienvenida = "Bienvenido al grupo" #Se guarda "Bienvenido al grupo" + bienvenida += str(cname) #Se le añade el nombre del chat detras de "Bienvenido al grupo" + bienvenida += " " + else: #Si el usuario tiene nickname + nun = m.new_chat_member.username #Se guarda en nun el nickname del usuario + bienvenida = "Bienvenido al grupo " #Se guarda "Bienvenido al grupo" + bienvenida += str(cname) #Se le añade el nombre del chat detras de "Bienvenido al grupo" + bienvenida += " @" + + bot.send_message(cid, str(bienvenida) + str(nun)) #Se envía el mensaje de bienvenida concatenando el nombre/nickname del usuario + + +#Respuesta a la salida de un usuario del grupo +@bot.message_handler(func=lambda message: True, content_types=['left_chat_member']) +def command_bye(m): + cid = m.chat.id #Id del grupo + despedida = "" #Variable dónde guardaremos el mensaje de despedida + + if (m.left_chat_member.username is None): #Si el usuario no tiene nickname + nun = m.left_chat_member.first_name #Guardamos el primer nombre del usuario + + if (m.left_chat_member.last_name is not None): #Si el usuario tiene apellido + nun += " " + nun += m.left_chat_member.last_name #Se guarda el apellido + + else: #Si el usuario tiene nickname + nun = m.left_chat_member.username #Se guarda en nun el nickname del usuario + despedida = "Hasta luego " #Se guarda "Hasta luego" + despedida += " @" + + bot.send_message(cid, str(despedida) + str(nun)) #Se envía el mensaje de despedida concatenando el nombre/nickname del usuario + + \ No newline at end of file diff --git a/plugins/leccion3.py b/plugins/leccion3.py new file mode 100644 index 0000000..3a9cdca --- /dev/null +++ b/plugins/leccion3.py @@ -0,0 +1,27 @@ +from config import * + +#Inicio charla 3 - 08/08/2018 + +@bot.message_handler(func=lambda message: True) # Respuestas del bot +def echo_message(message): + cid = message.chat.id # Guardamos en la variale cid el id de el mensaje recibido + idUsu = message.from_user.id + + + if message.text.lower().startswith('participo con el numero'): + + cid = message.chat.id + mensaje=message.text + rnd = randrange(0, int(9)) + respuesta = ' '.join(mensaje.split(" ")[4:]) + + #bot.send_message(cid, "la respuesta es: " + respuesta) + #bot.send_message(cid, str(rnd)) + + if int(respuesta) == rnd: + bot.send_message(cid, "Has acertado") + + else: + bot.send_message(cid, "Has fallado, el número era " + str(rnd)) + + #Fin charla 3 - 08/08/2018 \ No newline at end of file diff --git a/plugins/leccion4.py b/plugins/leccion4.py new file mode 100644 index 0000000..228a256 --- /dev/null +++ b/plugins/leccion4.py @@ -0,0 +1,35 @@ +from config import * + +#Inicio charla 4 - 29/08/2018 + +menuKeyboard = types.InlineKeyboardMarkup() +menuKeyboard.add(types.InlineKeyboardButton('Ayuda', callback_data='ayuda'), + types.InlineKeyboardButton('Creador', callback_data='creador')) + +@bot.message_handler(commands=['menu']) +def menu(m): + + cid = m.chat.id + bot.send_message(cid, "Menu", reply_markup=menuKeyboard, parse_mode="Markdown") + +@bot.callback_query_handler(func=lambda call: call.data in ['ayuda', 'creador']) +def callback_handlerMenu(call): + + cid = call.message.chat.id + mid = call.message.message_id + info = call.data + + #bot.send_message(cid, "Has pulsado " + str(info)) + + if info == "ayuda": + #bot.send_message(cid, "Entramos en " + str(info)) + + bot.edit_message_text("Has pulsado ayuda", cid, mid, reply_markup=menuKeyboard, parse_mode="Markdown") + + elif info == "creador": + + #bot.send_message(cid, "Entramos en " + str(info)) + + bot.edit_message_text("Mi creador es : @batichico" , cid, mid, reply_markup=menuKeyboard , parse_mode="Markdown") + + #Fin charla 4 - 29/08/2018 \ No newline at end of file diff --git a/plugins/master-apuntarse.py b/plugins/master-apuntarse.py new file mode 100644 index 0000000..6b87202 --- /dev/null +++ b/plugins/master-apuntarse.py @@ -0,0 +1,132 @@ +from config import * + +yoNuncaKeyboard = types.InlineKeyboardMarkup() +yoNuncaKeyboard.add(types.InlineKeyboardButton('Me apunto', callback_data='yo')) + +propuestaInlineKeyboard = types.InlineKeyboardMarkup() +propuestaInlineKeyboard.add(types.InlineKeyboardButton('Me apunto', callback_data='inlineApuntado')) + + +@bot.callback_query_handler(func=lambda call: call.data.startswith('propuesta')) +def function_button(call): + + mensaje = call.data.split(None, 1)[1] + + idUsuario = call.from_user.id + nombreUsuario = call.from_user.username + nombreUsuario = "@"+nombreUsuario + + todoCall = call + print(str(todoCall)) + + + mid = call.inline_message_id + + + contenido = mensaje + "\n\n" + + apuntados = mensaje.split("\n\n")[1:] + + #bot.answer_callback_query(call.id , str(mensaje) , show_alert=True) + + if nombreUsuario not in mensaje: + + mensaje = contenido + nombreUsuario + + bot.answer_callback_query(call.id , "Vamos a apuntarte, apuntados: " + str(apuntados) , show_alert=True) + bot.edit_message_text(mensaje, inline_message_id=call.inline_message_id , reply_markup=propuestaInlineKeyboard, parse_mode="Markdown") + + + apuntados = mensaje.split("\n\n")[1:] + + + else : + + apuntadosS = "" + + apuntados = mensaje.split("\n\n")[1:] + + contenido = mensaje.split("\n\n")[0] + + contenido = contenido + "\n\n" + + apuntados.remove(str(nombreUsuario)) + + + bot.answer_callback_query(call.id , str(apuntados) , show_alert=True) + + +@bot.callback_query_handler(func=lambda call: call.data in ['yo']) +def callback_handlerYoNunca(call): + + cid = call.message.chat.id + idUsuario = call.from_user.id + + if (call.from_user.username is None): + bot.answer_callback_query(call.id, "Tienes que tener nickname, @ lo que sea", show_alert=True) + else: + nombreUsuario = call.from_user.username + nombreUsuario = "@"+nombreUsuario + + mid = call.message.message_id + mensaje = call.message.text + + contenido = mensaje + "\n\n" + + apuntados = mensaje.split("\n\n")[1:] + + + if nombreUsuario == "@elraro": + + #print(str(call.id) + " " + nombreUsuario) + bot.answer_callback_query(call.id, "HDP", show_alert=True) + + else: + + if nombreUsuario not in mensaje: + + mensaje = contenido + nombreUsuario + bot.edit_message_text(mensaje, cid, mid, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") + + apuntados = mensaje.split("\n\n")[1:] + else : + + apuntadosS = "" + + apuntados = mensaje.split("\n\n")[1:] + + contenido = mensaje.split("\n\n")[0] + + contenido = contenido + "\n\n" + + apuntados.remove(str(nombreUsuario)) + + if len(apuntados) == 0 : + + bot.edit_message_text(contenido, cid, mid, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") + + elif len(apuntados) == 1 : + mensaje = contenido + apuntados[0] + bot.edit_message_text(mensaje, cid, mid, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") + + elif len(apuntados) >= 1 : + for apuntado in apuntados: + apuntadosS = apuntadosS + apuntado + "\n\n" + + mensaje = contenido + apuntadosS + bot.edit_message_text(mensaje, cid, mid, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") + + +@bot.message_handler(func=lambda message: True) # Respuestas del bot +def echo_message(message): + cid = message.chat.id # Guardamos en la variale cid el id de el mensaje recibido + idUsu = message.from_user.id + + if message.text.lower().startswith("propuesta") and len(message.text)>1: + cid = message.chat.id + nombre = message.from_user.first_name + mensaje = message.text + + respuesta = ' '.join(mensaje.split(" ")[1:]) + + bot.send_message(cid, respuesta, reply_markup=yoNuncaKeyboard, parse_mode="Markdown") \ No newline at end of file diff --git a/plugins/master-trucos.py b/plugins/master-trucos.py new file mode 100644 index 0000000..3a130a6 --- /dev/null +++ b/plugins/master-trucos.py @@ -0,0 +1,16 @@ +from config import * + +@bot.message_handler(func=lambda message: True) # Respuestas del bot +def echo_message(message): + cid = message.chat.id # Guardamos en la variale cid el id de el mensaje recibido + idUsu = message.from_user.id + + if message.text.lower() == "bot vete" : + + if idUsu== 239822769: + bot.send_message(cid, 'vale :C, adios mi gente!') + bot.leave_chat(cid) + + if len(set(message.text.lower().split()) & set(('martillazo','banea','baneiyo')))>0 : + + bot.send_message(cid, 'Martillazo rico') \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index b805775..41d6557 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ Flask -PyTelegramBotAPI \ No newline at end of file +PyTelegramBotAPI