botalan

discord bot
git clone git://git.benoneill.xyz/botalan
Log | Files | Refs | README | LICENSE

cmd.py (1037B)


      1 import random
      2 from subprocess import Popen, PIPE
      3 
      4 from tweet import tweets
      5 
      6 def cowsay(arg, msg):
      7     if arg == None:
      8         process = Popen(["cowsay", msg], stdout=PIPE)
      9     else:
     10         process = Popen(["cowsay", "-f", arg, msg], stdout=PIPE)
     11 
     12     (output, err) = process.communicate()
     13     exit_code = process.wait()
     14     return '```\n' + output.decode('utf-8') + '```\n'
     15 
     16 def tweet():
     17     return random.choice(tweets)
     18 
     19 def fortune(arg=None):
     20     if arg == None:
     21         process = Popen(["fortune"], stdout=PIPE)
     22     else:
     23         process = Popen(["fortune", arg], stdout=PIPE)
     24     (output, err) = process.communicate()
     25     exit_code = process.wait()
     26     return output.decode('utf-8')
     27 
     28 def cowfortune(arg=None):
     29     if arg == None:
     30         p1 = Popen(["fortune"], stdout=PIPE)
     31     else:
     32         p1 = Popen(["fortune", arg], stdout=PIPE)
     33 
     34     p2 = Popen(["cowsay"], stdin=p1.stdout, stdout=PIPE)
     35     p1.stdout.close()
     36     (output, err) = p2.communicate()
     37     exit_code = p2.wait()
     38     return '```\n' + output.decode('utf-8') + '```\n'