Forums - Open Redstone Engineers
Python 3.x IRC Bot Code - Printable Version

+- Forums - Open Redstone Engineers (https://forum.openredstone.org)
+-- Forum: Off-Topic (https://forum.openredstone.org/forum-4.html)
+--- Forum: Programming (https://forum.openredstone.org/forum-8.html)
+--- Thread: Python 3.x IRC Bot Code (/thread-3481.html)



Python 3.x IRC Bot Code - ddthj - 05-12-2014

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



RE: Python 3.x IRC Bot Code - AFtExploision - 05-12-2014

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.


RE: Python 3.x IRC Bot Code - ddthj - 05-13-2014

(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.


RE: Python 3.x IRC Bot Code - Phase - 10-30-2014

fancy


RE: Python 3.x IRC Bot Code - Apuly - 10-31-2014

Fokn bumps


RE: Python 3.x IRC Bot Code - greatgamer34 - 10-31-2014

bumps 4 dayZ


RE: Python 3.x IRC Bot Code - jxu - 10-31-2014

this is now a dayZ thread
post dayZ content here