Skip to content

Instantly share code, notes, and snippets.

@son-link
Created July 2, 2012 18:36
Show Gist options
  • Select an option

  • Save son-link/3034796 to your computer and use it in GitHub Desktop.

Select an option

Save son-link/3034796 to your computer and use it in GitHub Desktop.

Revisions

  1. son-link revised this gist Jul 2, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion calicobot.py
    Original file line number Diff line number Diff line change
    @@ -80,6 +80,7 @@ def send_msg(msg):
    send_msg("3 Puntos colega\n")

    if line[1] == '$ salir' :
    if line[0].startswith(':son_link'):
    # Change user for you IRC nick
    if line[0].startswith(':user'):
    send_msg("Hasta otra ^^\n")
    exit()
  2. son-link created this gist Jul 2, 2012.
    85 changes: 85 additions & 0 deletions calicobot.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,85 @@
    #!/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' :
    if line[0].startswith(':son_link'):
    send_msg("Hasta otra ^^\n")
    exit()