IRC Bot

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.

main.py

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.fullirc.com' #irc server
PORT = 6667 #port
NICK = 'NICKNAME'  #changethis
USERNAME = 'USERNAME'  #This 
REALNAME = "REALNAME!" # AND This

# 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()
irc.send(nick_cr)
username_credentials= ('USER NICK USERNAME REALNAME :HOST \r\n').encode()  # Change all this too
irc.send(username_credentials)

print('Checking credentials')

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

    print(data)

    time.sleep(0.5)

    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 https://fullirc.com/rules \r\n').encode())
        print('I sent the user to the rules!')

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

irc.close('I died')

replies.py

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

curses_replies = [
'Please do not swear in here',
'Oi please don't swear!'
]

words_in.py (I applogise for the launguage here but its needed for the curse filter)

greetings = [
    'HELLO',
    'HI',
    'GREETINGS'
]

suicide = [
    'SUICIDE',
    'SUICIDAL'
]

curses = [
    'SUCK',
    'STUPID',
    'PIMP',
    'DUMB',
    'HOMO',
    'SLUT',
    'DAMN',
    'ASS',
    'RAPE',
    'POOP',
    'COCK',
    'LOL',
    'CRAP',
    'SEX',
    'NAZI',
    'NEO-NAZI',
    'FUCK',
    'BITCH',
    'PUSSY',
    'PENIS',
    'VAGINA',
    'WHORE',
    'SHIT',
    'NIGGER',
    'NIGGA',
    'COCKSUCKER',
    'ASSRAPE',
    'MOTHERFUCKER',
    'WANKER',
    'CUNT',
    'FAGGOT',
    'FAGS',
    'ASSHOLE',
    'PISS',
    'CUM'
]

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *