#!/usr/bin/env python # If your not running linux then the above doesnt apply to you print "\nPyIRCnMo.py" from socket import * import random import time # for sleep(1) function #----Feel free to email me corrections to jmailone@gmail.com #----_______________________ #-------Classes__ class About: pass def _info_(self): print """ What this program basically does is it allows you to connect to any possible irc server and channel. Make sure they are valid servers though, however, if you have suggestions or comments, rants or raids then please email me @ jmailone@gmail.com. """ pass def _version_(self): print " VERSION : 1.05 BETA " pass def _copyright_(self): self.copyright = [] creator = """ Jamahrae M. Jackson December, 2005 (c) ALL Rights Reserved. EMAIL: jmailone@gmail.com """ pyVer = """ Created on Python 2.4 and SPE (Stani's Python Editor) """ name5 = " PyIRCnMo' " self.copyright.append(creator) self.copyright.append(pyVer) self.copyright.append(name5) return self.copyright def _name_(self): print "PyIRCnMo'" pass class IRC: pass admin = [] user = [random.randrange(999999, 9999999)] admin.append(user) dont_load_this_more_than_once=0 users = [] users.append(admin) users.append("NULL USER") channels = [] defaultNick = admin defaultChannel = "#binrev" defaultHOST = "irc.freenode.net" # Dont touch anything above HOST = "" PORT=6667 NICK=admin IDENT="The Original!" # REALNAME="##binrev" # CHANNEL = "" favorites2 = [] connected = False irc = socket(AF_INET, SOCK_STREAM) # Only touch those with the # in front of it def _cmd_(self): """Return a command list""" self.cmds = [ "isend", "iuser", "iconnect", "ibuddylist", "igennick", "ibuddyADD", "ibuddyDEL", "iserver", "irecv", "iBOT", "ijoin", "iwho", "ikick", "ileave", "inewserver", "iaway", "iHelp", "iwhowas", "imotd", "irecv", "itopic", "iconnected", "iping", "iwhois", "itime", "iuserhost", "iignoreADD", "iignoreDEL", "trace", "iinvite", "iclose", "icustomnick", "ifavoriteADD", "ifavoriteDEL", "iFavoritesLoad", "icmd", "inickserv", "icommands", "iabout", ] return self.cmds def newServer(self): """Join a new server/host""" try: if self.connected == True: self.irc.send("QUIT") self.HOST = "" # Set the host back to blank self.CHANNEL = "" # same for the cahnnel self.HOST = raw_input("What is the new host? ") self.CHANNEL = raw_input("What is the new channel? ") iconnect(self.HOST, self.PORT) if self.connected == False: print "Since your not connected you could just use iconnect\n" self.HOST = "" # self.CHANNEL = "" # self.HOST = raw_input("What is the new host? ") # self.CHANNEL = raw_input("What is the new channel? ") # iconnect(self.HOST, self.PORT) except: print "You are not connected, please connect before changing servers" tryReconnecting = raw_input("Whould you like me to connect you? ") if tryReconnecting == "yes" or "yah" or "ya" or "yep" or "y" or "True": print "Your being directed to the default server: ", IRC.defaultHOST," and channel: ", IRC.defaultChannel iconnect() else: print "Fine, be like that! :-)" pass def connect2(self, host="", channel="" ): try: if IRC.HOST == "": IRC.HOST = IRC.defaultHOST if IRC.CHANNEL == "": IRC.CHANNEL = IRC.defaultChannel if host != "": IRC.HOST = str(host) if channel != "": IRC.CHANNEL = str(channel) bong = (IRC.HOST, IRC.PORT) IRC.irc.connect(bong) self.irc.send("NICK %s \r\n" % IRC.NICK) self.irc.send("USER %s %s bla :%s\r\n" % (self.IDENT, self.HOST, self.REALNAME)) self.irc.send("JOIN %s\r\n" %IRC.CHANNEL) print print self.admin print "\n You are in HOST:", IRC.HOST, ",on CHANNEL:", IRC.CHANNEL irc.channels.append(IRC.CHANNEL) print self.irc.getpeername() print self.irc.getsockname() self.connected = True print "========================RECIEVING DATA FROM SERVER ===========================" self.irc.send("PING %s \r\n" % IRC.CHANNEL) self.irc.send("PONG %s \r\n" % IRC.CHANNEL) time.sleep(2) iserver() chgName = raw_input("Change name to J4YisL337? ") if chgName == "y":icustomnick("J4YisL337"),irecv() else: pass except: if irc.connected == True: print "Your already connected" else: IRC.HOST = str("") IRC.CHANNEL = str("") IRC.irc.close() print "Make sure host= 'example.freenode.net' and channel= '#example' <-- In that format" def closeConnection(self): ileave("QUIT!") self.irc.close() self.connected = False def isConnected(self): return self.connected def privMsg(self, message=""): """ Send a msg to the channel your currently in""" try: self.irc.send("privmsg "+self.CHANNEL+" : "+str(message)+" \r\n") print message except: print "? PRIVMSG ? For what server and channel... Try reconnecting!" def who(self): """List all users in the current channel""" try: self.irc.send("NAMES " + self.CHANNEL + "\r\n") servData = str(iserver()) if str(servData)==str("PRIVMSG"): return print servData except: print "? NAMES ? For what server and channel... Try reconnecting!" def generateNICK(self): """ Generates a new random nick""" try: if self.connected == True: user = [random.randrange(999999, 9999999)] self.admin[0:1] = "" self.admin[0:1] = user print "USERNAME IS NOW: ", self.NICK self.irc.send("NICK %s \r\n" % self.NICK) iserver() else: print "Your not connected! Please connect to a IRC server" except: print "Cant change your nick: Not connected" def customNick(self, newNick="", UserPass=""): """ If you dont like the random number nick... Change it to a custom one...""" try: if self.connected == True: user7 = str(newNick) self.NICK = user7 self.admin[0:1] = [str(user7)] print "USERNAME IS NOW: ", user7 self.irc.send("NICK %s \r\n" % self.NICK) if UserPass != "": irc.NickServ("IDENTIFY", UserPass, nick=newNick) iserver() iserver() except: print "Either no nick givin or not connected" def LoadFavorites(self): """Load all saved favorites""" try: favs1 = open("FavoriteIRC.txt", "r") self.favRead = favs1.read() irc.favorites2.append(self.favRead) print self.favRead except: print " Make sure you have favorites first..." def CreateFavorite(self, channel=""): """Leave blank if adding current channel""" try: if channel == "": channel = IRC.CHANNEL if channel != "": channel = channel self.favorites2.append(str(channel + " on " + IRC.HOST)) print "You have ("+str(len(self.favorites2))+") favorites saved" print self.favorites2 fav = open("FavoriteIRC.txt", "w") # Opens the file to write to fav.write(str(irc.favorites2)) # writes everything in list (irc.favorites2) > to file fav = open("FavoriteIRC.txt", "r") except TypeError: print "Not a number, a string value please" def DeleteFavorite(self, position_in_list=""): """Delete a favorite""" try: position = position_in_list-1 what = irc.favorites2[position] irc.favorites2.remove(what) fav2 = open("FavoriteIRC.txt", "w") # Opens the file to write to fav2.write(str(irc.favorites2)) # writes everything in list (irc.favorites2) > to file fav2 = open("FavoriteIRC.txt", "r") # open up for reading print "You now have ("+str(len(self.favorites2))+") favorites!" print irc.favorites2 except IndexError: print "The number is out of range" except TypeError: print "Not a string value, input a position number" def addUSER(self, buddy=""): """ Add a buddy """ if buddy == "": pass if buddy != "": buddy = buddy if irc.users != []: self.users.append(str(buddy + " from " + IRC.HOST)) print "ADDED" if irc.users == []: self.users = [str(buddy + " from " + IRC.HOST)] print "You have ("+str(len(self.users))+") buddy or buddies saved" budlist = open("IRC_Buddies.txt", "w") # Opens the file to write to budlist.write(str(irc.users)) # writes everything in list (irc.favorites2) > to file budlist = open("IRC_Buddies.txt", "r") # open up for reading irc.userList() def delUSER(self, position_in_list=""): position = position_in_list-1 who = irc.users[position] irc.users.remove(who) budlist = open("IRC_Buddies.txt", "w") # Opens the file to write to budlist.write(str(irc.users)) # writes everything in list (irc.favorites2) > to file budlist = open("IRC_Buddies.txt", "r") # open up for reading print "You now have ("+str(len(self.users))+") buddy or buddies saved" irc.userList() def BuddyList(self): """Print buddylist""" for user in irc.users: print "\t"+str(user) def ServerINFO(self): """ Dont call this command by itself! """ try: if self.connected == True: data2 = self.irc.recv(100000) time.sleep(2) print data2 except: print "NO HOST SPECIFIED OR JUST NOT CONNECTED" def bot(self, Message1, how_many_times): """Bot to repeat a messege how ever many times you specify""" try: if self.connected == True: for number in range(how_many_times+1): isend(Message1) irc.generateNICK() time.sleep(4) print number*10 except: print "? BOT ? For what server and channel... Try reconnecting!" def joinChannel(self, channel_name): """Join a channel > doesnt allow you to talk/recv from mulitple channels)""" try: self.channel_names = channel_name irc.channels.append(self.channel_names) print self.irc.send("JOIN %s\r\n" % self.channel_names) print self.channels iserver() except: print "? JOIN ? For what server and channel... Try reconnecting!" def leaveChannel(self, reason): """Leave the channel""" try: self.irc.send("PART " + self.CHANNEL + " " + reason + "\r\n") irc.channels.remove(self.CHANNEL) if irc.channels != []: irc.channels.remove(self.channel_names) print irc.channels iserver() except: print "Need to be in a channel to leave a channel smart one" def KICK(self, WHO): """Must be OPS: Kick a user""" try: self.irc.send("KICK " + self.CHANNEL + " " + WHO + "\r\n") iserver() except: print "? KICK ? For what server and channel... Try reconnecting!" def set_away(self, reason): """Appear as away""" try: self.irc.send("AWAY " + reason + "\r\n") iserver() except: print "? AWAY ? For what server and channel... Try reconnecting!" def MOTD(self): """Recieve the message of the day""" try: self.irc.send("MOTD " + "\r\n") iserver() except: print "? MOTD ? For what server and channel... Try reconnecting!" def WHOWAS(self, who): """er, dont know wat it does. lol""" try: self.irc.send("WHOWAS " + who + "\r\n") iserver() except: print "? WHOWAS ? For what server and channel... Try reconnecting!" def recvMsg(self): """Receive messages from the channel""" print "===============CURRENTLY WAITING FOR REPLY==============" recvdMsg = str(self.irc.recv(100000)) recvdMsg2 = str(recvdMsg) print recvdMsg2 def NickServ(self, cmd, password="", nick=""): """If certain things dont apply. Leave blank. 'cmd=HELP' for help""" nickker = "NickServ " if nick == "":nick = irc.NICK else: nick = nick if cmd == "REGISTER": REGISTER = self.irc.send("NICKSERV " + "REGISTER "+ password+"\r\n") irecv() if cmd == "DROP": DROP = self.irc.send("NICKSERV " + "DROP "+ nick+"\r\n") irecv() if cmd == "IDENTIFY": IDENTIFY = self.irc.send("NICKSERV " + "IDENTIFY "+ password+"\r\n") irecv() if cmd == "ACCESS": ACCESS = "Working on it... Just too busy looking for bugs...Remind me later, seriously..." print ACCESS if cmd == "SET": print "SET WHAT? ? ? " seting = icmd("NICKSERV Set options") print "TRY this icmd(',,