def run(irc, channel, message): #Get the YouTube link from the raw IRC data url = message.split(" ") url = url[3].split("//") url = url[1] reader = urllib2.urlopen("http://%s" %url) soup = BeautifulSoup(reader.read()) title = soup.title.string.replace("YouTube", "https://%s" %url) IRCBot.sendMessage(irc, channel, title)
def main(): # If all else fails, socket.setdefaulttimeout(60) sys.stderr.write("Griffonbot starting up...\n") log = Log(config.log) log.debug("Main: Setting up...") bot = IRCBot(config.irc, log) if config.twitter.enable: stream = Stream(config.twitter, bot.queue_message, log) if config.mail.enable: mail = Mail(config.mail, bot.queue_message, log) if config.stdin.enable: stdin = Stdin(config.stdin, bot.queue_message, log) log.info("Main: Starting...") bot.start() if config.twitter.enable: stream.start() if config.mail.enable: mail.start() if config.stdin.enable: stdin.start() log.debug("Main: Now waiting...") wait() log.notice("Dead: Exiting...") sys.exit(1)
import signal import logging from optparse import OptionParser import lockfile import daemon import log import config from bot import IRCBot LOG = logging.getLogger('main') LOCK = lockfile.FileLock('thbotter') ircbot = IRCBot(config.SERVER, config.CHANNELS, config.NICKNAME, config.REALNAME) def destroy(*args): LOG.info("Destroy IRC Bot by signal") print "Stop bot by os signal" ircbot.die() def run_daemonize(): LOG.debug("Start initialize daemon") bot_path = os.path.realpath(os.path.dirname(__file__)) context = daemon.DaemonContext( working_directory=bot_path, pidfile=LOCK )