#!/usr/bin/python # -*- coding: utf-8 -*- import brathuhn import subprocess import random from get_quote import * brathuhn.addCommand("quote","Usage: !quote language (two letter code) topic",quote) from logger import * brathuhn.addPrivateCommand("show_log","Usage: !show_log",show_log) brathuhn.addPrivateCommand("start_log","Usage: !start_log",start_log) brathuhn.addPrivateCommand("stop_log","Usage: !stop_log",stop_log) brathuhn.addPrivateCommand("delete_log","Usage: !delete_log",del_log) brathuhn.addGroupListener(message_logger) brathuhn.addStatusListener(status_logger) def cowsay(msg,args): cowfile="default" text="" if( len(args)==2 ): text=args[1] elif( len(args)>=3 ): cowfile=args[1] for i in range(2,len(args)): text+=args[i]+" " else: brathuhn.sendMsg(brathuhn.ROOM,"Usage: "+args[0]+" [cowfile] text",'groupchat') return try: txt=subprocess.check_output(["cowsay","-f",cowfile,text]) for line in txt.split('\n'): #brathuhn.sendStyledMsg(brathuhn.ROOM,line,'groupchat',) brathuhn.sendMonoMsg(brathuhn.ROOM,line,'groupchat') except subprocess.CalledProcessError: pass brathuhn.addCommand("cowsay","Usage: !cowsay [cowfile] text",cowsay) def choose(msg,args): if len(args)==1: brathuhn.sendMsg(brathuhn.ROOM,"Usage: "+args[0]+" item_1 item_2 ... item_n",'groupchat') else: brathuhn.sendMsg(brathuhn.ROOM,args[1+random.randint(0,len(args[1:])-1)],'groupchat') brathuhn.addCommand("choose","Usage: !choose item_1 item_2 ... item_n",choose) brathuhn.connect_and_join() brathuhn.loop()