Skip to content
Browse files

line printing adheres to debug flag

  • Loading branch information...
1 parent d0533f3 commit bf2e6e397f9ed613ec92cddf49182be1b9ac6fce @Swizec committed
Showing with 28 additions and 24 deletions.
  1. +28 −24 src/handler.py
View
52 src/handler.py
@@ -9,9 +9,9 @@
import asyncore
import asynchat
-
+
class Bot( asynchat.async_chat ):
-
+
REPOSTS = [
"I don't want to be rude %(nick)s, but %(repostNick)s has already posted this link!",
"I don't want to be Rude %(nick)s, but %(repostNick)s has already posted this link!",
@@ -28,7 +28,7 @@ class Bot( asynchat.async_chat ):
"%(nick)s, you know what you did... and so does %(repostNick)s.",
]
SELF_REPOSTS = [
-
+
"You really like that link, don't you? %(nick)s!",
"Hey everyone, %(nick)s is reposting his own link, so it has to be good.",
"I don't want to be rude %(nick)s, but you have already posted this link!",
@@ -66,7 +66,7 @@ class Bot( asynchat.async_chat ):
'/me is happy.',
"I see what you did there",
"Someday, I'm gonna be a real boy!",
- "/me does the robot",
+ "/me does the robot",
"/me is happy",
"/me missed you all",
"/me is alive",
@@ -79,7 +79,7 @@ class Bot( asynchat.async_chat ):
]
-
+
def __init__(self, debug = True):
asynchat.async_chat.__init__( self )
self.buffer = ''
@@ -94,44 +94,46 @@ def __init__(self, debug = True):
def write(self, text):
if self.debug:
print '>> %s' % text
- self.push( text + '\r\n' )
-
+ self.push( text + '\r\n' )
+
def say(self, text):
self.write('PRIVMSG ' + self.channel + ' :' + text)
-
+
def handle_connect(self):
self.write('NICK %s' % self.nick)
self.write('USER %s iw 0 :%s' % (self.ident, self.realname))
-
+
def collect_incoming_data(self, data):
self.buffer += data
-
+
def found_terminator(self):
line= self.buffer
self.buffer = ''
if self.debug:
print '%s' % line
-
+
# join desired channel:
if line.find('End of /MOTD command.') > 0:
self.write('JOIN %s' % self.channel)
-
+
# After NAMES list, the bot is in the channel
elif line.find(':End of /NAMES list.') > 0:
self.joined_channel = True
-
+
# respond to pings:
elif line.startswith('PING'):
self.write('PONG')
-
+
# if it isn't a ping request LOG IT:
-
+
elif self.joined_channel:
-
+
params = urlencode({'raw': line, 'token': settings.TOKEN})
f = urlopen(settings.SERVER_URL, params)
response = f.read()
- print line
+ if self.debug:
+ print line
+
if response.startswith('REPOST'):
(_, nick, repostNick, messageType) = response.split(" ")
if messageType == "M":
@@ -146,19 +148,21 @@ def found_terminator(self):
f.write(str(datetime.now()) + "\n")
f.write(str(response + "\n\n"))
f.close()
-
+
+
+
def run(self, host, port):
-
+
def handler(frame, neki):
-
+
self.write('PRIVMSG ' + self.channel + ' :' + self.MSGS[random.randint(0, len(self.MSGS)-1)])
signal.signal(signal.SIGALRM, handler)
signal.alarm(random.randint(10,20)*60*60)
-
-
+
+
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host, port))
-
+
from time import time
random.seed(time())
# Set the signal handler and a 5-second alarm
@@ -166,4 +170,4 @@ def handler(frame, neki):
signal.alarm(20)
asyncore.loop()
-
+

0 comments on commit bf2e6e3

Please sign in to comment.
Something went wrong with that request. Please try again.