Hi again! After some months i corrected some mistakes in this code and added a few things to make it act like a typical IRC Client.
It will now use an alternate nick when the nick is already in use.
It will now attempt to join the channel correctly and not attempt before successfull registration.
It will now send a small adv message when it successfully joins the channel!
Change INPUT_CHAN_HERE with the channel you want!
Change INPUT_SERVER_HERE with the server you want!
Enjoy!
v0.3 01 Oct 2016
Or do you want to donate some bucks because you like my scripts??? Visit https://www.paypal.me/OrFeAsGr
Thx! ^_^
### http://humanity.ucoz.com ###
### StatsPy Python Script v0.3 ###
### OrFeAsGr ###
import sys
import socket
import string
import time
# Don't remove the " " #
HOST = "INPUT_SERVER_HERE"
CHAN = "INPUT_CHAN_HERE"
PORT = 6667
NICK = "StatsPy"
IDENT = "Stats"
REALNAME = "http://humanity.ucoz.com"
readbuffer = ""
words = 0
letters = 0
joins = 0
parts = 0
modes = 0
statsdelay = 0
altnicks = 0
s=socket.socket( )
s.connect((HOST, PORT))
s.send(bytes("NICK %s\r\n" % NICK, "UTF-8"))
s.send(bytes("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME), "UTF-8"))
while 1:
readbuffer = readbuffer+s.recv(1024).decode("UTF-8")
temp = str.split(readbuffer, "\n")
readbuffer=temp.pop( )
for line in temp:
print(line)
line = str.rstrip(line)
line = str.split(line)
# If the nick is already used inc altnicks by 1 and retry with nick combined with altnicks (as a string) #
if(line[1] == "433"):
altnicks = altnicks + 1
s.send(bytes("NICK %s\r\n" % (NICK + str(altnicks)) , "UTF-8"))
# Send a small adv message when the End of names raw is sent. That way it knows it has successfully joined the channel.
if(line[1] == "366"):
if(line[3] == CHAN):
s.send(bytes("PRIVMSG %s :Hi! I'm here to keep the statistics of %s ! If you want to view them send !stats (StatsPy Python Script by OrFeAsGr http://humanity.ucoz.com)\r\n" % (CHAN, CHAN), "UTF-8"))
#send the join command only when it has completed registration (which it understands from the 001 raw event, the classic: Welcome to <server> server <nick> #
if(line[1] == "001"):
s.send(bytes("JOIN %s\r\n" % CHAN, "UTF-8"))
if(len(line) > 2):
if(line[2].strip(":") == CHAN):
if(line[1] == "JOIN"):
joins = joins + 1
elif(line[1] == "PART"):
parts = parts + 1
elif(line[1] == "MODE"):
modes = modes + 1
if(line[0] == "PING"):
s.send(bytes("PONG %s\r\n" % line[1], "UTF-8"))
if(line[1] == "PRIVMSG"):
sender = ""
for char in line[0]:
if(char == "!"):
break
if(char != ":"):
sender += char
size = len(line)
i = 3
message = ""
while(i < size):
message += line[i] + " "
i = i + 1
message.lstrip(":")
if(size > 2):
if(line[2] == CHAN):
print(line[3])
words = words + len(line[3:])
letters = letters + len(message)
print(letters)
print(words)
if(line[3] == ":!stats"):
s.send(bytes("PRIVMSG %s :%s > Stats: Words: %s Letters: %s Joins: %s Parts: %s Modes: %s\r\n" % (line[2], line[2], words, letters, joins, parts, modes), "UTF-8"))
Hi again! So.. i'm not sure about this but this could work provided that you haven't changed any of the python scripts lines. A better way to do this is to write the channel and network in a .txt and then reading it with python to get the values. But this kinda worked for me.
do !py server channel
replace server with the server you want and channel with the channel you want!
Good luck!
ON *:TEXT:*:#: {
if ($1 == !py) {
write -l10 <script path here> HOST = $+(",$strip($2),")
write -l11 <script path here> CHAN = $+(",$strip($3),")
run py <script path here>
}
}
Install Python and run the script or install py2exe and make an exe for the script.
https://www.python.org/ - Python Website
http://www.py2exe.org/ - py2exe website
hey :D sorry i was testing it on my channel and forgot to change xD please change it to CHAN
Also thanks xD i actually wanted to add that but forgot! I'll do it later!