Advertisement
Guest User

Untitled

a guest
Jan 30th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.84 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from time import sleep
  3. import sys
  4. import socket
  5. import string
  6. from datetime import datetime,timedelta
  7. import time
  8. from collections import defaultdict
  9.  
  10. SERVER = 'chat.freenode.net'
  11. PORT = 8001
  12. NICKNAME = 'Malyna'
  13. CHANNEL = '#MZForum'
  14. MODT = False
  15. lastusername = ""
  16. flood = 1
  17. #open a socket to handle the connection
  18. IRC = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  19. #open a connection with the server
  20. def irc_conn():
  21.     IRC.connect((SERVER, PORT))
  22.  
  23. #simple function to send data through the socket
  24. def send_data(command):
  25.     IRC.send(command + '\n')
  26.  
  27. #join the channel
  28. def join(channel):
  29.     send_data("JOIN %s" % channel)
  30.  
  31. #send login data (customizable)
  32. def login(nickname, username='user', password = None, realname='Pythonist', hostname='Helena', servername='Server'):
  33.     send_data("USER %s %s %s %s" % (username, hostname, servername, realname))
  34.     send_data("NICK " + nickname)
  35.  
  36. def Send_message(message):
  37.     IRC.send("PRIVMSG #MZForum :" + message + "\r\n")
  38.  
  39. irc_conn()
  40. login(NICKNAME)
  41. join(CHANNEL)
  42. readbuffer = ""
  43. end = datetime.now() + timedelta(seconds=10)
  44. timeflood = defaultdict(lambda: 0)
  45.  
  46. while True: #While Connection is Active
  47.     readbuffer = readbuffer + IRC.recv(1024)
  48.     temp = string.split(readbuffer, "\n")
  49.     readbuffer = temp.pop()
  50.    
  51.     now = datetime.now()
  52.     if now >= end:
  53.         timeflood.clear()
  54.         end = datetime.now() + timedelta(seconds=10)
  55.  
  56.     for line in temp:
  57.  
  58.         if line.find('PING') !=-1: #If server pings then pong
  59.             line=string.split(line," ")
  60.             IRC.send('PONG '+line[1]+'\r\n')
  61.             print "PONG "+line[1]+'\r\n'
  62.        
  63.         else:
  64.             parts = string.split(line, ":")
  65.  
  66.             if "QUIT" not in parts[1] and "JOIN" not in parts[1] and "PART" not in parts[1]:
  67.                 try:
  68.                     # Sets the message variable to the actual message sent
  69.                     message = parts[2][:len(parts[2]) - 1]
  70.                 except:
  71.                     message = ""
  72.                 # Sets the username variable to the actual username
  73.                 usernamesplit = string.split(parts[1], "!")
  74.                 username = usernamesplit[0]
  75.  
  76.                
  77.                 if MODT:
  78.                     print username + ": " + message
  79.  
  80.                     if end > now:
  81.                         timeflood[username] += 1
  82.  
  83.                         if timeflood[username] >= 4:
  84.                             Send_message("Nie rob spamu, " + username + " bo bedzie kick!")
  85.                             timeflood[username] = 0
  86.  
  87.                     #if username == lastusername:
  88.                     #    flood += 1
  89.                     #else:
  90.                     #    flood = 0
  91.  
  92.                     #if flood >= 4:
  93.                     #    Send_message("Nie rob spamu, " + username + " bo bedzie kick!")
  94.                     #    flood = 0
  95.  
  96.                     lastusername = username
  97.                     message = str.lower(message)
  98.  
  99.                     # interaction with bot
  100.                     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":
  101.                         Send_message("Witamy na #MZForum, " + username)
  102.  
  103.                     if message == "fuck you":
  104.                         Send_message("sam sie pieprz, " + username)
  105.  
  106.                     if 'malyna ' in message:
  107.                         Send_message("ktoś o mnie wspomniał? Srogo.")
  108.  
  109.                     if 'perła ' in message or 'perla ' in message:
  110.                         Send_message("Ktoś wspomniał o piifkuu? Mhmmm")
  111.  
  112.                     if 'bye' in message or 'dobranoc' in message:
  113.                         Send_message("Papa " + username + " mój dziubeczku :*")
  114.                      
  115.                     if message == "jpacanowski" or message == "jp":
  116.                         Send_message("Won, spal, hanba! na stos.")
  117.  
  118.                     if message == "lol":
  119.                         Send_message("NO LOL!")
  120.  
  121.                     if message == "comandeer":
  122.                         Send_message("Kłaniam się Comandeerowi!")
  123.  
  124.                     if message == "event15":
  125.                         Send_message("Toż to majster!")
  126.  
  127.                     if message == "ping":
  128.                         Send_message("pong ;)")
  129.  
  130.                     if message == "tomatosoup":
  131.                         Send_message("Co? Zupa? Wolę perłe")
  132.  
  133.                     if message == "szmq":
  134.                         Send_message("Ten to wie co ze mną robić!")
  135.  
  136.                     if message == "perła" or message == "perla" or message == "perłe" or message == "perle":
  137.                         Send_message("Takie piffko jest")
  138.  
  139.                     if message == "xd":
  140.                         Send_message("To wyżej to nie słowo, unikaj tego!")
  141.  
  142.                     if message == "spam" or message == "kick":
  143.                         Send_message("Teee, Ty wyluzuj i se łyknij perłe!")
  144.  
  145.                     if message == "ziew":
  146.                         Send_message("powiało ziewiem ;/")
  147.  
  148.                     if message == "wklej kod" or message == "podaj kod":
  149.                         Send_message("Nie badz noobem i wklej na: https://gist.github.com/")
  150.  
  151.                     if message == "caroline":
  152.                         Send_message("CO " + username + "?" )
  153.  
  154.                     if message == "jakie piwo polecacie?":
  155.                         Send_message("Perłe!")
  156.  
  157.                     if 'hej malyna' in message:
  158.                         Send_message("No hej, co tam?")
  159.  
  160.                 for l in parts:
  161.                     if "End of /NAMES list" in l:
  162.                         MODT = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement