Skip to content

Instantly share code, notes, and snippets.

@mauromarano
Created December 12, 2013 18:57
Show Gist options
  • Save mauromarano/7933447 to your computer and use it in GitHub Desktop.
Save mauromarano/7933447 to your computer and use it in GitHub Desktop.
This is a simple irc python bot
# ________ ______ ____ ____ ______
# / _/ __ \/ ____/ / __ )/ __ \/_ __/
# / // /_/ / / / __ / / / / / /
# _/ // _, _/ /___ / /_/ / /_/ / / /
# /___/_/ |_|\____/ /_____/\____/ /_/
# Author: Mauro Marano
# site: mauromarano.it
import socket
class IRC:
def __init__(self, server, channel, nick, port=6667):
self.server = server
self.channel = channel
self.nick = nick
self.port = port
self.events = []
self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.irc.connect((self.server, self.port))
self.irc.send("USER " + self.nick + " " + self.nick + " " +
self.nick + " :This is a fun bot!\n") # user authentication
self.irc.send("NICK " + self.nick + "\n") # sets nick
self.irc.send("PRIVMSG nickserv :iNOOPE\r\n") # auth
self.irc.send("JOIN " + self.channel + "\n") # join the chan
def send(self, message):
message = str('PRIVMSG ' + self.channel + ' :' + str(message) + '\r\n')
self.irc.send(message)
return True
def watch(self):
while 1:
text = client.irc.recv(2040)
for event in self.events:
if(text.find(':' + event['if'])) != -1:
self.send(event['do'])
client = IRC('irc.freenode.net', '#mychannel_983', 'mysecurebot123')
client.events = [
{
'if': '!list',
'do': 'Ecco la lista...'
},
{
'if': '!author',
'do': 'The author is Mauro Marano. Check it out mauromarano.it for more infos.'
},
{
'if': 'ciao',
'do': 'ciao a te caro!'
}
]
client.watch()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment