Added timestamp to log. Added start message.

This commit is contained in:
Christian P. MOMON 2016-10-15 03:41:54 +02:00 committed by root
parent c9d4a64dac
commit 01a5963fad
1 changed files with 4 additions and 2 deletions

6
bot.py Normal file → Executable file
View File

@ -1,9 +1,10 @@
#!/usr/bin/python
# -*- coding: utf-8 -1 -*- # -*- coding: utf-8 -1 -*-
# Welcome to WelcomeBot. Find source, documentation, etc here: https://github.com/shaunagm/WelcomeBot/ Licensed https://creativecommons.org/licenses/by-sa/2.0/ # Welcome to WelcomeBot. Find source, documentation, etc here: https://github.com/shaunagm/WelcomeBot/ Licensed https://creativecommons.org/licenses/by-sa/2.0/
# Import some necessary libraries. # Import some necessary libraries.
import socket, sys, time, csv, Queue, random, re, pdb, select, os.path import socket, sys, time, csv, Queue, random, re, pdb, select, os.path, datetime
from threading import Thread from threading import Thread
# To configure bot, please make changes in bot_settings.py # To configure bot, please make changes in bot_settings.py
@ -82,7 +83,7 @@ def join_irc(ircsock, botnick, channel):
def msg_handler(ircsock): # pragma: no cover (this excludes this function from testing) def msg_handler(ircsock): # pragma: no cover (this excludes this function from testing)
new_msg = ircsock.recv(2048) # receive data from the server new_msg = ircsock.recv(2048) # receive data from the server
new_msg = new_msg.strip('\n\r') # removing any unnecessary linebreaks new_msg = new_msg.strip('\n\r') # removing any unnecessary linebreaks
print(new_msg) #### Potentially make this a log instead? print(datetime.datetime.now().isoformat() + " " + new_msg) #### Potentially make this a log instead?
return new_msg return new_msg
# Called by bot on startup. Builds a regex that matches one of the options + (space) botnick. # Called by bot on startup. Builds a regex that matches one of the options + (space) botnick.
@ -236,6 +237,7 @@ def pong(ircsock, ircmsg):
########################## ##########################
def main(): def main():
print datetime.datetime.now().isoformat() + " WelcomeBot starting…"
ircsock = irc_start(settings.server) ircsock = irc_start(settings.server)
join_irc(ircsock, settings.botnick, settings.channel) join_irc(ircsock, settings.botnick, settings.channel)
WelcomeBot = Bot() WelcomeBot = Bot()