Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Echo, a simple IRC bot written in Python 3
#!/usr/bin/env python3
# ircecho.py
# Copyright (C) 2011 : Robert L Szkutak II - http://robertszkutak.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import sys
import socket
import string
HOST = "CHANGETHIS"
PORT = 6667
NICK = "CHANGETHIS"
IDENT = "CHANGETHIS"
REALNAME = "CHANGETHIS"
MASTER = "CHANGETHIS"
readbuffer = ""
s=socket.socket( )
s.connect((HOST, PORT))
s.send(bytes("NICK %s\r\n" % NICK, "UTF-8"))
s.send(bytes("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME), "UTF-8"))
s.send(bytes("JOIN #CHANGETHIS\r\n", "UTF-8"));
s.send(bytes("PRIVMSG %s :Hello Master\r\n" % MASTER, "UTF-8"))
while 1:
readbuffer = readbuffer+s.recv(1024).decode("UTF-8")
temp = str.split(readbuffer, "\n")
readbuffer=temp.pop( )
for line in temp:
line = str.rstrip(line)
line = str.split(line)
if(line[0] == "PING"):
s.send(bytes("PONG %s\r\n" % line[1], "UTF-8"))
if(line[1] == "PRIVMSG"):
sender = ""
for char in line[0]:
if(char == "!"):
break
if(char != ":"):
sender += char
size = len(line)
i = 3
message = ""
while(i < size):
message += line[i] + " "
i = i + 1
message.lstrip(":")
s.send(bytes("PRIVMSG %s %s \r\n" % (sender, message), "UTF-8"))
for index, i in enumerate(line):
print(line[index])
@naoliv

This comment has been minimized.

Copy link

@naoliv naoliv commented Jul 14, 2014

Copied/inspired from http://oreilly.com/pub/h/1968? (note that even the "bla" is the same)

@RobertSzkutak

This comment has been minimized.

Copy link
Owner Author

@RobertSzkutak RobertSzkutak commented Aug 30, 2014

Entirely possible that's the original source for the line to establish and listen from the connection. You can find that code in a lot of places though. Honestly couldn't tell you where I grabbed it from.

@diveyez

This comment has been minimized.

Copy link

@diveyez diveyez commented Mar 24, 2018

COPYPASTA! WATCH OUT, BAD SOCKET BAD SOCKET.
Seriously though, Python is horrible for the purpose of irc bots. I am a fan of python, but I WONT DO THAT.

@diveyez

This comment has been minimized.

Copy link

@diveyez diveyez commented Mar 24, 2018

Suggestion, Do not put a copyright claimer on some code you copy pasted. Bad idea.

@rjunior8

This comment has been minimized.

Copy link

@rjunior8 rjunior8 commented Jul 8, 2018

How to make it with Tor network?

@Y4kuzi

This comment has been minimized.

Copy link

@Y4kuzi Y4kuzi commented Aug 27, 2019

COPYPASTA! WATCH OUT, BAD SOCKET BAD SOCKET.
Seriously though, Python is horrible for the purpose of irc bots. I am a fan of python, but I WONT DO THAT.

Why do you think that? I've written multiple fully featured IRC bots without any issues.
I'm curious about your point of view on Python being horrible for IRC bots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment