Forums - Open Redstone Engineers

Full Version: Python 3.x IRC Bot Code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is just the basic stuff for python 3.x to get connected to IRC

Code:
import sys
import socket
import string
import random

HOST = "irc.freenode.net" #keep this the same
CHANNEL = "#OREServerChat" #keep this set to
PORT = 6667 #IRC's port, don't change
NICK = "CHANGEME" #name of your bot
IDENT = "CHANGEME" #more name of bot
REALNAME = "CHANGEME" #bot bot bot
MASTER = "CHANGEME" #you
readbuffer = "" #can't touch this.

password = str(random.randint(0,1111)) + "CHANGEME" #change to anything
print (password) #this prints your randomly-generated password
cmd = "CHANGEME" #what the bot looks for to execute commands

#getting connected
s=socket.socket( )
s.connect((HOST, PORT))
s.send(bytes("NICK %s\r\n" % NICK, "latin1"))
s.send(bytes("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME), "latin1"))
s.send(bytes("JOIN %s\r\n" % (CHANNEL), "latin1"));
s.send(bytes("PRIVMSG %s :Hello \r\n" % MASTER, "latin1"))

#what your bot does after its up and running
while 1:
    text = s.recv(2040).decode("latin1") #don't mess with this, idk what it does
    if text.find('PING') != -1:         #confirms connection to IRC
        s.send(bytes('PONG ' + text.split() [1] + '\r\n', "latin1"))


#quit bot when you type your cmd + quit + password(without space or +)
    if text.find(cmd + "quit" + str(password)) != -1:
        s.send(bytes("QUIT\r\n","latin1"))
        break
The line you don't know what does receives everything coming in from the IRC connection, up to 2040 bytes of it, and decodes it into latin1 encoding.
(05-12-2014, 03:27 AM)AFtExploision Wrote: [ -> ]The line you don't know what does receives everything coming in from the IRC connection, up to 2040 bytes of it, and decodes it into latin1 encoding.

well I knew that it received text and decoded it, but not the byte amount. thanks for the clarification though.
fancy
Fokn bumps
bumps 4 dayZ
this is now a dayZ thread
post dayZ content here