Last active
December 23, 2015 15:39
-
-
Save Xyphis12/6656623 to your computer and use it in GitHub Desktop.
Supports multiple channels and a command to join channels while connected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import socket | |
###SETUP### | |
# Edit These options as you need | |
botnick = 'botnick' # Nickname of the bot | |
server = "irc.network.net" # Server to connect to | |
channels = ["#channel1","#channel2"] # List of channels to join once connected | |
port = 6667 # Port used to connect with | |
prefix = "-" # Prefix to determine what is a command | |
# IRC socket setup | |
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
###FUNCTIONS### | |
def ping(): | |
ircsock.send("PONG :Pong\n") | |
def triggure(nick,channel,message): | |
if message[-2:]==":y": | |
pie(channel) | |
elif message.find(":"+prefix)!=-1: | |
command = message.split(":"+prefix)[1] | |
commands(nick,channel,message,command) | |
def pie(channel): | |
sendmsg(channel , "Here is some pie") | |
def sendmsg(channel , msg): | |
ircsock.send("PRIVMSG "+ channel +" :"+ msg +"\n") | |
def joinchan(channel): | |
ircsock.send("JOIN "+ channel +"\n") | |
def commands(nick,channel,message,command): | |
if command.find("join")!=-1: | |
print(command.split("join ")[1]) | |
joinchan(command.split("join ")[1]) | |
###IRC LOGIN### | |
# initial login to IRC | |
ircsock.connect((server, port)) | |
ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :Hey\n") | |
ircsock.send("NICK "+ botnick +"\n") | |
for i in channels: | |
joinchan(i) | |
###CONNECTION LOOP### | |
# Once connected it continues to search for a message | |
while 1: | |
ircmsg = ircsock.recv(2048) | |
ircmsg = ircmsg.strip('\n\r') | |
print(ircmsg) | |
if ircmsg.find(' PRIVMSG ')!=-1: | |
nick=ircmsg.split('!')[0][1:] | |
channel=ircmsg.split(' PRIVMSG ')[-1].split(' :')[0] | |
try: | |
triggure(nick,channel,ircmsg) | |
except: | |
pass | |
if ircmsg.find("PING :") != -1: | |
ping() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment