Post: [Python] IRC Bot template
10-12-2015, 04:38 AM #1
Python
Bebe Snek
(adsbygoogle = window.adsbygoogle || []).push({}); Enjoy Happy[/color]

    import socket,time
network = 'irc.example.net'
port = 6667
channels = ['#Channel1','#Channel2'] #Add as many as you want
nick = 'myIRCBot'
identify = True
password = 'superAwesomePassword'
irc = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
print "Connecting to "+network+" ..."
irc.connect ((network, port))
print "Changing nick to "+nick+"..."
irc.send ('NICK '+nick+'
'Winky Winky
if identify == True:
print "Verifying password..."
irc.send("PASS %s\n" % (password))
print "Setting login data..."
irc.send ('USER '+nick+' '+nick+' '+nick+' :'+nick+' IRC
'Winky Winky
time.sleep(1)
for channel in channels:
print "Joining "+channel+"..."
irc.send ('JOIN '+channel+'
'Winky Winky
irc.send ('PRIVMSG '+channel+' :'+nick+' Started! Type .help for more
'Winky Winky
time.sleep(1)
print nick+" bot started."
while True:
data = irc.recv(4096)
if data.find('PING'Winky Winky != -1:
irc.send('PONG '+data.split()[1]+'
'Winky Winky
try:
user = data.split("!",1)[0].replace(":","",1)
vhost = data.split(" ",1)[0].split("!",1)[1]
dType = data.split(" ",1)[1].split(" ",1)[0]
chan = data.split(" ",1)[1].split(" ",1)[1].split(" ",1)[0]
msg = data.split(" ",1)[1].split(" ",1)[1].split(" ",1)[1].replace(":","",1).replace("\n","",1).replace("\r","",1)
if msg == '.help':
irc.send ('PRIVMSG '+chan+' :This is the only command!
'Winky Winky
print user+" ("+vhost+") "+dType+" to "+chan+": "+msg
except:
pass

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo