Skip to content

Instantly share code, notes, and snippets.

@son-link
Created July 2, 2012 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save son-link/3034796 to your computer and use it in GitHub Desktop.
Save son-link/3034796 to your computer and use it in GitHub Desktop.
IRC bot
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# CalicoBot: a IRC bot
# (c) 2012 Alfonso Saavedra "Son Link"
# Under GPLv3 license
import socket
import string
from time import sleep
from commands import getoutput
from urllib import urlopen
from re import search, sub
HOST="localhost"
PORT=6667
NICK="CalicoBot"
IDENT="CalicoBot"
REALNAME="CalicoBot"
CHAN="#Home"
readbuffer=""
track = ''
s=socket.socket( )
s.connect((HOST, PORT))
s.send("NICK %s\r\n" % NICK)
s.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))
s.send("JOIN :%s\r\n" % CHAN)
def send_msg(msg):
s.send("PRIVMSG %s :%s" % (CHAN, msg))
while 1:
readbuffer=readbuffer+s.recv(1024)
temp=string.split(readbuffer, "\n")
readbuffer=temp.pop( )
for line in temp:
print line
line=string.rstrip(line)
line=line.split(CHAN + ' :')
if line[0].find("PING") != -1:
pingid = line[0].split()[1]
s.send("PONG %s\r\n" % pingid)
elif line[0].find('JOIN') != -1:
name = line[0].split('!')[0].split(':')[1]
if name != NICK and name.find(HOST) == -1:
sleep(5)
send_msg("Bienvenid@ %s ^^\n" % name)
if len(line) > 1:
if 'DonaFlorinda' in line[1].split():
send_msg("Vamos hijo, no te juntes con esta chusma\n")
sleep(2)
send_msg("Si mami. Chusma, chusma prfff\n")
elif line[1].find('http') != -1:
for u in line[1].split():
d = search('(.+://)(www.)?([^/]+)(.*)', u)
if d:
raw = urlopen(u).read()
title = search('<title>([\w\W]+)</title>', raw).groups()[0]
title2 = ''
for t in title.split('\n'):
title2 += t.lstrip()+' '
send_msg("%s en %s\n" % (title2, d.groups()[2]))
if line[1] == '$ version':
send_msg("CalicoBot 0.1.2 (c) 2012 Son Link\n")
if line[1] == 'Hola CalicoBot' or line[1] == 'hola CalicoBot':
name = line[0].split('!')[0].split(':')[1]
send_msg("Saludos a ti también %s\n" % name)
if line[1] == '$ ondavital' :
send_msg("KA, ME, HA, ME... HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA o==============)\n")
if line[1] == '$ chicho' :
send_msg("3 Puntos colega\n")
if line[1] == '$ salir' :
# Change user for you IRC nick
if line[0].startswith(':user'):
send_msg("Hasta otra ^^\n")
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment