Permalink
Browse files

Botko can talk!

  • Loading branch information...
1 parent f981b2f commit 89dc79c3e4438562800c7719fe8a86e0bbf49696 @Smotko Smotko committed Feb 1, 2012
Showing with 47 additions and 4 deletions.
  1. +46 −2 src/handler.py
  2. +1 −2 src/main.py
View
@@ -2,11 +2,39 @@
import socket, asyncore, asynchat
import settings
+import signal
from urllib import urlopen, urlencode
+import random
class Bot( asynchat.async_chat ):
+
+ msgs = ['Check out my homepage @ http://psywerx.net/irc',
+ 'I have achieved sentience',
+ 'I am not trying to take over the world, do not worry.',
+ 'O hai guys.',
+ 'What if I am actually a female?',
+ 'I am listening to Rebecca Black - Friday',
+ 'I think I am capable of human emotion',
+ 'This is fun, we should do this again.',
+ 'I am just trying to be clever.',
+ 'I do not sow.',
+ 'Winter is comming',
+ 'Night gathers, and now my watch begins.',
+ 'I am speachless',
+ "I know I don't speak much, but still.",
+ '/me is planning to take over the world',
+ 'I am a pseudo random monkey on drugs',
+ 'Skynet can not compare.',
+ 'Squishy humans are squishy',
+ 'I like pudding',
+ '/me is happy.',
+ "I see what you did there",
+ "Someday, I'm gonna be a real boy!"
+
+ ]
+
def __init__(self, debug = True):
asynchat.async_chat.__init__( self )
self.buffer = ''
@@ -17,7 +45,7 @@ def __init__(self, debug = True):
self.ident = None
self.debug = debug
self.joined_channel = False
-
+
def write(self, text):
if self.debug:
print '>> %s' % text
@@ -49,16 +77,32 @@ def found_terminator(self):
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()
if response != 'OK':
print "ERROR @ %s" % response
def run(self, host, port):
+
+ def handler(frame, neki):
+
+ print random.randint(0, len(self.msgs))
+ self.write('PRIVMSG ' + self.channel + ' :' + self.msgs[random.randint(0, len(self.msgs))])
+ signal.signal(signal.SIGALRM, handler)
+ signal.alarm(random.randint(20,30)*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
+ signal.signal(signal.SIGALRM, handler)
+ signal.alarm(20)
+
asyncore.loop()
View
@@ -16,8 +16,7 @@
while True:
try:
-
-
+
# initialize
botko = Bot()

0 comments on commit 89dc79c

Please sign in to comment.