Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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 string
- import socket
- import ssl
- import time
- import types
- def recvall(sock):
- data=""
- while True:
- chunk=str(sock.recv(4096),"utf-8")
- data+=chunk
- if data.endswith("\n"):
- return data.splitlines()
- def send(sock,data,verbose=True):
- if verbose:print(">",data)
- return sock.send(bytes(data,"utf-8")+b"\n")
- def recvall(sock):
- data=""
- while True:
- chunk=str(sock.recv(4096),"utf-8")
- data+=chunk
- if data.endswith("\n"):
- return data.splitlines()
- ## Settings
- ### IRC
- server = "irc.bonerjamz.us"
- port = 6697
- channel = "#idletown"
- botnick = "welpbot"
- irc_s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- irc = ssl.wrap_socket(irc_s) #defines the socket
- print("Establishing connection to [{}]".format(server))
- irc.connect((server, port))
- send(irc,"USER "+ botnick +" "+ botnick +" "+ botnick +" :welpbot\n")
- send(irc,"NICK "+ botnick +"\n")
- send(irc,"JOIN "+ channel +"\n")
- send(irc,"NICK "+ botnick +"\n")
- lines=[]
- while 1:
- lines += recvall(irc)
- while lines:
- line = lines.pop()
- print(line)
- line = str.rstrip(line)
- line = str.split(line)
- if(line[0] == "PING"):
- send(irc,"PONG {}\r\n".format(line[1]))
- if(line[1] == "MSG"):
- if line.contains("welp"):
- message = "welp!"
- send(irc,"MSG {} {} \r\n".format(message))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement