Last active
December 16, 2015 19:29
-
-
Save daryo918/5485189 to your computer and use it in GitHub Desktop.
bot en desarrollo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ch | |
import time | |
import random | |
import re,os | |
import subprocess | |
class TestBot(ch.RoomManager): | |
def onConnect(self, room): | |
print("Connected") | |
cerrar=False | |
self.cerrar=cerrar | |
self.log=open("logschat.txt","a") | |
def onReconnect(self, room): | |
print("Reconnected") | |
def onDisconnect(self, room): | |
print("Disconnected") | |
def onMessage(self, room, user, message): | |
print(user.name+":"+message.body) | |
self.log.write(user.name+":"+message.body+"\n") | |
#asi divido los mensajes en palabras util para comandos | |
n=message.body.split(" ") | |
#--------------------------------------------------------- | |
#if message.body.startswith("!a"): # podria servir :D | |
if message.body.startswith("!creador"): | |
room.message("mi creador es daryo") | |
if(message.getBody() == "!hora"): | |
da = time.time() | |
room.message(time.asctime(time.localtime(da))) | |
if(message.getBody() == "!drusus"): | |
room.message("no pondre este mensaje aca :P") | |
try: | |
if(n[0]=="!frase" and n[1]!="!frase"): | |
# aca borro el comando | |
del n[0] | |
#--------------------- | |
frase=" ".join(n) | |
#y uno a frase | |
room.message(frase) | |
except: | |
pass | |
if (message.getBody() == "!cmds"): | |
room.message("esto es un cmds temporal : !log ,!flag ,!hora , !frase , !cmds, !creador, !bye y comando(comando solo para daryo),!dado") | |
# cerrado con despido---------------------------------------------------- | |
if (user.name=="daryo" and message.getBody() == "!bye"): | |
self.log.close() | |
room.message("adios") | |
self.cerrar=True | |
if(user.name=="nombre_del_bot" and message.getBody() == "adios" and cerrar): | |
pm.disconect() | |
elif (user.name!="daryo" and message.getBody() == "!bye"): | |
room.message("no tienes los permisos para cerrarme :@") | |
#------------------------------------------------------- | |
try: | |
if(n[0]=="!flag" and n[1]!="!flag"): | |
room.flagUser(n[1]) | |
room.message("flageado "+n[1]) | |
except: | |
pass | |
if(message.getBody() == "!dado"): | |
room.message("sacaste: "+ str(random.randrange(1, 7))) | |
# hay que cambiar muchas cosas de la python 2.0 la idea des que lea los post nuevos | |
if(message.getBody() == "!CPH"): | |
room.message("en un futuro se podra hacer esto :(") | |
#_------------------ | |
# estos dos comandos se guardan en una carpeta de un servidor web por eso el enlace en un futuro los subira por ftp a un hosting | |
if(message.getBody() == "!log"): | |
self.log.close() | |
room.message("guardando log "+ "http://dominio.org/logschat.txt") | |
self.log=open("logschat.txt","a") | |
try: | |
if(n[0] == "!comando" and n[1] != "!comando" and user.name=="daryo"): #ejecutar comandos en mi pc | |
del n[0] | |
n=" ".join(n) | |
print (n) | |
n=n+ ">comando.txt" | |
os.system(n) | |
room.message("comando ejectuado "+ "http://dominio.org/comando.txt") | |
print(ver) | |
elif(n[0] == "!comando" and n[1] != "!comando" and user.name!="daryo"): | |
room.message("no tienes permiso para ejecutar comandos en mi pc :@+70") | |
except: | |
pass | |
#------------------------------------------------------------------------ | |
def onFloodWarning(self, room): | |
room.reconnect() | |
def onPMMessage(self, pm, user, body): | |
pm.message(user, body) # echo | |
if __name__ == "__main__": | |
TestBot.easy_start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment