Now logging to stdout.
This commit is contained in:
parent
0f6df932ce
commit
b25c5ddeea
1 changed files with 17 additions and 10 deletions
27
lolbot.py
27
lolbot.py
|
|
@ -7,13 +7,16 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Useful bot for folks stuck behind censor walls at work
|
Useful bot for folks stuck behind censor walls at work
|
||||||
|
Logs a channel and collects URLs for later.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, string, random, time
|
import sys, string, random, time
|
||||||
from ircbot import SingleServerIRCBot
|
from ircbot import SingleServerIRCBot
|
||||||
from irclib import nm_to_n, nm_to_h, irc_lower
|
from irclib import nm_to_n, nm_to_h, irc_lower
|
||||||
import botcommon
|
import botcommon
|
||||||
import time
|
import os
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
from mechanize import Browser
|
from mechanize import Browser
|
||||||
|
|
||||||
# Exclamations - wrong input
|
# Exclamations - wrong input
|
||||||
|
|
@ -31,6 +34,8 @@ ponderings = [
|
||||||
"Hi, can I have a medium lamb roast, with just potatoes.",
|
"Hi, can I have a medium lamb roast, with just potatoes.",
|
||||||
"Can I slurp on your Big Cock?",
|
"Can I slurp on your Big Cock?",
|
||||||
"Your Mum likes it two in the pink one in the stink.",
|
"Your Mum likes it two in the pink one in the stink.",
|
||||||
|
"Quentin Tarantino is so awesome I want to have his babies.",
|
||||||
|
"No it's a week night 8pm is past my bedtime.",
|
||||||
]
|
]
|
||||||
|
|
||||||
class LolBot(SingleServerIRCBot):
|
class LolBot(SingleServerIRCBot):
|
||||||
|
|
@ -40,7 +45,6 @@ class LolBot(SingleServerIRCBot):
|
||||||
self.channel = channel
|
self.channel = channel
|
||||||
self.nickname = nickname
|
self.nickname = nickname
|
||||||
self.urls = {}
|
self.urls = {}
|
||||||
self.logfile = open('/tmp/lolbot.log', 'a')
|
|
||||||
|
|
||||||
self.helptext = "Adds URLs to a list. Commands: list - prints a bunch of URLs; clear - clears the list; lol - say something funny; <url> - adds the URL to the list; help - this message."
|
self.helptext = "Adds URLs to a list. Commands: list - prints a bunch of URLs; clear - clears the list; lol - say something funny; <url> - adds the URL to the list; help - this message."
|
||||||
|
|
||||||
|
|
@ -54,11 +58,18 @@ class LolBot(SingleServerIRCBot):
|
||||||
br.open(url)
|
br.open(url)
|
||||||
title = br.title()
|
title = br.title()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print ex
|
|
||||||
title = ''
|
title = ''
|
||||||
self.urls[url] = title
|
self.urls[url] = title
|
||||||
return title
|
return title
|
||||||
|
|
||||||
|
def now(self):
|
||||||
|
return datetime.today().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
def log_event(self, event):
|
||||||
|
nick = nm_to_n(event.source())
|
||||||
|
text = event.arguments()[0]
|
||||||
|
print "(%s) %s: %s" % (self.now(), nick, text)
|
||||||
|
|
||||||
def on_nicknameinuse(self, connection, event):
|
def on_nicknameinuse(self, connection, event):
|
||||||
self.nickname = connection.get_nickname() + "_"
|
self.nickname = connection.get_nickname() + "_"
|
||||||
connection.nick(self.nickname)
|
connection.nick(self.nickname)
|
||||||
|
|
@ -75,7 +86,7 @@ class LolBot(SingleServerIRCBot):
|
||||||
"Deal with a public message in a channel."
|
"Deal with a public message in a channel."
|
||||||
|
|
||||||
# log it
|
# log it
|
||||||
self.logfile.write("%s\n" % event.arguments()[0])
|
self.log_event(event)
|
||||||
|
|
||||||
from_nick = nm_to_n(event.source())
|
from_nick = nm_to_n(event.source())
|
||||||
args = string.split(event.arguments()[0], ":", 1)
|
args = string.split(event.arguments()[0], ":", 1)
|
||||||
|
|
@ -92,6 +103,7 @@ class LolBot(SingleServerIRCBot):
|
||||||
def say_public(self, text):
|
def say_public(self, text):
|
||||||
"Print TEXT into public channel, for all to see."
|
"Print TEXT into public channel, for all to see."
|
||||||
self.queue.send(text, self.channel)
|
self.queue.send(text, self.channel)
|
||||||
|
print "(%s) %s: %s" % (self.now(), self.nickname, text)
|
||||||
|
|
||||||
def say_private(self, nick, text):
|
def say_private(self, nick, text):
|
||||||
"Send private message of TEXT to NICK."
|
"Send private message of TEXT to NICK."
|
||||||
|
|
@ -105,7 +117,7 @@ class LolBot(SingleServerIRCBot):
|
||||||
self.say_public(text)
|
self.say_public(text)
|
||||||
|
|
||||||
def ponder(self):
|
def ponder(self):
|
||||||
"Return a random string indicating what Pinky's pondering."
|
"Return a random pondering."
|
||||||
return random.choice(ponderings)
|
return random.choice(ponderings)
|
||||||
|
|
||||||
def exclaim(self):
|
def exclaim(self):
|
||||||
|
|
@ -119,15 +131,10 @@ class LolBot(SingleServerIRCBot):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if event.eventtype() == "pubmsg":
|
if event.eventtype() == "pubmsg":
|
||||||
# self.reply() sees 'from_private = None' and sends to public channel.
|
|
||||||
target = None
|
target = None
|
||||||
else:
|
else:
|
||||||
# assume that from_private comes from a 'privmsg' event.
|
|
||||||
target = from_private.strip()
|
target = from_private.strip()
|
||||||
|
|
||||||
# Be forgiving about capitalization and whitespace.
|
|
||||||
#cmd = cmd.replace(" ", "").lower()
|
|
||||||
|
|
||||||
if cmd == 'help':
|
if cmd == 'help':
|
||||||
self.reply(self.helptext, target)
|
self.reply(self.helptext, target)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue