IRC bot module.

This is the place to post any code that you want to share with the community. Only completed scripts should be posted here.
Note: posts here are not necessarily endorsed by the community, and may represent amateur or even bad practices.

IRC bot module.

Postby RainbowShibe » Wed Jan 01, 2014 8:23 pm

I will lable all of the strings you will need,i will the non-threaded version, i will also label weither they need to be a string or not. I will also include the help file fore the !help command

Nick = Your bots nick

Server = the server of wich it will be connected to

Channel = the channel it will be connected to (it will change when you change the channel too)

Password = the nicks password (you may have to edit this if the server uses something other than nickserv)

Owner = the owners nick

Connection = this has to be socket.socket(socket.AF_INET, socket.SOCK_STREAM)

Deftimeout = the default timeout (aka socket.getdefaulttimeout())

Deftimeoutstr = the deftimeout as a string

Newtimeout = i usually set this as "A new string has not been set"

Host = your host, i never really knew what exactly to set this as, and i found it didnt matter much so i usually set it as "None" or "none" (has to be a string)

Here is the Non-threaded version:
The only function you will need from this is bot, so i would just do from botScript import bot

Code: Select all
import socket
import sys
import string
import random
import time
import os
def bot(nick, server, channel, password, owner, connection, deftimeout, deftimeoutstr, newtimeout, host):
   irc = connection
   open ='/home/alucero565/MyFiles/python/bots/help', os.O_RDONLY)
   file = str(os.stat('/home/alucero565/MyFiles/python/bots/help').st_size)
   file = file.strip('L')
   file = int(file)
   file =, file)
   help = str(file)
   connected = True
   while 1:
      if recieve.find('PING ') !=-1:
         irc.send('PONG '+message1+'\r\n')
         print("PONG ", recieve.split()[1])
      if recieve.find(':hello '+nick) !=-1:
         c=recieve.split(':hello '+nick)
         irc.send('PRIVMSG '+channel+' :hello\r\n')
      if recieve.find(nick+' :!disconnect 1597 ') !=-1:
         c=recieve.split(' :!disconnect 1597 ')
         irc.send('QUIT :'+a+'\r\n')
      if recieve.find(':!say ') !=-1:
         c=recieve.split(':!say ')
         irc.send('PRIVMSG '+channel+' :'+a+'\r\n')
      if recieve.find(nick+' :!join ') !=-1:
         c=recieve.split(nick+' :!join ')
         irc.send(' JOIN '+a+'\r\n')
      if recieve.find(':!part ') !=-1:
         c=recieve.split(':!part ')
         irc.send('PART '+a+'\r\n')
      if recieve.find(':!help') !=-1:
         irc.send('PRIVMSG '+channel+help)
      if recieve.find(':!nick '+nick+' ') !=-1:
         c=recieve.split(':!nick '+nick+' ')
         irc.send('NICK '+a+'\n')
      if recieve.find(':!me ') !=-1:
         c=recieve.split(':!me ')
         irc.send('PRIVMSG '+channel+' :\001ACTION '+a+'\001\r\n')
      if recieve.find(':!') !=-1:
         irc.send('PRIVMSG '+channel+' :'+deftimeoutstr+'\r\n')
      if recieve.find(':!deftimeout.set ') !=-1:
         c=recieve.split(':!deftimeout.set ')
         if a!='None':
            if a!='none':
               irc.send('PRIVMSG '+channel+' :The new default timeout is: '+str(t)+'\r\n')
               print('default timeout: '+str(t))
         elif a=='None':
            irc.send('PRIVMSG '+channel+' :Cannot set to None\r\n')
         elif a=='none':
            irc.send('PRIVMSG '+channel+' :Cannot set to none\r\n')
      if recieve.find(':!deftimeout.reset') !=-1:
         irc.send('PRIVMSG '+channel+' :Default Timeout: None\r\n')
      if recieve.find(':!commands.deftimeout') !=-1:
         irc.send('PRIVMSG '+channel+' :!deftimeout::   ! reads the current default timeout   !deftimeout.set: sets a new default timeout (only use numbers)   !deftimeout.reset: resets the default timeout to infinite (aka None)\r\n')
      if recieve.find(channel) !=-1:
         value=random.randrange(1, 100)
         if value==50:
            irc.send('PRIVMSG '+channel+' :hello\r\n')
      if recieve.find(':!roll') !=-1:
         if a.find('.sides') !=-1:
            roll=str(random.randrange(1, amountofsides))
            irc.send('PRIVMSG '+channel+' :'+roll+'\r\n')
         if a.find('.reg') !=-1:
            roll=str(random.randrange(1, 6))
            irc.send('PRIVMSG '+channel+' :'+roll+'\r\n')
      if recieve.find(':!identify ') !=-1:
         c=recieve.split(':!identify ')
         irc.send('PRIVMSG NickServ :IDENTIFY '+r+'\r\n')
      if recieve.find(':!reset') !=-1:
         irc.send('PRIVMSG '+channel+' :this command is still in beta\r\n')

And the help file: (it isnt code but ill put a code tag in anyways)

Code: Select all
:Commands::   !help: displays this   !join: joins a channel   hello '+nick+': '+nick+' will say hello back   !disconnect: disconnects from the server, and can only be accessed by pming   !nick: changes nick   !me: the me command   !deftimeout (do !commands.deftimeout for more info)   !say: sais what you want it to   !part: parts the channel specified   !roll: rolls the dice\r\n

The threaded version does not work completely yet, i cannot figure out how to get the command checking part to start, although I will update it when it works.
User avatar
Posts: 10
Joined: Wed Jan 01, 2014 12:39 am
Location: Somewhere Over The Rainbow

Re: IRC bot module.

Postby metulburr » Thu Jan 02, 2014 12:07 am

it would be better suited as a class instead ofa function with a list of if's
we will be moving to on October 1 2016
more details here
User avatar
Posts: 2244
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Return to Completed Scripts

Who is online

Users browsing this forum: No registered users and 5 guests