Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import socket, string, sys, os
- from copy import copy
- from urllib.request import urlopen
- from time import time
- map = []
- mody = ["mlodypatyk", "Krajuuuuu", "shabobot","rewoniasty"]
- file = 0
- komendy = []
- #print(dirs)
- def reload():
- global komendy
- dir = "komendy/"
- dirs = os.listdir(dir)
- komendy = []
- for file in dirs:
- #print(file)
- file2 = open("komendy/" + file, 'r', encoding='utf-8')
- odp = [line.rstrip('\n') for line in file2]
- #print(odp[0])
- komenda = [file,odp[0]]
- #print(komenda)
- komendy += [komenda]
- print(komendy)
- reload()
- try:
- file = open('workfileorkfile', 'r')
- except IOError:
- file = open('workfile', 'w')
- file.close()
- file = open('workfile','r')
- f2 = 0
- try:
- f2 = open('pucek', 'r')
- except IOError:
- f2 = open('pucek', 'w')
- f2.close()
- f2 = open('pucek','r')
- f3 = 0
- try:
- f3 = open('punkty', 'r')
- except IOError:
- f3 = open('punkty', 'w')
- f3.close()
- f3 = open('punkty','r')
- femote = 0
- try:
- femote = open('emotki' ,'r')
- except IOError:
- print("Nie masz pliku z emotkami biedaku")
- femote = open('emotki', 'w')
- femote.write("Kappa\n")
- femote.close()
- femote =open('emotki','r')
- lines = [line.rstrip('\n') for line in file]
- pucek = 0
- try:
- pucek = int([line.rstrip('\n') for line in f2][0])
- except IndexError:
- pucek = 0
- lines2 = [line.rstrip('\n') for line in f3]
- emotki = [line.rstrip('\n') for line in femote]
- #print emotki[:-1]
- dawg = []
- pt = []
- ptmap = []
- for x in lines:
- if dawg==[]:
- dawg+=[x]
- else:
- dawg+=[int(x)]
- map+=[dawg]
- dawg=[]
- for x in lines2:
- if pt==[]:
- pt+=[x]
- else:
- pt+=[int(x)]
- ptmap+=[pt]
- pt=[]
- print(ptmap)
- file.close
- def addpt(user, amount):
- global ptmap
- done = False
- for x in ptmap:
- if(x[0]==user):
- x[1]+=amount
- done = True
- if(done==False):
- ptmap+=[[user,1]]
- def ept(user):
- global ptmap
- isis = False
- for x in ptmap:
- if(x[0]==user and x[1]>=10):
- x[1]-=10
- return True
- return isis
- def emotesAmount(message):
- czesci = message.split(" ")
- global emotki
- amount = 0
- for y in czesci:
- for x in emotki[:-1]:
- if x in y:
- amount+=1
- return amount
- def punkty(user):
- global ptmap
- for x in ptmap:
- if(x[0]==user):
- return x[1]
- return 0
- def timeouttime(user):
- global map
- for x in map:
- if(x[0]==user):
- x[1] = x[1] + 30
- return x[1]
- map+=[[user,60]]
- return 60
- def rm(user):
- global map
- for x in map:
- if(x[0]==user):
- x[1] = 30
- def isCommand(m,c):
- return m.startswith('!'+c)
- def getUser(line):
- separate = line.split(":", 3)
- user = separate[1].split("!", 1)
- return user[0]
- def getMessage(line):
- separate = line.split(":", 2)
- message = separate[2]
- return message
- def mquit():
- global pucek
- f = open('workfile', 'w')
- f2 = open('pucek', 'w')
- f3 = open('punkty', 'w')
- for x in map:
- f.write(x[0] + "\n" + str(x[1]) + "\n")
- f.close()
- f2.write(str(pucek) + "\n")
- f2.close()
- for x in ptmap:
- f3.write(x[0]+ "\n" + str(x[1]) + "\n")
- sys.exit("blablabla")
- NICK = "shabobot"
- HOST = "irc.twitch.tv"
- PORT= 6667
- PASS = "oauth:73hqznjeownydhqnov7wwpnbm3dpfw"
- CHANNEL = "mlodypatyk"
- s = socket.socket()
- s.connect((HOST,PORT))
- s.send(("PASS " + PASS + "\r\n").encode("utf-8"))
- s.send(("NICK " + NICK + "\r\n").encode("utf-8"))
- s.send(("JOIN #" + CHANNEL + "\r\n").encode("utf-8"))
- def send_message(message):
- s.send(("PRIVMSG #" + CHANNEL + " :" + message + "\r\n").encode("utf-8"))
- def timeout(user, time):
- s.send(("PRIVMSG #" + CHANNEL + " :.timeout " + user + " " + str(time) + "\r\n").encode("utf-8"))
- def ban(user):
- s.send(("PRIVMSG #" + CHANNEL + " :.ban " + user + "\r\n").encode("utf-8"))
- def unban(user):
- s.send(("PRIVMSF #" + CHANNEL + " :.unban " + user + "\r\n").encode("utf-8"))
- readbuffer = ""
- Loading = True
- while Loading:
- readbuffer = readbuffer + s.recv(1024).decode("utf-8")
- temp = readbuffer.split("\n")
- readbuffer = temp.pop()
- #print("jestem")
- for line in temp:
- print(line)
- if("End of /NAMES list" in line):
- Loading = False
- #send_message("/w krajuuuuu masz")
- addpt("mlodypatyk",500000)
- addpt("krajuuuuu", 500000)
- send_message("/mods")
- #timeout("mlodypatyk","1")
- def restart():
- send_message("Shabbot podłączony PogChamp")
- readbuffer = ""
- mval = True
- iler = 0
- ltime = time()
- while mval:
- readbuffer = readbuffer + s.recv(1024).decode("utf-8")
- temp = readbuffer.split("\n")
- ntime = time()
- delta = ntime - ltime
- #if delta > 6000:
- print(delta)
- readbuffer = temp.pop
- for line in temp:
- czy = True
- if line=="":
- czy = False
- magia = "PING"
- test = True
- if(czy):
- for i in range(4):
- if(line[i]!=magia[i]):
- test = False
- if test:
- czy = False
- s.send(("PONG %s\r\n" % line[1]).encode("utf-8"))
- #print(line)
- #print line
- if czy:
- user = getUser(line)
- messagel = getMessage(line)
- message = ""
- for i in range(len(messagel)):
- if(i<len(messagel)-1):
- message+= messagel[i]
- print([user,message])
- if emotesAmount(message)>10 and user not in mody:
- czas = timeouttime(user)
- timeout(user,czas)
- send_message("Nieładnie " + user + "!")
- else:
- addpt(user.lower(), 1)
- #print(user + ": " + message)
- for m in komendy:
- if message==m[0]:
- send_message(m[1])
- if(isCommand(message, "pause") and user in mody):
- x = raw_input("> ")
- send_message(x)
- if(isCommand(message,"song") and user in mody):
- pios = 0
- try:
- pios = open('song', 'r')
- except IOError:
- pios = open('song', 'w')
- pios.close()
- pios = open('song','r')
- plines = [line.rstrip('\n') for line in pios]
- for i in plines:
- send_message(i)
- if(isCommand(message, "lucek")):
- if(ept(user)):
- global pucek
- pucek+=1
- send_message("Pucek został nakarmiony " + str(pucek) + " razy! Keepo Zostalo ci " + str(punkty(user)) + " punktów!")
- else:
- send_message("Nie mogłeś nakarmić Pucka, ponieważ masz tylko " + str(punkty(user)) + " punktów!")
- if(message=='!reload' and user in mody):
- reload()
- send_message("noo i gitara 4Head")
- if(isCommand(message, "exitbot") and user in mody):
- mval = False
- send_message("Shabobot odłączony BibleThump")
- mquit()
- if(isCommand(message, "rmtimeout") and user in mody):
- xxx = message.split(" ")
- y = xxx[1][:-1]
- timeout(y,1)
- rm(y)
- print("usuwam timeout dla " + xxx[1])
- if(isCommand(message, "addpoints") and user in mody):
- tab = message.split(" ")
- if len(tab)>1:
- y = tab[1]
- addpt(y.lower(), 1000)
- if(isCommand(message, "playlist")):
- send_message("@"+user+" https://open.spotify.com/user/1195654127")
- if(isCommand(message, "punkty")):
- send_message(user + " Masz " + str(punkty(user)) + " punktów!")
- if(len(message)>250 ):
- czas = timeouttime(user)
- timeout(user,czas)
- send_message("Nieładnie " + user + "! Timeout na " + str(czas) + " sekund!")
- if(isCommand(message, "komendy")):
- send_message("Komendy: !kraju, !playlist, !csconfig, !shab, !rewon, !lucek, !gruby, !pucek, !ala, !lena, !kondziu, !paweł, !komendy, !pancake, !naleśnik, !punkty, !kaoserg")
- readbuffer = ""
- restart()
- #coś nowego
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement