Code: Alles auswählen
import time
import socket
from contextlib import closing
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
class bot:
def main(self):
print "Socket(Client)"
host = "irc.iz-smart.net"
port = 6667
PASS = "7987fshd"
NICK = "Testikus"
USER = "Testikus localhost irc.iz-smart.net :Testikus"
self.login(PASS, NICK, USER, host, port)
print "Verbindung aufgebaut zu {0}(IP:{1})".format(
host, socket.gethostbyname(host)
)
self.schleife()
def schleife(self):
while True:
antwort = sock.recv(4096)
join = "JOIN #testblablub \r\n"
print antwort
if antwort[0:4] == "PING":
self.pong(antwort, join)
elif antwort.split()[3] != "":
self.reply()
def pong(self, antwort, join):
sock.sendall("PONG " + antwort.split()[1] + "\n")
time.sleep(2)
sock.sendall(join)
sock.sendall("PRIVMSG #testblablub hi \r\n")
def constants(self):
pass
def login(self, PASS, NICK, USER, host, port):
sock.connect((host, port))
sock.sendall("PASS "+PASS+"\n")
sock.sendall("NICK "+NICK+"\n")
sock.sendall("USER "+USER+"\n")
def reply(self):
sock.sendall("PRIVMSG #testblablub du hast was geschrieben \r\n")
ausfuehren = bot()
ausfuehren.main()
LG