I have started to make a bot in Python for IRC. I wanted to post it here in case you want to use one on the new network I launched called FULLirc. This is being released to #mhmatters channel on the FULLirc network. This is in very early infancy so I will add updates as I go along. This will also replace MHBot thats on the website.

from words_in import *
from replies import *
import socket
import random
import time

identified = False # used to check if Bot nickname is identified

irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
HOST = '' #irc server
PORT = 6667 #port
NICK = 'NICKNAME'  #changethis

# Channel(s)
CHANNEL = '#CHANNEL1'  # channels to connect to
CHANNEL2 = '#CHANNEL2'  # If you need more channels add them here and go to line 59

Password =('ENTERYOURPASSHERE')  # Change password

replied_times = 0

print('Socket created |', irc)
remote_ip = socket.gethostbyname(HOST)
print('ip of irc server is:', remote_ip)

irc.connect((HOST, PORT))

print('connected to: ', HOST, PORT)
print('sending info')

nick_cr = ('NICK ' + NICK + '\r\n').encode()
username_credentials= ('USER NICK USERNAME REALNAME :HOST \r\n').encode()  # Change all this too

print('Checking credentials')

while 1:
    data = irc.recv(4096).decode('utf-8').upper()



    if data.find('PING') != -1:
        irc.send(str('PONG ' + data.split(':')[1] + '\r\n').encode())
        print('PONG sent \n')

        #irc.send('JOIN #fullirc \r\n'.encode())

        while identified == False:
            # I don't quote know how this fixed an issue i was having but it did and now its a feature
            irc.send('nickserv identify '.encode() + Password.encode() + '\r\n'.encode())
            identified = True
            irc.send('JOIN '.encode() + CHANNEL.encode() + '\r\n'.encode())
            irc.send('JOIN '.encode() + CHANNEL2.encode() + '\r\n'.encode())

    elif data.find('PASSWORD ACCEPTED - YOU ARE NOW RECOGNIZED') != -1:
        print("All done and now im listening!!")

    elif any(word in data for word in greetings):
        print("Number of times i have responded ")
        words = random.choice(greeting_replies)
        irc.send((str('PRIVMSG ' + data.split()[2]) + " " + words + "\r\n").encode())

    elif any(word in data for word in curses):
        swearwords = random.choice(curses_replies)
        irc.send((str('PRIVMSG ' + data.split()[2]) + " " + swearwords + "\r\n").encode())

    elif data.find('!RULES') != -1:
        irc.send((str('PRIVMSG ' + data.split()[2]) + ' For the rules of the channel please go to \r\n').encode())
        print('I sent the user to the rules!')

    elif data.find('!MYDATA') != -1:
        print('Data send: ' + data)

irc.close('I died')

greeting_replies = [
    'Hello You :)',
    'Hi there!'

curses_replies = [
'Please do not swear in here',
'Oi please don't swear!'
] (I applogise for the launguage here but its needed for the curse filter)

greetings = [

suicide = [

curses = [

Related Post

Leave a Reply

Your email address will not be published.