#!/usr/bin/env python2

import socket
import os
import sys
import yaml
import datetime

class IRCbot:
    def __init__(self):
        self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        config = yaml.safe_load(open("./ircbot.config"))
        self.channel  = config['channel']
        self.server   = config['server']
        self.port     = config['port']
        self.botnick = config['nickname']

    def send(self, chan, msg):
        self.irc.send("PRIVMSG " + chan + " " + msg + "\n")


    def connect(self):
        self.irc.connect((self.server,self.port))
        self.irc.send("USER " + self.botnick + " " + self.botnick +" " + self.botnick + " :IRCbot!\n")
        self.irc.send("NICK " + self.botnick + "\n")
        self.irc.send("JOIN " + self.channel + "\n")

    def disconnect(self):
        self.irc.close()

    def reconnect(self):
        self.irc.close()
        self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.connect()

    def get_text(self):
        text = self.irc.recv(2040)

        if text.startswith('PING'):
            self.irc.send('PONG ' + text.split()[1] + '\r\n')

        return text

    def run(self):
        text = self.get_text()
        print str(datetime.datetime.time(datetime.datetime.now())) + " " + text,


if __name__ == '__main__':

    irc = IRCbot()
    irc.connect()
    while 1:
        irc.run()


@@ -111,32 +111,67 @@
 __init__(self):%0A
+        ''' Initialize instance'''%0A
         self.irc
@@ -215,32 +215,32 @@
 et.SOCK_STREAM)%0A
-
         config =
@@ -476,16 +476,72 @@
 , msg):%0A
+        ''' Function to send message to irc channel '''%0A
         
@@ -609,32 +609,71 @@
  connect(self):%0A
+        ''' Connect to IRC channel '''%0A
         self.irc
@@ -934,32 +934,91 @@
 sconnect(self):%0A
+        ''' Disconnect from IRC server, closing socket '''%0A
         self.irc
@@ -1044,32 +1044,73 @@
 econnect(self):%0A
+        ''' Reconnect to IRC Channel '''%0A
         self.irc
@@ -1227,32 +1227,107 @@
 get_text(self):%0A
+        ''' Function that recieves text from IRC server and returns it '''%0A
         text = s
@@ -1466,16 +1466,16 @@
 n text%0A%0A
-
     def 
@@ -1477,32 +1477,75 @@
  def run(self):%0A
+        ''' Main function running logic'''%0A
         text = s

Add comments to functions