Separated in modules, cleanup

master
Stefan Krulj 14 years ago
parent 7b3ddc12d2
commit c47ca3b625
  1. 1
      .gitignore
  2. 8
      choose.py
  3. 23
      cowsay.py
  4. 2
      get_quote.py
  5. 21
      kraken.py
  6. 7
      logger.py
  7. 68
      main.py
  8. 0
      quote.py
  9. 14
      sortiere.py

1
.gitignore vendored

@ -0,0 +1 @@
*~

@ -0,0 +1,8 @@
import brathuhn
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)

@ -0,0 +1,23 @@
import brathuhn, subprocess
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)

@ -88,4 +88,4 @@ def quote(msg,args):
except exceptions.Exception as e:
brathuhn.sendMsg(brathuhn.ROOM,"Network Error "+unicode(e),'groupchat')
brathuhn.addCommand("quote","Usage: !quote language (two letter code) topic",quote)

@ -0,0 +1,21 @@
import brathuhn
kraken_img = """
_,.---. ,''-._
Release the kraken! ;- X ,/-- \\
/ \\ ' `. :
| \\ / | | )
,''-..--'\\ \\....-'__ '
/ .-...--'': ,. , _.-'O,'
.'/ _O_ O / /O)\\ \\''-O,-'
[\\_ .' /,' ,+-'._/O/ / /_
\\/'-' :/ ' '`'''''`+
_;._.:..."""
def kraken(mfrom,msg):
if "kraken" in msg.lower() and not brathuhn.room_nick in mfrom:
for line in kraken_img.split('\n'):
brathuhn.sendMonoMsg(brathuhn.ROOM,line,'groupchat')
brathuhn.addGroupListener(kraken)

@ -61,3 +61,10 @@ def status_logger(mfrom,msg,status):
user_logs[key].write(unicode(mfrom)+" is now away\n")
if status==brathuhn.STATUS_UNKNOWN:
user_logs[key].write(unicode(mfrom)+" is now ???\n")
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)

@ -2,70 +2,12 @@
# -*- 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)
kraken_img = """
_,.---. ,''-._
Release the kraken! ;- X ,/-- \\
/ \\ ' `. :
| \\ / | | )
,''-..--'\\ \\....-'__ '
/ .-...--'': ,. , _.-'O,'
.'/ _O_ O / /O)\\ \\''-O,-'
[\\_ .' /,' ,+-'._/O/ / /_
\\/'-' :/ ' '`'''''`+
_;._.:..."""
def kraken(mfrom,msg):
if "kraken" in msg.lower() and not brathuhn.room_nick in mfrom:
for line in kraken_img.split('\n'):
brathuhn.sendMonoMsg(brathuhn.ROOM,line,'groupchat')
brathuhn.addGroupListener(kraken)
import kraken
import get_quote
import logger
import cowsay
import choose
brathuhn.connect_and_join()
brathuhn.loop()

@ -1,14 +0,0 @@
#!/usr/bin/python
def sortiere(liste):
if len(liste)==1:
pivot = liste[0]
return [liste[0]]
elif len(liste)==0:
return []
pivot = liste[0]
return sortiere([x for x in liste[1:] if x<= pivot]) + \
[pivot] + \
sortiere([x for x in liste[1:] if x> pivot])
print sortiere([2,3,4,1,2,8,9])
Loading…
Cancel
Save