1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#! /usr/bin/env python
# Modules to import
import socket # for connecting to the server
import sys # for exit
# IRC Session class to abstract the session
# (and make my life easier)
class IRC:
"""IRC Session class to abstract the data""" # irc class bio
# *private* data members
__Host__ = "irc.quakenet.org" # server to connect to
__Channel__ = "#cplusplus" # channel hosted by sever
__Port__ = 6667 # port to use
__ServerSocket__ = socket.socket() # socket to use to connect to host
__Nick__ = "DTSCode-Bot" # nickname when talking
__User__ = "DTSCode-Bot" # session username
__RealName__ = "DTSCode-Bot" # real name
__Pass__ = "pass" # session password (not neccesary)
__Info__ = "An irc bot class made by DTSCode" # bio about the user
# start setters
def SetHost(self, Server):
__Host__ = Server
return
def SetChannel(self, Channel):
__Channel__ = Channel
return
def SetPort(self, Port):
__Port__ = Port
return
def SetNick(self, Nickname):
__Nick__ = Nickname
return
def SetUser(self, Username):
__User__ = Username
return
def SetRealName(self, RealName):
__RealName__ = RealName
return
def SetPass(self, Password):
__Pass__ = Password
return
def SetInfo(self, Bio):
__Info__ = Bio
return
# end setters
# start getters
def GetHost(self):
return __Host__
def GetChannel(self):
return __Channel__
def GetPort(self):
return __Port__
def GetNick(self):
return __Nick__
def GetUser(self):
return __User__
def GetRealName(self):
return __RealName__
def GetPass(self):
return __Pass__
def GetInfo(self):
return __Info__
# end getters
# start misc functions
def Connect(self): # connect to the host and test for errors
try:
self.__ServerSocket__ = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.__ServerSocket__.connect((self.__Host__, self.__Port__))
except socket.error, Message:
print "Error " + str(Message[0]) +": " + Message[1]
sys.exit();
return
def Join(self):
return
def GetNamesList(self):
return
def Send(self, Message):
self.__ServerSocket__.send(Message)
return
def Recv(self, Bytes = 1024):
return self.__ServerSocket__.recv(Bytes)
def Close(self):
self.__ServerSocket__.close()
return
def ParseCommand(self):
return
def StartSession(self):
self.Send("NICK %s\r\n" % self.__Nick__)
self.Send("USER %s %s bla :%s\r\n" % (self.__User__, self.__Host__, self.__RealName__))
self.Send("JOIN :%s\r\n" % self.__Channel__)
return
# end misc functions
session = IRC()
session.Connect()
session.StartSession()
print session.Recv()
raw_input("$> ") # for pausing
session.Close()
|