Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from time import sleep
- import sys
- import socket
- import string
- from datetime import datetime,timedelta
- import time
- from collections import defaultdict
- SERVER = 'chat.freenode.net'
- PORT = 8001
- NICKNAME = 'Malyna'
- CHANNEL = '#MZForum'
- MODT = False
- lastusername = ""
- flood = 1
- #open a socket to handle the connection
- IRC = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- #open a connection with the server
- def irc_conn():
- IRC.connect((SERVER, PORT))
- #simple function to send data through the socket
- def send_data(command):
- IRC.send(command + '\n')
- #join the channel
- def join(channel):
- send_data("JOIN %s" % channel)
- #send login data (customizable)
- def login(nickname, username='user', password = None, realname='Pythonist', hostname='Helena', servername='Server'):
- send_data("USER %s %s %s %s" % (username, hostname, servername, realname))
- send_data("NICK " + nickname)
- def Send_message(message):
- IRC.send("PRIVMSG #MZForum :" + message + "\r\n")
- irc_conn()
- login(NICKNAME)
- join(CHANNEL)
- readbuffer = ""
- end = datetime.now() + timedelta(seconds=10)
- timeflood = defaultdict(lambda: 0)
- while True: #While Connection is Active
- readbuffer = readbuffer + IRC.recv(1024)
- temp = string.split(readbuffer, "\n")
- readbuffer = temp.pop()
- now = datetime.now()
- if now >= end:
- timeflood.clear()
- end = datetime.now() + timedelta(seconds=10)
- for line in temp:
- if line.find('PING') !=-1: #If server pings then pong
- line=string.split(line," ")
- IRC.send('PONG '+line[1]+'\r\n')
- print "PONG "+line[1]+'\r\n'
- else:
- parts = string.split(line, ":")
- if "QUIT" not in parts[1] and "JOIN" not in parts[1] and "PART" not in parts[1]:
- try:
- # Sets the message variable to the actual message sent
- message = parts[2][:len(parts[2]) - 1]
- except:
- message = ""
- # Sets the username variable to the actual username
- usernamesplit = string.split(parts[1], "!")
- username = usernamesplit[0]
- if MODT:
- print username + ": " + message
- if end > now:
- timeflood[username] += 1
- if timeflood[username] >= 4:
- Send_message("Nie rob spamu, " + username + " bo bedzie kick!")
- timeflood[username] = 0
- #if username == lastusername:
- # flood += 1
- #else:
- # flood = 0
- #if flood >= 4:
- # Send_message("Nie rob spamu, " + username + " bo bedzie kick!")
- # flood = 0
- lastusername = username
- message = str.lower(message)
- # interaction with bot
- if message == "hey" or message == "witam" or message == "czesc" or message == "cześć" or message == "elo" or message == "ahoj" or message == "jo" or message == "yo" or message == "hej" or message == "siema" or message == "hello" or message == "bry" or message == "siemka":
- Send_message("Witamy na #MZForum, " + username)
- if message == "fuck you":
- Send_message("sam sie pieprz, " + username)
- if 'malyna ' in message:
- Send_message("ktoś o mnie wspomniał? Srogo.")
- if 'perła ' in message or 'perla ' in message:
- Send_message("Ktoś wspomniał o piifkuu? Mhmmm")
- if 'bye' in message or 'dobranoc' in message:
- Send_message("Papa " + username + " mój dziubeczku :*")
- if message == "jpacanowski" or message == "jp":
- Send_message("Won, spal, hanba! na stos.")
- if message == "lol":
- Send_message("NO LOL!")
- if message == "comandeer":
- Send_message("Kłaniam się Comandeerowi!")
- if message == "event15":
- Send_message("Toż to majster!")
- if message == "ping":
- Send_message("pong ;)")
- if message == "tomatosoup":
- Send_message("Co? Zupa? Wolę perłe")
- if message == "szmq":
- Send_message("Ten to wie co ze mną robić!")
- if message == "perła" or message == "perla" or message == "perłe" or message == "perle":
- Send_message("Takie piffko jest")
- if message == "xd":
- Send_message("To wyżej to nie słowo, unikaj tego!")
- if message == "spam" or message == "kick":
- Send_message("Teee, Ty wyluzuj i se łyknij perłe!")
- if message == "ziew":
- Send_message("powiało ziewiem ;/")
- if message == "wklej kod" or message == "podaj kod":
- Send_message("Nie badz noobem i wklej na: https://gist.github.com/")
- if message == "caroline":
- Send_message("CO " + username + "?" )
- if message == "jakie piwo polecacie?":
- Send_message("Perłe!")
- if 'hej malyna' in message:
- Send_message("No hej, co tam?")
- for l in parts:
- if "End of /NAMES list" in l:
- MODT = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement