Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
```
120 changes: 120 additions & 0 deletions ban.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#Importaciones.
import datetime
import time
Expand Down Expand Up @@ -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")
Loading